Gecko:Image Snapping and Rendering: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 28: Line 28:
# Every pixel (in the plane of tiled images) 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 pixel (in the plane of tiled images) 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.)
# 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.)
# 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.)
# The anchor point, mapped back to image space via the initial rect, rounded to the nearest image pixel boundaries, and then mapped to device space via the algorithm's image space to device space transform, should end up at the original anchor point rounded to device pixel boundaries *in a manner consistent with the snapping of the fill rect*. (RATIONALE: A CSS background-position:right/bottom image should actually be drawn with the rightmost/bottommost set of pixels at the appropriate edge of the element, no matter what scaling is in effect, so we need to be told which edges should line up and make sure they do.)
# The anchor point, mapped back to image space via the initial rect, and then mapped to device space via the algorithm's image space to device space transform, should end up at the original anchor point transformed by the logical-fill-rectangle-to-device-fill-rectangle transform. (RATIONALE: A CSS background-position:right/bottom image should actually be drawn with the rightmost/bottommost set of pixels at the appropriate edge of the element, no matter what scaling is in effect, so we need to be told which edges should line up and make sure they do.)
 
To round a point P to device pixel boundaries "in a manner consistent with the snapping of rect R", let R' be the snapped R, and let M be the transform that maps R to R'. Then compute M(P) and round it to the nearest device pixel boundary.


Requirements 5 and 6 imply the following additional requirement:
Requirements 5 and 6 imply the following additional requirement:
Line 44: Line 42:
* 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.
* Map the anchor point back to image space (using the initial rect) and call the result P. Snap the anchor point to device pixels *consistent with the snapping of the fill rect* and call the result P'. Then the transformation from image space to device space is the transformation whose scale factors are the ratio of initial rectangle size in device pixels to image size in pixels, and which transforms P to P'.
* Map the anchor point back to image space (using the initial rect) and call the result P. Let P' be the anchor point transformed by the same transform tha maps the logical fill rectangle to the device pixel fill rectangle. Then the transformation from image space to device space is the transformation whose scale factors are the ratio of initial rectangle size in device pixels to image size in pixels, and which transforms P to P'.


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, 5 and 6 are satisfied by construction.
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, 5 and 6 are satisfied by construction.


This is really the only sensible algorithm that could satisfy the above requirements.
This is really the only sensible algorithm that could satisfy the above requirements.
1,295

edits

Navigation menu