MCPcopy Create free account
hub / github.com/ImageOptim/libimagequant / new_internal

Method new_internal

src/image.rs:78–113  ·  view source on GitHub ↗
(
        attr: &Attributes,
        pixels: PixelsSource<'pixels, 'pixels>,
        width: u32,
        height: u32,
        gamma: f64,
    )

Source from the content-addressed store, hash-verified

76 }
77
78 pub(crate) fn new_internal(
79 attr: &Attributes,
80 pixels: PixelsSource<'pixels, 'pixels>,
81 width: u32,
82 height: u32,
83 gamma: f64,
84 ) -> Result<Self, Error> {
85 if !Self::check_image_size(width, height) {
86 return Err(ValueOutOfRange);
87 }
88
89 if !(0. ..=1.).contains(&gamma) {
90 attr.verbose_print(" error: gamma must be >= 0 and <= 1 (try 1/gamma instead)");
91 return Err(ValueOutOfRange);
92 }
93 let img = Image {
94 px: DynamicRows::new(
95 width,
96 height,
97 pixels,
98 if gamma > 0. { gamma } else { 0.45455 },
99 ),
100 importance_map: None,
101 edges: None,
102 dither_map: None,
103 background: None,
104 fixed_colors: Vec::new(),
105 };
106 // if image is huge or converted pixels are not likely to be reused then don't cache converted pixels
107 let low_memory_hint = !attr.use_contrast_maps && attr.use_dither_map == DitherMapMode::None;
108 let limit = if low_memory_hint { LIQ_HIGH_MEMORY_LIMIT / 8 } else { LIQ_HIGH_MEMORY_LIMIT } / std::mem::size_of::<f_pixel>();
109 if (img.width()) * (img.height()) > limit {
110 attr.verbose_print(" conserving memory"); // for simplicity of this API there's no explicit pixels argument,
111 }
112 Ok(img)
113 }
114
115 fn check_image_size(width: u32, height: u32) -> bool {
116 if width == 0 || height == 0 {

Callers

nothing calls this directly

Calls 5

check_image_sizeFunction · 0.85
newFunction · 0.85
verbose_printMethod · 0.80
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected