Skip to content

Commit 8cb097f

Browse files
committed
[css-images-3] Merge crisp-edges and nearest-neighbor, retaining the older crisp-edges name. #6038
1 parent 2263308 commit 8cb097f

File tree

1 file changed

+47
-27
lines changed

1 file changed

+47
-27
lines changed

css-images-3/Overview.bs

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ Determining How To Scale an Image: the 'image-rendering' property {#the-image-re
16881688

16891689
16901690
Name: image-rendering
1691-
Value: auto | smooth | high-quality | crisp-edges | pixelated
1691+
Value: auto | smooth | high-quality | pixelated | crisp-edges
16921692
Initial: auto
16931693
Applies to: all elements
16941694
Inherited: yes
@@ -1743,33 +1743,28 @@ Determining How To Scale an Image: the 'image-rendering' property {#the-image-re
17431743
pixelated
17441744
17451745
The image is scaled in a way that preserves the pixelated nature of the original as much as possible,
1746-
but allows minor smoothing instead of awkward distortion in some cases.
1746+
but allows minor smoothing instead of awkward distortion when necessary.
17471747

17481748
For each axis,
17491749
independently determine the integer multiple of its natural size
17501750
that puts it closest to the target size
17511751
and is greater than zero.
17521752

1753-
Scale it to this integer-multiple-size as for ''nearest-neighbor'',
1753+
Scale it to this integer-multiple-size as for ''crisp-edges'',
17541754
then scale it the rest of the way to the target size as for ''smooth''.
17551755

17561756
Note: At integer multiples of the natural size,
1757-
this gives the same results as ''nearest-neighbor''.
1757+
this gives the same results as ''crisp-edges''.
17581758
At non-integer multiples, this usually gives better visual results,
17591759
even for pixel art,
17601760
but it does incur a performance penalty
17611761
due to the "two-step" rendering requirement.
17621762

17631763
crisp-edges
17641764
1765-
The image must be scaled with an algorithm that preserves contrast and edges in the image,
1765+
The image is scaled in a way that preserves contrast and edges,
17661766
and which does not smooth colors or introduce blur to the image in the process.
17671767

1768-
This may be identical to ''nearest-neighbor'',
1769-
but UAs may use any algorithm that meets the requirements.
1770-
1771-
nearest-neighbor
1772-
17731768
The image must be scaled with the "nearest neighbor" algorithm:
17741769
treating the original image's pixel grid as a literal grid of rectangles,
17751770
scale those to the desired size,
@@ -1779,56 +1774,81 @@ Determining How To Scale an Image: the 'image-rendering' property {#the-image-re
17791774
Note: If the new size is not an integer multiple of the original size,
17801775
the NN algorithm can introduce significant "aliasing" bugs;
17811776
lines that were the same thickness in the original image
1782-
might be a pixel thinner or thicker in the scaled image,
1777+
might be a pixel thinner or thicker in the scaled image
17831778
depending on where they appear,
17841779
etc.
17851780
17861781

1787-
This property does not dictate any particular scaling algorithm to be used.
1782+
Other than ''crisp-edges''
1783+
and the portion of ''pixelated'' that acts like ''crisp-edges'',
1784+
this property does not dictate any particular scaling algorithm to be used.
17881785
For example, with ''image-rendering: auto'',
17891786
a user agent might scale images with bilinear interpolation by default,
17901787
switch to nearest-neighbor interpolation in high-load situations,
1791-
and switch to a high-quality scaling algorithm like Lanczos interpolation for static images that aren't moving or changing.
1792-
Similarly, with 'image-rendering: crisp-edges',
1793-
a user agent might scale images with nearest-neighbor interpolation by default,
1794-
and switch to EPX interpolation in low-load situations.
1788+
and switch to a high-quality scaling algorithm like Lanczos interpolation
1789+
for static images that aren't moving or changing.
17951790

17961791
17971792
For example, given the following small image:
17981793

17991794
18001795
1801-
A small pixel-art image.
1796+
A small pixel-art image.
18021797
18031798

18041799
Scaling it up 3x might look like the following,
18051800
depending on the value of 'image-rendering':
18061801

18071802
18081803
1809-
The image scaled with ''image-rendering/auto''
1804+
The image scaled with ''smooth''
18101805
18111806

18121807
18131808
1814-
The image scaled with ''pixelated''
1809+
The image scaled with ''pixelated'' or ''crisp-edges''
1810+
1811+
1812+
1813+
1814+
At the 3x scaling as in the preceding example,
1815+
''pixelated'' and ''crisp-edges'' give identical results.
1816+
At scale ratios in-between integer multiples,
1817+
however,
1818+
they'll act differently:
1819+
1820+
1821+
1822+
The same small pixel-art image as before.
1823+
1824+
1825+
1826+
1827+
The image scaled 2.5x with ''smooth''
18151828
18161829

18171830
1818-
1819-
1820-
The image scaled with ''crisp-edges''.
1821-
(Or it might look like ''nearest-neighbor'',
1822-
or as another type of pixel-scaling algorithm,
1823-
depending on the browser.)
1824-
1831+
1832+
The image scaled 2.5x with ''pixelated''
18251833
1834+
1835+
1836+
1837+
The image scaled 2.5x with ''crisp-edges''
1838+
1839+
1840+
The ''pixelated'' version maintains the overall look of simply scaling the pixels up,
1841+
at the cost of slight blurring,
1842+
tho much less blurring than the ''smooth'' scaling gives.
1843+
Meanwhile, ''crisp-edges'' avoids introducing any blurring at all,
1844+
at the cost of aliasing artifacts
1845+
making the "pixels" look irregularly sized.
18261846
18271847

18281848
This property previously accepted the values ''optimizeSpeed'' and ''optimizeQuality''.
18291849
These are now deprecated;
18301850
a user agent must accept them as valid values
1831-
but must treat them as having the same behavior as ''nearest-neighbor'' and ''smooth'' respectively,
1851+
but must treat them as having the same behavior as ''crisp-edges'' and ''smooth'' respectively,
18321852
and authors must not use them.
18331853

18341854

0 commit comments

Comments
 (0)