blob: 26c7f8d709e78af1f53b360e89c17ba491f343db [file] [log] [blame]
Dima Zavin32276312010-02-04 12:15:09 -08001/*
2 * Copyright (C) 2009 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 <android/bitmap.h>
Derek Sollenberger6c41ab12019-11-08 08:50:58 -050018#include <android/graphics/bitmap.h>
Leon Scroggins III1994fcb2020-01-10 13:40:07 -050019#include <android/data_space.h>
Dima Zavin32276312010-02-04 12:15:09 -080020
21int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
22 AndroidBitmapInfo* info) {
23 if (NULL == env || NULL == jbitmap) {
24 return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
25 }
26
Dima Zavin32276312010-02-04 12:15:09 -080027 if (info) {
Derek Sollenberger6c41ab12019-11-08 08:50:58 -050028 *info = ABitmap_getInfoFromJava(env, jbitmap);
Dima Zavin32276312010-02-04 12:15:09 -080029 }
Andrew Hsieheba82542012-12-12 11:27:44 +080030 return ANDROID_BITMAP_RESULT_SUCCESS;
Dima Zavin32276312010-02-04 12:15:09 -080031}
32
Leon Scroggins III1994fcb2020-01-10 13:40:07 -050033int32_t AndroidBitmap_getDataSpace(JNIEnv* env, jobject jbitmap) {
34 if (NULL == env || NULL == jbitmap) {
35 return ADATASPACE_UNKNOWN; // Or return a real error?
36 }
37
38 android::graphics::Bitmap bitmap(env, jbitmap);
39 return bitmap.getDataSpace();
40}
41
Dima Zavin32276312010-02-04 12:15:09 -080042int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr) {
43 if (NULL == env || NULL == jbitmap) {
44 return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
45 }
46
Derek Sollenberger6c41ab12019-11-08 08:50:58 -050047 android::graphics::Bitmap bitmap(env, jbitmap);
48 void* addr = bitmap.isValid() ? bitmap.getPixels() : nullptr;
49
John Reck00799f72017-03-01 18:05:41 -080050 if (!addr) {
Dima Zavin32276312010-02-04 12:15:09 -080051 return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
52 }
53
Derek Sollenberger6c41ab12019-11-08 08:50:58 -050054 ABitmap_acquireRef(bitmap.get());
55
Dima Zavin32276312010-02-04 12:15:09 -080056 if (addrPtr) {
57 *addrPtr = addr;
58 }
Andrew Hsieheba82542012-12-12 11:27:44 +080059 return ANDROID_BITMAP_RESULT_SUCCESS;
Dima Zavin32276312010-02-04 12:15:09 -080060}
61
62int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap) {
63 if (NULL == env || NULL == jbitmap) {
64 return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
65 }
66
Derek Sollenberger6c41ab12019-11-08 08:50:58 -050067 android::graphics::Bitmap bitmap(env, jbitmap);
68
69 if (!bitmap.isValid()) {
Dima Zavin32276312010-02-04 12:15:09 -080070 return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
71 }
Derek Sollenberger6c41ab12019-11-08 08:50:58 -050072
73 bitmap.notifyPixelsChanged();
74 ABitmap_releaseRef(bitmap.get());
Andrew Hsieheba82542012-12-12 11:27:44 +080075 return ANDROID_BITMAP_RESULT_SUCCESS;
Dima Zavin32276312010-02-04 12:15:09 -080076}