Skip to content
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

Merged
merged 1 commit into from
Feb 3, 2025
Merged

Conversation

weihsinyeh
Copy link
Collaborator

@weihsinyeh weihsinyeh commented Feb 3, 2025

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

include/twin.h Outdated Show resolved Hide resolved
src/draw-common.c Outdated Show resolved Hide resolved
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]>
@jserv jserv merged commit 122f696 into sysprog21:main Feb 3, 2025
3 checks passed
@jserv
Copy link
Contributor

jserv commented Feb 3, 2025

Thank @weihsinyeh for contributing!

Copy link

bito-code-review bot commented Feb 3, 2025

Code Review Agent Run #332d03

Actionable Suggestions - 1
  • src/draw-common.c - 1
    • Consider refactoring byte order handling logic · Line 10-34
Review Details
  • Files reviewed - 5 · Commit Range: 7c83fa7..7c83fa7
    • Makefile
    • include/twin.h
    • src/draw-builtin.c
    • src/draw-common.c
    • src/draw-pixman.c
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Fb Infer (Static Code Analysis) - ✖︎ Failed

AI Code Review powered by Bito Logo

Copy link

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Code Organization and Refactoring

Makefile - Added draw-common.c and renamed draw.c to draw-builtin.c

twin.h - Updated header comments to reflect new file structure

draw-builtin.c - Removed common alpha handling routines

draw-common.c - Created new file with common alpha handling routines

draw-pixman.c - Removed duplicate alpha handling routines

Comment on lines +10 to +34
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
Copy link

@bito-code-review bito-code-review bot Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider refactoring byte order handling logic

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
Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants