Skip to content

Commit

Permalink
fix: item brushes images
Browse files Browse the repository at this point in the history
  • Loading branch information
phacUFPE committed Oct 1, 2024
1 parent d7ae1a9 commit de117ae
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions source/sprite_appearances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,28 @@ wxImage SpriteAppearances::getWxImageBySpriteId(int id, bool toSavePng /* = fals
}

const int bgshade = g_settings.getInteger(Config::ICON_BACKGROUND);
const uint32_t magenta = 0xFF00FF;
const uint32_t lightMagenta = 0xD000CF;
constexpr uint32_t magenta = 0xFF00FF;
constexpr uint32_t lightMagenta = 0xD000CF;

const int width = sprite->size.width;
const int width = sprite->size.height <= rme::SpritePixels && sprite->size.width <= rme::SpritePixels ? sprite->size.width : rme::SpritePixels + 32;
const int height = sprite->size.height;
auto pixels = sprite->pixels.data();
wxImage image(width, height);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
const int index = (y * width + x) * 4;
uint8_t r = pixels[index + 2];
uint8_t g = pixels[index + 1];
uint8_t b = pixels[index];

// Starts with magenta color
uint8_t r = 255;
uint8_t g = 0;
uint8_t b = 255;

// If index is inside pixels bounds applies the color of the sprite
if (sprite->pixels.size() > index) {
r = pixels[index + 2];
g = pixels[index + 1];
b = pixels[index];
}

// Combines the color channels into a single 32-bit value
uint32_t color = (r << 16) | (g << 8) | b;
Expand All @@ -241,10 +250,17 @@ wxImage SpriteAppearances::getWxImageBySpriteId(int id, bool toSavePng /* = fals
if (color == magenta || color == lightMagenta) {
r = g = b = bgshade; // Sets RGB to the background color
}

image.SetRGB(x, y, r, g, b);
}
}

// Cut duplicated image and sets to the selected bgshade the empty background
if (sprite->size.width > rme::SpritePixels && sprite->size.height <= rme::SpritePixels) {
const auto imageSize = image.GetSize();
image.Resize(wxSize(imageSize.x, imageSize.y), wxPoint(-imageSize.x + rme::SpritePixels, 0), bgshade, bgshade, bgshade);
}

return image;
}

Expand Down

0 comments on commit de117ae

Please sign in to comment.