Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DrawAffineImage lacking precision? #5497

Closed
afalkenhahn opened this issue Aug 27, 2022 · 1 comment
Closed

DrawAffineImage lacking precision? #5497

afalkenhahn opened this issue Aug 27, 2022 · 1 comment

Comments

@afalkenhahn
Copy link

ImageMagick version

7.1.0.46

Operating system

Linux

Operating system, version and so on

Ubuntu

Description

I was wondering if DrawAffineImage should be improved to have a better precision. It currently does this:

  extent[0].x=0.0;
  extent[0].y=0.0;
  extent[1].x=(double) source->columns-1.0;
  extent[1].y=0.0;
  extent[2].x=(double) source->columns-1.0;
  extent[2].y=(double) source->rows-1.0;
  extent[3].x=0.0;
  extent[3].y=(double) source->rows-1.0;
  for (i=0; i < 4; i++)
  {
    PointInfo
      point;

    point=extent[i];
    extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx;
    extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty;
  }
  min=extent[0];
  max=extent[0];
  for (i=1; i < 4; i++)
  {
    if (min.x > extent[i].x)
      min.x=extent[i].x;
    if (min.y > extent[i].y)
      min.y=extent[i].y;
    if (max.x < extent[i].x)
      max.x=extent[i].x;
    if (max.y < extent[i].y)
      max.y=extent[i].y;
  }

Now imagine applying an affine transform consisting of sx=10 and sy=10 to a 10x10 pixel image. Since DrawAffineImage subtracts 1.0 from the edges before applying the affine transform we'll end up with a max.x and max.y of 90 instead of 100, which is rather imprecise.

Is this a bug or am I missing something here? AFAICT it'd be better to not subtract 1.0 from the right and bottom edges before applying the transform. Then applying a matrix of sx=10 and sy=10 to a 10x10 pixel image would result in a 100x100 image, as expected.

Steps to Reproduce

see above

Images

No response

@urban-warrior
Copy link
Member

Your analysis is correct, we should check the bounds after the transform. We'll apply a patch ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants