bitmap.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. * @addtogroup Bitmap
  18. * @{
  19. */
  20. /**
  21. * @file bitmap.h
  22. */
  23. #ifndef ANDROID_BITMAP_H
  24. #define ANDROID_BITMAP_H
  25. #include <stdint.h>
  26. #include <jni.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /** AndroidBitmap functions result code. */
  31. enum {
  32. /** Operation was successful. */
  33. ANDROID_BITMAP_RESULT_SUCCESS = 0,
  34. /** Bad parameter. */
  35. ANDROID_BITMAP_RESULT_BAD_PARAMETER = -1,
  36. /** JNI exception occured. */
  37. ANDROID_BITMAP_RESULT_JNI_EXCEPTION = -2,
  38. /** Allocation failed. */
  39. ANDROID_BITMAP_RESULT_ALLOCATION_FAILED = -3,
  40. };
  41. /** Backward compatibility: this macro used to be misspelled. */
  42. #define ANDROID_BITMAP_RESUT_SUCCESS ANDROID_BITMAP_RESULT_SUCCESS
  43. /** Bitmap pixel format. */
  44. enum AndroidBitmapFormat {
  45. /** No format. */
  46. ANDROID_BITMAP_FORMAT_NONE = 0,
  47. /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/
  48. ANDROID_BITMAP_FORMAT_RGBA_8888 = 1,
  49. /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/
  50. ANDROID_BITMAP_FORMAT_RGB_565 = 4,
  51. /** Red: 4 bits, Green: 4 bits, Blue: 4 bits, Alpha: 4 bits. **/
  52. ANDROID_BITMAP_FORMAT_RGBA_4444 = 7,
  53. /** Deprecated. */
  54. ANDROID_BITMAP_FORMAT_A_8 = 8,
  55. };
  56. /** Bitmap info, see AndroidBitmap_getInfo(). */
  57. typedef struct {
  58. /** The bitmap width in pixels. */
  59. uint32_t width;
  60. /** The bitmap height in pixels. */
  61. uint32_t height;
  62. /** The number of byte per row. */
  63. uint32_t stride;
  64. /** The bitmap pixel format. See {@link AndroidBitmapFormat} */
  65. int32_t format;
  66. /** Unused. */
  67. uint32_t flags; // 0 for now
  68. } AndroidBitmapInfo;
  69. /**
  70. * Given a java bitmap object, fill out the AndroidBitmapInfo struct for it.
  71. * If the call fails, the info parameter will be ignored.
  72. */
  73. int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
  74. AndroidBitmapInfo* info);
  75. /**
  76. * Given a java bitmap object, attempt to lock the pixel address.
  77. * Locking will ensure that the memory for the pixels will not move
  78. * until the unlockPixels call, and ensure that, if the pixels had been
  79. * previously purged, they will have been restored.
  80. *
  81. * If this call succeeds, it must be balanced by a call to
  82. * AndroidBitmap_unlockPixels, after which time the address of the pixels should
  83. * no longer be used.
  84. *
  85. * If this succeeds, *addrPtr will be set to the pixel address. If the call
  86. * fails, addrPtr will be ignored.
  87. */
  88. int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr);
  89. /**
  90. * Call this to balance a successful call to AndroidBitmap_lockPixels.
  91. */
  92. int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap);
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif
  97. /** @} */