diff --git a/graphic/graphic_2d/native_drawing/BUILD.gn b/graphic/graphic_2d/native_drawing/BUILD.gn index 35a37961937cb91ad9e352fea4d09163a04ef754..f4ba43a3231d40be0e78cba1dd72e539284520fe 100644 --- a/graphic/graphic_2d/native_drawing/BUILD.gn +++ b/graphic/graphic_2d/native_drawing/BUILD.gn @@ -29,6 +29,7 @@ ohos_ndk_headers("native_drawing_header") { "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_font_mgr.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_gpu_context.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_image.h", + "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_image_filter.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_mask_filter.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_matrix.h", "//interface/sdk_c/graphic/graphic_2d/native_drawing/drawing_memory_stream.h", @@ -83,6 +84,7 @@ ohos_ndk_library("libnative_drawing_ndk") { "native_drawing/drawing_register_font.h", "native_drawing/drawing_round_rect.h", "native_drawing/drawing_image.h", + "native_drawing/drawing_image_filter.h", "native_drawing/drawing_sampling_options.h", "native_drawing/drawing_shader_effect.h", "native_drawing/drawing_shadow_layer.h", diff --git a/graphic/graphic_2d/native_drawing/drawing_brush.h b/graphic/graphic_2d/native_drawing/drawing_brush.h index 98a50756b87b1e9572fecf919a5eb5e50630b55d..f42094efe9131bc5f6363ed0f4982cfef526a5eb 100644 --- a/graphic/graphic_2d/native_drawing/drawing_brush.h +++ b/graphic/graphic_2d/native_drawing/drawing_brush.h @@ -53,6 +53,17 @@ extern "C" { */ OH_Drawing_Brush* OH_Drawing_BrushCreate(void); +/** + * @brief Creates an OH_Drawing_Brush copy object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Brush Indicates the pointer to an OH_Drawing_Brush object. + * @return Returns the pointer to the OH_Drawing_Brush object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Brush* OH_Drawing_BrushCopy(OH_Drawing_Brush*); + /** * @brief Destroys an OH_Drawing_Brush object and reclaims the memory occupied by the object. * diff --git a/graphic/graphic_2d/native_drawing/drawing_filter.h b/graphic/graphic_2d/native_drawing/drawing_filter.h index 556c19d85ca81f103cb50f3ba1cd85e37cd80941..57eac2fa6d16252fd815966602d05de554570a01 100644 --- a/graphic/graphic_2d/native_drawing/drawing_filter.h +++ b/graphic/graphic_2d/native_drawing/drawing_filter.h @@ -53,6 +53,17 @@ extern "C" { */ OH_Drawing_Filter* OH_Drawing_FilterCreate(void); +/** + * @brief Sets an OH_Drawing_ImageFilter object for an OH_Drawing_Filter object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Filter Indicates the pointer to an OH_Drawing_Filter object. + * @param OH_Drawing_ImageFilter Indicates the pointer to an OH_Drawing_ImageFilter object. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_FilterSetImageFilter(OH_Drawing_Filter*, OH_Drawing_ImageFilter*); + /** * @brief Sets an OH_Drawing_MaskFilter object for an OH_Drawing_Filter object. * diff --git a/graphic/graphic_2d/native_drawing/drawing_image.h b/graphic/graphic_2d/native_drawing/drawing_image.h index ed2f1f4914cc0deb31957b99d3f4697ab851c061..1a0824db0fa669734948e3f7d5a37755e25df3c4 100644 --- a/graphic/graphic_2d/native_drawing/drawing_image.h +++ b/graphic/graphic_2d/native_drawing/drawing_image.h @@ -53,6 +53,19 @@ extern "C" { */ OH_Drawing_Image* OH_Drawing_ImageCreate(void); +/** + * @brief Creates an OH_Drawing_Image object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param data Indicates the pointer to the encoded data, it must not be null. + * @param size Indicates the size of the encoded data. + * @param copyData Indicates whether should copy the data to create the image. + * @return Returns the pointer to the OH_Drawing_Image object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Image* OH_Drawing_ImageCreateFromEncodedData(const void* data, size_t size, bool copyData); + /** * @brief Destroys an OH_Drawing_Image object and reclaims the memory occupied by the object. * diff --git a/graphic/graphic_2d/native_drawing/drawing_image_filter.h b/graphic/graphic_2d/native_drawing/drawing_image_filter.h new file mode 100644 index 0000000000000000000000000000000000000000..ebb5436ffb3150dcfd67d2bbe94db3eb14155bbd --- /dev/null +++ b/graphic/graphic_2d/native_drawing/drawing_image_filter.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef C_INCLUDE_DRAWING_IMAGE_FILTER_H +#define C_INCLUDE_DRAWING_IMAGE_FILTER_H + +/** + * @addtogroup Drawing + * @{ + * + * @brief Provides functions such as 2D graphics rendering, text drawing, and image display. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * + * @since 12 + * @version 1.0 + */ + +/** + * @file drawing_image_filter.h + * + * @brief Declares functions related to the imageFilter object in the drawing module. + * + * @since 12 + * @version 1.0 + */ + +#include "drawing_shader_effect.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Drawing_ImageFilter object that blurs its input by the separate x and y sigmas. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param sigmaX Indicates the Gaussian sigma value for blurring along the x axis. + * @param sigmaY Indicates the Gaussian sigma value for blurring along the y axis. + * @param OH_Drawing_TileMode Indicates the tile mode applied at edges. + * @param OH_Drawing_ImageFilter Indicates the input filter that is blurred, uses source bitmap if this is null. + * @return Returns the pointer to the OH_Drawing_ImageFilter object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_ImageFilter* OH_Drawing_ImageFilterCreateBlur(float sigmaX, float sigmaY, OH_Drawing_TileMode, + OH_Drawing_ImageFilter*); + +/** + * @brief Creates an OH_Drawing_ImageFilter object that applies the color filter to the input. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_ColorFilter Indicates the color filter that transforms the input image. + * @param OH_Drawing_ImageFilter Indicates the input filter, or uses the source bitmap if this is null. + * @return Returns the pointer to the OH_Drawing_ImageFilter object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_ImageFilter* OH_Drawing_ImageFilterCreateFromColorFilter(OH_Drawing_ColorFilter*, OH_Drawing_ImageFilter*); + +/** + * @brief Destroys an OH_Drawing_ImageFilter object and reclaims the memory occupied by the object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_ImageFilter Indicates the pointer to an OH_Drawing_ImageFilter object. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_ImageFilterDestroy(OH_Drawing_ImageFilter*); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif \ No newline at end of file diff --git a/graphic/graphic_2d/native_drawing/drawing_pen.h b/graphic/graphic_2d/native_drawing/drawing_pen.h index 8d7f38726b951ade72a0c9adaec9d56acebd02ad..a541fef46030c8df47ca978adab1e80e3a7aa7e1 100644 --- a/graphic/graphic_2d/native_drawing/drawing_pen.h +++ b/graphic/graphic_2d/native_drawing/drawing_pen.h @@ -53,6 +53,17 @@ extern "C" { */ OH_Drawing_Pen* OH_Drawing_PenCreate(void); +/** + * @brief Creates an OH_Drawing_Pen copy object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Pen Indicates the pointer to an OH_Drawing_Pen object. + * @return Returns the pointer to the OH_Drawing_Pen object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_Pen* OH_Drawing_PenCopy(OH_Drawing_Pen*); + /** * @brief Destroys an OH_Drawing_Pen object and reclaims the memory occupied by the object. * @@ -335,6 +346,24 @@ void OH_Drawing_PenGetFilter(OH_Drawing_Pen*, OH_Drawing_Filter*); */ void OH_Drawing_PenSetBlendMode(OH_Drawing_Pen*, OH_Drawing_BlendMode); +/** + * @brief Gets the filled equivalent of the src path. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_Pen Indicates the pointer to an OH_Drawing_Pen object. + * @param src Indicates the Path read to create a filled version. + * @param dst Indicates the resulting Path. + * @param OH_Drawing_Rect Indicates the pointer to an OH_Drawing_Rect object that limits the PathEffect area if + Pen has PathEffect. + * @param OH_Drawing_Matrix Indicates the pointer to an OH_Drawing_Matrix object that tranfomation applied to + PathEffect if Pen has PathEffect. + * @return true if get success, otherwise false. + * @since 12 + * @version 1.0 + */ +bool OH_Drawing_PenGetFillPath(OH_Drawing_Pen*, const OH_Drawing_Path* src, OH_Drawing_Path* dst, + const OH_Drawing_Rect*, const OH_Drawing_Matrix*); + /** * @brief Resets all pen contents to their initial values. * diff --git a/graphic/graphic_2d/native_drawing/drawing_pixel_map.h b/graphic/graphic_2d/native_drawing/drawing_pixel_map.h index 2203d9fd23694d89a2bbe86414ddb2a92cbb8e76..88d787dc127b0de5c942c25423aa5ac73b583995 100644 --- a/graphic/graphic_2d/native_drawing/drawing_pixel_map.h +++ b/graphic/graphic_2d/native_drawing/drawing_pixel_map.h @@ -50,6 +50,13 @@ extern "C" { */ struct NativePixelMap_; +/** + * @brief Introduces the native pixel map information defined by image framework. + * @since 12 + * @version 1.0 + */ +struct OH_PixelmapNative; + /** * @brief Gets an OH_Drawing_PixelMap object. * @@ -61,6 +68,28 @@ struct NativePixelMap_; */ OH_Drawing_PixelMap* OH_Drawing_PixelMapGetFromNativePixelMap(NativePixelMap_*); +/** + * @brief Gets an OH_Drawing_PixelMap object. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_PixelmapNative Indicates a pointer to the OH_PixelmapNative object supported by image framework. + * @return Returns the pointer to the OH_Drawing_PixelMap object. + * @since 12 + * @version 1.0 + */ +OH_Drawing_PixelMap* OH_Drawing_PixelMapGetFromOhPixelMapNative(OH_PixelmapNative*); + +/** + * @brief Dissolves the relationship between OH_Drawing_PixelMap object and NativePixelMap_ or + OH_PixelmapNative which is build by 'GetFrom' function. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param OH_Drawing_PixelMap Indicates a pointer to the OH_Drawing_PixelMap. + * @since 12 + * @version 1.0 + */ +void OH_Drawing_PixelMapDissolve(OH_Drawing_PixelMap*); + #ifdef __cplusplus } #endif diff --git a/graphic/graphic_2d/native_drawing/drawing_shader_effect.h b/graphic/graphic_2d/native_drawing/drawing_shader_effect.h index 3bd2368d2639045f2cf4c2f346fa6edba69ee865..d180fd0257f72f61ece7b54a01ae224592d9d529 100644 --- a/graphic/graphic_2d/native_drawing/drawing_shader_effect.h +++ b/graphic/graphic_2d/native_drawing/drawing_shader_effect.h @@ -69,6 +69,17 @@ typedef enum { DECAL, } OH_Drawing_TileMode; +/** + * @brief Creates an OH_Drawing_ShaderEffect that generates a shader with single color. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param color Indicates the color used by the shader. + * @return Returns the pointer to the OH_Drawing_ShaderEffect object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateColorShader(const uint32_t color); + /** * @brief Creates an OH_Drawing_ShaderEffect that generates a linear gradient between the two specified points. * @@ -86,6 +97,28 @@ typedef enum { OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateLinearGradient(const OH_Drawing_Point* startPt, const OH_Drawing_Point* endPt, const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); +/** + * @brief Creates an OH_Drawing_ShaderEffect that generates a linear gradient between the two specified points. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param startPt Indicates the start point for the gradient. + * @param endPt Indicates the end point for the gradient. + * @param colors Indicates the colors to be distributed between the two points. + * @param pos Indicates the relative position of each corresponding color in the colors array. + * If pos is nullptr, the colors are evenly distributed between the start and end point. + * @param size Indicates the number of colors and pos(if pos is not nullptr). + * @param OH_Drawing_TileMode Indicates the tile mode. + * @param OH_Drawing_Matrix Indicates the pointer to an OH_Drawing_Matrix object, + which represents the local matrix of the created OH_Drawing_ShaderEffect object. + If matrix is nullptr, defaults to the identity matrix. + * @return Returns the pointer to the OH_Drawing_ShaderEffect object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateLinearGradientWithLocalMatrix( + const OH_Drawing_Point2D* startPt, const OH_Drawing_Point2D* endPt, const uint32_t* colors, const float* pos, + uint32_t size, OH_Drawing_TileMode, const OH_Drawing_Matrix*); + /** * @brief Creates an OH_Drawing_ShaderEffect that generates a radial gradient given the center and radius. * @@ -103,6 +136,27 @@ OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateLinearGradient(const OH_Dr OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateRadialGradient(const OH_Drawing_Point* centerPt, float radius, const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); +/** + * @brief Creates an OH_Drawing_ShaderEffect that generates a radial gradient given the center and radius. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param centerPt Indicates the center of the circle for the gradient. + * @param radius Indicates the radius of the circle for this gradient. + * @param colors Indicates the colors to be distributed between the two points. + * @param pos Indicates the relative position of each corresponding color in the colors array. + * @param size Indicates the number of colors and pos. + * @param OH_Drawing_TileMode Indicates the tile mode. + * @param OH_Drawing_Matrix Indicates the pointer to an OH_Drawing_Matrix object, + which represents the local matrix of the created OH_Drawing_ShaderEffect object. + If matrix is nullptr, defaults to the identity matrix. + * @return Returns the pointer to the OH_Drawing_ShaderEffect object created. + * @since 12 + * @version 1.0 + */ +OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateRadialGradientWithLocalMatrix( + const OH_Drawing_Point2D* centerPt, float radius, const uint32_t* colors, const float* pos, uint32_t size, + OH_Drawing_TileMode, const OH_Drawing_Matrix*); + /** * @brief Creates an OH_Drawing_ShaderEffect that generates a sweep gradient given a center. * diff --git a/graphic/graphic_2d/native_drawing/drawing_types.h b/graphic/graphic_2d/native_drawing/drawing_types.h index 870a910b4936912b7bbbdc342f1f17ddea26fd31..1f1a94aeee303a26a6a5cca863e95660ec4c0e5b 100644 --- a/graphic/graphic_2d/native_drawing/drawing_types.h +++ b/graphic/graphic_2d/native_drawing/drawing_types.h @@ -197,7 +197,7 @@ typedef struct OH_Drawing_ShaderEffect OH_Drawing_ShaderEffect; typedef struct OH_Drawing_ShadowLayer OH_Drawing_ShadowLayer; /** - * @brief Defines a filter, which is used to store maskFilter and colorFilter. + * @brief Defines a filter, which is used to store maskFilter, colorFilter and imageFilter. * * @since 11 * @version 1.0 @@ -261,6 +261,14 @@ typedef struct OH_Drawing_TextBlob OH_Drawing_TextBlob; */ typedef struct OH_Drawing_Image OH_Drawing_Image; +/** + * @brief Defines a image filter, which is used to operate on all the color bits of pixels that make up an image. + * + * @since 12 + * @version 1.0 + */ +typedef struct OH_Drawing_ImageFilter OH_Drawing_ImageFilter; + /** * @brief Defines a sampling options, which is used to describe the sampling mode. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index e41daf79704162c2bff6fbd9146f76e5dbfc9cd9..c4548a80a1494bd21607ea0e6670f4e04f6490d8 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -23,6 +23,10 @@ "name": "OH_Drawing_BitmapReadPixels" }, { "name": "OH_Drawing_BrushCreate" }, + { + "first_introduced": "12", + "name": "OH_Drawing_BrushCopy" + }, { "name": "OH_Drawing_BrushDestroy" }, { "name": "OH_Drawing_BrushGetAlpha" }, { "name": "OH_Drawing_BrushSetAlpha" }, @@ -134,6 +138,10 @@ "first_introduced": "12", "name": "OH_Drawing_FilterGetColorFilter" }, + { + "first_introduced": "12", + "name": "OH_Drawing_FilterSetImageFilter" + }, { "name": "OH_Drawing_FilterSetMaskFilter" }, { "name": "OH_Drawing_FilterDestroy" }, { "name": "OH_Drawing_FontCreate" }, @@ -234,6 +242,18 @@ "first_introduced": "12", "name": "OH_Drawing_GpuContextDestroy" }, + { + "first_introduced": "12", + "name": "OH_Drawing_ImageFilterCreateBlur" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_ImageFilterCreateFromColorFilter" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_ImageFilterDestroy" + }, { "name": "OH_Drawing_MaskFilterCreateBlur" }, { "name": "OH_Drawing_MaskFilterDestroy" }, { "name": "OH_Drawing_MatrixCreate" }, @@ -364,6 +384,10 @@ }, { "name": "OH_Drawing_PathReset" }, { "name": "OH_Drawing_PenCreate" }, + { + "first_introduced": "12", + "name": "OH_Drawing_PenCopy" + }, { "name": "OH_Drawing_PenDestroy" }, { "name": "OH_Drawing_PenGetAlpha" }, { "name": "OH_Drawing_PenSetAlpha" }, @@ -380,6 +404,10 @@ { "name": "OH_Drawing_PenSetCap" }, { "name": "OH_Drawing_PenGetJoin" }, { "name": "OH_Drawing_PenSetJoin" }, + { + "first_introduced": "12", + "name": "OH_Drawing_PenGetFillPath" + }, { "name": "OH_Drawing_PenSetFilter" }, { "first_introduced": "12", @@ -492,8 +520,20 @@ { "name": "OH_Drawing_SetTextStyleFontFamilies" }, { "name": "OH_Drawing_SetTextStyleFontStyle" }, { "name": "OH_Drawing_SetTextStyleLocale" }, + { + "first_introduced": "12", + "name": "OH_Drawing_ShaderEffectCreateColorShader" + }, { "name": "OH_Drawing_ShaderEffectCreateLinearGradient" }, + { + "first_introduced": "12", + "name": "OH_Drawing_ShaderEffectCreateLinearGradientWithLocalMatrix" + }, { "name": "OH_Drawing_ShaderEffectCreateRadialGradient" }, + { + "first_introduced": "12", + "name": "OH_Drawing_ShaderEffectCreateRadialGradientWithLocalMatrix" + }, { "name": "OH_Drawing_ShaderEffectCreateSweepGradient" }, { "first_introduced": "12", @@ -559,7 +599,19 @@ "first_introduced": "12", "name": "OH_Drawing_PixelMapGetFromNativePixelMap" }, + { + "first_introduced": "12", + "name": "OH_Drawing_PixelMapGetFromOhPixelMapNative" + }, + { + "first_introduced": "12", + "name": "OH_Drawing_PixelMapDissolve" + }, { "name": "OH_Drawing_ImageCreate" }, + { + "first_introduced": "12", + "name": "OH_Drawing_ImageCreateFromEncodedData" + }, { "name": "OH_Drawing_ImageDestroy" }, { "name": "OH_Drawing_ImageBuildFromBitmap" }, { "name": "OH_Drawing_ImageGetWidth" },