The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
| 17 | #include <stdio.h> |
| 18 | #include <assert.h> |
| 19 | |
| 20 | #include <ui/PixelFormat.h> |
| 21 | |
| 22 | #include "jni.h" |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 23 | #include "JNIHelp.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <android_runtime/AndroidRuntime.h> |
| 25 | #include <utils/misc.h> |
| 26 | |
| 27 | // ---------------------------------------------------------------------------- |
| 28 | |
| 29 | namespace android { |
| 30 | |
| 31 | // ---------------------------------------------------------------------------- |
| 32 | |
| 33 | struct offsets_t { |
| 34 | jfieldID bytesPerPixel; |
| 35 | jfieldID bitsPerPixel; |
| 36 | }; |
| 37 | |
| 38 | static offsets_t offsets; |
| 39 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | // ---------------------------------------------------------------------------- |
| 41 | |
| 42 | static void android_graphics_getPixelFormatInfo( |
| 43 | JNIEnv* env, jobject clazz, jint format, jobject pixelFormatObject) |
| 44 | { |
| 45 | PixelFormatInfo info; |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 46 | status_t err; |
| 47 | |
| 48 | // we need this for backward compatibility with PixelFormat's |
| 49 | // deprecated constants |
| 50 | switch (format) { |
| 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; |
| 55 | goto done; |
| 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; |
| 60 | goto done; |
| 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; |
| 65 | goto done; |
| 66 | } |
| 67 | |
| 68 | err = getPixelFormatInfo(format, &info); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | if (err < 0) { |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 70 | jniThrowException(env, "java/lang/IllegalArgumentException", NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | return; |
| 72 | } |
Mathias Agopian | a696f5d | 2010-02-17 17:53:09 -0800 | [diff] [blame] | 73 | |
| 74 | done: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | env->SetIntField(pixelFormatObject, offsets.bytesPerPixel, info.bytesPerPixel); |
| 76 | env->SetIntField(pixelFormatObject, offsets.bitsPerPixel, info.bitsPerPixel); |
| 77 | } |
| 78 | // ---------------------------------------------------------------------------- |
| 79 | |
| 80 | const char* const kClassPathName = "android/graphics/PixelFormat"; |
| 81 | |
| 82 | static void nativeClassInit(JNIEnv* env, jclass clazz); |
| 83 | |
| 84 | static JNINativeMethod gMethods[] = { |
| 85 | { "nativeClassInit", "()V", |
| 86 | (void*)nativeClassInit }, |
| 87 | { "getPixelFormatInfo", "(ILandroid/graphics/PixelFormat;)V", |
| 88 | (void*)android_graphics_getPixelFormatInfo |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | void nativeClassInit(JNIEnv* env, jclass clazz) |
| 93 | { |
| 94 | offsets.bytesPerPixel = env->GetFieldID(clazz, "bytesPerPixel", "I"); |
Elliott Hughes | 8451b25 | 2011-04-07 19:17:57 -0700 | [diff] [blame] | 95 | offsets.bitsPerPixel = env->GetFieldID(clazz, "bitsPerPixel", "I"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | int register_android_graphics_PixelFormat(JNIEnv* env) |
| 99 | { |
| 100 | return AndroidRuntime::registerNativeMethods(env, |
| 101 | kClassPathName, gMethods, NELEM(gMethods)); |
| 102 | } |
| 103 | |
| 104 | }; |