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 * @kit ArkGraphics2D 37 * @library libnative_drawing.so 38 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 39 * @since 8 40 * @version 1.0 41 */ 42 43#include "drawing_types.h" 44 45#ifdef __cplusplus 46extern "C" { 47#endif 48 49/** 50 * @brief Defines the pixel format of a bitmap, including the color type and alpha type. 51 * 52 * @since 8 53 * @version 1.0 54 */ 55typedef struct { 56 /** Storage format of bitmap pixels */ 57 OH_Drawing_ColorFormat colorFormat; 58 /** Alpha format of bitmap pixels */ 59 OH_Drawing_AlphaFormat alphaFormat; 60} OH_Drawing_BitmapFormat; 61 62/** 63 * @brief Creates an <b>OH_Drawing_Bitmap</b> object. 64 * 65 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 66 * @return Returns the pointer to the <b>OH_Drawing_Bitmap</b> object created. 67 * @since 8 68 * @version 1.0 69 */ 70OH_Drawing_Bitmap* OH_Drawing_BitmapCreate(void); 71 72/** 73 * @brief Destroys an <b>OH_Drawing_Bitmap</b> object and reclaims the memory occupied by the object. 74 * 75 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 76 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 77 * @since 8 78 * @version 1.0 79 */ 80void OH_Drawing_BitmapDestroy(OH_Drawing_Bitmap*); 81 82/** 83 * @brief Creates an <b>OH_Drawing_Bitmap</b> object with <b>OH_Drawing_Image_Info</b> object 84 * and sets the mem address or pixel storage. 85 * 86 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 87 * @param OH_Drawing_Image_Info Indicates the pointer to an <b>OH_Drawing_Image_Info</b> object. 88 * @param pixels the pointer to memory address or pixel storage. 89 * @param rowBytes size of pixel row or larger. 90 * @return Returns the pointer to the <b>OH_Drawing_Bitmap</b> object created. 91 * @since 12 92 * @version 1.0 93 */ 94OH_Drawing_Bitmap* OH_Drawing_BitmapCreateFromPixels(OH_Drawing_Image_Info*, void* pixels, uint32_t rowBytes); 95 96/** 97 * @brief Initializes the width and height of an <b>OH_Drawing_Bitmap</b> object 98 * and sets the pixel format for the bitmap. 99 * 100 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 101 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 102 * @param width Indicates the width of the bitmap to be initialized. 103 * @param height Indicates the height of the bitmap to be initialized. 104 * @param OH_Drawing_BitmapFormat Indicates the pixel format of the bitmap to be initialized, 105 * including the pixel color type and alpha type. 106 * @since 8 107 * @version 1.0 108 */ 109void OH_Drawing_BitmapBuild( 110 OH_Drawing_Bitmap*, const uint32_t width, const uint32_t height, const OH_Drawing_BitmapFormat*); 111 112/** 113 * @brief Obtains the width of a bitmap. 114 * 115 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 116 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 117 * @return Returns the width. 118 * @since 8 119 * @version 1.0 120 */ 121uint32_t OH_Drawing_BitmapGetWidth(OH_Drawing_Bitmap*); 122 123/** 124 * @brief Obtains the height of a bitmap. 125 * 126 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 127 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 128 * @return Returns the height. 129 * @since 8 130 * @version 1.0 131 */ 132uint32_t OH_Drawing_BitmapGetHeight(OH_Drawing_Bitmap*); 133 134/** 135 * @brief Obtains the color format of a bitmap. 136 * 137 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 138 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 139 * @return Returns the bitmap color format. 140 * @since 12 141 * @version 1.0 142 */ 143OH_Drawing_ColorFormat OH_Drawing_BitmapGetColorFormat(OH_Drawing_Bitmap*); 144 145/** 146 * @brief Obtains the alpha format of a bitmap. 147 * 148 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 149 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 150 * @return Returns the bitmap alpha format. 151 * @since 12 152 * @version 1.0 153 */ 154OH_Drawing_AlphaFormat OH_Drawing_BitmapGetAlphaFormat(OH_Drawing_Bitmap*); 155 156/** 157 * @brief Obtains the pixel address of a bitmap. You can use this address to obtain the pixel data of the bitmap. 158 * 159 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 160 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 161 * @return Returns the pixel address. 162 * @since 8 163 * @version 1.0 164 */ 165void* OH_Drawing_BitmapGetPixels(OH_Drawing_Bitmap*); 166 167/** 168 * @brief Gets the image info. 169 * 170 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 171 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 172 * @param OH_Drawing_Image_Info Indicates the pointer to an <b>OH_Drawing_Image_Info</b> object. 173 * @since 12 174 * @version 1.0 175 */ 176void OH_Drawing_BitmapGetImageInfo(OH_Drawing_Bitmap*, OH_Drawing_Image_Info*); 177 178/** 179 * @brief Copies a rect of pixels from bitmap to dstPixels. Copy starts at (srcX, srcY), 180 * and does not exceed bitmap width and height. 181 * 182 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 183 * @param OH_Drawing_Bitmap Indicates the pointer to an <b>OH_Drawing_Bitmap</b> object. 184 * @param dstInfo Indicates the pointer to an <b>OH_Drawing_Image_Info</b> object. 185 * @param dstPixels Destination pixel storage. 186 * @param dstRowBytes Destination row length. 187 * @param srcX Column index whose absolute value is less than width. 188 * @param srcY Row index whose absolute value is less than height. 189 * @return Returns true if pixels are copied to dstPixels. 190 * @since 12 191 * @version 1.0 192 */ 193bool OH_Drawing_BitmapReadPixels(OH_Drawing_Bitmap*, const OH_Drawing_Image_Info* dstInfo, 194 void* dstPixels, size_t dstRowBytes, int32_t srcX, int32_t srcY); 195#ifdef __cplusplus 196} 197#endif 198/** @} */ 199#endif 200