0

Running in circles in grepcode trying to find the source for how a rotated image is drawn with subpixel accuracy. I am specifically interested in the method drawImage(Image img, AffineTransform xform, ImageObserver obs) which handles rotations but lacks implementation detail.

A rotation is rarely a mapping from integer (i,j) to integer (u,v) so at some intermediate level a sub-pixel view of the rotated image is created. This is not exposed to us via any API (that I know of) so I cannot inspect it, we are only given the imageraster. So how does graphics2d handle subpixel drawing when pixel coordinates are integers?

arynaq
  • 6,710
  • 9
  • 44
  • 74
  • I don't know what you mean by subpixel accuracy. A pixel is the smallest unit of picture that a computer can display. I don't see why it wouldn't be just an integer mapping based on the angle of rotation. – Cruncher Oct 09 '13 at 17:57
  • Because the image looks too nice to be (int) value of rotation on (i,j). Also imagine chaining rotations, int casting will ruin the image in a few rotations which is clearly not the case. – arynaq Oct 09 '13 at 18:00
  • It likely saves an accurate pixel location, and then rounds them to display. When it rotates again, it uses the absolute locations, then casts again to display. – Cruncher Oct 09 '13 at 18:03
  • Another(probably better) possibility, is that is saves all of the original pixel locations, and the angle, and everytime you change the angle, it recomputes off of the original image. – Cruncher Oct 09 '13 at 18:04

1 Answers1

1

There is no single implementation for that, actually there is no specification on how that is implemented. The Oracle JRE implements Graphics2D in sun.java2d.SunGraphics2D (for which no source is provided in the Oracle JDK).

And that implementation is probably just a facade for the underlying OS graphics system, which in turn will probably delegate most of the work further down to the graphics driver. Implementation will certainly contain platform specific code at some point. I suggest you take a look at the OpenJDK sources for one example of implementation: http://openjdk.java.net/groups/2d/

Durandal
  • 19,919
  • 4
  • 36
  • 70