aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2021-04-20 09:11:22 +1000
committerNeil <nyamatongwe@gmail.com>2021-04-20 09:11:22 +1000
commited434975e5de00e91718b075f04492f69c1bb04a (patch)
treee9026a3fa701c1e11babb26aea766bfa9abda7b9 /src
parenteb5616987e0c064a175d5eb111338e1e6f5af54c (diff)
downloadscintilla-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')
-rw-r--r--src/Indicator.cxx18
-rw-r--r--src/XPM.cxx37
-rw-r--r--src/XPM.h8
3 files changed, 28 insertions, 35 deletions
diff --git a/src/Indicator.cxx b/src/Indicator.cxx
index 1ebc18b7f..f65b461ef 100644
--- a/src/Indicator.cxx
+++ b/src/Indicator.cxx
@@ -74,17 +74,19 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r
const int width = std::min(4000, static_cast<int>(rcSquiggle.Width()));
RGBAImage image(width, 3, 1.0, nullptr);
- enum { alphaFull = 0xff, alphaSide = 0x2f, alphaSide2=0x5f };
+ constexpr unsigned int alphaFull = 0xff;
+ constexpr unsigned int alphaSide = 0x2f;
+ constexpr unsigned int alphaSide2 = 0x5f;
for (int x = 0; x < width; x++) {
if (x%2) {
// Two halfway columns have a full pixel in middle flanked by light pixels
- image.SetPixel(x, 0, sacDraw.fore, alphaSide);
- image.SetPixel(x, 1, sacDraw.fore, alphaFull);
- image.SetPixel(x, 2, sacDraw.fore, alphaSide);
+ image.SetPixel(x, 0, ColourAlpha(sacDraw.fore, alphaSide));
+ image.SetPixel(x, 1, ColourAlpha(sacDraw.fore, alphaFull));
+ image.SetPixel(x, 2, ColourAlpha(sacDraw.fore, alphaSide));
} else {
// Extreme columns have a full pixel at bottom or top and a mid-tone pixel in centre
- image.SetPixel(x, (x % 4) ? 0 : 2, sacDraw.fore, alphaFull);
- image.SetPixel(x, 1, sacDraw.fore, alphaSide2);
+ image.SetPixel(x, (x % 4) ? 0 : 2, ColourAlpha(sacDraw.fore, alphaFull));
+ image.SetPixel(x, 1, ColourAlpha(sacDraw.fore, alphaSide2));
}
}
surface->DrawRGBAImage(rcSquiggle, image.GetWidth(), image.GetHeight(), image.Pixels());
@@ -207,13 +209,13 @@ void Indicator::Draw(Surface *surface, const PRectangle &rc, const PRectangle &r
// Draw horizontal lines top and bottom
for (int x=0; x<width; x++) {
for (int y = 0; y< height; y += height - 1) {
- image.SetPixel(x, y, sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha);
+ image.SetPixel(x, y, ColourAlpha(sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha));
}
}
// Draw vertical lines left and right
for (int y = 1; y<height; y++) {
for (int x=0; x<width; x += width-1) {
- image.SetPixel(x, y, sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha);
+ image.SetPixel(x, y, ColourAlpha(sacDraw.fore, ((x + y) % 2) ? outlineAlpha : fillAlpha));
}
}
surface->DrawRGBAImage(rcBox, image.GetWidth(), image.GetHeight(), image.Pixels());
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.
diff --git a/src/XPM.h b/src/XPM.h
index cacae9b8a..3f7b66b9a 100644
--- a/src/XPM.h
+++ b/src/XPM.h
@@ -18,9 +18,9 @@ class XPM {
int width=1;
int nColours=1;
std::vector<unsigned char> pixels;
- ColourDesired colourCodeTable[256];
+ ColourAlpha colourCodeTable[256];
char codeTransparent=' ';
- ColourDesired ColourFromCode(int ch) const noexcept;
+ ColourAlpha ColourFromCode(int ch) const noexcept;
void FillRun(Surface *surface, int code, int startX, int y, int x) const;
public:
explicit XPM(const char *textForm);
@@ -36,7 +36,7 @@ public:
void Draw(Surface *surface, const PRectangle &rc);
int GetHeight() const noexcept { return height; }
int GetWidth() const noexcept { return width; }
- void PixelAt(int x, int y, ColourDesired &colour, bool &transparent) const noexcept;
+ ColourAlpha PixelAt(int x, int y) const noexcept;
private:
static std::vector<const char *>LinesFormFromTextForm(const char *textForm);
};
@@ -65,7 +65,7 @@ public:
float GetScaledWidth() const noexcept { return width / scale; }
int CountBytes() const noexcept;
const unsigned char *Pixels() const noexcept;
- void SetPixel(int x, int y, ColourDesired colour, int alpha) noexcept;
+ void SetPixel(int x, int y, ColourAlpha colour) noexcept;
static void BGRAFromRGBA(unsigned char *pixelsBGRA, const unsigned char *pixelsRGBA, size_t count) noexcept;
};