@@ -61,7 +61,7 @@ pub(crate) const fn get_encoders(format: Format) -> Option<EncoderSet> {
6161 Format :: Y410 => Y410 ,
6262 Format :: Y416 => Y416 ,
6363
64- // sub-sampled formats
64+ // subsampled formats
6565 Format :: R1_UNORM => R1_UNORM ,
6666 Format :: R8G8_B8G8_UNORM => R8G8_B8G8_UNORM ,
6767 Format :: G8R8_G8B8_UNORM => G8R8_G8B8_UNORM ,
@@ -222,6 +222,12 @@ fn encode_parallel(
222222 progress. checked_report ( 1.0 )
223223}
224224
225+ /// Options for encoding images.
226+ ///
227+ /// ## See also
228+ ///
229+ /// - [`encode`]
230+ /// - [`Encoder::encoding`](crate::Encoder::encoding)
225231#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
226232#[ non_exhaustive]
227233pub struct EncodeOptions {
@@ -240,6 +246,9 @@ pub struct EncodeOptions {
240246 pub dithering : Dithering ,
241247 /// The error metric for block compression formats.
242248 ///
249+ /// This is currently only supported for BC1-3. All other formats will
250+ /// ignore this option and assume [`ErrorMetric::Uniform`].
251+ ///
243252 /// Default: [`ErrorMetric::Uniform`]
244253 pub error_metric : ErrorMetric ,
245254 /// The compression quality.
@@ -276,6 +285,8 @@ impl Default for EncodeOptions {
276285 }
277286}
278287
288+ /// Specifies whether dithering is enabled/supported for color and/or alpha
289+ /// channels.
279290#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , Default ) ]
280291pub enum Dithering {
281292 /// Dithering is disabled for all channels.
@@ -289,6 +300,7 @@ pub enum Dithering {
289300 Alpha = 0b10 ,
290301}
291302impl Dithering {
303+ /// Creates a new `Dithering` given the channels it is enabled for.
292304 pub const fn new ( color : bool , alpha : bool ) -> Self {
293305 match ( color, alpha) {
294306 ( true , true ) => Dithering :: ColorAndAlpha ,
@@ -298,9 +310,11 @@ impl Dithering {
298310 }
299311 }
300312
313+ /// Whether dithering is enabled for color channels.
301314 pub const fn color ( self ) -> bool {
302315 matches ! ( self , Dithering :: ColorAndAlpha | Dithering :: Color )
303316 }
317+ /// Whether dithering is enabled for the alpha channel.
304318 pub const fn alpha ( self ) -> bool {
305319 matches ! ( self , Dithering :: ColorAndAlpha | Dithering :: Alpha )
306320 }
@@ -318,10 +332,20 @@ impl Dithering {
318332 }
319333}
320334
335+ /// The error metric encoders use to optimize compressed formats.
336+ ///
337+ /// Not all formats support all error metrics. See
338+ /// [`EncodeOptions::error_metric`] for more details.
321339#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash , Default ) ]
322340pub enum ErrorMetric {
341+ /// The error of all channels is weighted equally.
323342 #[ default]
324343 Uniform ,
344+ /// Color is assumed to be sRGB, and the error is calculated in a
345+ /// perceptually uniform color space.
346+ ///
347+ /// [Oklab](https://en.wikipedia.org/wiki/Oklab_color_space) is currently
348+ /// used as the perceptually uniform color space.
325349 Perceptual ,
326350}
327351
0 commit comments