2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <ui/PixelFormat.h>
24 #include <android_runtime/AndroidRuntime.h>
25 #include <utils/misc.h>
27 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
34 jfieldID bytesPerPixel;
35 jfieldID bitsPerPixel;
38 static offsets_t offsets;
40 // ----------------------------------------------------------------------------
42 static void android_graphics_getPixelFormatInfo(
43 JNIEnv* env, jobject clazz, jint format, jobject pixelFormatObject)
48 // we need this for backward compatibility with PixelFormat's
49 // deprecated constants
51 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
52 // defined as the bytes per pixel of the Y plane
53 info.bytesPerPixel = 1;
54 info.bitsPerPixel = 16;
56 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
57 // defined as the bytes per pixel of the Y plane
58 info.bytesPerPixel = 1;
59 info.bitsPerPixel = 12;
61 case HAL_PIXEL_FORMAT_YCbCr_422_I:
62 // defined as the bytes per pixel of the Y plane
63 info.bytesPerPixel = 1;
64 info.bitsPerPixel = 16;
68 err = getPixelFormatInfo(format, &info);
70 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
75 env->SetIntField(pixelFormatObject, offsets.bytesPerPixel, info.bytesPerPixel);
76 env->SetIntField(pixelFormatObject, offsets.bitsPerPixel, info.bitsPerPixel);
78 // ----------------------------------------------------------------------------
80 const char* const kClassPathName = "android/graphics/PixelFormat";
82 static void nativeClassInit(JNIEnv* env, jclass clazz);
84 static JNINativeMethod gMethods[] = {
85 { "nativeClassInit", "()V",
86 (void*)nativeClassInit },
87 { "getPixelFormatInfo", "(ILandroid/graphics/PixelFormat;)V",
88 (void*)android_graphics_getPixelFormatInfo
92 void nativeClassInit(JNIEnv* env, jclass clazz)
94 offsets.bytesPerPixel = env->GetFieldID(clazz, "bytesPerPixel", "I");
95 offsets.bitsPerPixel = env->GetFieldID(clazz, "bitsPerPixel", "I");
98 int register_android_graphics_PixelFormat(JNIEnv* env)
100 return AndroidRuntime::registerNativeMethods(env,
101 kClassPathName, gMethods, NELEM(gMethods));