blob: 1c5bc17d8759afdb60634067e743b05e263d862f [file] [log] [blame]
Christine Chen0ed3f712011-09-22 11:57:23 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#define LOG_NDEBUG 0
17
18#define LOG_TAG "ImageTestHandler"
19#include <utils/Log.h>
20#include <utils/Timers.h>
21#include <cmath>
Christine Chen0ed3f712011-09-22 11:57:23 -070022
23#include "vec2.h"
24#include "vec3.h"
25#include "imagetesthandler.h"
26
27void ImageTestHandler::initDebugImage() {
28 mDebugOutput = NULL;
29}
30
31// Initializes the debug image with a given height and width.
32void ImageTestHandler::initDebugImage(int debugHeight,
33 int debugWidth) {
34 mDebugOutput = NULL;
35 mDebugOutput = new unsigned char[debugHeight * debugWidth * 4];
36 memset(mDebugOutput, 0, debugHeight * debugWidth * 4);
37
38 mDebugHeight = debugHeight;
39 mDebugWidth = debugWidth;
40}
41
42// Copies an existing image to the debug image.
43void ImageTestHandler::copyDebugImage(int inputHeight, int inputWidth,
44 const unsigned char* inputImage) {
45 if ((inputHeight == mDebugHeight) && (inputWidth == mDebugWidth)) {
46 ALOGV("Copying debug images");
47 memcpy(mDebugOutput, inputImage, mDebugHeight * mDebugWidth * 4);
48 }
49}
50
51void ImageTestHandler::clearDebugImage() {
52 if (mDebugOutput != NULL) {
53 delete[] mDebugOutput;
54 mDebugOutput = new unsigned char[mDebugHeight * mDebugWidth * 4];
55 memset(mDebugOutput, 0, mDebugHeight * mDebugWidth * 4);
56 }
57}
58
59
60// Draws a point of a given color.
61void ImageTestHandler::drawPoint(int row, int column, const Vec3i &color) {
62 if ((row >= 0) && (column >= 0) &&
63 (column < mDebugWidth) && (row < mDebugHeight)) {
64 mDebugOutput[(row*mDebugWidth + column) * 4] = color.r();
65 mDebugOutput[(row*mDebugWidth + column) * 4+1] = color.g();
66 mDebugOutput[(row*mDebugWidth + column) * 4+2] = color.b();
67 mDebugOutput[(row*mDebugWidth + column) * 4+3] = 255;
68 }
69}
70
71// Draws a point in Vec2 format of a given color.
72void ImageTestHandler::drawPoint(const Vec2i &point, const Vec3i &color) {
73 drawPoint((int) point.y(), (int) point.x(), color);
74}
75
76// Draws a line of a given color.
77void ImageTestHandler::drawLine(int angle, int radius, const Vec3i &color) {
78 const int r = color.r();
79 const int g = color.g();
80 const int b = color.b();
81 const int a = 255;
82
83 int shiftedMin = -113;
84 int shiftedMax = 83;
85
86 float radiusDouble = static_cast<float>(radius);
87
88 float angleRad = static_cast<float>(angle) * M_PI / 180.0;
89
90 //ALOGV("draw line for (%d, %d)", angle, radius);
91 for (int i = shiftedMin; i <= shiftedMax; ++i) {
92 float j;
93
94 assert(angle != 0);
95 j = (i - radiusDouble / sin(angleRad)) * tan(angleRad);
96 float x = (static_cast<float>(i) + j) / sqrt(2.0);
97 float y = (j - static_cast<float>(i)) / sqrt(2.0);
98
99 drawPoint(x, y, color);
100 }
101}