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 "WhiteBalanceJNI"
     19 #include <utils/Log.h>
     20 #include "com_android_cts_verifier_camera_analyzer_WhiteBalanceTest.h"
     21 
     22 #include <vector>
     23 #include <string>
     24 #include <string.h>
     25 
     26 #include "testingimage.h"
     27 #include "whitebalancetest.h"
     28 #include "vec2.h"
     29 #include "android/bitmap.h"
     30 
     31 jlong Java_com_android_cts_verifier_camera_analyzer_WhiteBalanceTest_createWhiteBalanceTest(
     32         JNIEnv*      env,
     33         jobject      thiz) {
     34 
     35     WhiteBalanceTest* testHandler = new WhiteBalanceTest();
     36     long handlerAddress = (long)testHandler;
     37     return handlerAddress;
     38 }
     39 
     40 void Java_com_android_cts_verifier_camera_analyzer_WhiteBalanceTest_createWhiteBalanceClass(
     41         JNIEnv*      env,
     42         jobject      thiz,
     43         jlong        inputImageAddress,
     44         jlong        inputHandlerAddress,
     45         jlong        checkercenterAddress,
     46         jlong        checkerradiusAddress,
     47         jstring      whiteBalance){
     48 
     49     ALOGV("JNI createWhiteBalanceClass starts!");
     50     long imageAddress = (long)inputImageAddress;
     51     long handlerAddress = (long)inputHandlerAddress;
     52 
     53     TestingImage *image = (TestingImage*) imageAddress;
     54     WhiteBalanceTest *testHandler = (WhiteBalanceTest*) 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     jboolean isCopy;
     63     const char* stringWhiteBalance =
     64             env->GetStringUTFChars(whiteBalance, &isCopy);
     65     ALOGV("White Balance is %s", stringWhiteBalance);
     66 
     67     // Adds the gray checker's RGB values to the test handler.
     68     testHandler->addDataToList(stringWhiteBalance,
     69                                image->getColorChecker(3, 4, 0, 6,
     70                                                       checkerCenter,
     71                                                       checkerRadius));
     72 
     73     env->ReleaseStringUTFChars(whiteBalance, stringWhiteBalance);
     74     delete image;
     75 }
     76 
     77 jint Java_com_android_cts_verifier_camera_analyzer_WhiteBalanceTest_processWhiteBalanceTest(
     78     JNIEnv*      env,
     79     jobject      thiz,
     80     jlong        inputHandlerAddress) {
     81   ALOGV("Processing white balance test");
     82 
     83   long handlerAddress = (long) inputHandlerAddress;
     84   WhiteBalanceTest *testHandler = (WhiteBalanceTest*) handlerAddress;
     85 
     86   testHandler->processData();
     87 
     88   ALOGV("CCT is %d", testHandler->getCorrelatedColorTemp());
     89   return testHandler->getCorrelatedColorTemp();
     90 }
     91