Skip to content

Commit 24b32ab

Browse files
ssiebest31
authored andcommittedApr 5, 2016
Fix compiler warnings from "Add an option to colorize to respect the destination alpha"
Fix warnings added by commit 01ae43c Fixes #3952
1 parent 01ae43c commit 24b32ab

File tree

1 file changed

+9
-41
lines changed

1 file changed

+9
-41
lines changed
 

‎src/client/tile.cpp

+9-41
Original file line numberDiff line numberDiff line change
@@ -553,16 +553,11 @@ static void blit_with_alpha(video::IImage *src, video::IImage *dst,
553553
static void blit_with_alpha_overlay(video::IImage *src, video::IImage *dst,
554554
v2s32 src_pos, v2s32 dst_pos, v2u32 size);
555555

556-
// Like blit_with_alpha overlay, but uses an int to calculate the ratio
557-
// and modifies any destination pixels that are not fully transparent
558-
static void blit_with_interpolate_overlay(video::IImage *src, video::IImage *dst,
559-
v2s32 src_pos, v2s32 dst_pos, v2u32 size, int ratio);
560-
561556
// Apply a color to an image. Uses an int (0-255) to calculate the ratio.
562557
// If the ratio is 255 or -1 and keep_alpha is true, then it multiples the
563558
// color alpha with the destination alpha.
564559
// Otherwise, any pixels that are not fully transparent get the color alpha.
565-
static void apply_colorize(video::IImage *dst, v2s32 dst_pos, v2u32 size,
560+
static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size,
566561
video::SColor color, int ratio, bool keep_alpha);
567562

568563
// Apply a mask to an image
@@ -1656,7 +1651,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
16561651
else if (ratio_str == "alpha")
16571652
keep_alpha = true;
16581653

1659-
apply_colorize(baseimg, v2s32(0, 0), baseimg->getDimension(), color, ratio, keep_alpha);
1654+
apply_colorize(baseimg, v2u32(0, 0), baseimg->getDimension(), color, ratio, keep_alpha);
16601655
}
16611656
else if (str_starts_with(part_of_name, "[applyfiltersformesh"))
16621657
{
@@ -1753,62 +1748,35 @@ static void blit_with_alpha_overlay(video::IImage *src, video::IImage *dst,
17531748
}
17541749
}
17551750

1756-
/*
1757-
Draw an image on top of an another one, using the specified ratio
1758-
modify all partially-opaque pixels in the destination.
1759-
*/
1760-
static void blit_with_interpolate_overlay(video::IImage *src, video::IImage *dst,
1761-
v2s32 src_pos, v2s32 dst_pos, v2u32 size, int ratio)
1762-
{
1763-
for (u32 y0 = 0; y0 < size.Y; y0++)
1764-
for (u32 x0 = 0; x0 < size.X; x0++)
1765-
{
1766-
s32 src_x = src_pos.X + x0;
1767-
s32 src_y = src_pos.Y + y0;
1768-
s32 dst_x = dst_pos.X + x0;
1769-
s32 dst_y = dst_pos.Y + y0;
1770-
video::SColor src_c = src->getPixel(src_x, src_y);
1771-
video::SColor dst_c = dst->getPixel(dst_x, dst_y);
1772-
if (dst_c.getAlpha() > 0 && src_c.getAlpha() != 0)
1773-
{
1774-
if (ratio == -1)
1775-
dst_c = src_c.getInterpolated(dst_c, (float)src_c.getAlpha()/255.0f);
1776-
else
1777-
dst_c = src_c.getInterpolated(dst_c, (float)ratio/255.0f);
1778-
dst->setPixel(dst_x, dst_y, dst_c);
1779-
}
1780-
}
1781-
}
1782-
17831751
/*
17841752
Apply color to destination
17851753
*/
1786-
static void apply_colorize(video::IImage *dst, v2s32 dst_pos, v2u32 size,
1754+
static void apply_colorize(video::IImage *dst, v2u32 dst_pos, v2u32 size,
17871755
video::SColor color, int ratio, bool keep_alpha)
17881756
{
17891757
u32 alpha = color.getAlpha();
17901758
video::SColor dst_c;
17911759
if ((ratio == -1 && alpha == 255) || ratio == 255) { // full replacement of color
17921760
if (keep_alpha) { // replace the color with alpha = dest alpha * color alpha
17931761
dst_c = color;
1794-
for (s32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++)
1795-
for (s32 x = dst_pos.X; x < dst_pos.X + size.X; x++) {
1762+
for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++)
1763+
for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) {
17961764
u32 dst_alpha = dst->getPixel(x, y).getAlpha();
17971765
if (dst_alpha > 0) {
17981766
dst_c.setAlpha(dst_alpha * alpha / 255);
17991767
dst->setPixel(x, y, dst_c);
18001768
}
18011769
}
18021770
} else { // replace the color including the alpha
1803-
for (s32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++)
1804-
for (s32 x = dst_pos.X; x < dst_pos.X + size.X; x++)
1771+
for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++)
1772+
for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++)
18051773
if (dst->getPixel(x, y).getAlpha() > 0)
18061774
dst->setPixel(x, y, color);
18071775
}
18081776
} else { // interpolate between the color and destination
18091777
float interp = (ratio == -1 ? color.getAlpha() / 255.0f : ratio / 255.0f);
1810-
for (s32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++)
1811-
for (s32 x = dst_pos.X; x < dst_pos.X + size.X; x++) {
1778+
for (u32 y = dst_pos.Y; y < dst_pos.Y + size.Y; y++)
1779+
for (u32 x = dst_pos.X; x < dst_pos.X + size.X; x++) {
18121780
dst_c = dst->getPixel(x, y);
18131781
if (dst_c.getAlpha() > 0) {
18141782
dst_c = color.getInterpolated(dst_c, interp);

0 commit comments

Comments
 (0)
Please sign in to comment.