2 * Copyright 2016 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
28 #include "color_gamma.h"
31 #define NUM_PTS_IN_REGION 16
32 #define NUM_REGIONS 32
33 #define MAX_HW_POINTS (NUM_PTS_IN_REGION*NUM_REGIONS)
35 static struct hw_x_point coordinates_x[MAX_HW_POINTS + 2];
37 static struct fixed31_32 pq_table[MAX_HW_POINTS + 2];
38 static struct fixed31_32 de_pq_table[MAX_HW_POINTS + 2];
40 static bool pq_initialized; /* = false; */
41 static bool de_pq_initialized; /* = false; */
43 /* one-time setup of X points */
44 void setup_x_points_distribution(void)
46 struct fixed31_32 region_size = dc_fixpt_from_int(128);
50 struct fixed31_32 increment;
52 coordinates_x[MAX_HW_POINTS].x = region_size;
53 coordinates_x[MAX_HW_POINTS + 1].x = region_size;
55 for (segment = 6; segment > (6 - NUM_REGIONS); segment--) {
56 region_size = dc_fixpt_div_int(region_size, 2);
57 increment = dc_fixpt_div_int(region_size,
59 seg_offset = (segment + (NUM_REGIONS - 7)) * NUM_PTS_IN_REGION;
60 coordinates_x[seg_offset].x = region_size;
62 for (index = seg_offset + 1;
63 index < seg_offset + NUM_PTS_IN_REGION;
65 coordinates_x[index].x = dc_fixpt_add
66 (coordinates_x[index-1].x, increment);
71 static void compute_pq(struct fixed31_32 in_x, struct fixed31_32 *out_y)
73 /* consts for PQ gamma formula. */
74 const struct fixed31_32 m1 =
75 dc_fixpt_from_fraction(159301758, 1000000000);
76 const struct fixed31_32 m2 =
77 dc_fixpt_from_fraction(7884375, 100000);
78 const struct fixed31_32 c1 =
79 dc_fixpt_from_fraction(8359375, 10000000);
80 const struct fixed31_32 c2 =
81 dc_fixpt_from_fraction(188515625, 10000000);
82 const struct fixed31_32 c3 =
83 dc_fixpt_from_fraction(186875, 10000);
85 struct fixed31_32 l_pow_m1;
86 struct fixed31_32 base;
88 if (dc_fixpt_lt(in_x, dc_fixpt_zero))
91 l_pow_m1 = dc_fixpt_pow(in_x, m1);
94 (dc_fixpt_mul(c2, l_pow_m1))),
95 dc_fixpt_add(dc_fixpt_one,
96 (dc_fixpt_mul(c3, l_pow_m1))));
97 *out_y = dc_fixpt_pow(base, m2);
100 static void compute_de_pq(struct fixed31_32 in_x, struct fixed31_32 *out_y)
102 /* consts for dePQ gamma formula. */
103 const struct fixed31_32 m1 =
104 dc_fixpt_from_fraction(159301758, 1000000000);
105 const struct fixed31_32 m2 =
106 dc_fixpt_from_fraction(7884375, 100000);
107 const struct fixed31_32 c1 =
108 dc_fixpt_from_fraction(8359375, 10000000);
109 const struct fixed31_32 c2 =
110 dc_fixpt_from_fraction(188515625, 10000000);
111 const struct fixed31_32 c3 =
112 dc_fixpt_from_fraction(186875, 10000);
114 struct fixed31_32 l_pow_m1;
115 struct fixed31_32 base, div;
118 if (dc_fixpt_lt(in_x, dc_fixpt_zero))
119 in_x = dc_fixpt_zero;
121 l_pow_m1 = dc_fixpt_pow(in_x,
122 dc_fixpt_div(dc_fixpt_one, m2));
123 base = dc_fixpt_sub(l_pow_m1, c1);
125 if (dc_fixpt_lt(base, dc_fixpt_zero))
126 base = dc_fixpt_zero;
128 div = dc_fixpt_sub(c2, dc_fixpt_mul(c3, l_pow_m1));
130 *out_y = dc_fixpt_pow(dc_fixpt_div(base, div),
131 dc_fixpt_div(dc_fixpt_one, m1));
134 /* one-time pre-compute PQ values - only for sdr_white_level 80 */
135 void precompute_pq(void)
139 const struct hw_x_point *coord_x = coordinates_x + 32;
140 struct fixed31_32 scaling_factor =
141 dc_fixpt_from_fraction(80, 10000);
143 /* pow function has problems with arguments too small */
144 for (i = 0; i < 32; i++)
145 pq_table[i] = dc_fixpt_zero;
147 for (i = 32; i <= MAX_HW_POINTS; i++) {
148 x = dc_fixpt_mul(coord_x->x, scaling_factor);
149 compute_pq(x, &pq_table[i]);
154 /* one-time pre-compute dePQ values - only for max pixel value 125 FP16 */
155 void precompute_de_pq(void)
159 uint32_t begin_index, end_index;
161 struct fixed31_32 scaling_factor = dc_fixpt_from_int(125);
163 /* X points is 2^-25 to 2^7
164 * De-gamma X is 2^-12 to 2^0 – we are skipping first -12-(-25) = 13 regions
166 begin_index = 13 * NUM_PTS_IN_REGION;
167 end_index = begin_index + 12 * NUM_PTS_IN_REGION;
169 for (i = 0; i <= begin_index; i++)
170 de_pq_table[i] = dc_fixpt_zero;
172 for (; i <= end_index; i++) {
173 compute_de_pq(coordinates_x[i].x, &y);
174 de_pq_table[i] = dc_fixpt_mul(y, scaling_factor);
177 for (; i <= MAX_HW_POINTS; i++)
178 de_pq_table[i] = de_pq_table[i-1];
181 struct fixed31_32 divider1;
182 struct fixed31_32 divider2;
183 struct fixed31_32 divider3;
186 static void build_coefficients(struct gamma_coefficients *coefficients, bool is_2_4)
188 static const int32_t numerator01[] = { 31308, 180000};
189 static const int32_t numerator02[] = { 12920, 4500};
190 static const int32_t numerator03[] = { 55, 99};
191 static const int32_t numerator04[] = { 55, 99};
192 static const int32_t numerator05[] = { 2400, 2200};
195 uint32_t index = is_2_4 == true ? 0:1;
198 coefficients->a0[i] = dc_fixpt_from_fraction(
199 numerator01[index], 10000000);
200 coefficients->a1[i] = dc_fixpt_from_fraction(
201 numerator02[index], 1000);
202 coefficients->a2[i] = dc_fixpt_from_fraction(
203 numerator03[index], 1000);
204 coefficients->a3[i] = dc_fixpt_from_fraction(
205 numerator04[index], 1000);
206 coefficients->user_gamma[i] = dc_fixpt_from_fraction(
207 numerator05[index], 1000);
210 } while (i != ARRAY_SIZE(coefficients->a0));
213 static struct fixed31_32 translate_from_linear_space(
214 struct fixed31_32 arg,
215 struct fixed31_32 a0,
216 struct fixed31_32 a1,
217 struct fixed31_32 a2,
218 struct fixed31_32 a3,
219 struct fixed31_32 gamma)
221 const struct fixed31_32 one = dc_fixpt_from_int(1);
223 if (dc_fixpt_lt(one, arg))
226 if (dc_fixpt_le(arg, dc_fixpt_neg(a0)))
235 dc_fixpt_recip(gamma))));
236 else if (dc_fixpt_le(a0, arg))
244 dc_fixpt_recip(gamma))),
252 static struct fixed31_32 translate_to_linear_space(
253 struct fixed31_32 arg,
254 struct fixed31_32 a0,
255 struct fixed31_32 a1,
256 struct fixed31_32 a2,
257 struct fixed31_32 a3,
258 struct fixed31_32 gamma)
260 struct fixed31_32 linear;
262 a0 = dc_fixpt_mul(a0, a1);
263 if (dc_fixpt_le(arg, dc_fixpt_neg(a0)))
265 linear = dc_fixpt_neg(
268 dc_fixpt_sub(a2, arg),
270 dc_fixpt_one, a3)), gamma));
272 else if (dc_fixpt_le(dc_fixpt_neg(a0), arg) &&
273 dc_fixpt_le(arg, a0))
274 linear = dc_fixpt_div(arg, a1);
276 linear = dc_fixpt_pow(
278 dc_fixpt_add(a2, arg),
280 dc_fixpt_one, a3)), gamma);
285 static inline struct fixed31_32 translate_from_linear_space_ex(
286 struct fixed31_32 arg,
287 struct gamma_coefficients *coeff,
288 uint32_t color_index)
290 return translate_from_linear_space(
292 coeff->a0[color_index],
293 coeff->a1[color_index],
294 coeff->a2[color_index],
295 coeff->a3[color_index],
296 coeff->user_gamma[color_index]);
300 static inline struct fixed31_32 translate_to_linear_space_ex(
301 struct fixed31_32 arg,
302 struct gamma_coefficients *coeff,
303 uint32_t color_index)
305 return translate_to_linear_space(
307 coeff->a0[color_index],
308 coeff->a1[color_index],
309 coeff->a2[color_index],
310 coeff->a3[color_index],
311 coeff->user_gamma[color_index]);
315 static bool find_software_points(
316 const struct dc_gamma *ramp,
317 const struct gamma_pixel *axis_x,
318 struct fixed31_32 hw_point,
319 enum channel_name channel,
320 uint32_t *index_to_start,
321 uint32_t *index_left,
322 uint32_t *index_right,
323 enum hw_point_position *pos)
325 const uint32_t max_number = ramp->num_entries + 3;
327 struct fixed31_32 left, right;
329 uint32_t i = *index_to_start;
331 while (i < max_number) {
332 if (channel == CHANNEL_NAME_RED) {
335 if (i < max_number - 1)
336 right = axis_x[i + 1].r;
338 right = axis_x[max_number - 1].r;
339 } else if (channel == CHANNEL_NAME_GREEN) {
342 if (i < max_number - 1)
343 right = axis_x[i + 1].g;
345 right = axis_x[max_number - 1].g;
349 if (i < max_number - 1)
350 right = axis_x[i + 1].b;
352 right = axis_x[max_number - 1].b;
355 if (dc_fixpt_le(left, hw_point) &&
356 dc_fixpt_le(hw_point, right)) {
360 if (i < max_number - 1)
361 *index_right = i + 1;
363 *index_right = max_number - 1;
365 *pos = HW_POINT_POSITION_MIDDLE;
368 } else if ((i == *index_to_start) &&
369 dc_fixpt_le(hw_point, left)) {
374 *pos = HW_POINT_POSITION_LEFT;
377 } else if ((i == max_number - 1) &&
378 dc_fixpt_le(right, hw_point)) {
383 *pos = HW_POINT_POSITION_RIGHT;
394 static bool build_custom_gamma_mapping_coefficients_worker(
395 const struct dc_gamma *ramp,
396 struct pixel_gamma_point *coeff,
397 const struct hw_x_point *coordinates_x,
398 const struct gamma_pixel *axis_x,
399 enum channel_name channel,
400 uint32_t number_of_points)
404 while (i <= number_of_points) {
405 struct fixed31_32 coord_x;
407 uint32_t index_to_start = 0;
408 uint32_t index_left = 0;
409 uint32_t index_right = 0;
411 enum hw_point_position hw_pos;
413 struct gamma_point *point;
415 struct fixed31_32 left_pos;
416 struct fixed31_32 right_pos;
418 if (channel == CHANNEL_NAME_RED)
419 coord_x = coordinates_x[i].regamma_y_red;
420 else if (channel == CHANNEL_NAME_GREEN)
421 coord_x = coordinates_x[i].regamma_y_green;
423 coord_x = coordinates_x[i].regamma_y_blue;
425 if (!find_software_points(
426 ramp, axis_x, coord_x, channel,
427 &index_to_start, &index_left, &index_right, &hw_pos)) {
432 if (index_left >= ramp->num_entries + 3) {
437 if (index_right >= ramp->num_entries + 3) {
442 if (channel == CHANNEL_NAME_RED) {
445 left_pos = axis_x[index_left].r;
446 right_pos = axis_x[index_right].r;
447 } else if (channel == CHANNEL_NAME_GREEN) {
450 left_pos = axis_x[index_left].g;
451 right_pos = axis_x[index_right].g;
455 left_pos = axis_x[index_left].b;
456 right_pos = axis_x[index_right].b;
459 if (hw_pos == HW_POINT_POSITION_MIDDLE)
460 point->coeff = dc_fixpt_div(
467 else if (hw_pos == HW_POINT_POSITION_LEFT)
468 point->coeff = dc_fixpt_zero;
469 else if (hw_pos == HW_POINT_POSITION_RIGHT)
470 point->coeff = dc_fixpt_from_int(2);
476 point->left_index = index_left;
477 point->right_index = index_right;
486 static struct fixed31_32 calculate_mapped_value(
487 struct pwl_float_data *rgb,
488 const struct pixel_gamma_point *coeff,
489 enum channel_name channel,
492 const struct gamma_point *point;
494 struct fixed31_32 result;
496 if (channel == CHANNEL_NAME_RED)
498 else if (channel == CHANNEL_NAME_GREEN)
503 if ((point->left_index < 0) || (point->left_index > max_index)) {
505 return dc_fixpt_zero;
508 if ((point->right_index < 0) || (point->right_index > max_index)) {
510 return dc_fixpt_zero;
513 if (point->pos == HW_POINT_POSITION_MIDDLE)
514 if (channel == CHANNEL_NAME_RED)
515 result = dc_fixpt_add(
519 rgb[point->right_index].r,
520 rgb[point->left_index].r)),
521 rgb[point->left_index].r);
522 else if (channel == CHANNEL_NAME_GREEN)
523 result = dc_fixpt_add(
527 rgb[point->right_index].g,
528 rgb[point->left_index].g)),
529 rgb[point->left_index].g);
531 result = dc_fixpt_add(
535 rgb[point->right_index].b,
536 rgb[point->left_index].b)),
537 rgb[point->left_index].b);
538 else if (point->pos == HW_POINT_POSITION_LEFT) {
540 result = dc_fixpt_zero;
543 result = dc_fixpt_one;
549 static void build_pq(struct pwl_float_data_ex *rgb_regamma,
550 uint32_t hw_points_num,
551 const struct hw_x_point *coordinate_x,
552 uint32_t sdr_white_level)
554 uint32_t i, start_index;
556 struct pwl_float_data_ex *rgb = rgb_regamma;
557 const struct hw_x_point *coord_x = coordinate_x;
559 struct fixed31_32 output;
560 struct fixed31_32 scaling_factor =
561 dc_fixpt_from_fraction(sdr_white_level, 10000);
563 if (!pq_initialized && sdr_white_level == 80) {
565 pq_initialized = true;
568 /* TODO: start index is from segment 2^-24, skipping first segment
569 * due to x values too small for power calculations
573 coord_x += start_index;
575 for (i = start_index; i <= hw_points_num; i++) {
576 /* Multiply 0.008 as regamma is 0-1 and FP16 input is 0-125.
579 if (sdr_white_level == 80) {
580 output = pq_table[i];
582 x = dc_fixpt_mul(coord_x->x, scaling_factor);
583 compute_pq(x, &output);
586 /* should really not happen? */
587 if (dc_fixpt_lt(output, dc_fixpt_zero))
588 output = dc_fixpt_zero;
589 else if (dc_fixpt_lt(dc_fixpt_one, output))
590 output = dc_fixpt_one;
601 static void build_de_pq(struct pwl_float_data_ex *de_pq,
602 uint32_t hw_points_num,
603 const struct hw_x_point *coordinate_x)
606 struct fixed31_32 output;
608 struct fixed31_32 scaling_factor = dc_fixpt_from_int(125);
610 if (!de_pq_initialized) {
612 de_pq_initialized = true;
616 for (i = 0; i <= hw_points_num; i++) {
617 output = de_pq_table[i];
618 /* should really not happen? */
619 if (dc_fixpt_lt(output, dc_fixpt_zero))
620 output = dc_fixpt_zero;
621 else if (dc_fixpt_lt(scaling_factor, output))
622 output = scaling_factor;
629 static void build_regamma(struct pwl_float_data_ex *rgb_regamma,
630 uint32_t hw_points_num,
631 const struct hw_x_point *coordinate_x, bool is_2_4)
635 struct gamma_coefficients coeff;
636 struct pwl_float_data_ex *rgb = rgb_regamma;
637 const struct hw_x_point *coord_x = coordinate_x;
639 build_coefficients(&coeff, is_2_4);
643 while (i != hw_points_num + 1) {
644 /*TODO use y vs r,g,b*/
645 rgb->r = translate_from_linear_space_ex(
646 coord_x->x, &coeff, 0);
655 static void build_degamma(struct pwl_float_data_ex *curve,
656 uint32_t hw_points_num,
657 const struct hw_x_point *coordinate_x, bool is_2_4)
660 struct gamma_coefficients coeff;
661 uint32_t begin_index, end_index;
663 build_coefficients(&coeff, is_2_4);
666 /* X points is 2^-25 to 2^7
667 * De-gamma X is 2^-12 to 2^0 – we are skipping first -12-(-25) = 13 regions
669 begin_index = 13 * NUM_PTS_IN_REGION;
670 end_index = begin_index + 12 * NUM_PTS_IN_REGION;
672 while (i != begin_index) {
673 curve[i].r = dc_fixpt_zero;
674 curve[i].g = dc_fixpt_zero;
675 curve[i].b = dc_fixpt_zero;
679 while (i != end_index) {
680 curve[i].r = translate_to_linear_space_ex(
681 coordinate_x[i].x, &coeff, 0);
682 curve[i].g = curve[i].r;
683 curve[i].b = curve[i].r;
686 while (i != hw_points_num + 1) {
687 curve[i].r = dc_fixpt_one;
688 curve[i].g = dc_fixpt_one;
689 curve[i].b = dc_fixpt_one;
694 static void scale_gamma(struct pwl_float_data *pwl_rgb,
695 const struct dc_gamma *ramp,
696 struct dividers dividers)
698 const struct fixed31_32 max_driver = dc_fixpt_from_int(0xFFFF);
699 const struct fixed31_32 max_os = dc_fixpt_from_int(0xFF00);
700 struct fixed31_32 scaler = max_os;
702 struct pwl_float_data *rgb = pwl_rgb;
703 struct pwl_float_data *rgb_last = rgb + ramp->num_entries - 1;
708 if (dc_fixpt_lt(max_os, ramp->entries.red[i]) ||
709 dc_fixpt_lt(max_os, ramp->entries.green[i]) ||
710 dc_fixpt_lt(max_os, ramp->entries.blue[i])) {
715 } while (i != ramp->num_entries);
720 rgb->r = dc_fixpt_div(
721 ramp->entries.red[i], scaler);
722 rgb->g = dc_fixpt_div(
723 ramp->entries.green[i], scaler);
724 rgb->b = dc_fixpt_div(
725 ramp->entries.blue[i], scaler);
729 } while (i != ramp->num_entries);
731 rgb->r = dc_fixpt_mul(rgb_last->r,
733 rgb->g = dc_fixpt_mul(rgb_last->g,
735 rgb->b = dc_fixpt_mul(rgb_last->b,
740 rgb->r = dc_fixpt_mul(rgb_last->r,
742 rgb->g = dc_fixpt_mul(rgb_last->g,
744 rgb->b = dc_fixpt_mul(rgb_last->b,
749 rgb->r = dc_fixpt_mul(rgb_last->r,
751 rgb->g = dc_fixpt_mul(rgb_last->g,
753 rgb->b = dc_fixpt_mul(rgb_last->b,
757 static void scale_gamma_dx(struct pwl_float_data *pwl_rgb,
758 const struct dc_gamma *ramp,
759 struct dividers dividers)
762 struct fixed31_32 min = dc_fixpt_zero;
763 struct fixed31_32 max = dc_fixpt_one;
765 struct fixed31_32 delta = dc_fixpt_zero;
766 struct fixed31_32 offset = dc_fixpt_zero;
768 for (i = 0 ; i < ramp->num_entries; i++) {
769 if (dc_fixpt_lt(ramp->entries.red[i], min))
770 min = ramp->entries.red[i];
772 if (dc_fixpt_lt(ramp->entries.green[i], min))
773 min = ramp->entries.green[i];
775 if (dc_fixpt_lt(ramp->entries.blue[i], min))
776 min = ramp->entries.blue[i];
778 if (dc_fixpt_lt(max, ramp->entries.red[i]))
779 max = ramp->entries.red[i];
781 if (dc_fixpt_lt(max, ramp->entries.green[i]))
782 max = ramp->entries.green[i];
784 if (dc_fixpt_lt(max, ramp->entries.blue[i]))
785 max = ramp->entries.blue[i];
788 if (dc_fixpt_lt(min, dc_fixpt_zero))
789 delta = dc_fixpt_neg(min);
791 offset = dc_fixpt_add(min, max);
793 for (i = 0 ; i < ramp->num_entries; i++) {
794 pwl_rgb[i].r = dc_fixpt_div(
796 ramp->entries.red[i], delta), offset);
797 pwl_rgb[i].g = dc_fixpt_div(
799 ramp->entries.green[i], delta), offset);
800 pwl_rgb[i].b = dc_fixpt_div(
802 ramp->entries.blue[i], delta), offset);
806 pwl_rgb[i].r = dc_fixpt_sub(dc_fixpt_mul_int(
807 pwl_rgb[i-1].r, 2), pwl_rgb[i-2].r);
808 pwl_rgb[i].g = dc_fixpt_sub(dc_fixpt_mul_int(
809 pwl_rgb[i-1].g, 2), pwl_rgb[i-2].g);
810 pwl_rgb[i].b = dc_fixpt_sub(dc_fixpt_mul_int(
811 pwl_rgb[i-1].b, 2), pwl_rgb[i-2].b);
813 pwl_rgb[i].r = dc_fixpt_sub(dc_fixpt_mul_int(
814 pwl_rgb[i-1].r, 2), pwl_rgb[i-2].r);
815 pwl_rgb[i].g = dc_fixpt_sub(dc_fixpt_mul_int(
816 pwl_rgb[i-1].g, 2), pwl_rgb[i-2].g);
817 pwl_rgb[i].b = dc_fixpt_sub(dc_fixpt_mul_int(
818 pwl_rgb[i-1].b, 2), pwl_rgb[i-2].b);
821 /* todo: all these scale_gamma functions are inherently the same but
822 * take different structures as params or different format for ramp
823 * values. We could probably implement it in a more generic fashion
825 static void scale_user_regamma_ramp(struct pwl_float_data *pwl_rgb,
826 const struct regamma_ramp *ramp,
827 struct dividers dividers)
829 unsigned short max_driver = 0xFFFF;
830 unsigned short max_os = 0xFF00;
831 unsigned short scaler = max_os;
833 struct pwl_float_data *rgb = pwl_rgb;
834 struct pwl_float_data *rgb_last = rgb + GAMMA_RGB_256_ENTRIES - 1;
838 if (ramp->gamma[i] > max_os ||
839 ramp->gamma[i + 256] > max_os ||
840 ramp->gamma[i + 512] > max_os) {
845 } while (i != GAMMA_RGB_256_ENTRIES);
849 rgb->r = dc_fixpt_from_fraction(
850 ramp->gamma[i], scaler);
851 rgb->g = dc_fixpt_from_fraction(
852 ramp->gamma[i + 256], scaler);
853 rgb->b = dc_fixpt_from_fraction(
854 ramp->gamma[i + 512], scaler);
858 } while (i != GAMMA_RGB_256_ENTRIES);
860 rgb->r = dc_fixpt_mul(rgb_last->r,
862 rgb->g = dc_fixpt_mul(rgb_last->g,
864 rgb->b = dc_fixpt_mul(rgb_last->b,
869 rgb->r = dc_fixpt_mul(rgb_last->r,
871 rgb->g = dc_fixpt_mul(rgb_last->g,
873 rgb->b = dc_fixpt_mul(rgb_last->b,
878 rgb->r = dc_fixpt_mul(rgb_last->r,
880 rgb->g = dc_fixpt_mul(rgb_last->g,
882 rgb->b = dc_fixpt_mul(rgb_last->b,
887 * RS3+ color transform DDI - 1D LUT adjustment is composed with regamma here
888 * Input is evenly distributed in the output color space as specified in
891 * Interpolation details:
892 * 1D LUT has 4096 values which give curve correction in 0-1 float range
893 * for evenly spaced points in 0-1 range. lut1D[index] gives correction
895 * First we find index for which:
896 * index/4095 < regamma_y < (index+1)/4095 =>
897 * index < 4095*regamma_y < index + 1
898 * norm_y = 4095*regamma_y, and index is just truncating to nearest integer
899 * lut1 = lut1D[index], lut2 = lut1D[index+1]
901 *adjustedY is then linearly interpolating regamma Y between lut1 and lut2
903 static void apply_lut_1d(
904 const struct dc_gamma *ramp,
905 uint32_t num_hw_points,
906 struct dc_transfer_func_distributed_points *tf_pts)
910 struct fixed31_32 *regamma_y;
911 struct fixed31_32 norm_y;
912 struct fixed31_32 lut1;
913 struct fixed31_32 lut2;
914 const int max_lut_index = 4095;
915 const struct fixed31_32 max_lut_index_f =
916 dc_fixpt_from_int(max_lut_index);
917 int32_t index = 0, index_next = 0;
918 struct fixed31_32 index_f;
919 struct fixed31_32 delta_lut;
920 struct fixed31_32 delta_index;
922 if (ramp->type != GAMMA_CS_TFM_1D)
923 return; // this is not expected
925 for (i = 0; i < num_hw_points; i++) {
926 for (color = 0; color < 3; color++) {
928 regamma_y = &tf_pts->red[i];
930 regamma_y = &tf_pts->green[i];
932 regamma_y = &tf_pts->blue[i];
934 norm_y = dc_fixpt_mul(max_lut_index_f,
936 index = dc_fixpt_floor(norm_y);
937 index_f = dc_fixpt_from_int(index);
939 if (index < 0 || index > max_lut_index)
942 index_next = (index == max_lut_index) ? index : index+1;
945 lut1 = ramp->entries.red[index];
946 lut2 = ramp->entries.red[index_next];
947 } else if (color == 1) {
948 lut1 = ramp->entries.green[index];
949 lut2 = ramp->entries.green[index_next];
951 lut1 = ramp->entries.blue[index];
952 lut2 = ramp->entries.blue[index_next];
955 // we have everything now, so interpolate
956 delta_lut = dc_fixpt_sub(lut2, lut1);
957 delta_index = dc_fixpt_sub(norm_y, index_f);
959 *regamma_y = dc_fixpt_add(lut1,
960 dc_fixpt_mul(delta_index, delta_lut));
965 static void build_evenly_distributed_points(
966 struct gamma_pixel *points,
967 uint32_t numberof_points,
968 struct dividers dividers)
970 struct gamma_pixel *p = points;
971 struct gamma_pixel *p_last = p + numberof_points - 1;
976 struct fixed31_32 value = dc_fixpt_from_fraction(i,
977 numberof_points - 1);
985 } while (i != numberof_points);
987 p->r = dc_fixpt_div(p_last->r, dividers.divider1);
988 p->g = dc_fixpt_div(p_last->g, dividers.divider1);
989 p->b = dc_fixpt_div(p_last->b, dividers.divider1);
993 p->r = dc_fixpt_div(p_last->r, dividers.divider2);
994 p->g = dc_fixpt_div(p_last->g, dividers.divider2);
995 p->b = dc_fixpt_div(p_last->b, dividers.divider2);
999 p->r = dc_fixpt_div(p_last->r, dividers.divider3);
1000 p->g = dc_fixpt_div(p_last->g, dividers.divider3);
1001 p->b = dc_fixpt_div(p_last->b, dividers.divider3);
1004 static inline void copy_rgb_regamma_to_coordinates_x(
1005 struct hw_x_point *coordinates_x,
1006 uint32_t hw_points_num,
1007 const struct pwl_float_data_ex *rgb_ex)
1009 struct hw_x_point *coords = coordinates_x;
1011 const struct pwl_float_data_ex *rgb_regamma = rgb_ex;
1013 while (i <= hw_points_num + 1) {
1014 coords->regamma_y_red = rgb_regamma->r;
1015 coords->regamma_y_green = rgb_regamma->g;
1016 coords->regamma_y_blue = rgb_regamma->b;
1024 static bool calculate_interpolated_hardware_curve(
1025 const struct dc_gamma *ramp,
1026 struct pixel_gamma_point *coeff128,
1027 struct pwl_float_data *rgb_user,
1028 const struct hw_x_point *coordinates_x,
1029 const struct gamma_pixel *axis_x,
1030 uint32_t number_of_points,
1031 struct dc_transfer_func_distributed_points *tf_pts)
1034 const struct pixel_gamma_point *coeff = coeff128;
1035 uint32_t max_entries = 3 - 1;
1039 for (i = 0; i < 3; i++) {
1040 if (!build_custom_gamma_mapping_coefficients_worker(
1041 ramp, coeff128, coordinates_x, axis_x, i,
1047 max_entries += ramp->num_entries;
1049 /* TODO: float point case */
1051 while (i <= number_of_points) {
1052 tf_pts->red[i] = calculate_mapped_value(
1053 rgb_user, coeff, CHANNEL_NAME_RED, max_entries);
1054 tf_pts->green[i] = calculate_mapped_value(
1055 rgb_user, coeff, CHANNEL_NAME_GREEN, max_entries);
1056 tf_pts->blue[i] = calculate_mapped_value(
1057 rgb_user, coeff, CHANNEL_NAME_BLUE, max_entries);
1066 /* The "old" interpolation uses a complicated scheme to build an array of
1067 * coefficients while also using an array of 0-255 normalized to 0-1
1068 * Then there's another loop using both of the above + new scaled user ramp
1069 * and we concatenate them. It also searches for points of interpolation and
1070 * uses enums for positions.
1072 * This function uses a different approach:
1073 * user ramp is always applied on X with 0/255, 1/255, 2/255, ..., 255/255
1074 * To find index for hwX , we notice the following:
1075 * i/255 <= hwX < (i+1)/255 <=> i <= 255*hwX < i+1
1076 * See apply_lut_1d which is the same principle, but on 4K entry 1D LUT
1078 * Once the index is known, combined Y is simply:
1079 * user_ramp(index) + (hwX-index/255)*(user_ramp(index+1) - user_ramp(index)
1081 * We should switch to this method in all cases, it's simpler and faster
1082 * ToDo one day - for now this only applies to ADL regamma to avoid regression
1083 * for regular use cases (sRGB and PQ)
1085 static void interpolate_user_regamma(uint32_t hw_points_num,
1086 struct pwl_float_data *rgb_user,
1088 struct dc_transfer_func_distributed_points *tf_pts)
1094 struct fixed31_32 *tf_point;
1095 struct fixed31_32 hw_x;
1096 struct fixed31_32 norm_factor =
1097 dc_fixpt_from_int(255);
1098 struct fixed31_32 norm_x;
1099 struct fixed31_32 index_f;
1100 struct fixed31_32 lut1;
1101 struct fixed31_32 lut2;
1102 struct fixed31_32 delta_lut;
1103 struct fixed31_32 delta_index;
1106 /* fixed_pt library has problems handling too small values */
1108 tf_pts->red[i] = dc_fixpt_zero;
1109 tf_pts->green[i] = dc_fixpt_zero;
1110 tf_pts->blue[i] = dc_fixpt_zero;
1113 while (i <= hw_points_num + 1) {
1114 for (color = 0; color < 3; color++) {
1116 tf_point = &tf_pts->red[i];
1117 else if (color == 1)
1118 tf_point = &tf_pts->green[i];
1120 tf_point = &tf_pts->blue[i];
1122 if (apply_degamma) {
1124 hw_x = coordinates_x[i].regamma_y_red;
1125 else if (color == 1)
1126 hw_x = coordinates_x[i].regamma_y_green;
1128 hw_x = coordinates_x[i].regamma_y_blue;
1130 hw_x = coordinates_x[i].x;
1132 norm_x = dc_fixpt_mul(norm_factor, hw_x);
1133 index = dc_fixpt_floor(norm_x);
1134 if (index < 0 || index > 255)
1137 index_f = dc_fixpt_from_int(index);
1138 index_next = (index == 255) ? index : index + 1;
1141 lut1 = rgb_user[index].r;
1142 lut2 = rgb_user[index_next].r;
1143 } else if (color == 1) {
1144 lut1 = rgb_user[index].g;
1145 lut2 = rgb_user[index_next].g;
1147 lut1 = rgb_user[index].b;
1148 lut2 = rgb_user[index_next].b;
1151 // we have everything now, so interpolate
1152 delta_lut = dc_fixpt_sub(lut2, lut1);
1153 delta_index = dc_fixpt_sub(norm_x, index_f);
1155 *tf_point = dc_fixpt_add(lut1,
1156 dc_fixpt_mul(delta_index, delta_lut));
1162 static void build_new_custom_resulted_curve(
1163 uint32_t hw_points_num,
1164 struct dc_transfer_func_distributed_points *tf_pts)
1170 while (i != hw_points_num + 1) {
1171 tf_pts->red[i] = dc_fixpt_clamp(
1172 tf_pts->red[i], dc_fixpt_zero,
1174 tf_pts->green[i] = dc_fixpt_clamp(
1175 tf_pts->green[i], dc_fixpt_zero,
1177 tf_pts->blue[i] = dc_fixpt_clamp(
1178 tf_pts->blue[i], dc_fixpt_zero,
1185 static void apply_degamma_for_user_regamma(struct pwl_float_data_ex *rgb_regamma,
1186 uint32_t hw_points_num)
1190 struct gamma_coefficients coeff;
1191 struct pwl_float_data_ex *rgb = rgb_regamma;
1192 const struct hw_x_point *coord_x = coordinates_x;
1194 build_coefficients(&coeff, true);
1197 while (i != hw_points_num + 1) {
1198 rgb->r = translate_from_linear_space_ex(
1199 coord_x->x, &coeff, 0);
1208 static bool map_regamma_hw_to_x_user(
1209 const struct dc_gamma *ramp,
1210 struct pixel_gamma_point *coeff128,
1211 struct pwl_float_data *rgb_user,
1212 struct hw_x_point *coords_x,
1213 const struct gamma_pixel *axis_x,
1214 const struct pwl_float_data_ex *rgb_regamma,
1215 uint32_t hw_points_num,
1216 struct dc_transfer_func_distributed_points *tf_pts,
1219 /* setup to spare calculated ideal regamma values */
1222 struct hw_x_point *coords = coords_x;
1223 const struct pwl_float_data_ex *regamma = rgb_regamma;
1226 copy_rgb_regamma_to_coordinates_x(coords,
1230 calculate_interpolated_hardware_curve(
1231 ramp, coeff128, rgb_user, coords, axis_x,
1232 hw_points_num, tf_pts);
1234 /* just copy current rgb_regamma into tf_pts */
1235 while (i <= hw_points_num) {
1236 tf_pts->red[i] = regamma->r;
1237 tf_pts->green[i] = regamma->g;
1238 tf_pts->blue[i] = regamma->b;
1245 /* this should be named differently, all it does is clamp to 0-1 */
1246 build_new_custom_resulted_curve(hw_points_num, tf_pts);
1251 #define _EXTRA_POINTS 3
1253 bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf,
1254 const struct dc_gamma *ramp, bool mapUserRamp)
1256 struct dc_transfer_func_distributed_points *tf_pts = &output_tf->tf_pts;
1257 struct dividers dividers;
1259 struct pwl_float_data *rgb_user = NULL;
1260 struct pwl_float_data_ex *rgb_regamma = NULL;
1261 struct gamma_pixel *axix_x = NULL;
1262 struct pixel_gamma_point *coeff = NULL;
1263 enum dc_transfer_func_predefined tf = TRANSFER_FUNCTION_SRGB;
1266 if (output_tf->type == TF_TYPE_BYPASS)
1269 /* we can use hardcoded curve for plain SRGB TF */
1270 if (output_tf->type == TF_TYPE_PREDEFINED &&
1271 output_tf->tf == TRANSFER_FUNCTION_SRGB &&
1272 (!mapUserRamp && ramp->type == GAMMA_RGB_256))
1275 output_tf->type = TF_TYPE_DISTRIBUTED_POINTS;
1277 rgb_user = kvzalloc(sizeof(*rgb_user) * (ramp->num_entries + _EXTRA_POINTS),
1280 goto rgb_user_alloc_fail;
1281 rgb_regamma = kvzalloc(sizeof(*rgb_regamma) * (MAX_HW_POINTS + _EXTRA_POINTS),
1284 goto rgb_regamma_alloc_fail;
1285 axix_x = kvzalloc(sizeof(*axix_x) * (ramp->num_entries + 3),
1288 goto axix_x_alloc_fail;
1289 coeff = kvzalloc(sizeof(*coeff) * (MAX_HW_POINTS + _EXTRA_POINTS), GFP_KERNEL);
1291 goto coeff_alloc_fail;
1293 dividers.divider1 = dc_fixpt_from_fraction(3, 2);
1294 dividers.divider2 = dc_fixpt_from_int(2);
1295 dividers.divider3 = dc_fixpt_from_fraction(5, 2);
1299 build_evenly_distributed_points(
1304 if (ramp->type == GAMMA_RGB_256 && mapUserRamp)
1305 scale_gamma(rgb_user, ramp, dividers);
1306 else if (ramp->type == GAMMA_RGB_FLOAT_1024)
1307 scale_gamma_dx(rgb_user, ramp, dividers);
1309 if (tf == TRANSFER_FUNCTION_PQ) {
1310 tf_pts->end_exponent = 7;
1311 tf_pts->x_point_at_y1_red = 125;
1312 tf_pts->x_point_at_y1_green = 125;
1313 tf_pts->x_point_at_y1_blue = 125;
1315 build_pq(rgb_regamma,
1318 output_tf->sdr_ref_white_level);
1320 tf_pts->end_exponent = 0;
1321 tf_pts->x_point_at_y1_red = 1;
1322 tf_pts->x_point_at_y1_green = 1;
1323 tf_pts->x_point_at_y1_blue = 1;
1325 build_regamma(rgb_regamma,
1327 coordinates_x, tf == TRANSFER_FUNCTION_SRGB ? true:false);
1330 map_regamma_hw_to_x_user(ramp, coeff, rgb_user,
1331 coordinates_x, axix_x, rgb_regamma,
1332 MAX_HW_POINTS, tf_pts,
1333 (mapUserRamp || ramp->type != GAMMA_RGB_256) &&
1334 ramp->type != GAMMA_CS_TFM_1D);
1336 if (ramp->type == GAMMA_CS_TFM_1D)
1337 apply_lut_1d(ramp, MAX_HW_POINTS, tf_pts);
1345 kvfree(rgb_regamma);
1346 rgb_regamma_alloc_fail:
1348 rgb_user_alloc_fail:
1352 bool calculate_user_regamma_coeff(struct dc_transfer_func *output_tf,
1353 const struct regamma_lut *regamma)
1355 struct gamma_coefficients coeff;
1356 const struct hw_x_point *coord_x = coordinates_x;
1360 coeff.a0[i] = dc_fixpt_from_fraction(
1361 regamma->coeff.A0[i], 10000000);
1362 coeff.a1[i] = dc_fixpt_from_fraction(
1363 regamma->coeff.A1[i], 1000);
1364 coeff.a2[i] = dc_fixpt_from_fraction(
1365 regamma->coeff.A2[i], 1000);
1366 coeff.a3[i] = dc_fixpt_from_fraction(
1367 regamma->coeff.A3[i], 1000);
1368 coeff.user_gamma[i] = dc_fixpt_from_fraction(
1369 regamma->coeff.gamma[i], 1000);
1375 /* fixed_pt library has problems handling too small values */
1377 output_tf->tf_pts.red[i] = dc_fixpt_zero;
1378 output_tf->tf_pts.green[i] = dc_fixpt_zero;
1379 output_tf->tf_pts.blue[i] = dc_fixpt_zero;
1383 while (i != MAX_HW_POINTS + 1) {
1384 output_tf->tf_pts.red[i] = translate_from_linear_space_ex(
1385 coord_x->x, &coeff, 0);
1386 output_tf->tf_pts.green[i] = translate_from_linear_space_ex(
1387 coord_x->x, &coeff, 1);
1388 output_tf->tf_pts.blue[i] = translate_from_linear_space_ex(
1389 coord_x->x, &coeff, 2);
1394 // this function just clamps output to 0-1
1395 build_new_custom_resulted_curve(MAX_HW_POINTS, &output_tf->tf_pts);
1396 output_tf->type = TF_TYPE_DISTRIBUTED_POINTS;
1401 bool calculate_user_regamma_ramp(struct dc_transfer_func *output_tf,
1402 const struct regamma_lut *regamma)
1404 struct dc_transfer_func_distributed_points *tf_pts = &output_tf->tf_pts;
1405 struct dividers dividers;
1407 struct pwl_float_data *rgb_user = NULL;
1408 struct pwl_float_data_ex *rgb_regamma = NULL;
1411 if (regamma == NULL)
1414 output_tf->type = TF_TYPE_DISTRIBUTED_POINTS;
1416 rgb_user = kzalloc(sizeof(*rgb_user) * (GAMMA_RGB_256_ENTRIES + _EXTRA_POINTS),
1419 goto rgb_user_alloc_fail;
1421 rgb_regamma = kzalloc(sizeof(*rgb_regamma) * (MAX_HW_POINTS + _EXTRA_POINTS),
1424 goto rgb_regamma_alloc_fail;
1426 dividers.divider1 = dc_fixpt_from_fraction(3, 2);
1427 dividers.divider2 = dc_fixpt_from_int(2);
1428 dividers.divider3 = dc_fixpt_from_fraction(5, 2);
1430 scale_user_regamma_ramp(rgb_user, ®amma->ramp, dividers);
1432 if (regamma->flags.bits.applyDegamma == 1) {
1433 apply_degamma_for_user_regamma(rgb_regamma, MAX_HW_POINTS);
1434 copy_rgb_regamma_to_coordinates_x(coordinates_x,
1435 MAX_HW_POINTS, rgb_regamma);
1438 interpolate_user_regamma(MAX_HW_POINTS, rgb_user,
1439 regamma->flags.bits.applyDegamma, tf_pts);
1441 // no custom HDR curves!
1442 tf_pts->end_exponent = 0;
1443 tf_pts->x_point_at_y1_red = 1;
1444 tf_pts->x_point_at_y1_green = 1;
1445 tf_pts->x_point_at_y1_blue = 1;
1447 // this function just clamps output to 0-1
1448 build_new_custom_resulted_curve(MAX_HW_POINTS, tf_pts);
1453 rgb_regamma_alloc_fail:
1455 rgb_user_alloc_fail:
1459 bool mod_color_calculate_degamma_params(struct dc_transfer_func *input_tf,
1460 const struct dc_gamma *ramp, bool mapUserRamp)
1462 struct dc_transfer_func_distributed_points *tf_pts = &input_tf->tf_pts;
1463 struct dividers dividers;
1465 struct pwl_float_data *rgb_user = NULL;
1466 struct pwl_float_data_ex *curve = NULL;
1467 struct gamma_pixel *axix_x = NULL;
1468 struct pixel_gamma_point *coeff = NULL;
1469 enum dc_transfer_func_predefined tf = TRANSFER_FUNCTION_SRGB;
1472 if (input_tf->type == TF_TYPE_BYPASS)
1475 /* we can use hardcoded curve for plain SRGB TF */
1476 if (input_tf->type == TF_TYPE_PREDEFINED &&
1477 input_tf->tf == TRANSFER_FUNCTION_SRGB &&
1478 (!mapUserRamp && ramp->type == GAMMA_RGB_256))
1481 input_tf->type = TF_TYPE_DISTRIBUTED_POINTS;
1483 rgb_user = kvzalloc(sizeof(*rgb_user) * (ramp->num_entries + _EXTRA_POINTS),
1486 goto rgb_user_alloc_fail;
1487 curve = kvzalloc(sizeof(*curve) * (MAX_HW_POINTS + _EXTRA_POINTS),
1490 goto curve_alloc_fail;
1491 axix_x = kvzalloc(sizeof(*axix_x) * (ramp->num_entries + _EXTRA_POINTS),
1494 goto axix_x_alloc_fail;
1495 coeff = kvzalloc(sizeof(*coeff) * (MAX_HW_POINTS + _EXTRA_POINTS), GFP_KERNEL);
1497 goto coeff_alloc_fail;
1499 dividers.divider1 = dc_fixpt_from_fraction(3, 2);
1500 dividers.divider2 = dc_fixpt_from_int(2);
1501 dividers.divider3 = dc_fixpt_from_fraction(5, 2);
1505 build_evenly_distributed_points(
1510 if (ramp->type == GAMMA_RGB_256 && mapUserRamp)
1511 scale_gamma(rgb_user, ramp, dividers);
1512 else if (ramp->type == GAMMA_RGB_FLOAT_1024)
1513 scale_gamma_dx(rgb_user, ramp, dividers);
1515 if (tf == TRANSFER_FUNCTION_PQ)
1520 build_degamma(curve,
1523 tf == TRANSFER_FUNCTION_SRGB ? true:false);
1525 tf_pts->end_exponent = 0;
1526 tf_pts->x_point_at_y1_red = 1;
1527 tf_pts->x_point_at_y1_green = 1;
1528 tf_pts->x_point_at_y1_blue = 1;
1530 map_regamma_hw_to_x_user(ramp, coeff, rgb_user,
1531 coordinates_x, axix_x, curve,
1532 MAX_HW_POINTS, tf_pts,
1544 rgb_user_alloc_fail:
1551 bool mod_color_calculate_curve(enum dc_transfer_func_predefined trans,
1552 struct dc_transfer_func_distributed_points *points)
1556 struct pwl_float_data_ex *rgb_regamma = NULL;
1558 if (trans == TRANSFER_FUNCTION_UNITY ||
1559 trans == TRANSFER_FUNCTION_LINEAR) {
1560 points->end_exponent = 0;
1561 points->x_point_at_y1_red = 1;
1562 points->x_point_at_y1_green = 1;
1563 points->x_point_at_y1_blue = 1;
1565 for (i = 0; i <= MAX_HW_POINTS ; i++) {
1566 points->red[i] = coordinates_x[i].x;
1567 points->green[i] = coordinates_x[i].x;
1568 points->blue[i] = coordinates_x[i].x;
1571 } else if (trans == TRANSFER_FUNCTION_PQ) {
1572 rgb_regamma = kvzalloc(sizeof(*rgb_regamma) *
1573 (MAX_HW_POINTS + _EXTRA_POINTS),
1576 goto rgb_regamma_alloc_fail;
1577 points->end_exponent = 7;
1578 points->x_point_at_y1_red = 125;
1579 points->x_point_at_y1_green = 125;
1580 points->x_point_at_y1_blue = 125;
1583 build_pq(rgb_regamma,
1587 for (i = 0; i <= MAX_HW_POINTS ; i++) {
1588 points->red[i] = rgb_regamma[i].r;
1589 points->green[i] = rgb_regamma[i].g;
1590 points->blue[i] = rgb_regamma[i].b;
1594 kvfree(rgb_regamma);
1595 } else if (trans == TRANSFER_FUNCTION_SRGB ||
1596 trans == TRANSFER_FUNCTION_BT709) {
1597 rgb_regamma = kvzalloc(sizeof(*rgb_regamma) *
1598 (MAX_HW_POINTS + _EXTRA_POINTS),
1601 goto rgb_regamma_alloc_fail;
1602 points->end_exponent = 0;
1603 points->x_point_at_y1_red = 1;
1604 points->x_point_at_y1_green = 1;
1605 points->x_point_at_y1_blue = 1;
1607 build_regamma(rgb_regamma,
1609 coordinates_x, trans == TRANSFER_FUNCTION_SRGB ? true:false);
1610 for (i = 0; i <= MAX_HW_POINTS ; i++) {
1611 points->red[i] = rgb_regamma[i].r;
1612 points->green[i] = rgb_regamma[i].g;
1613 points->blue[i] = rgb_regamma[i].b;
1617 kvfree(rgb_regamma);
1619 rgb_regamma_alloc_fail:
1624 bool mod_color_calculate_degamma_curve(enum dc_transfer_func_predefined trans,
1625 struct dc_transfer_func_distributed_points *points)
1629 struct pwl_float_data_ex *rgb_degamma = NULL;
1631 if (trans == TRANSFER_FUNCTION_UNITY ||
1632 trans == TRANSFER_FUNCTION_LINEAR) {
1634 for (i = 0; i <= MAX_HW_POINTS ; i++) {
1635 points->red[i] = coordinates_x[i].x;
1636 points->green[i] = coordinates_x[i].x;
1637 points->blue[i] = coordinates_x[i].x;
1640 } else if (trans == TRANSFER_FUNCTION_PQ) {
1641 rgb_degamma = kvzalloc(sizeof(*rgb_degamma) *
1642 (MAX_HW_POINTS + _EXTRA_POINTS),
1645 goto rgb_degamma_alloc_fail;
1648 build_de_pq(rgb_degamma,
1651 for (i = 0; i <= MAX_HW_POINTS ; i++) {
1652 points->red[i] = rgb_degamma[i].r;
1653 points->green[i] = rgb_degamma[i].g;
1654 points->blue[i] = rgb_degamma[i].b;
1658 kvfree(rgb_degamma);
1659 } else if (trans == TRANSFER_FUNCTION_SRGB ||
1660 trans == TRANSFER_FUNCTION_BT709) {
1661 rgb_degamma = kvzalloc(sizeof(*rgb_degamma) *
1662 (MAX_HW_POINTS + _EXTRA_POINTS),
1665 goto rgb_degamma_alloc_fail;
1667 build_degamma(rgb_degamma,
1669 coordinates_x, trans == TRANSFER_FUNCTION_SRGB ? true:false);
1670 for (i = 0; i <= MAX_HW_POINTS ; i++) {
1671 points->red[i] = rgb_degamma[i].r;
1672 points->green[i] = rgb_degamma[i].g;
1673 points->blue[i] = rgb_degamma[i].b;
1677 kvfree(rgb_degamma);
1679 points->end_exponent = 0;
1680 points->x_point_at_y1_red = 1;
1681 points->x_point_at_y1_green = 1;
1682 points->x_point_at_y1_blue = 1;
1684 rgb_degamma_alloc_fail: