-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move common routines to draw-common.c #98
Conversation
Move the common routines twin_premultiply_alpha() and _twin_apply_alpha() in src/draw.c to src/draw-common.c and put the dedicated implementations into src/draw-builtin.c and src/draw-pixman.c, respectively. Signed-off-by: Wei-Hsin Yeh <[email protected]>
Thank @weihsinyeh for contributing! |
Code Review Agent Run #332d03Actionable Suggestions - 1
Review Details
|
Changelist by BitoThis pull request implements the following key changes.
|
static twin_argb32_t _twin_apply_alpha(twin_argb32_t v) | ||
{ | ||
uint16_t t1, t2, t3; | ||
twin_a8_t alpha = twin_get_8(v, | ||
#if __BYTE_ORDER == __BIG_ENDIAN | ||
0 | ||
#else | ||
24 | ||
#endif | ||
); | ||
|
||
/* clear RGB data if alpha is zero */ | ||
if (!alpha) | ||
return 0; | ||
|
||
#if __BYTE_ORDER == __BIG_ENDIAN | ||
/* twin needs ARGB format */ | ||
return alpha << 24 | twin_int_mult(twin_get_8(v, 24), alpha, t1) << 16 | | ||
twin_int_mult(twin_get_8(v, 16), alpha, t2) << 8 | | ||
twin_int_mult(twin_get_8(v, 8), alpha, t3) << 0; | ||
#else | ||
return alpha << 24 | twin_int_mult(twin_get_8(v, 0), alpha, t1) << 16 | | ||
twin_int_mult(twin_get_8(v, 8), alpha, t2) << 8 | | ||
twin_int_mult(twin_get_8(v, 16), alpha, t3) << 0; | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting the byte order specific logic into separate helper functions. The current implementation duplicates logic between big and little endian cases in _twin_apply_alpha
.
Code suggestion
Check the AI-generated fix before applying
static twin_argb32_t _twin_apply_alpha(twin_argb32_t v) | |
{ | |
uint16_t t1, t2, t3; | |
twin_a8_t alpha = twin_get_8(v, | |
#if __BYTE_ORDER == __BIG_ENDIAN | |
0 | |
#else | |
24 | |
#endif | |
); | |
/* clear RGB data if alpha is zero */ | |
if (!alpha) | |
return 0; | |
#if __BYTE_ORDER == __BIG_ENDIAN | |
/* twin needs ARGB format */ | |
return alpha << 24 | twin_int_mult(twin_get_8(v, 24), alpha, t1) << 16 | | |
twin_int_mult(twin_get_8(v, 16), alpha, t2) << 8 | | |
twin_int_mult(twin_get_8(v, 8), alpha, t3) << 0; | |
#else | |
return alpha << 24 | twin_int_mult(twin_get_8(v, 0), alpha, t1) << 16 | | |
twin_int_mult(twin_get_8(v, 8), alpha, t2) << 8 | | |
twin_int_mult(twin_get_8(v, 16), alpha, t3) << 0; | |
#endif | |
static twin_argb32_t _twin_apply_alpha_be(twin_argb32_t v, twin_a8_t alpha) { | |
uint16_t t1, t2, t3; | |
return alpha << 24 | twin_int_mult(twin_get_8(v, 24), alpha, t1) << 16 | | |
twin_int_mult(twin_get_8(v, 16), alpha, t2) << 8 | | |
twin_int_mult(twin_get_8(v, 8), alpha, t3) << 0; | |
} | |
static twin_argb32_t _twin_apply_alpha_le(twin_argb32_t v, twin_a8_t alpha) { | |
uint16_t t1, t2, t3; | |
return alpha << 24 | twin_int_mult(twin_get_8(v, 0), alpha, t1) << 16 | | |
twin_int_mult(twin_get_8(v, 8), alpha, t2) << 8 | | |
twin_int_mult(twin_get_8(v, 16), alpha, t3) << 0; | |
} | |
Code Review Run #332d03
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
Move the common routines twin_premultiply_alpha() and _twin_apply_alpha() in src/draw.c to src/draw-common.c and put the dedicated implementations into src/draw-builtin.c and src/draw-pixman.c, respectively.
Summary by Bito
Reorganization of alpha handling routines by moving twin_premultiply_alpha and _twin_apply_alpha from src/draw.c to new src/draw-common.c file. Draw.c renamed to draw-builtin.c and removed duplicate implementations from draw-pixman.c. Includes updates to Makefile and header files to reflect the structural changes.Unit tests added: False
Estimated effort to review (1-5, lower is better): 2