1e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/* 2e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Copyright (C) 2009 The Android Open Source Project 3e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 4e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * you may not use this file except in compliance with the License. 6e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * You may obtain a copy of the License at 7e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 8e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 10e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Unless required by applicable law or agreed to in writing, software 11e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * See the License for the specific language governing permissions and 14e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * limitations under the License. 15e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 16e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 17bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 18bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * @addtogroup Bitmap 19bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * @{ 20bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */ 21bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine 22bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 23bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * @file bitmap.h 24bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */ 25bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine 26e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifndef ANDROID_BITMAP_H 27e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#define ANDROID_BITMAP_H 28e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 29e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#include <stdint.h> 30e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#include <jni.h> 31e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 32e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus 33e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianextern "C" { 34e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif 35e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 36bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** AndroidBitmap functions result code. */ 37bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosineenum { 38bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Operation was successful. */ 39bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine ANDROID_BITMAP_RESULT_SUCCESS = 0, 40bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Bad parameter. */ 41bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine ANDROID_BITMAP_RESULT_BAD_PARAMETER = -1, 42bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** JNI exception occured. */ 43bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine ANDROID_BITMAP_RESULT_JNI_EXCEPTION = -2, 44bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Allocation failed. */ 45bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine ANDROID_BITMAP_RESULT_ALLOCATION_FAILED = -3, 46bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine}; 47e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 48bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** Backward compatibility: this macro used to be misspelled. */ 49370980c52867864e1b0acd9f132e527fb6b2adeeAndrew Hsieh#define ANDROID_BITMAP_RESUT_SUCCESS ANDROID_BITMAP_RESULT_SUCCESS 50370980c52867864e1b0acd9f132e527fb6b2adeeAndrew Hsieh 51bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** Bitmap pixel format. */ 52e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianenum AndroidBitmapFormat { 53bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** No format. */ 54e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_NONE = 0, 55bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/ 56e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_RGBA_8888 = 1, 57bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/ 58e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_RGB_565 = 4, 59bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Red: 4 bits, Green: 4 bits, Blue: 4 bits, Alpha: 4 bits. **/ 60e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_RGBA_4444 = 7, 61bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Deprecated. */ 62e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_A_8 = 8, 63e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian}; 64e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 65bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** Bitmap info, see AndroidBitmap_getInfo(). */ 66e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopiantypedef struct { 67bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** The bitmap width in pixels. */ 68e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian uint32_t width; 69bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** The bitmap height in pixels. */ 70e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian uint32_t height; 71bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** The number of byte per row. */ 72e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian uint32_t stride; 73bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** The bitmap pixel format. See {@link AndroidBitmapFormat} */ 74e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian int32_t format; 75bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Unused. */ 76e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian uint32_t flags; // 0 for now 77e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian} AndroidBitmapInfo; 78e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 79e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 80bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * Given a java bitmap object, fill out the AndroidBitmapInfo struct for it. 81bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * If the call fails, the info parameter will be ignored. 82e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 83e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, 84e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian AndroidBitmapInfo* info); 85e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 86e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 87e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Given a java bitmap object, attempt to lock the pixel address. 88e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Locking will ensure that the memory for the pixels will not move 89e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * until the unlockPixels call, and ensure that, if the pixels had been 90e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * previously purged, they will have been restored. 91e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 92e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * If this call succeeds, it must be balanced by a call to 93e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * AndroidBitmap_unlockPixels, after which time the address of the pixels should 94e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * no longer be used. 95e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 96e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * If this succeeds, *addrPtr will be set to the pixel address. If the call 97e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * fails, addrPtr will be ignored. 98e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 99e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr); 100e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 101e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 102bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * Call this to balance a successful call to AndroidBitmap_lockPixels. 103e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 104e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap); 105e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 106e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus 107e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian} 108e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif 109e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 110e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif 111bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine 112bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** @} */ 113