diff options
author | Neil <nyamatongwe@gmail.com> | 2021-04-20 09:11:22 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2021-04-20 09:11:22 +1000 |
commit | ed434975e5de00e91718b075f04492f69c1bb04a (patch) | |
tree | e9026a3fa701c1e11babb26aea766bfa9abda7b9 /src/XPM.cxx | |
parent | eb5616987e0c064a175d5eb111338e1e6f5af54c (diff) | |
download | scintilla-mirror-ed434975e5de00e91718b075f04492f69c1bb04a.tar.gz |
Feature [feature-requests:#1402]. Unify colour type with ColourAlpha.
Change ColourDesired to ColourAlpha in XPM and RGBAImage.
Diffstat (limited to 'src/XPM.cxx')
-rw-r--r-- | src/XPM.cxx | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/src/XPM.cxx b/src/XPM.cxx index c310911f6..ef2ba961a 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -60,17 +60,17 @@ unsigned int ValueOfHex(const char ch) noexcept { return 0; } -ColourDesired ColourFromHex(const char *val) noexcept { +ColourAlpha ColourFromHex(const char *val) noexcept { const unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]); const unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]); const unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]); - return ColourDesired(r, g, b); + return ColourAlpha(r, g, b); } } -ColourDesired XPM::ColourFromCode(int ch) const noexcept { +ColourAlpha XPM::ColourFromCode(int ch) const noexcept { return colourCodeTable[ch]; } @@ -116,7 +116,7 @@ void XPM::Init(const char *const *linesForm) { if (!linesForm) return; - std::fill(colourCodeTable, std::end(colourCodeTable), ColourDesired(0)); + std::fill(colourCodeTable, std::end(colourCodeTable), ColourAlpha(0, 0, 0)); const char *line0 = linesForm[0]; width = atoi(line0); line0 = NextField(line0); @@ -134,7 +134,7 @@ void XPM::Init(const char *const *linesForm) { const char *colourDef = linesForm[c+1]; const char code = colourDef[0]; colourDef += 4; - ColourDesired colour(0xff, 0xff, 0xff); + ColourAlpha colour(0, 0, 0, 0); if (*colourDef == '#') { colour = ColourFromHex(colourDef+1); } else { @@ -173,19 +173,13 @@ void XPM::Draw(Surface *surface, const PRectangle &rc) { } } -void XPM::PixelAt(int x, int y, ColourDesired &colour, bool &transparent) const noexcept { - if (pixels.empty() || (x<0) || (x >= width) || (y<0) || (y >= height)) { - colour = ColourDesired(0); - transparent = true; - return; +ColourAlpha XPM::PixelAt(int x, int y) const noexcept { + if (pixels.empty() || (x < 0) || (x >= width) || (y < 0) || (y >= height)) { + // Out of bounds -> transparent black + return ColourAlpha(0, 0, 0, 0); } const int code = pixels[y * width + x]; - transparent = code == codeTransparent; - if (transparent) { - colour = ColourDesired(0); - } else { - colour = ColourFromCode(code); - } + return ColourFromCode(code); } std::vector<const char *> XPM::LinesFormFromTextForm(const char *textForm) { @@ -239,10 +233,7 @@ RGBAImage::RGBAImage(const XPM &xpm) { pixelBytes.resize(CountBytes()); for (int y=0; y<height; y++) { for (int x=0; x<width; x++) { - ColourDesired colour; - bool transparent = false; - xpm.PixelAt(x, y, colour, transparent); - SetPixel(x, y, colour, transparent ? 0 : 255); + SetPixel(x, y, xpm.PixelAt(x, y)); } } } @@ -258,13 +249,13 @@ const unsigned char *RGBAImage::Pixels() const noexcept { return &pixelBytes[0]; } -void RGBAImage::SetPixel(int x, int y, ColourDesired colour, int alpha) noexcept { - unsigned char *pixel = &pixelBytes[0] + (y*width+x) * 4; +void RGBAImage::SetPixel(int x, int y, ColourAlpha colour) noexcept { + unsigned char *pixel = &pixelBytes[0] + (y * width + x) * 4; // RGBA pixel[0] = colour.GetRed(); pixel[1] = colour.GetGreen(); pixel[2] = colour.GetBlue(); - pixel[3] = static_cast<unsigned char>(alpha); + pixel[3] = colour.GetAlpha(); } // Transform a block of pixels from RGBA to BGRA with premultiplied alpha. |