Permalink
Browse files

Fix rendering issues with multiples of 3 zoom factors (fix #1349)

  • Loading branch information...
dacap committed Dec 28, 2016
1 parent 4892785 commit 0a68c4626db4a8f1b26a2d1fd10ff0c07b165d1c
Showing with 61 additions and 5 deletions.
  1. +7 −5 src/render/render.cpp
  2. +54 −0 src/render/render_tests.cpp
View
@@ -422,7 +422,7 @@ void composite_image_general(
double srcXDelta = 1.0 / sx;
int srcWidth = src->width();
for (int y=0; y<dstBounds.h; ++y, ++dstY) {
int srcY = (srcBounds.y+y) / sy;
int srcY = (srcBounds.y+double(y)) / sy;
double srcX = srcXStart;
int oldSrcX;
@@ -435,17 +435,19 @@ void composite_image_general(
int dstX = dstBounds.x;
#endif
for (int x=0; x<dstBounds.w; ++x, ++dstPtr) {
for (int x=0; x<dstBounds.w; ++dstPtr) {
ASSERT(dstX >= 0 && dstX < dst->width());
ASSERT(srcX >= 0 && srcX < src->width());
*dstPtr = blender(*dstPtr, *srcPtr, opacity);
++x;
oldSrcX = int(srcX);
srcX += srcXDelta;
if (srcX >= srcWidth)
srcX = srcXStart + srcXDelta*x;
if (srcX >= srcWidth) {
break;
srcPtr += (int(srcX) - oldSrcX);
}
srcPtr += int(srcX - oldSrcX);
#if _DEBUG
++dstX;
@@ -212,6 +212,60 @@ TEST(Render, ZoomAndDstBounds)
0, 0, 0, 0);
}
TEST(Render, BugWithMultiplesOf3ZoomFactors)
{
Context ctx;
Document* doc = ctx.documents().add(4, 4, ColorMode::RGB);
Image* src = doc->sprite()->root()->firstLayer()->cel(0)->image();
clear_image(src, 0);
draw_line(src, 0, 0, 3, 3, rgba(255, 0, 0, 255));
// Added other factors (like 1, 2, 4, etc.) too
int zooms[] = { 1, 2, 3, 4, 6, 8, 9, 12, 15, 16, 18, 21, 24, 27,
30, 32, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60,
63, 66, 69, 72, 75, 78, 81 };
for (int zoom : zooms) {
base::UniquePtr<Image> dst(Image::create(IMAGE_RGB, 4*zoom, 4*zoom));
clear_image(dst, 0);
Render render;
render.setBgType(BgType::CHECKED);
render.setBgZoom(false);
render.setBgColor1(rgba(128, 128, 128, 255));
render.setBgColor2(rgba(64, 64, 64, 255));
render.setBgCheckedSize(gfx::Size(2, 2));
render.setProjection(Projection(PixelRatio(1, 1), Zoom(zoom, 1)));
render.renderSprite(
dst, doc->sprite(), frame_t(0),
gfx::Clip(0, 0, 0, 0, 4*zoom, 4*zoom));
for (int y=0; y<dst->height(); ++y) {
for (int x=0; x<dst->width(); ++x) {
color_t c = get_pixel(dst, x, y);
if (x / zoom == y / zoom) {
EXPECT_EQ(c, rgba(255, 0, 0, 255))
<< " zoom=" << zoom << " x=" << x << " y=" << y;
}
else {
EXPECT_NE(c, rgba(255, 0, 0, 255))
<< " zoom=" << zoom << " x=" << x << " y=" << y;
int gridBg = ((x / 2) + (y / 2)) % 2;
if (gridBg == 0) {
EXPECT_EQ(c, rgba(128, 128, 128, 255))
<< " zoom=" << zoom << " x=" << x << " y=" << y;
}
else {
EXPECT_EQ(c, rgba(64, 64, 64, 255))
<< " zoom=" << zoom << " x=" << x << " y=" << y;
}
}
}
}
}
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);

0 comments on commit 0a68c46

Please sign in to comment.