diff --git a/tests/alpha-blending-test.c b/tests/alpha-blending-test.c index e2916be9..b3f8bdee 100644 --- a/tests/alpha-blending-test.c +++ b/tests/alpha-blending-test.c @@ -299,7 +299,7 @@ check_blend_pattern(struct buffer *bg, struct buffer *fg, struct buffer *shot, uint32_t *bg_row = get_middle_row(bg); uint32_t *fg_row = get_middle_row(fg); uint32_t *shot_row = get_middle_row(shot); - struct color_float max_diff = { 0.0f, 0.0f, 0.0f, 0.0f }; + struct color_float max_diff = { .rgb = { 0.0f, 0.0f, 0.0f } }; bool ret = true; int x; diff --git a/tests/color-shaper-matrix-test.c b/tests/color-shaper-matrix-test.c index 0c04e070..331336a3 100644 --- a/tests/color-shaper-matrix-test.c +++ b/tests/color-shaper-matrix-test.c @@ -193,7 +193,7 @@ gen_ramp_rgb(const struct image_header *header, int bitwidth, int width_bar) hue_index = MIN(hue_index, num_hues - 1); for (x = 0; x < header->width; x++) { - struct color_float rgb = { 0, 0, 0 }; + struct color_float rgb = { .rgb = { 0, 0, 0 } }; value = (float)x / (float)(header->width - 1); @@ -360,7 +360,7 @@ process_pipeline_comparison(const struct image_header *src, const struct setup_args * arg) { const float max_pixel_value = 255.0; - struct color_float max_diff_pipeline = { 0.0f, 0.0f, 0.0f, 0.0f }; + struct color_float max_diff_pipeline = { .rgb = { 0.0f, 0.0f, 0.0f } }; float max_allow_diff = arg->pipeline.tolerance / max_pixel_value; float max_err = 0; float f_max_err = 0; diff --git a/tests/color_util.c b/tests/color_util.c index 511b8d9e..bc5ca801 100644 --- a/tests/color_util.c +++ b/tests/color_util.c @@ -29,8 +29,18 @@ #include #include #include +#include #include "shared/helpers.h" +static_assert(sizeof(struct color_float) == 4 * sizeof(float), + "unexpected padding in struct color_float"); +static_assert(offsetof(struct color_float, r) == offsetof(struct color_float, rgb[COLOR_CHAN_R]), + "unexpected offset for struct color_float::r"); +static_assert(offsetof(struct color_float, g) == offsetof(struct color_float, rgb[COLOR_CHAN_G]), + "unexpected offset for struct color_float::g"); +static_assert(offsetof(struct color_float, b) == offsetof(struct color_float, rgb[COLOR_CHAN_B]), + "unexpected offset for struct color_float::b"); + struct color_tone_curve { enum transfer_fn fn; enum transfer_fn inv_fn; @@ -154,9 +164,10 @@ Power2_4_EOTF_inv(float o) void sRGB_linearize(struct color_float *cf) { - cf->r = sRGB_EOTF(cf->r); - cf->g = sRGB_EOTF(cf->g); - cf->b = sRGB_EOTF(cf->b); + int i; + + for (i = 0; i < COLOR_CHAN_NUM; i++) + cf->rgb[i] = sRGB_EOTF(cf->rgb[i]); } static float @@ -191,9 +202,10 @@ apply_tone_curve(enum transfer_fn fn, float r) void sRGB_delinearize(struct color_float *cf) { - cf->r = sRGB_EOTF_inv(cf->r); - cf->g = sRGB_EOTF_inv(cf->g); - cf->b = sRGB_EOTF_inv(cf->b); + int i; + + for (i = 0; i < COLOR_CHAN_NUM; i++) + cf->rgb[i] = sRGB_EOTF_inv(cf->rgb[i]); } struct color_float diff --git a/tests/color_util.h b/tests/color_util.h index 96f50049..f822d00a 100644 --- a/tests/color_util.h +++ b/tests/color_util.h @@ -27,8 +27,21 @@ #include #include +enum color_chan_index { + COLOR_CHAN_R = 0, + COLOR_CHAN_G, + COLOR_CHAN_B, + COLOR_CHAN_NUM +}; + struct color_float { - float r, g, b, a; + union { + float rgb[COLOR_CHAN_NUM]; + struct { + float r, g, b; + }; + }; + float a; }; struct lcmsVEC3 {