1 /* 2 * Copyright (C) 2015 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 #ifndef BITMAP_H_ 17 #define BITMAP_H_ 18 19 #include <jni.h> 20 #include <android/bitmap.h> 21 #include <SkBitmap.h> 22 #include <SkColorTable.h> 23 #include <SkImageInfo.h> 24 #include <SkPixelRef.h> 25 26 namespace android { 27 28 class Bitmap; 29 30 namespace bitmap { 31 32 enum BitmapCreateFlags { 33 kBitmapCreateFlag_None = 0x0, 34 kBitmapCreateFlag_Mutable = 0x1, 35 kBitmapCreateFlag_Premultiplied = 0x2, 36 }; 37 38 jobject createBitmap(JNIEnv* env, Bitmap* bitmap, 39 int bitmapCreateFlags, jbyteArray ninePatchChunk = NULL, 40 jobject ninePatchInsets = NULL, int density = -1); 41 42 43 void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap); 44 45 Bitmap& toBitmap(JNIEnv* env, jobject bitmap); 46 Bitmap& toBitmap(JNIEnv* env, jlong bitmapHandle); 47 48 // NDK access 49 void imageInfo(JNIEnv* env, jobject bitmap, AndroidBitmapInfo* info); 50 // Returns a pointer to the pixels or nullptr if the bitmap is not valid 51 void* lockPixels(JNIEnv* env, jobject bitmap); 52 // Returns true if unlocked, false if the bitmap is no longer valid (destroyed) 53 bool unlockPixels(JNIEnv* env, jobject bitmap); 54 55 /** Reinitialize a bitmap. bitmap must already have its SkAlphaType set in 56 sync with isPremultiplied 57 */ 58 void reinitBitmap(JNIEnv* env, jobject javaBitmap, const SkImageInfo& info, 59 bool isPremultiplied); 60 61 int getBitmapAllocationByteCount(JNIEnv* env, jobject javaBitmap); 62 63 } // namespace bitmap 64 65 } // namespace android 66 67 #endif /* BITMAP_H_ */ 68