MCPcopy Create free account
hub / github.com/TASEmulators/fceux / blend32

Function blend32

src/lua-engine.cpp:3527–3550  ·  view source on GitHub ↗

write a pixel to buffer

Source from the content-addressed store, hash-verified

3525
3526// write a pixel to buffer
3527static inline void blend32(uint32 *dstPixel, uint32 colour)
3528{
3529 uint8 *dst = (uint8*) dstPixel;
3530 int a, r, g, b;
3531 LUA_DECOMPOSE_PIXEL(colour, a, r, g, b);
3532
3533 if (a == 255 || dst[3] == 0) {
3534 // direct copy
3535 *(uint32*)(dst) = colour;
3536 }
3537 else if (a == 0) {
3538 // do not copy
3539 }
3540 else {
3541 // alpha-blending
3542 int a_dst = ((255 - a) * dst[3] + 128) / 255;
3543 int a_new = a + a_dst;
3544
3545 dst[0] = (uint8) ((( dst[0] * a_dst + b * a) + (a_new / 2)) / a_new);
3546 dst[1] = (uint8) ((( dst[1] * a_dst + g * a) + (a_new / 2)) / a_new);
3547 dst[2] = (uint8) ((( dst[2] * a_dst + r * a) + (a_new / 2)) / a_new);
3548 dst[3] = (uint8) a_new;
3549 }
3550}
3551// check if a pixel is in the lua canvas
3552static inline bool gui_check_boundary(int x, int y) {
3553 return !(x < 0 || x >= LUA_SCREEN_WIDTH || y < 0 || y >= LUA_SCREEN_HEIGHT);

Callers 1

gui_drawpixel_fastFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected