blob: 1fc363b3c86e9cc32df83c3b3efbb5c801512128 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Hughes8451b252011-04-07 19:17:57 -070023#include "JNIHelp.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <android_runtime/AndroidRuntime.h>
25#include <utils/misc.h>
26
27// ----------------------------------------------------------------------------
28
29namespace android {
30
31// ----------------------------------------------------------------------------
32
33struct offsets_t {
34 jfieldID bytesPerPixel;
35 jfieldID bitsPerPixel;
36};
37
38static offsets_t offsets;
39
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040// ----------------------------------------------------------------------------
41
42static void android_graphics_getPixelFormatInfo(
43 JNIEnv* env, jobject clazz, jint format, jobject pixelFormatObject)
44{
45 PixelFormatInfo info;
Mathias Agopiana696f5d2010-02-17 17:53:09 -080046 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 Project9066cfe2009-03-03 19:31:44 -080069 if (err < 0) {
Elliott Hughes8451b252011-04-07 19:17:57 -070070 jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 return;
72 }
Mathias Agopiana696f5d2010-02-17 17:53:09 -080073
74done:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080075 env->SetIntField(pixelFormatObject, offsets.bytesPerPixel, info.bytesPerPixel);
76 env->SetIntField(pixelFormatObject, offsets.bitsPerPixel, info.bitsPerPixel);
77}
78// ----------------------------------------------------------------------------
79
80const char* const kClassPathName = "android/graphics/PixelFormat";
81
82static void nativeClassInit(JNIEnv* env, jclass clazz);
83
84static JNINativeMethod gMethods[] = {
85 { "nativeClassInit", "()V",
86 (void*)nativeClassInit },
87 { "getPixelFormatInfo", "(ILandroid/graphics/PixelFormat;)V",
88 (void*)android_graphics_getPixelFormatInfo
89 }
90};
91
92void nativeClassInit(JNIEnv* env, jclass clazz)
93{
94 offsets.bytesPerPixel = env->GetFieldID(clazz, "bytesPerPixel", "I");
Elliott Hughes8451b252011-04-07 19:17:57 -070095 offsets.bitsPerPixel = env->GetFieldID(clazz, "bitsPerPixel", "I");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096}
97
98int register_android_graphics_PixelFormat(JNIEnv* env)
99{
100 return AndroidRuntime::registerNativeMethods(env,
101 kClassPathName, gMethods, NELEM(gMethods));
102}
103
104};