Gecko:Image Snapping and Rendering: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
Line 22: Line 22:
# Every image pixel sampled in actual rendering would also be sampled by an ideal rendering to an infinite-resolution device. (RATIONALE: Web authors should not be faced with fringes contributed by pixels they did not intend to be sampled.)
# Every image pixel sampled in actual rendering would also be sampled by an ideal rendering to an infinite-resolution device. (RATIONALE: Web authors should not be faced with fringes contributed by pixels they did not intend to be sampled.)
# If the initial rectangle size in device pixels equals the image size in CSS pixels, then the filled area is rendered as a simple copy of the ideal rendering translated by less than or equal to half a pixel in the horizontal and vertical directions (except where image pixels in the ideal rendering do not contain the center of any device pixel --- i.e. partial pixels). (RATIONALE: If the scale factor in the author's design is exactly the inverse of the scale required by the device, we must avoid scaling and subpixel translation or there will be unnecessary image blurring and performance penalty; in fact, all we're allowed to do is translate the rendering by a minimal amount to pixel-align the image.)
# If the initial rectangle size in device pixels equals the image size in CSS pixels, then the filled area is rendered as a simple copy of the ideal rendering translated by less than or equal to half a pixel in the horizontal and vertical directions (except where image pixels in the ideal rendering do not contain the center of any device pixel --- i.e. partial pixels). (RATIONALE: If the scale factor in the author's design is exactly the inverse of the scale required by the device, we must avoid scaling and subpixel translation or there will be unnecessary image blurring and performance penalty; in fact, all we're allowed to do is translate the rendering by a minimal amount to pixel-align the image.)
# The ratio of initial rectangle size in device pixels to image size in CSS pixels, along both axes, must be used as the scale factors for the image space to device space transform. (RATIONALE: Otherwise scaled image tiling will become grossly incorrect at large distances.)


Note that requirements 3 and 5 together imply that, if no scaling was requested, a whole image pixel in the ideal rendering will be present in the actual rendering, translated by at most half a pixel in each direction.
Note that requirements 3 and 5 together imply that, if no scaling was requested, a whole image pixel in the ideal rendering will be present in the actual rendering, translated by at most half a pixel in each direction.
Line 32: Line 33:
* Compute device pixel fill rectangle by snapping the logical fill rectangle to device pixels, preserving device pixel centers, thus ensuring requirement 3.
* Compute device pixel fill rectangle by snapping the logical fill rectangle to device pixels, preserving device pixel centers, thus ensuring requirement 3.
* Compute device pixel draw rectangle by intersecting the device pixel fill rectangle with the dirty rectangle scaled to device pixels and rounded out. This is the area to cairo_fill.
* Compute device pixel draw rectangle by intersecting the device pixel fill rectangle with the dirty rectangle scaled to device pixels and rounded out. This is the area to cairo_fill.
* Compute the transformation from image space to device space: compute the device pixel initial rectangle by snapping the initial rectangle to device pixels, preserving device pixel centers. Then the transformation from image space to device space is the transformation that maps the image bounds to the device pixel initial rectangle.
* Compute the transformation from image space to device space: compute the device pixel initial rectangle by snapping the initial rectangle to device pixels, preserving device pixel centers. Then the transformation from image space to device space is the transformation that maps the top-left of the image to the top-left of the device pixel initial rectangle, and whose scale factors are ratio of initial rectangle size in device pixels to image size in pixels.


Requirement 2 is obviously satisfied since the dirty rect is only used to constrain the filled area and does not affect the mapping from image space to device space. Requirements 3 and 4 are satisfied by construction. Proof that requirement 5 is always satisfied:
Requirement 2 is obviously satisfied since the dirty rect is only used to constrain the filled area and does not affect the mapping from image space to device space. Requirements 3, 4 and 6 are satisfied by construction. Proof that requirement 5 is always satisfied:


Assume the initial rectangle size in device pixels equals the image size in CSS pixels. Then the initial rectangle size is integral numbers of device pixels, so the device pixel initial rectangle has the same size. So the scale factors of the transform are 1. Now, the translation from image space to device context space in the ideal rendering is just the top-left of the initial rectangle
Assume the initial rectangle size in device pixels equals the image size in CSS pixels. Then the initial rectangle size is integral numbers of device pixels, so the device pixel initial rectangle has the same size. So the scale factors of the transform are 1. Now, the translation from image space to device context space in the ideal rendering is just the top-left of the initial rectangle
in device pixels. The translation in our rendering is the top-left of the device pixel initial rectangle, which is the top-left of the initial rectangle snapped to the nearest pixel edges --- a translation of at most half a pixel in each direction. The only other thing we need to show is that every image pixel whose ideal rendering contains a device pixel center is actually rendered; this follows because the device pixel fill rectangle preserves the device pixel centres of the logical fill rectangle. QED.
in device pixels. The translation in our rendering is the top-left of the device pixel initial rectangle, which is the top-left of the initial rectangle snapped to the nearest pixel edges --- a translation of at most half a pixel in each direction. The only other thing we need to show is that every image pixel whose ideal rendering contains a device pixel center is actually rendered; this follows because the device pixel fill rectangle preserves the device pixel centres of the logical fill rectangle. QED.
1,295

edits

Navigation menu