![]() |
Color Extraction Developer Insights - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: Color Extraction Developer Insights (/showthread.php?tid=2412) Pages:
1
2
|
RE: Color Extraction Developer Insights - SMcNeill - 01-28-2024 Seeing what you're doing now, let me draw your attention to: https://qb64phoenix.com/forum/showthread.php?tid=1360 RE: Color Extraction Developer Insights - SMcNeill - 01-28-2024 To break down how I did this: temp = _NewImage(_Width(image), _Height(image), 256) _Dest temp: For i = 0 To 255: _PaletteColor i, _RGB32(i): Next: _Dest d The above creates a 256 color screen for us, and sets to to be 256 color grayscale. r = _MemGet(m(0), o(0) + 1, _Unsigned _Byte): g = _MemGet(m(0), o(0) + 2, _Unsigned _Byte): b = _MemGet(m(0), o(0) + 3, _Unsigned _Byte) Then I read the RGB values. (Alpha shouldn't be needed here, as 256 color images don't carry an alpha channel usually, so I'm assuming they're all full alpha.) _MemPut m(1), o(1), _RGB(r, g, b, temp) As _UNSIGNED _BYTE And then I use the native _RGB command to match the closest color in my grayscale palette to the 32-bit color value, and I put that value to the new grayscale image. And using this trick, I can set up my 256-color screen to use *any* palette that I want to match with as closely as possible. (In fact, I could use this method to dither from 32-bit images to 256-color images, if I wanted to.) With just a tweak of the palette, I can create Red-Scale, Blue-Scale, Green-Scale images, as you see easily in the demo if you follow the link. ![]() |