blob: 41718b2904bde8d0454bc2cdab33661b271f5920 [file] [log] [blame]
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001/*
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
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070017/**
18 * @addtogroup Bitmap
19 * @{
20 */
21
22/**
23 * @file bitmap.h
24 */
25
Mathias Agopiane1c61d32012-03-23 14:19:36 -070026#ifndef ANDROID_BITMAP_H
27#define ANDROID_BITMAP_H
28
29#include <stdint.h>
30#include <jni.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070036/** AndroidBitmap functions result code. */
37enum {
38 /** Operation was successful. */
39 ANDROID_BITMAP_RESULT_SUCCESS = 0,
40 /** Bad parameter. */
41 ANDROID_BITMAP_RESULT_BAD_PARAMETER = -1,
42 /** JNI exception occured. */
43 ANDROID_BITMAP_RESULT_JNI_EXCEPTION = -2,
44 /** Allocation failed. */
45 ANDROID_BITMAP_RESULT_ALLOCATION_FAILED = -3,
46};
Mathias Agopiane1c61d32012-03-23 14:19:36 -070047
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070048/** Backward compatibility: this macro used to be misspelled. */
Andrew Hsieh370980c2012-12-17 08:01:36 +080049#define ANDROID_BITMAP_RESUT_SUCCESS ANDROID_BITMAP_RESULT_SUCCESS
50
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070051/** Bitmap pixel format. */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070052enum AndroidBitmapFormat {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070053 /** No format. */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070054 ANDROID_BITMAP_FORMAT_NONE = 0,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070055 /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/
Mathias Agopiane1c61d32012-03-23 14:19:36 -070056 ANDROID_BITMAP_FORMAT_RGBA_8888 = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070057 /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/
Mathias Agopiane1c61d32012-03-23 14:19:36 -070058 ANDROID_BITMAP_FORMAT_RGB_565 = 4,
Quddus Chong4a1a45b2017-02-08 10:38:21 -080059 /** Deprecated in API level 13. Because of the poor quality of this configuration, it is advised to use ARGB_8888 instead. **/
Mathias Agopiane1c61d32012-03-23 14:19:36 -070060 ANDROID_BITMAP_FORMAT_RGBA_4444 = 7,
Quddus Chong4a1a45b2017-02-08 10:38:21 -080061 /** Alpha: 8 bits. */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070062 ANDROID_BITMAP_FORMAT_A_8 = 8,
Leon Scroggins IIIf73f5f22019-08-12 13:43:55 -040063 /** Each component is stored as a half float. **/
64 ANDROID_BITMAP_FORMAT_RGBA_F16 = 9,
Mathias Agopiane1c61d32012-03-23 14:19:36 -070065};
66
Leon Scroggins III0dd622e2019-08-23 15:44:21 -040067/** Bitmap alpha format */
68enum {
69 /** Pixel components are premultiplied by alpha. */
70 ANDROID_BITMAP_FLAGS_ALPHA_PREMUL = 0,
71 /** Pixels are opaque. */
72 ANDROID_BITMAP_FLAGS_ALPHA_OPAQUE = 1,
73 /** Pixel components are independent of alpha. */
74 ANDROID_BITMAP_FLAGS_ALPHA_UNPREMUL = 2,
75 /** Bit mask for AndroidBitmapFormat.flags to isolate the alpha. */
76 ANDROID_BITMAP_FLAGS_ALPHA_MASK = 0x3,
77 /** Shift for AndroidBitmapFormat.flags to isolate the alpha. */
78 ANDROID_BITMAP_FLAGS_ALPHA_SHIFT = 0,
79};
80
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070081/** Bitmap info, see AndroidBitmap_getInfo(). */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070082typedef struct {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070083 /** The bitmap width in pixels. */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070084 uint32_t width;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070085 /** The bitmap height in pixels. */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070086 uint32_t height;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070087 /** The number of byte per row. */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070088 uint32_t stride;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070089 /** The bitmap pixel format. See {@link AndroidBitmapFormat} */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070090 int32_t format;
Leon Scroggins III0dd622e2019-08-23 15:44:21 -040091 /** Two bits are used to encode alpha. Use ANDROID_BITMAP_FLAGS_ALPHA_MASK
92 * and ANDROID_BITMAP_FLAGS_ALPHA_SHIFT to retrieve them. */
93 uint32_t flags;
Mathias Agopiane1c61d32012-03-23 14:19:36 -070094} AndroidBitmapInfo;
95
96/**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070097 * Given a java bitmap object, fill out the AndroidBitmapInfo struct for it.
98 * If the call fails, the info parameter will be ignored.
Mathias Agopiane1c61d32012-03-23 14:19:36 -070099 */
100int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
101 AndroidBitmapInfo* info);
102
Leon Scroggins III3dd64552020-01-10 13:41:44 -0500103#if __ANDROID_API__ >= 30
104
105/**
106 * Given a java bitmap object, return its ADataSpace.
107 *
108 * Note that ADataSpace only exposes a few values. This may return
109 * ADATASPACE_UNKNOWN, even for Named ColorSpaces, if they have no
110 * corresponding ADataSpace.
111 */
112int32_t AndroidBitmap_getDataSpace(JNIEnv* env, jobject jbitmap) __INTRODUCED_IN(30);
113
114#endif // __ANDROID_API__ >= 30
115
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700116/**
117 * Given a java bitmap object, attempt to lock the pixel address.
118 * Locking will ensure that the memory for the pixels will not move
119 * until the unlockPixels call, and ensure that, if the pixels had been
120 * previously purged, they will have been restored.
121 *
122 * If this call succeeds, it must be balanced by a call to
123 * AndroidBitmap_unlockPixels, after which time the address of the pixels should
124 * no longer be used.
125 *
126 * If this succeeds, *addrPtr will be set to the pixel address. If the call
127 * fails, addrPtr will be ignored.
128 */
129int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr);
130
131/**
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700132 * Call this to balance a successful call to AndroidBitmap_lockPixels.
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700133 */
134int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap);
135
136#ifdef __cplusplus
137}
138#endif
139
140#endif
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700141
142/** @} */