MCPcopy Create free account
hub / github.com/buggins/coolreader / DitherNBitColor

Function DitherNBitColor

crengine/src/lvdrawbuf.cpp:132–154  ·  view source on GitHub ↗

returns byte with higher significant bits, lower bits are 0

Source from the content-addressed store, hash-verified

130
131// returns byte with higher significant bits, lower bits are 0
132lUInt32 DitherNBitColor( lUInt32 color, lUInt32 x, lUInt32 y, int bits )
133{
134 int mask = ((1<<bits)-1)<<(8-bits);
135 // gray = (r + 2*g + b)>>2
136 //int cl = ((((color>>16) & 255) + ((color>>(8-1)) & (255<<1)) + ((color) & 255)) >> 2) & 255;
137 int cl = ((((color>>16) & 255) + ((color>>(8-1)) & (255<<1)) + ((color) & 255)) >> 2) & 255;
138 int white = (1<<bits) - 1;
139 int precision = white;
140 if (cl<precision)
141 return 0;
142 else if (cl>=255-precision)
143 return mask;
144 //int d = dither_2bpp_4x4[(x&3) | ( (y&3) << 2 )] - 1;
145 // dither = 0..63
146 int d = dither_2bpp_8x8[(x&7) | ( (y&7) << 3 )] - 1;
147 int shift = bits-2;
148 cl = ( (cl<<shift) + d - 32 ) >> shift;
149 if ( cl>255 )
150 cl = 255;
151 if ( cl<0 )
152 cl = 0;
153 return cl & mask;
154}
155
156lUInt32 Dither2BitColor( lUInt32 color, lUInt32 x, lUInt32 y )
157{

Callers 1

OnLineDecodedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected