tests: fix MAKE_RGBA macro for 10bpp modes
PATCH 1/1 tests: fix MAKE_RGBA macro for 10bpp modes
We need to shift the values up, otherwise we'd end up with a negative shift. This works for up-to 16-bit components, which is fine for now.
--- tests/util/pattern.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
tests/util/pattern.c +10 -4
@@ -64,11 +64,17 @@ struct color_yuv { .u = MAKE_YUV_601_U(r, g, b), \ .v = MAKE_YUV_601_V(r, g, b) } +static inline uint32_t shiftcolor (const struct util_color_component *comp, +uint32_t value) +{ +return ((value <<8 ) >> (16 - comp->length)) << comp->offset; +} +#define MAKE_RGBA (rgb, r, g, b, a) \ - ((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \ - (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \ - (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \ - (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset)) + (shiftcolor(&(rgb)->red, (r)) | \ + shiftcolor(&(rgb)->green, (g)) | \ + shiftcolor(&(rgb)->blue, (b)) | \ + shiftcolor(&(rgb)->alpha, (a)))#define MAKE_RGB24 (rgb, r, g, b) \ { .value = MAKE_RGBA(rgb, r, g, b, 0) }
Signature · 6 lines
2.13.6 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 2 lines · Ilia Mirkin
We need to shift the values up, otherwise we'd end up with a negative shift. This works for up-to 16-bit components, which is fine for now.
Shouldn't we actually replicate the high bits in the low bits?
Quoted 39 lines
Signed-off-by Ilia Mirkin <[email protected]>--- tests/util/pattern.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)tests/util/pattern.c +10
-4@@ -64,11 +64,17 @@ struct color_yuv { .u = MAKE_YUV_601_U(r, g, b), \ .v = MAKE_YUV_601_V(r, g, b) } +static inline uint32_t shiftcolor (const struct util_color_component *comp, +uint32_t value) +{ +return ((value <<8 ) >> (16 - comp->length)) << comp->offset; +} +#define MAKE_RGBA (rgb, r, g, b, a) \ - ((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \ - (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \ - (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \ - (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset)) + (shiftcolor(&(rgb)->red, (r)) | \ + shiftcolor(&(rgb)->green, (g)) | \ + shiftcolor(&(rgb)->blue, (b)) | \ + shiftcolor(&(rgb)->alpha, (a)))#define MAKE_RGB24 (rgb, r, g, b) \ { .value = MAKE_RGBA(rgb, r, g, b, 0) }Signature · 6 lines
2.13.6 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 5 lines · Ville Syrjälä
Quoted 2 lines · Ilia Mirkin
We need to shift the values up, otherwise we'd end up with a negative shift. This works for up-to 16-bit components, which is fine for now.
Shouldn't we actually replicate the high bits in the low bits?
Not entirely sure what you're proposing...
Ideally we wouldn't be lazy and pass e.g. 16-bit values to MAKE_RGBA which would then shift down as necessary (and even there, you could end up with off-by-1's maybe?). For e.g. 0xff, that should become 0x3ff but with my code will become 0x3fc. But for other values, it's less clear what to do with the low bits. I figured it didn't really matter.
Do you have a concrete proposal?
-ilia
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 6 lines · Ilia Mirkin
Quoted 4 lines · Ville Syrjälä
Quoted 2 lines · Ilia Mirkin
We need to shift the values up, otherwise we'd end up with a negative shift. This works for up-to 16-bit components, which is fine for now.
Quoted 8 lines
Quoted 1 line
Shouldn't we actually replicate the high bits in the low bits?
Not entirely sure what you're proposing...
Ideally we wouldn't be lazy and pass e.g. 16-bit values to
MAKE_RGBAwhich would then shift down as necessary (and even there, you could end up with off-by-1's maybe?). For e.g.0xff, that should become0x3ffbut with my code will become0x3fc.
Exactly the issue.
Quoted 5 lines
But for other values, it's
less clear what to do with the low bits. I figured it didn't really matter.Do you have a concrete proposal?
The usual thing would be just
(value) * 0x3ff / 0xff
or
((value) << 2) | ((value) >> 6)
Signature · 6 lines
Ville Syrjälä Intel OTC _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 24 lines · Ville Syrjälä
Quoted 6 lines · Ilia Mirkin
Quoted 4 lines · Ville Syrjälä
Quoted 2 lines · Ilia Mirkin
We need to shift the values up, otherwise we'd end up with a negative shift. This works for up-to 16-bit components, which is fine for now.
Quoted 8 lines
Quoted 1 line
Shouldn't we actually replicate the high bits in the low bits?
Not entirely sure what you're proposing...
Ideally we wouldn't be lazy and pass e.g. 16-bit values to
MAKE_RGBAwhich would then shift down as necessary (and even there, you could end up with off-by-1's maybe?). For e.g.0xff, that should become0x3ffbut with my code will become0x3fc.Exactly the issue.
Quoted 5 lines
But for other values, it's
less clear what to do with the low bits. I figured it didn't really matter.Do you have a concrete proposal?
Quoted 7 lines
The usual thing would be just
(value) *
0x3ff/0xffor
((value) << 2) | ((value) >> 6)
The latter method is interesting, it slowly biases from rounding down to rounding up as you go through the range. Clever. I guess I could change my function to use
(value << 8) | value
and then use that to shift around. I'll send a v2.
-ilia
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel