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 17e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifndef ANDROID_BITMAP_H 18e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#define ANDROID_BITMAP_H 19e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 20e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#include <stdint.h> 21e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#include <jni.h> 22e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 23e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus 24e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianextern "C" { 25e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif 26e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 27e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#define ANDROID_BITMAP_RESUT_SUCCESS 0 28e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#define ANDROID_BITMAP_RESULT_BAD_PARAMETER -1 29e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#define ANDROID_BITMAP_RESULT_JNI_EXCEPTION -2 30e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#define ANDROID_BITMAP_RESULT_ALLOCATION_FAILED -3 31e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 32e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianenum AndroidBitmapFormat { 33e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_NONE = 0, 34e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_RGBA_8888 = 1, 35e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_RGB_565 = 4, 36e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_RGBA_4444 = 7, 37e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ANDROID_BITMAP_FORMAT_A_8 = 8, 38e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian}; 39e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 40e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopiantypedef struct { 41e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian uint32_t width; 42e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian uint32_t height; 43e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian uint32_t stride; 44e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian int32_t format; 45e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian uint32_t flags; // 0 for now 46e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian} AndroidBitmapInfo; 47e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 48e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 49e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Given a java bitmap object, fill out the AndroidBitmap struct for it. 50e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * If the call fails, the info parameter will be ignored 51e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 52e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, 53e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian AndroidBitmapInfo* info); 54e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 55e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 56e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Given a java bitmap object, attempt to lock the pixel address. 57e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Locking will ensure that the memory for the pixels will not move 58e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * until the unlockPixels call, and ensure that, if the pixels had been 59e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * previously purged, they will have been restored. 60e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 61e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * If this call succeeds, it must be balanced by a call to 62e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * AndroidBitmap_unlockPixels, after which time the address of the pixels should 63e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * no longer be used. 64e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 65e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * If this succeeds, *addrPtr will be set to the pixel address. If the call 66e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * fails, addrPtr will be ignored. 67e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 68e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr); 69e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 70e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 71e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Call this to balanace a successful call to AndroidBitmap_lockPixels 72e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 73e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap); 74e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 75e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus 76e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian} 77e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif 78e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 79e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif 80