From 971b53e2a969a367b6ec1c31c0f309a963ee20d3 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Mon, 31 Oct 2022 11:15:55 +0900 Subject: [PATCH] display: add getter/setter for white balance Add a getter and setter function of display white balance which controls RGB gain and offset. White balancing is adjusting standard point of white color, this because the light source is different for each device. gain value is a value to be multiplied for RGB calculation. offset value is a value to be added for RGB calculation. These are function prototype to be added. int device_display_set_white_balance(int display_index, display_white_balance_e white_balance_type, int value); int device_display_get_white_balance(int display_index, display_white_balance_e white_balance_type, int *value); With this enum type, we can get and set RGB gain and offset value for white balancing. It is used as a parameter of getter and setter. typedef enum { DISPLAY_WHITE_BALANCE_R_GAIN = 0, /** White balance R Gain */ DISPLAY_WHITE_BALANCE_G_GAIN, /** White balance G Gain */ DISPLAY_WHITE_BALANCE_B_GAIN, /** White balance B Gain */ DISPLAY_WHITE_BALANCE_R_OFFSET, /** White balance R Offset */ DISPLAY_WHITE_BALANCE_G_OFFSET, /** White balance G Offset */ DISPLAY_WHITE_BALANCE_B_OFFSET, /** White balance B Offset */ } display_white_balance_e; Change-Id: Ie0adc74e76bcc8e8324767448aa03e3cce585af4 Signed-off-by: Yunhee Seo --- include/display-enum.h | 12 +++++- include/display-internal.h | 44 +++++++++++++++++++ src/display.c | 103 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+), 1 deletion(-) diff --git a/include/display-enum.h b/include/display-enum.h index 9434bde..c1decbc 100644 --- a/include/display-enum.h +++ b/include/display-enum.h @@ -22,9 +22,19 @@ typedef enum } display_state_e; /** - * @} + * @brief Enumeration for the adjustment display white balance. + * @since_tizen 7.0 */ +typedef enum +{ + DISPLAY_WHITE_BALANCE_R_GAIN = 0, /** White balance R Gain */ + DISPLAY_WHITE_BALANCE_G_GAIN, /** White balance G Gain */ + DISPLAY_WHITE_BALANCE_B_GAIN, /** White balance B Gain */ + DISPLAY_WHITE_BALANCE_R_OFFSET, /** White balance R Offset */ + DISPLAY_WHITE_BALANCE_G_OFFSET, /** White balance G Offset */ + DISPLAY_WHITE_BALANCE_B_OFFSET, /** White balance B Offset */ +} display_white_balance_e; #ifdef __cplusplus } diff --git a/include/display-internal.h b/include/display-internal.h index f80e58e..d214553 100644 --- a/include/display-internal.h +++ b/include/display-internal.h @@ -136,6 +136,50 @@ int is_feature_display_supported(void); * otherwise 0 */ int is_feature_display_state_supported(void); + +/** + * @brief Change display white balance value. + * @since_tizen 7.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display \n + * @param[in] display_index The index of the display \n +* It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n +* The index zero is always assigned to the main display + * @param[in] white_balance_type The type to adjust white balance value + * @param[in] value The value to be set for white balance type + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported in this device + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @see device_display_get_numbers() + */ +int device_display_set_white_balance(int display_index, display_white_balance_e white_balance_type, int value); + +/** + * @brief Get display white balance value. + * @since_tizen 7.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display \n + * @param[in] display_index The index of the display \n +* It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n +* The index zero is always assigned to the main display + * @param[in] white_balance_type The type to get current white balance value + * @param[out] value The white balance type value of the display + * @return @c 0 on success, + * otherwise a negative error value + * @retval #DEVICE_ERROR_NONE Successful + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported in this device + * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation not permitted + * @see device_display_get_numbers() + */ +int device_display_get_white_balance(int display_index, display_white_balance_e white_balance_type, int *value); + #ifdef __cplusplus } #endif diff --git a/src/display.c b/src/display.c index e8e25c8..0a9d9ce 100644 --- a/src/display.c +++ b/src/display.c @@ -34,11 +34,18 @@ #define METHOD_SET_BRIGHTNESS "SetBrightness" #define METHOD_CHANGE_STATE "changestate" #define METHOD_CHANGE_STATE_BY_REASON "ChangeStateByReason" +#define METHOD_GET_WHITE_BALANCE "GetWhiteBalance" +#define METHOD_SET_WHITE_BALANCE "SetWhiteBalance" #define STR_LCD_OFF "lcdoff" #define STR_LCD_DIM "lcddim" #define STR_LCD_ON "lcdon" +#define DISPLAY_WHITE_BALANCE_GAIN_MAX 2047 +#define DISPLAY_WHITE_BALANCE_GAIN_MIN 0 +#define DISPLAY_WHITE_BALANCE_OFFSET_MAX 2047 +#define DISPLAY_WHITE_BALANCE_OFFSET_MIN 0 + static int display_cnt = -1; struct display { int normal_max; @@ -487,3 +494,99 @@ int is_feature_display_state_supported(void) } else return true; } + +int device_display_set_white_balance(int display_index, display_white_balance_e white_balance_type, int value) +{ + int ret; + + if (!is_feature_display_supported()) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret != DEVICE_ERROR_NONE) + return ret; + } + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + switch (white_balance_type) { + case DISPLAY_WHITE_BALANCE_R_GAIN: + case DISPLAY_WHITE_BALANCE_G_GAIN: + case DISPLAY_WHITE_BALANCE_B_GAIN: + if (value < DISPLAY_WHITE_BALANCE_GAIN_MIN || value > DISPLAY_WHITE_BALANCE_GAIN_MAX) { + _E("Invalid value of white balance gain (%d)", white_balance_type); + return DEVICE_ERROR_INVALID_PARAMETER; + } + break; + case DISPLAY_WHITE_BALANCE_R_OFFSET: + case DISPLAY_WHITE_BALANCE_G_OFFSET: + case DISPLAY_WHITE_BALANCE_B_OFFSET: + if (value < DISPLAY_WHITE_BALANCE_OFFSET_MIN || value > DISPLAY_WHITE_BALANCE_OFFSET_MAX) { + _E("Invalid value of white balance offset (%d)", white_balance_type); + return DEVICE_ERROR_INVALID_PARAMETER; + } + break; + default: + _E("Unknown white balance type"); + return DEVICE_ERROR_INVALID_PARAMETER; + } + + ret = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_SET_WHITE_BALANCE, g_variant_new("(ii)", + (int)white_balance_type, value), + NULL); + + if (ret < 0) + return errno_to_device_error(ret); + + return DEVICE_ERROR_NONE; +} + +int device_display_get_white_balance(int display_index, display_white_balance_e white_balance_type, int *value) +{ + int ret, reply; + + if (!is_feature_display_supported()) + return DEVICE_ERROR_NOT_SUPPORTED; + + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret != DEVICE_ERROR_NONE) + return ret; + } + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + + switch (white_balance_type) { + case DISPLAY_WHITE_BALANCE_R_GAIN: + case DISPLAY_WHITE_BALANCE_G_GAIN: + case DISPLAY_WHITE_BALANCE_B_GAIN: + case DISPLAY_WHITE_BALANCE_R_OFFSET: + case DISPLAY_WHITE_BALANCE_G_OFFSET: + case DISPLAY_WHITE_BALANCE_B_OFFSET: + break; + default: + _E("Unknown white balance type"); + return DEVICE_ERROR_INVALID_PARAMETER; + } + + ret = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_WHITE_BALANCE, g_variant_new("(i)", + (int)white_balance_type), + &reply); + + if (ret < 0) + return errno_to_device_error(ret); + + if (reply < 0) + return DEVICE_ERROR_OPERATION_FAILED; + + *value = reply; + + return DEVICE_ERROR_NONE; +} \ No newline at end of file -- 2.7.4