1 /* 2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef C_INCLUDE_DRAWING_BITMAP_H 17 #define C_INCLUDE_DRAWING_BITMAP_H 18 19 /** 20 * @addtogroup Drawing 21 * @{ 22 * 23 * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. 24 * 25 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 26 * 27 * @since 8 28 * @version 1.0 29 */ 30 31 /** 32 * @file drawing_bitmap.h 33 * 34 * @brief Declares functions related to the <b>bitmap</b> object in the drawing module. 35 * 36 * @since 8 37 * @version 1.0 38 */ 39 40 #include "drawing_types.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /** 47 * @brief Defines the pixel format of a bitmap, including the color type and alpha type. 48 * 49 * @since 8 50 * @version 1.0 51 */ 52 typedef struct { 53 /** Storage format of bitmap pixels */ 54 OH_Drawing_ColorFormat colorFormat; 55 /** Alpha format of bitmap pixels */ 56 OH_Drawing_AlphaFormat alphaFormat; 57 } OH_Drawing_BitmapFormat; 58 59 /** 60 * @brief Creates an <b>OH_Drawing_Bitmap</b> object. 61 * 62 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 63 * @return Returns the pointer to the <b>OH_Drawing_Bitmap</b> object created. 64 * @since 8 65 * @version 1.0 66 */ 67 OH_Drawing_Bitmap* OH_Drawing_BitmapCreate(void); 68 69 /** 70 * @brief Destroys an <b>OH_Drawing_Bitmap</b> object and reclaims the memory occupied by the object. 71 * 72 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 73 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 74 * @since 8 75 * @version 1.0 76 */ 77 void OH_Drawing_BitmapDestroy(OH_Drawing_Bitmap*); 78 79 /** 80 * @brief Creates an <b>OH_Drawing_Bitmap</b> object with <b>OH_Drawing_Image_Info</b> object 81 * and sets the mem address or pixel storage. 82 * 83 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 84 * @param OH_Drawing_Image_Info Indicates the pointer to an <b>OH_Drawing_Image_Info</b> object. 85 * @param pixels the pointer to memory address or pixel storage. 86 * @param rowBytes size of pixel row or larger. 87 * @return Returns the pointer to the <b>OH_Drawing_Bitmap</b> object created. 88 * @since 12 89 * @version 1.0 90 */ 91 OH_Drawing_Bitmap* OH_Drawing_BitmapCreateFromPixels(OH_Drawing_Image_Info*, void* pixels, uint32_t rowBytes); 92 93 /** 94 * @brief Initializes the width and height of an <b>OH_Drawing_Bitmap</b> object 95 * and sets the pixel format for the bitmap. 96 * 97 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 98 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 99 * @param width Indicates the width of the bitmap to be initialized. 100 * @param height Indicates the height of the bitmap to be initialized. 101 * @param OH_Drawing_BitmapFormat Indicates the pixel format of the bitmap to be initialized, 102 * including the pixel color type and alpha type. 103 * @since 8 104 * @version 1.0 105 */ 106 void OH_Drawing_BitmapBuild( 107 OH_Drawing_Bitmap*, const uint32_t width, const uint32_t height, const OH_Drawing_BitmapFormat*); 108 109 /** 110 * @brief Obtains the width of a bitmap. 111 * 112 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 113 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 114 * @return Returns the width. 115 * @since 8 116 * @version 1.0 117 */ 118 uint32_t OH_Drawing_BitmapGetWidth(OH_Drawing_Bitmap*); 119 120 /** 121 * @brief Obtains the height of a bitmap. 122 * 123 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 124 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 125 * @return Returns the height. 126 * @since 8 127 * @version 1.0 128 */ 129 uint32_t OH_Drawing_BitmapGetHeight(OH_Drawing_Bitmap*); 130 131 /** 132 * @brief Obtains the color format of a bitmap. 133 * 134 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 135 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 136 * @return Returns the bitmap color format. 137 * @since 12 138 * @version 1.0 139 */ 140 OH_Drawing_ColorFormat OH_Drawing_BitmapGetColorFormat(OH_Drawing_Bitmap*); 141 142 /** 143 * @brief Obtains the alpha format of a bitmap. 144 * 145 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 146 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 147 * @return Returns the bitmap alpha format. 148 * @since 12 149 * @version 1.0 150 */ 151 OH_Drawing_AlphaFormat OH_Drawing_BitmapGetAlphaFormat(OH_Drawing_Bitmap*); 152 153 /** 154 * @brief Obtains the pixel address of a bitmap. You can use this address to obtain the pixel data of the bitmap. 155 * 156 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 157 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 158 * @return Returns the pixel address. 159 * @since 8 160 * @version 1.0 161 */ 162 void* OH_Drawing_BitmapGetPixels(OH_Drawing_Bitmap*); 163 164 /** 165 * @brief Gets the image info. 166 * 167 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 168 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 169 * @param OH_Drawing_Image_Info Indicates the pointer to an <b>OH_Drawing_Image_Info</b> object. 170 * @since 12 171 * @version 1.0 172 */ 173 void OH_Drawing_BitmapGetImageInfo(OH_Drawing_Bitmap*, OH_Drawing_Image_Info*); 174 175 /** 176 * @brief Copies a rect of pixels from bitmap to dstPixels. Copy starts at (srcX, srcY), 177 * and does not exceed bitmap width and height. 178 * 179 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 180 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 181 * @param dstInfo Indicates the pointer to an <b>OH_Drawing_Image_Info</b> object. 182 * @param dstPixels Destination pixel storage. 183 * @param dstRowBytes Destination row length. 184 * @param srcX Column index whose absolute value is less than width. 185 * @param srcY Row index whose absolute value is less than height. 186 * @return Returns true if pixels are copied to dstPixels. 187 * @since 12 188 * @version 1.0 189 */ 190 bool OH_Drawing_BitmapReadPixels(OH_Drawing_Bitmap*, const OH_Drawing_Image_Info* dstInfo, 191 void* dstPixels, size_t dstRowBytes, int32_t srcX, int32_t srcY); 192 #ifdef __cplusplus 193 } 194 #endif 195 /** @} */ 196 #endif 197