From 541d805c67fe1e95bb441217a4834092b0aaa478 Mon Sep 17 00:00:00 2001 From: lw19901203 Date: Mon, 28 Apr 2025 13:38:27 +0800 Subject: [PATCH] drawing colorspace interface C upload Signed-off-by: lw19901203 --- .../graphic_2d/native_drawing/drawing_brush.h | 86 ++++++++++++++++++- .../graphic_2d/native_drawing/drawing_pen.h | 86 ++++++++++++++++++- .../native_drawing/libnative_drawing.ndk.json | 40 +++++++++ 3 files changed, 210 insertions(+), 2 deletions(-) diff --git a/graphic/graphic_2d/native_drawing/drawing_brush.h b/graphic/graphic_2d/native_drawing/drawing_brush.h index d677d9aec..0621b9628 100644 --- a/graphic/graphic_2d/native_drawing/drawing_brush.h +++ b/graphic/graphic_2d/native_drawing/drawing_brush.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -40,12 +40,19 @@ #ifndef C_INCLUDE_DRAWING_BRUSH_H #define C_INCLUDE_DRAWING_BRUSH_H +#include "drawing_error_code.h" #include "drawing_types.h" #ifdef __cplusplus extern "C" { #endif +/** + * @brief Defines a colorspace manager. Introduces the color space information defined by ColorManager. + * @since 20 + */ +typedef struct OH_NativeColorSpaceManager OH_NativeColorSpaceManager; + /** * @brief Creates an OH_Drawing_Brush object. * @@ -148,6 +155,83 @@ uint8_t OH_Drawing_BrushGetAlpha(const OH_Drawing_Brush* brush); */ void OH_Drawing_BrushSetAlpha(OH_Drawing_Brush* brush, uint8_t alpha); +/** + * @brief Sets the color for a brush. The color will be used by the brush to fill in a shape. + * The color is an ARGB structure described by floating point numbers and interpreted as being in the colorSpaceManager. + * If colorSpaceManager is nullptr, then color is assumed to be in the sRGB color space. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param brush Indicates the pointer to an OH_Drawing_Brush object. + * @param a Indicates the alpha component of color, represented as a floating point number between 0 and 1. + * @param r Indicates the red component of color, represented as a floating point number between 0 and 1. + * @param g Indicates the green component of color, represented as a floating point number between 0 and 1. + * @param b Indicates the blue component of color, represented as a floating point number between 0 and 1. + * @param colorSpaceManager Indicates the the pointer to an OH_NativeColorSpaceManager object. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_BrushSetColor4f(OH_Drawing_Brush* brush, float a, float r, float g, float b, + OH_NativeColorSpaceManager* colorSpaceManager); + +/** + * @brief Obtains the alpha component of a brush. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param brush Indicates the pointer to an OH_Drawing_Brush object. + * @param a Indicates the alpha component of color. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush or a is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_BrushGetAlphaFloat(const OH_Drawing_Brush* brush, float* a); + +/** + * @brief Obtains the red component of a brush. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param brush Indicates the pointer to an OH_Drawing_Brush object. + * @param r Indicates the red component of color. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush or r is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_BrushGetRedFloat(const OH_Drawing_Brush* brush, float* r); + +/** + * @brief Obtains the green component of a brush. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param brush Indicates the pointer to an OH_Drawing_Brush object. + * @param g Indicates the green component of color. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush or g is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_BrushGetGreenFloat(const OH_Drawing_Brush* brush, float* g); + +/** + * @brief Obtains the blue component of a brush. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param brush Indicates the pointer to an OH_Drawing_Brush object. + * @param b Indicates the blue component of color. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if brush or b is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_BrushGetBlueFloat(const OH_Drawing_Brush* brush, float* b); + /** * @brief Sets the shaderEffect for a brush. * diff --git a/graphic/graphic_2d/native_drawing/drawing_pen.h b/graphic/graphic_2d/native_drawing/drawing_pen.h index 7465f4eba..cd76b1914 100644 --- a/graphic/graphic_2d/native_drawing/drawing_pen.h +++ b/graphic/graphic_2d/native_drawing/drawing_pen.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 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 @@ -40,12 +40,19 @@ #ifndef C_INCLUDE_DRAWING_PEN_H #define C_INCLUDE_DRAWING_PEN_H +#include "drawing_error_code.h" #include "drawing_types.h" #ifdef __cplusplus extern "C" { #endif +/** + * @brief Defines a colorspace manager. Introduces the color space information defined by ColorManager. + * @since 20 + */ +typedef struct OH_NativeColorSpaceManager OH_NativeColorSpaceManager; + /** * @brief Creates an OH_Drawing_Pen object. * @@ -148,6 +155,83 @@ uint8_t OH_Drawing_PenGetAlpha(const OH_Drawing_Pen* pen); */ void OH_Drawing_PenSetAlpha(OH_Drawing_Pen* pen, uint8_t alpha); +/** + * @brief Sets the color for a pen. The color will be used by the pen to fill in a shape. + * The color is an ARGB structure described by floating point numbers and interpreted as being in the colorSpaceManager. + * If colorSpaceManager is nullptr, then color is assumed to be in the sRGB color space. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param pen Indicates the pointer to an OH_Drawing_Pen object. + * @param a Indicates the alpha component of color, represented as a floating point number between 0 and 1. + * @param r Indicates the red component of color, represented as a floating point number between 0 and 1. + * @param g Indicates the green component of color, represented as a floating point number between 0 and 1. + * @param b Indicates the blue component of color, represented as a floating point number between 0 and 1. + * @param colorSpaceManager Indicates the the pointer to an OH_NativeColorSpaceManager object. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if pen is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_PenSetColor4f(OH_Drawing_Pen* pen, float a, float r, float g, float b, + OH_NativeColorSpaceManager* colorSpaceManager); + +/** + * @brief Obtains the alpha component of a pen. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param pen Indicates the pointer to an OH_Drawing_Pen object. + * @param a Indicates the alpha component of color. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if pen or a is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_PenGetAlphaFloat(OH_Drawing_Pen* pen, float* a); + +/** + * @brief Obtains the red component of a pen. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param pen Indicates the pointer to an OH_Drawing_Pen object. + * @param r Indicates the red component of color. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if pen or r is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_PenGetRedFloat(OH_Drawing_Pen* pen, float* r); + +/** + * @brief Obtains the green component of a pen. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param pen Indicates the pointer to an OH_Drawing_Pen object. + * @param g Indicates the green component of color. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if pen or g is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_PenGetGreenFloat(OH_Drawing_Pen* pen, float* g); + +/** + * @brief Obtains the blue component of a pen. + * + * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing + * @param pen Indicates the pointer to an OH_Drawing_Pen object. + * @param b Indicates the blue component of color. + * @return Returns the error code. + * Returns {@link OH_DRAWING_SUCCESS} if the operation is successful. + * Returns {@link OH_DRAWING_ERROR_INVALID_PARAMETER} if pen or b is nullptr. + * @since 20 + * @version 1.0 + */ +OH_Drawing_ErrorCode OH_Drawing_PenGetBlueFloat(OH_Drawing_Pen* pen, float* b); + /** * @brief Obtains the thickness of a pen. This thickness determines the width of the outline of a shape. * diff --git a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json index e13687d42..0f69ff4ac 100644 --- a/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json +++ b/graphic/graphic_2d/native_drawing/libnative_drawing.ndk.json @@ -29,12 +29,32 @@ }, { "name": "OH_Drawing_BrushDestroy" }, { "name": "OH_Drawing_BrushGetAlpha" }, + { + "first_introduced": "20", + "name": "OH_Drawing_BrushGetAlphaFloat" + }, + { + "first_introduced": "20", + "name": "OH_Drawing_BrushGetRedFloat" + }, + { + "first_introduced": "20", + "name": "OH_Drawing_BrushGetGreenFloat" + }, + { + "first_introduced": "20", + "name": "OH_Drawing_BrushGetBlueFloat" + }, { "name": "OH_Drawing_BrushSetAlpha" }, { "name": "OH_Drawing_BrushSetBlendMode" }, { "name": "OH_Drawing_BrushIsAntiAlias" }, { "name": "OH_Drawing_BrushSetAntiAlias" }, { "name": "OH_Drawing_BrushGetColor" }, { "name": "OH_Drawing_BrushSetColor" }, + { + "first_introduced": "20", + "name": "OH_Drawing_BrushSetColor4f" + }, { "name": "OH_Drawing_BrushSetFilter" }, { "first_introduced": "12", @@ -523,11 +543,31 @@ { "name": "OH_Drawing_PenDestroy" }, { "name": "OH_Drawing_PenGetAlpha" }, { "name": "OH_Drawing_PenSetAlpha" }, + { + "first_introduced": "20", + "name": "OH_Drawing_PenGetAlphaFloat" + }, + { + "first_introduced": "20", + "name": "OH_Drawing_PenGetRedFloat" + }, + { + "first_introduced": "20", + "name": "OH_Drawing_PenGetGreenFloat" + }, + { + "first_introduced": "20", + "name": "OH_Drawing_PenGetBlueFloat" + }, { "name": "OH_Drawing_PenSetBlendMode" }, { "name": "OH_Drawing_PenIsAntiAlias" }, { "name": "OH_Drawing_PenSetAntiAlias" }, { "name": "OH_Drawing_PenGetColor" }, { "name": "OH_Drawing_PenSetColor" }, + { + "first_introduced": "20", + "name": "OH_Drawing_PenSetColor4f" + }, { "name": "OH_Drawing_PenGetWidth" }, { "name": "OH_Drawing_PenSetWidth" }, { "name": "OH_Drawing_PenGetMiterLimit" }, -- Gitee