Skip to content

Commit

Permalink
Merge remote-tracking branch 'src/main' into feature/ngp-ngpc
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Jan 2, 2025
2 parents 16eb035 + 3691d8c commit 70f5379
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ constexpr channel_t scale_up(channel_t value, unsigned shift) {
}
}

// scale down value, rounding evenly
constexpr channel_t scale_down(channel_t value, unsigned shift) {
return (value + (1 << (shift - 1))) >> shift;
}

//
// rgba_color / hsva_color
//
Expand Down
21 changes: 12 additions & 9 deletions src/Mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ inline rgba_t reduce_color(const rgba_t color, Mode to_mode) {
return transparent_color;
} else {
rgba_color c(color);
c.r >>= 3;
c.g >>= 3;
c.b >>= 3;
c.r = scale_down(c.r, 3);
c.g = scale_down(c.g, 3);
c.b = scale_down(c.b, 3);
rgba_t scaled = c;
return (scaled & 0x00ffffff) + 0xff000000;
}
Expand Down Expand Up @@ -405,16 +405,19 @@ inline rgba_t reduce_color(const rgba_t color, Mode to_mode) {
return transparent_color;
} else {
rgba_color c(color);
c.r >>= 5;
c.g >>= 5;
c.b >>= 5;
c.r = scale_down(c.r, 5);
c.g = scale_down(c.g, 5);
c.b = scale_down(c.b, 5);
rgba_t scaled = c;
return (scaled & 0x00ffffff) + 0xff000000;
}
break;
case Mode::sms:
{
rgba_color c(color);
c.r = scale_down(c.r, 6);
c.g = scale_down(c.g, 6);
c.b = scale_down(c.b, 6);
c.r >>= 6;
c.g >>= 6;
c.b >>= 6;
Expand All @@ -430,9 +433,9 @@ inline rgba_t reduce_color(const rgba_t color, Mode to_mode) {
return transparent_color;
} else {
rgba_color c(color);
c.r >>= 4;
c.g >>= 4;
c.b >>= 4;
c.r = scale_down(c.r, 4);
c.g = scale_down(c.g, 4);
c.b = scale_down(c.b, 4);
rgba_t scaled = c;
return (scaled & 0x00ffffff) + 0xff000000;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ std::vector<Tile> Tileset::remap_tiles_for_output(const std::vector<Tile>& tiles

for (unsigned i = 0; i < tiles.size(); ++i) {
unsigned base_pos =
(((i / tiles_per_row) * cells_per_tile_v) * cells_per_row) + ((i % tiles_per_row) << (cells_per_tile_h - 2));
(((i / tiles_per_row) * cells_per_tile_v) * cells_per_row) + ((i % tiles_per_row) * cells_per_tile_h);
const auto ct = tiles[i].crops(8, 8);
for (unsigned cy = 0; cy < cells_per_tile_v; ++cy) {
for (unsigned cx = 0; cx < cells_per_tile_h; ++cx) {
Expand Down

0 comments on commit 70f5379

Please sign in to comment.