Created
April 6, 2022 03:57
-
-
Save QuantumApprentice/90e229b0bc48ddcefdb3b95b7aec4d7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| for (unsigned int i = 0; i < frame_size; i++) | |
| { | |
| uint8_t Palette_Index; | |
| memcpy(&Palette_Index, (uint8_t*)Paletted_Surface->pixels + i, sizeof(uint8_t)); | |
| uint32_t w_PaletteColor = 0; | |
| w_PaletteColor = (uint32_t)(&pxlFMT_Pal.palette + Palette_Index); | |
| ((uint32_t*)Output_Surface->pixels)[i] = w_PaletteColor; | |
| //int w_smallest = INT_MAX; | |
| //w_PaletteColor = SDL_MapRGBA(&pxlFMT_Pal, abgr_.r, abgr_.g, abgr_.b, abgr_.a); | |
| //for (int j = 0; j < 256; j++) | |
| //{ | |
| // int s = (abgr_.r - PaletteColors[j].r); | |
| // int t = (abgr_.g - PaletteColors[j].g); | |
| // int u = (abgr_.b - PaletteColors[j].b); | |
| // int v = (abgr_.a - PaletteColors[j].a); | |
| // s *= s; | |
| // t *= t; | |
| // u *= u; | |
| // v *= v; | |
| // int w = sqrt(s + t + u + v); | |
| // if (w < w_smallest) { | |
| // w_smallest = w; | |
| // w_PaletteColor = j; | |
| // } | |
| // //printf("stuv: %d %d %d %d", s, t, u, v); | |
| //} | |
| if (i == 100) { printf("loop #: %d\n", i); } | |
| if (i == 1000) { printf("loop #: %d\n", i); } | |
| if (i == 10000) { printf("loop #: %d\n", i); } | |
| if (i == 100000) { printf("loop #: %d\n", i); } | |
| if (i == 1000000) { printf("loop #: %d\n", i); } | |
| if (i == 2000000) { printf("loop #: %d\n", i); } | |
| } |
Author
Author
If using this, remember to pay attention to the color channels, they may (and probably are) mixed up for the output format.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is from my attempt to convert a paletted image to a regular 32bit image, but turned out to be unnecessary because SDL_ConvertSurface did the job on its own.