display: add getter/setter for white balance 90/284290/1 accepted/tizen/7.0/unified/20221117.014346
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 31 Oct 2022 02:15:55 +0000 (11:15 +0900)
committeryunhee seo <yuni.seo@samsung.com>
Tue, 15 Nov 2022 04:51:42 +0000 (04:51 +0000)
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 <yuni.seo@samsung.com>
(cherry picked from commit 971b53e2a969a367b6ec1c31c0f309a963ee20d3)

include/display-enum.h
include/display-internal.h
src/display.c

index 9434bde3478441ea27e363f9201ef78dee02d85b..c1decbc4fc563bde4d4aa7abce15c3bc7af5e705 100644 (file)
@@ -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
 }
index f80e58e0b49e68226931f9c686204483e223da7c..d214553424786e8a9088f2698ff97c527560494f 100644 (file)
@@ -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
index e8e25c89e7949f2114f0d2761f809849d26ef21d..0a9d9ce70b9860500d3624cadc652e5ca4012cf1 100644 (file)
 #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