bitmap.h revision 370980c52867864e1b0acd9f132e527fb6b2adee
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
27370980c52867864e1b0acd9f132e527fb6b2adeeAndrew Hsieh#define ANDROID_BITMAP_RESULT_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
32370980c52867864e1b0acd9f132e527fb6b2adeeAndrew Hsieh/* Backward compatibility: this macro used to be misspelled. */
33370980c52867864e1b0acd9f132e527fb6b2adeeAndrew Hsieh#define ANDROID_BITMAP_RESUT_SUCCESS ANDROID_BITMAP_RESULT_SUCCESS
34370980c52867864e1b0acd9f132e527fb6b2adeeAndrew Hsieh
35e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianenum AndroidBitmapFormat {
36e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    ANDROID_BITMAP_FORMAT_NONE      = 0,
37e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    ANDROID_BITMAP_FORMAT_RGBA_8888 = 1,
38e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    ANDROID_BITMAP_FORMAT_RGB_565   = 4,
39e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    ANDROID_BITMAP_FORMAT_RGBA_4444 = 7,
40e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    ANDROID_BITMAP_FORMAT_A_8       = 8,
41e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian};
42e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
43e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopiantypedef struct {
44e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    uint32_t    width;
45e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    uint32_t    height;
46e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    uint32_t    stride;
47e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    int32_t     format;
48e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    uint32_t    flags;      // 0 for now
49e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian} AndroidBitmapInfo;
50e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
51e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
52e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Given a java bitmap object, fill out the AndroidBitmap struct for it.
53e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * If the call fails, the info parameter will be ignored
54e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
55e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
56e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian                          AndroidBitmapInfo* info);
57e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
58e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
59e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Given a java bitmap object, attempt to lock the pixel address.
60e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Locking will ensure that the memory for the pixels will not move
61e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * until the unlockPixels call, and ensure that, if the pixels had been
62e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * previously purged, they will have been restored.
63e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *
64e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * If this call succeeds, it must be balanced by a call to
65e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * AndroidBitmap_unlockPixels, after which time the address of the pixels should
66e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * no longer be used.
67e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *
68e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * If this succeeds, *addrPtr will be set to the pixel address. If the call
69e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * fails, addrPtr will be ignored.
70e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
71e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr);
72e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
73e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
74e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Call this to balanace a successful call to AndroidBitmap_lockPixels
75e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
76e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap);
77e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
78e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus
79e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian}
80e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif
81e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
82e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif
83