Skip to content

Fix zoom level 20% distorts layers (fix #5774)#5776

Merged
dacap merged 1 commit into
aseprite:mainfrom
Gasparoken:fix-zoom
Apr 28, 2026
Merged

Fix zoom level 20% distorts layers (fix #5774)#5776
dacap merged 1 commit into
aseprite:mainfrom
Gasparoken:fix-zoom

Conversation

@Gasparoken

Copy link
Copy Markdown
Member

The problem was that sx was 0.20000000000000001 and then 1.0/sx gave 5.0 which naturally was truncated to 5. In the other hand, sy was 0.20000000000000004 and then 1.0/sy gave 4.9999999999999991 which was truncated to 4.

int step_w = int(1.0 / sx);
int step_h = int(1.0 / sy);

It would seem better to remove the multiplication and division of celBounds.w / double(cel_image->width()) and celBounds.h / double(cel_image->height()) that resulted in 0.20000000000000004 in the first place:

aseprite/src/render/render.cpp

Lines 1368 to 1369 in e053655

m_proj.scaleX() * celBounds.w / double(cel_image->width()),
m_proj.scaleY() * celBounds.h / double(cel_image->height()),

However, if I'm not mistaken, this is intended for reference layers. Therefore, I'll leave it as is.

Fix #5774

@Gasparoken Gasparoken requested a review from dacap as a code owner April 28, 2026 16:40
@Gasparoken Gasparoken assigned Gasparoken and unassigned dacap Apr 28, 2026

@aseprite-bot aseprite-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread src/render/render.cpp
BlenderHelper<DstTraits, SrcTraits> blender(dst, src, pal, blendMode, newBlend);
int step_w = int(1.0 / sx);
int step_h = int(1.0 / sy);
int step_w = int(std::round(1.0 / sx));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'step_w' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int step_w = int(std::round(1.0 / sx));
int const step_w = int(std::round(1.0 / sx));

Comment thread src/render/render.cpp
int step_w = int(1.0 / sx);
int step_h = int(1.0 / sy);
int step_w = int(std::round(1.0 / sx));
int step_h = int(std::round(1.0 / sy));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'step_h' of type 'int' can be declared 'const' [misc-const-correctness]

Suggested change
int step_h = int(std::round(1.0 / sy));
int const step_h = int(std::round(1.0 / sy));

@dacap

dacap commented Apr 28, 2026

Copy link
Copy Markdown
Member

It works great 👍 I'll merge it as it is (probably a release in main will include this fix tomorrow)

There are some crashes with the render logic which might be due to some similar issues, i.e. src/dst bounds being calculated outside the valid image bounds, e.g. in composite_image_general ASEPRITE-4AZ

@dacap dacap merged commit 793fb65 into aseprite:main Apr 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Zoom level 20% distorts layers

3 participants