| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef ANDROID_GRAPHICS_BITMAP_H |
| 17 |
#define ANDROID_GRAPHICS_BITMAP_H |
| 18 |
|
| 19 |
#include <android/bitmap.h> |
| 20 |
#include <android/data_space.h> |
| 21 |
#include <cutils/compiler.h> |
| 22 |
#include <jni.h> |
| 23 |
#include <sys/cdefs.h> |
| 24 |
|
| 25 |
struct AHardwareBuffer; |
| 26 |
|
| 27 |
__BEGIN_DECLS |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
typedef struct ABitmap ABitmap; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
ANDROID_API AndroidBitmapInfo ABitmap_getInfoFromJava(JNIEnv* env, jobject bitmapObj); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
ANDROID_API ABitmap* ABitmap_acquireBitmapFromJava(JNIEnv* env, jobject bitmapObj); |
| 49 |
|
| 50 |
ANDROID_API ABitmap* ABitmap_copy(ABitmap* srcBitmap, AndroidBitmapFormat dstFormat); |
| 51 |
|
| 52 |
ANDROID_API void ABitmap_acquireRef(ABitmap* bitmap); |
| 53 |
ANDROID_API void ABitmap_releaseRef(ABitmap* bitmap); |
| 54 |
|
| 55 |
ANDROID_API AndroidBitmapInfo ABitmap_getInfo(ABitmap* bitmap); |
| 56 |
ANDROID_API ADataSpace ABitmap_getDataSpace(ABitmap* bitmap); |
| 57 |
|
| 58 |
ANDROID_API void* ABitmap_getPixels(ABitmap* bitmap); |
| 59 |
ANDROID_API void ABitmap_notifyPixelsChanged(ABitmap* bitmap); |
| 60 |
|
| 61 |
ANDROID_API AndroidBitmapFormat ABitmapConfig_getFormatFromConfig(JNIEnv* env, jobject bitmapConfigObj); |
| 62 |
ANDROID_API jobject ABitmapConfig_getConfigFromFormat(JNIEnv* env, AndroidBitmapFormat format); |
| 63 |
|
| 64 |
|
| 65 |
ANDROID_API int ABitmap_compress(const AndroidBitmapInfo* info, ADataSpace dataSpace, const void* pixels, |
| 66 |
AndroidBitmapCompressFormat format, int32_t quality, void* userContext, |
| 67 |
AndroidBitmap_CompressWriteFunc); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
ANDROID_API AHardwareBuffer* ABitmap_getHardwareBuffer(ABitmap* bitmap); |
| 80 |
|
| 81 |
__END_DECLS |
| 82 |
|
| 83 |
#ifdef __cplusplus |
| 84 |
namespace android { |
| 85 |
namespace graphics { |
| 86 |
class Bitmap { |
| 87 |
public: |
| 88 |
Bitmap() : mBitmap(nullptr) {} |
| 89 |
Bitmap(JNIEnv* env, jobject bitmapObj) : |
| 90 |
mBitmap(ABitmap_acquireBitmapFromJava(env, bitmapObj)) {} |
| 91 |
Bitmap(const Bitmap& src) : mBitmap(src.mBitmap) { ABitmap_acquireRef(src.mBitmap); } |
| 92 |
~Bitmap() { ABitmap_releaseRef(mBitmap); } |
| 93 |
|
| 94 |
|
| 95 |
Bitmap& operator=(const Bitmap& other) { |
| 96 |
if (&other != this) { |
| 97 |
ABitmap_releaseRef(mBitmap); |
| 98 |
mBitmap = other.mBitmap; |
| 99 |
ABitmap_acquireRef(mBitmap); |
| 100 |
} |
| 101 |
return *this; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
Bitmap& operator=(Bitmap&& other) { |
| 106 |
if (&other != this) { |
| 107 |
ABitmap_releaseRef(mBitmap); |
| 108 |
mBitmap = other.mBitmap; |
| 109 |
other.mBitmap = nullptr; |
| 110 |
} |
| 111 |
return *this; |
| 112 |
} |
| 113 |
|
| 114 |
Bitmap copy(AndroidBitmapFormat dstFormat) const { |
| 115 |
return Bitmap(ABitmap_copy(mBitmap, dstFormat)); |
| 116 |
} |
| 117 |
|
| 118 |
bool isValid() const { return mBitmap != nullptr; } |
| 119 |
bool isEmpty() const { |
| 120 |
AndroidBitmapInfo info = getInfo(); |
| 121 |
return info.width <= 0 || info.height <= 0; |
| 122 |
} |
| 123 |
void reset() { |
| 124 |
ABitmap_releaseRef(mBitmap); |
| 125 |
mBitmap = nullptr; |
| 126 |
} |
| 127 |
|
| 128 |
ABitmap* get() const { return mBitmap; } |
| 129 |
|
| 130 |
AndroidBitmapInfo getInfo() const { return ABitmap_getInfo(mBitmap); } |
| 131 |
ADataSpace getDataSpace() const { return ABitmap_getDataSpace(mBitmap); } |
| 132 |
void* getPixels() const { return ABitmap_getPixels(mBitmap); } |
| 133 |
void notifyPixelsChanged() const { ABitmap_notifyPixelsChanged(mBitmap); } |
| 134 |
AHardwareBuffer* getHardwareBuffer() const { return ABitmap_getHardwareBuffer(mBitmap); } |
| 135 |
|
| 136 |
private: |
| 137 |
|
| 138 |
Bitmap(ABitmap* bitmap) : mBitmap(bitmap) {} |
| 139 |
|
| 140 |
ABitmap* mBitmap; |
| 141 |
}; |
| 142 |
}; |
| 143 |
}; |
| 144 |
#endif |
| 145 |
|
| 146 |
#endif |