MCPcopy Create free account
hub / github.com/NetHack/NetHack / pixel_element

Function pixel_element

win/share/bmptiles.c:576–594  ·  view source on GitHub ↗

Extract one element (red, green, blue or alpha) from a pixel */

Source from the content-addressed store, hash-verified

574
575/* Extract one element (red, green, blue or alpha) from a pixel */
576static unsigned char
577pixel_element(uint32 mask, uint32 color)
578{
579 uint32 bits, shift;
580
581 if (mask == 0) return 0;
582 bits = 0xFFFF; /* 0xFF, 0xF, 0x3, 0x1 */
583 shift = 16; /* 8, 4, 2, 1 */
584 while (shift != 0) {
585 if ((mask & bits) == 0) {
586 mask >>= shift;
587 color >>= shift;
588 }
589 shift /= 2;
590 bits >>= shift;
591 }
592 color &= mask;
593 return color * 255 / mask;
594}

Callers 1

build_pixelFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected