-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from weihsinyeh/draw
Move common routines to draw-common.c
- Loading branch information
Showing
5 changed files
with
55 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Twin - A Tiny Window System | ||
* Copyright (c) 2004 Keith Packard <[email protected]> | ||
* Copyright (c) 2024 National Cheng Kung University, Taiwan | ||
* All rights reserved. | ||
*/ | ||
|
||
#include "twin_private.h" | ||
|
||
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 | ||
} | ||
|
||
void twin_premultiply_alpha(twin_pixmap_t *px) | ||
{ | ||
if (px->format != TWIN_ARGB32) | ||
return; | ||
|
||
for (twin_coord_t y = 0; y < px->height; y++) { | ||
twin_pointer_t p = {.b = px->p.b + y * px->stride}; | ||
|
||
for (twin_coord_t x = 0; x < px->width; x++) | ||
p.argb32[x] = _twin_apply_alpha(p.argb32[x]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters