Home | History | Annotate | Download | only in cameraanalyzer
      1 /*
      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 "MeteringJNI"
     19 #include <utils/Log.h>
     20 #include "com_android_cts_verifier_camera_analyzer_MeteringTest.h"
     21 
     22 #include <vector>
     23 #include <string>
     24 #include <string.h>
     25 #include <math.h>
     26 
     27 #include "testingimage.h"
     28 #include "meteringtest.h"
     29 #include "vec2.h"
     30 #include "android/bitmap.h"
     31 
     32 jlong Java_com_android_cts_verifier_camera_analyzer_MeteringTest_createMeteringTest(
     33         JNIEnv*      env,
     34         jobject      thiz) {
     35 
     36     MeteringTest* testHandler = new MeteringTest();
     37     long handlerAddress = (long)testHandler;
     38     return handlerAddress;
     39 }
     40 
     41 void Java_com_android_cts_verifier_camera_analyzer_MeteringTest_createMeteringClass(
     42         JNIEnv*      env,
     43         jobject      thiz,
     44         jlong        inputImageAddress,
     45         jlong        inputHandlerAddress,
     46         jlong        checkercenterAddress,
     47         jlong        checkerradiusAddress){
     48 
     49     ALOGV("JNI createMeteringClass starts!");
     50     long imageAddress = (long)inputImageAddress;
     51     long handlerAddress = (long)inputHandlerAddress;
     52 
     53     TestingImage *image = (TestingImage*) imageAddress;
     54     MeteringTest *testHandler = (MeteringTest*) handlerAddress;
     55 
     56     std::vector<std::vector< Vec2f > >* checkerCenter =
     57             (std::vector<std::vector< Vec2f > >*) (long) checkercenterAddress;
     58     std::vector<std::vector< float > >* checkerRadius =
     59             (std::vector<std::vector< float > >*) (long) checkerradiusAddress;
     60     ALOGV("Classes recovered");
     61 
     62     testHandler->addDataToList(image->getColorChecker(3, 4, 0, 6,
     63                                                       checkerCenter,
     64                                                       checkerRadius));
     65 
     66     delete image;
     67 }
     68 
     69 void Java_com_android_cts_verifier_camera_analyzer_MeteringTest_processMeteringTest(
     70         JNIEnv*          env,
     71         jobject          thiz,
     72         jlong            inputHandlerAddress,
     73         jbooleanArray    tempArray) {
     74 
     75     ALOGV("Processing Auto Lock data!");
     76 
     77     long handlerAddress = (long) inputHandlerAddress;
     78     MeteringTest *testHandler = (MeteringTest*) handlerAddress;
     79 
     80     testHandler->processData();
     81 
     82     const std::vector<bool>* nativeComparisonResults =
     83             testHandler->getComparisonResults();
     84     jboolean jComparisonResults[nativeComparisonResults->size()];
     85 
     86     for (int i = 0; i < nativeComparisonResults->size(); ++i) {
     87         jComparisonResults[i] = (jboolean) (*nativeComparisonResults)[i];
     88     }
     89 
     90     env->SetBooleanArrayRegion(tempArray,
     91                                0, nativeComparisonResults->size(),
     92                                jComparisonResults);
     93     testHandler->clearData();
     94 }
     95 
     96 // Find the gray checker borders from the native array of checker center and
     97 // radius. Convert the coordinate to the coordinates accepted by Android
     98 // Camera.Area type, which defines the top left corner to (-1000, -1000) and
     99 // bottom right corner to (1000, 1000).
    100 void Java_com_android_cts_verifier_camera_analyzer_MeteringTest_findGreyCoordinates(
    101         JNIEnv*      env,
    102         jobject      thiz,
    103         jintArray    greyCoordinates,
    104         jlong        checkercenterAddress,
    105         jlong        checkerradiusAddress){
    106 
    107     ALOGV("Start finding grey coordinates");
    108 
    109     std::vector<std::vector< Vec2f > >* checkerCenter =
    110             (std::vector<std::vector< Vec2f > >*) (long) checkercenterAddress;
    111     std::vector<std::vector< float > >* checkerRadius =
    112             (std::vector<std::vector< float > >*) (long) checkerradiusAddress;
    113 
    114     ALOGV("Checker recovered!");
    115     int nativeGreyCoordinates[24];
    116 
    117     for (int i = 0; i < 6; ++i) {
    118         float radius = sqrt((*checkerRadius)[3][i]);
    119         nativeGreyCoordinates[i * 4] = static_cast<int>(
    120                 ((*checkerCenter)[3][i].y() - radius)
    121                 / 160.0 * 2000.0 - 1000.0);
    122         nativeGreyCoordinates[i * 4 + 1] = static_cast<int>(
    123                 ((*checkerCenter)[3][i].x() - radius)
    124                 / 120.0 * 2000.0 - 1000.0);
    125         nativeGreyCoordinates[i * 4 + 2] = static_cast<int>(
    126                 ((*checkerCenter)[3][i].y() + radius)
    127                 / 160.0 * 2000.0 - 1000.0);
    128         nativeGreyCoordinates[i * 4 + 3] = static_cast<int>(
    129                 ((*checkerCenter)[3][i].x() + radius)
    130                 / 120.0 * 2000.0 - 1000.0);
    131 
    132         ALOGV("checker is bounded by %f, %f, %f",
    133              (*checkerCenter)[3][i].x(), (*checkerCenter)[3][i].y(), radius);
    134 
    135         ALOGV("Square is bounded by %d, %d, %d, %d",
    136              nativeGreyCoordinates[i * 4], nativeGreyCoordinates[i * 4 + 1],
    137              nativeGreyCoordinates[i * 4 + 2],
    138              nativeGreyCoordinates[i * 4 + 3]);
    139     }
    140 
    141     env->SetIntArrayRegion(greyCoordinates, 0, 24, nativeGreyCoordinates);
    142 }
    143