Skip to content

Commit

Permalink
Merge pull request #773 from jpcima/image-alpha
Browse files Browse the repository at this point in the history
Support transparent background images
  • Loading branch information
jpcima authored Apr 3, 2021
2 parents e7290b1 + 128a94e commit 387297f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plugins/editor/src/editor/ImageHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ SharedPointer<CBitmap> loadAnyFormatImage(const fs::path& filePath)

const unsigned char* pixel = image.get();
do {
CColor c(pixel[0], pixel[1], pixel[2], pixel[3]);
accessor->setColor(c);
uint8_t r = pixel[0];
uint8_t g = pixel[1];
uint8_t b = pixel[2];
uint8_t a = pixel[3];

// premultiply alpha
r = uint8_t((r * a) / 255);
g = uint8_t((g * a) / 255);
b = uint8_t((b * a) / 255);

accessor->setColor(CColor(r, g, b, a));
pixel += 4;
} while (++*accessor);
accessor = nullptr;
Expand Down

0 comments on commit 387297f

Please sign in to comment.