add canvas:sub method

This commit is contained in:
MihailRis
2025-11-11 19:34:40 +03:00
parent 83f7bf80c4
commit 34d13442b6
5 changed files with 25 additions and 8 deletions
+4 -4
View File
@@ -448,7 +448,7 @@ void ImageData::mulColor(const glm::ivec4& color) {
}
}
void ImageData::addColor(const ImageData& other) {
void ImageData::addColor(const ImageData& other, int multiplier) {
check_matching(*this, other);
uint comps;
@@ -462,7 +462,7 @@ void ImageData::addColor(const ImageData& other) {
for (uint x = 0; x < width; x++) {
uint idx = (y * width + x) * comps;
for (uint c = 0; c < comps; c++) {
int val = data[idx + c] + other.data[idx + c];
int val = data[idx + c] + other.data[idx + c] * multiplier;
data[idx + c] =
static_cast<ubyte>(std::min(std::max(val, 0), 255));
}
@@ -470,7 +470,7 @@ void ImageData::addColor(const ImageData& other) {
}
}
void ImageData::addColor(const glm::ivec4& color) {
void ImageData::addColor(const glm::ivec4& color, int multiplier) {
uint comps;
switch (format) {
case ImageFormat::rgb888: comps = 3; break;
@@ -482,7 +482,7 @@ void ImageData::addColor(const glm::ivec4& color) {
for (uint x = 0; x < width; x++) {
uint idx = (y * width + x) * comps;
for (uint c = 0; c < comps; c++) {
int val = data[idx + c] + color[c];
int val = data[idx + c] + color[c] * multiplier;
data[idx + c] =
static_cast<ubyte>(std::min(std::max(val, 0), 255));
}
+2 -2
View File
@@ -34,8 +34,8 @@ public:
void fixAlphaColor();
void mulColor(const glm::ivec4& color);
void mulColor(const ImageData& other);
void addColor(const glm::ivec4& color);
void addColor(const ImageData& other);
void addColor(const glm::ivec4& color, int multiplier);
void addColor(const ImageData& other, int multiplier);
std::unique_ptr<ImageData> cropped(int x, int y, int width, int height) const;