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