gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 62c838c672904e058dfeab514109e760610fd072 parent ff5cecd2e688dda7b398e10c266a09b1d87b6a4f Author: bbbbbr <bbbbbr@users.noreply.github.com> Date: Tue, 14 Nov 2023 01:26:11 -0800 Merge pull request #595 from bbbbbr/png2asset/misc png2asset: a couple more tabs to spaces files Diffstat:
| M | gbdk-support/png2asset/cmp_int_color.cpp | 32 | ++++++++++++++++---------------- |
| M | gbdk-support/png2asset/cmp_int_color.h | 46 | +++++++++++++++++++++++----------------------- |
| M | gbdk-support/png2asset/palettes.cpp | 134 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
3 files changed, 106 insertions(+), 106 deletions(-)
diff --git a/gbdk-support/png2asset/cmp_int_color.cpp b/gbdk-support/png2asset/cmp_int_color.cpp @@ -20,22 +20,22 @@ using namespace std; SetPal GetPaletteColors(const PNGImage& image, int x, int y, int w, int h) { - SetPal ret; - for(int j = y; j < (y + h); ++j) - { - for(int i = x; i < (x + w); ++i) - { - const unsigned char* color = &image.data[(j * image.w + i) * RGBA32_SZ]; - int color_int = (color[0] << 24) | (color[1] << 16) | (color[2] << 8) | color[3]; - ret.insert(color_int); - } - } + SetPal ret; + for(int j = y; j < (y + h); ++j) + { + for(int i = x; i < (x + w); ++i) + { + const unsigned char* color = &image.data[(j * image.w + i) * RGBA32_SZ]; + int color_int = (color[0] << 24) | (color[1] << 16) | (color[2] << 8) | color[3]; + ret.insert(color_int); + } + } - for(SetPal::iterator it = ret.begin(); it != ret.end(); ++it) - { - if(it != ret.begin() && ((0xFF & *it) != 0xFF)) //ret.begin() should be the only one transparent - printf("Warning: found more than one transparent color in tile at x:%d, y:%d of size w:%d, h:%d\n", x, y, w, h); - } + for(SetPal::iterator it = ret.begin(); it != ret.end(); ++it) + { + if(it != ret.begin() && ((0xFF & *it) != 0xFF)) //ret.begin() should be the only one transparent + printf("Warning: found more than one transparent color in tile at x:%d, y:%d of size w:%d, h:%d\n", x, y, w, h); + } - return ret; + return ret; } diff --git a/gbdk-support/png2asset/cmp_int_color.h b/gbdk-support/png2asset/cmp_int_color.h @@ -7,30 +7,30 @@ using namespace std; //Functor to compare entries in SetPal struct CmpIntColor { - bool operator() (unsigned int const& c1, unsigned int const& c2) const - { - unsigned char* c1_ptr = (unsigned char*)&c1; - unsigned char* c2_ptr = (unsigned char*)&c2; + bool operator() (unsigned int const& c1, unsigned int const& c2) const + { + unsigned char* c1_ptr = (unsigned char*)&c1; + unsigned char* c2_ptr = (unsigned char*)&c2; - //Compare alpha first, transparent color is considered smaller - if(c1_ptr[0] != c2_ptr[0]) - { - return c1_ptr[0] < c2_ptr[0]; - } - else - { - // Do a compare with luminance in upper bits, and original rgb24 in lower bits. - // This prefers luminance, but considers RGB values for equal-luminance cases to - // make sure the compare functor satisifed the strictly weak ordering requirement - uint64_t lum_1 = (unsigned int)(c1_ptr[3] * 299 + c1_ptr[2] * 587 + c1_ptr[1] * 114); - uint64_t lum_2 = (unsigned int)(c2_ptr[3] * 299 + c2_ptr[2] * 587 + c2_ptr[1] * 114); - uint64_t rgb_1 = (c1_ptr[3] << 16) | (c1_ptr[2] << 8) | c1_ptr[1]; - uint64_t rgb_2 = (c2_ptr[3] << 16) | (c2_ptr[2] << 8) | c2_ptr[1]; - uint64_t all_1 = (lum_1 << 24) | rgb_1; - uint64_t all_2 = (lum_2 << 24) | rgb_2; - return all_1 > all_2; - } - } + //Compare alpha first, transparent color is considered smaller + if(c1_ptr[0] != c2_ptr[0]) + { + return c1_ptr[0] < c2_ptr[0]; + } + else + { + // Do a compare with luminance in upper bits, and original rgb24 in lower bits. + // This prefers luminance, but considers RGB values for equal-luminance cases to + // make sure the compare functor satisifed the strictly weak ordering requirement + uint64_t lum_1 = (unsigned int)(c1_ptr[3] * 299 + c1_ptr[2] * 587 + c1_ptr[1] * 114); + uint64_t lum_2 = (unsigned int)(c2_ptr[3] * 299 + c2_ptr[2] * 587 + c2_ptr[1] * 114); + uint64_t rgb_1 = (c1_ptr[3] << 16) | (c1_ptr[2] << 8) | c1_ptr[1]; + uint64_t rgb_2 = (c2_ptr[3] << 16) | (c2_ptr[2] << 8) | c2_ptr[1]; + uint64_t all_1 = (lum_1 << 24) | rgb_1; + uint64_t all_2 = (lum_2 << 24) | rgb_2; + return all_1 > all_2; + } + } }; //This set will keep colors in the palette ordered based on their grayscale values to ensure they look good on DMG diff --git a/gbdk-support/png2asset/palettes.cpp b/gbdk-support/png2asset/palettes.cpp @@ -25,43 +25,43 @@ using namespace std; unsigned int PaletteCountApplyMaxLimit(unsigned int max_palettes, unsigned int cur_palette_size) { - if(cur_palette_size > max_palettes) - { - printf("Warning: %d palettes found, truncating to %d (-max_palettes)\n", (unsigned int)cur_palette_size, (unsigned int)max_palettes); - return max_palettes; - } - else - return cur_palette_size; + if(cur_palette_size > max_palettes) + { + printf("Warning: %d palettes found, truncating to %d (-max_palettes)\n", (unsigned int)cur_palette_size, (unsigned int)max_palettes); + return max_palettes; + } + else + return cur_palette_size; } int FindOrCreateSubPalette(const SetPal& pal, vector< SetPal >& palettes, size_t colors_per_pal) { - // Return -1 if colors can't even fit in sub-palette hardware limit - if(pal.size() > colors_per_pal) - { - return -1; - } - //Check if it matches any palettes or create a new one - int i; - for(i = 0; i < (int)palettes.size(); ++i) - { - //Try to merge this palette with any of the palettes (checking if they are equal is not enough since the palettes can have less than 4 colors) - SetPal merged(palettes[i]); - merged.insert(pal.begin(), pal.end()); - if(merged.size() <= colors_per_pal) - { - if(palettes[i].size() <= colors_per_pal) - palettes[i] = merged; //Increase colors with this palette (it has less than 4 colors) - return i; //Found palette - } - } + // Return -1 if colors can't even fit in sub-palette hardware limit + if(pal.size() > colors_per_pal) + { + return -1; + } + //Check if it matches any palettes or create a new one + int i; + for(i = 0; i < (int)palettes.size(); ++i) + { + //Try to merge this palette with any of the palettes (checking if they are equal is not enough since the palettes can have less than 4 colors) + SetPal merged(palettes[i]); + merged.insert(pal.begin(), pal.end()); + if(merged.size() <= colors_per_pal) + { + if(palettes[i].size() <= colors_per_pal) + palettes[i] = merged; //Increase colors with this palette (it has less than 4 colors) + return i; //Found palette + } + } - if(i == (int)palettes.size()) - { - //Palette not found, add a new one - palettes.push_back(pal); - } - return i; + if(i == (int)palettes.size()) + { + //Palette not found, add a new one + palettes.push_back(pal); + } + return i; } @@ -78,40 +78,40 @@ int FindOrCreateSubPalette(const SetPal& pal, vector< SetPal >& palettes, size_t // int* BuildPalettesAndAttributes(const PNGImage& image32, vector< SetPal >& palettes, bool half_resolution) { - int* palettes_per_tile = new int[(image32.w / image32.tile_w) * (image32.h / image32.tile_h)]; - int sx = half_resolution ? 2 : 1; - int sy = half_resolution ? 2 : 1; - for(unsigned int y = 0; y < image32.h; y += image32.tile_h * sy) - { - for(unsigned int x = 0; x < image32.w; x += image32.tile_w * sx) - { - //Get palette colors on (x, y, image32.tile_w, image32.tile_h) - SetPal pal = GetPaletteColors(image32, (x / sx) * sx, (y / sy) * sy, sx * image32.tile_w, sy * image32.tile_h); + int* palettes_per_tile = new int[(image32.w / image32.tile_w) * (image32.h / image32.tile_h)]; + int sx = half_resolution ? 2 : 1; + int sy = half_resolution ? 2 : 1; + for(unsigned int y = 0; y < image32.h; y += image32.tile_h * sy) + { + for(unsigned int x = 0; x < image32.w; x += image32.tile_w * sx) + { + //Get palette colors on (x, y, image32.tile_w, image32.tile_h) + SetPal pal = GetPaletteColors(image32, (x / sx) * sx, (y / sy) * sy, sx * image32.tile_w, sy * image32.tile_h); - int subPalIndex = FindOrCreateSubPalette(pal, palettes, image32.colors_per_pal); - if(subPalIndex < 0) - { - printf("Error: more than %d colors found in tile at x:%d, y:%d of size w:%d, h:%d\n", - (unsigned int)image32.colors_per_pal, - (x / sx) * sx, - (y / sy) * sy, - sx * image32.tile_w, - sy * image32.tile_h); - subPalIndex = 0; // Force to sub-palette 0, to allow getting a partially-incorrect output image - } - // Assign single or multiple entries in palettes_per_tile, to keep it independent of - // of half_resolution parameter - int dx = ((x / image32.tile_w) / sx) * sx; - int dy = ((y / image32.tile_h) / sy) * sy; - int w = (image32.w / image32.tile_w); - for(int yy = 0; yy < sy; yy++) - { - for(int xx = 0; xx < sx; xx++) - { - palettes_per_tile[(dy + yy) * w + dx + xx] = subPalIndex; - } - } - } - } - return palettes_per_tile; + int subPalIndex = FindOrCreateSubPalette(pal, palettes, image32.colors_per_pal); + if(subPalIndex < 0) + { + printf("Error: more than %d colors found in tile at x:%d, y:%d of size w:%d, h:%d\n", + (unsigned int)image32.colors_per_pal, + (x / sx) * sx, + (y / sy) * sy, + sx * image32.tile_w, + sy * image32.tile_h); + subPalIndex = 0; // Force to sub-palette 0, to allow getting a partially-incorrect output image + } + // Assign single or multiple entries in palettes_per_tile, to keep it independent of + // of half_resolution parameter + int dx = ((x / image32.tile_w) / sx) * sx; + int dy = ((y / image32.tile_h) / sy) * sy; + int w = (image32.w / image32.tile_w); + for(int yy = 0; yy < sy; yy++) + { + for(int xx = 0; xx < sx; xx++) + { + palettes_per_tile[(dy + yy) * w + dx + xx] = subPalIndex; + } + } + } + } + return palettes_per_tile; }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.