Dima Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 1 | /* |
| 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 Sollenberger | 6c41ab1 | 2019-11-08 08:50:58 -0500 | [diff] [blame] | 18 | #include <android/graphics/bitmap.h> |
Leon Scroggins III | 1994fcb | 2020-01-10 13:40:07 -0500 | [diff] [blame^] | 19 | #include <android/data_space.h> |
Dima Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 20 | |
| 21 | int 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 Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 27 | if (info) { |
Derek Sollenberger | 6c41ab1 | 2019-11-08 08:50:58 -0500 | [diff] [blame] | 28 | *info = ABitmap_getInfoFromJava(env, jbitmap); |
Dima Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 29 | } |
Andrew Hsieh | eba8254 | 2012-12-12 11:27:44 +0800 | [diff] [blame] | 30 | return ANDROID_BITMAP_RESULT_SUCCESS; |
Dima Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 31 | } |
| 32 | |
Leon Scroggins III | 1994fcb | 2020-01-10 13:40:07 -0500 | [diff] [blame^] | 33 | int32_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 Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 42 | int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr) { |
| 43 | if (NULL == env || NULL == jbitmap) { |
| 44 | return ANDROID_BITMAP_RESULT_BAD_PARAMETER; |
| 45 | } |
| 46 | |
Derek Sollenberger | 6c41ab1 | 2019-11-08 08:50:58 -0500 | [diff] [blame] | 47 | android::graphics::Bitmap bitmap(env, jbitmap); |
| 48 | void* addr = bitmap.isValid() ? bitmap.getPixels() : nullptr; |
| 49 | |
John Reck | 00799f7 | 2017-03-01 18:05:41 -0800 | [diff] [blame] | 50 | if (!addr) { |
Dima Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 51 | return ANDROID_BITMAP_RESULT_JNI_EXCEPTION; |
| 52 | } |
| 53 | |
Derek Sollenberger | 6c41ab1 | 2019-11-08 08:50:58 -0500 | [diff] [blame] | 54 | ABitmap_acquireRef(bitmap.get()); |
| 55 | |
Dima Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 56 | if (addrPtr) { |
| 57 | *addrPtr = addr; |
| 58 | } |
Andrew Hsieh | eba8254 | 2012-12-12 11:27:44 +0800 | [diff] [blame] | 59 | return ANDROID_BITMAP_RESULT_SUCCESS; |
Dima Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap) { |
| 63 | if (NULL == env || NULL == jbitmap) { |
| 64 | return ANDROID_BITMAP_RESULT_BAD_PARAMETER; |
| 65 | } |
| 66 | |
Derek Sollenberger | 6c41ab1 | 2019-11-08 08:50:58 -0500 | [diff] [blame] | 67 | android::graphics::Bitmap bitmap(env, jbitmap); |
| 68 | |
| 69 | if (!bitmap.isValid()) { |
Dima Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 70 | return ANDROID_BITMAP_RESULT_JNI_EXCEPTION; |
| 71 | } |
Derek Sollenberger | 6c41ab1 | 2019-11-08 08:50:58 -0500 | [diff] [blame] | 72 | |
| 73 | bitmap.notifyPixelsChanged(); |
| 74 | ABitmap_releaseRef(bitmap.get()); |
Andrew Hsieh | eba8254 | 2012-12-12 11:27:44 +0800 | [diff] [blame] | 75 | return ANDROID_BITMAP_RESULT_SUCCESS; |
Dima Zavin | 3227631 | 2010-02-04 12:15:09 -0800 | [diff] [blame] | 76 | } |