| 1 | /* |
| 2 | * Copyright (c) 2023. |
| 3 | * |
| 4 | * This software is free software; |
| 5 | * |
| 6 | * You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license |
| 7 | */ |
| 8 | |
| 9 | //! Main image logic. |
| 10 | #![allow(clippy::doc_markdown)] |
| 11 | |
| 12 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::ToStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/ToString#; |
| 13 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 14 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/}; |
| 15 | |
| 16 | use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::bytestreamrust-analyzer cargo zune-core 0.5.1 bytestream/::{ZByteReaderTraitrust-analyzer cargo zune-core 0.5.1 bytestream/traits/ZByteReaderTrait#, ZReaderrust-analyzer cargo zune-core 0.5.1 bytestream/reader/ZReader#}; |
| 17 | use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::colorspacerust-analyzer cargo zune-core 0.5.1 colorspace/::ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#; |
| 18 | use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::logrust-analyzer cargo log 0.4.29 crate/::{errorrust-analyzer cargo log 0.4.29 macros/error!, tracerust-analyzer cargo log 0.4.29 macros/trace!, warnrust-analyzer cargo log 0.4.29 macros/warn!}; |
| 19 | use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::optionsrust-analyzer cargo zune-core 0.5.1 options/::DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#; |
| 20 | |
| 21 | use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::color_convertrust-analyzer cargo zune-jpeg 0.5.15 color_convert/::choose_ycbcr_to_rgb_convert_funcrust-analyzer cargo zune-jpeg 0.5.15 color_convert/choose_ycbcr_to_rgb_convert_func().; |
| 22 | use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::componentsrust-analyzer cargo zune-jpeg 0.5.15 components/::{Componentsrust-analyzer cargo zune-jpeg 0.5.15 components/Components#, SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#}; |
| 23 | use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::errorsrust-analyzer cargo zune-jpeg 0.5.15 errors/::{DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#, UnsupportedSchemesrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#}; |
| 24 | use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::headersrust-analyzer cargo zune-jpeg 0.5.15 headers/::{ |
| 25 | parse_app1rust-analyzer cargo zune-jpeg 0.5.15 headers/parse_app1()., parse_app13rust-analyzer cargo zune-jpeg 0.5.15 headers/parse_app13()., parse_app14rust-analyzer cargo zune-jpeg 0.5.15 headers/parse_app14()., parse_app2rust-analyzer cargo zune-jpeg 0.5.15 headers/parse_app2()., parse_dqtrust-analyzer cargo zune-jpeg 0.5.15 headers/parse_dqt()., parse_huffmanrust-analyzer cargo zune-jpeg 0.5.15 headers/parse_huffman()., parse_sosrust-analyzer cargo zune-jpeg 0.5.15 headers/parse_sos()., |
| 26 | parse_start_of_framerust-analyzer cargo zune-jpeg 0.5.15 headers/parse_start_of_frame(). |
| 27 | }; |
| 28 | use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::huffmanrust-analyzer cargo zune-jpeg 0.5.15 huffman/::HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#; |
| 29 | use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::idctrust-analyzer cargo zune-jpeg 0.5.15 idct/::{choose_idct_funcrust-analyzer cargo zune-jpeg 0.5.15 idct/choose_idct_func()., choose_idct_1x1_funcrust-analyzer cargo zune-jpeg 0.5.15 idct/choose_idct_1x1_func()., choose_idct_4x4_funcrust-analyzer cargo zune-jpeg 0.5.15 idct/choose_idct_4x4_func().}; |
| 30 | use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::markerrust-analyzer cargo zune-jpeg 0.5.15 marker/::Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#; |
| 31 | use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::miscrust-analyzer cargo zune-jpeg 0.5.15 misc/::SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#; |
| 32 | use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::upsamplerrust-analyzer cargo zune-jpeg 0.5.15 upsampler/::{ |
| 33 | choose_horizontal_samp_functionrust-analyzer cargo zune-jpeg 0.5.15 upsampler/choose_horizontal_samp_function()., choose_hv_samp_functionrust-analyzer cargo zune-jpeg 0.5.15 upsampler/choose_hv_samp_function()., choose_v_samp_functionrust-analyzer cargo zune-jpeg 0.5.15 upsampler/choose_v_samp_function()., |
| 34 | generic_samplerrust-analyzer cargo zune-jpeg 0.5.15 upsampler/generic_sampler()., upsample_no_oprust-analyzer cargo zune-jpeg 0.5.15 upsampler/upsample_no_op(). |
| 35 | }; |
| 36 | |
| 37 | /// Maximum components |
| 38 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) const MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.: usize = 4; |
| 39 | |
| 40 | /// Maximum image dimensions supported. |
| 41 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) const MAX_DIMENSIONSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_DIMENSIONS.: usize = 1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<i32>`]shl().27; |
| 42 | |
| 43 | /// Color conversion function that can convert YCbCr colorspace to RGB(A/X) for |
| 44 | /// 16 values |
| 45 | /// |
| 46 | /// The following are guarantees to the following functions |
| 47 | /// |
| 48 | /// 1. The `&[i16]` slices passed contain 16 items |
| 49 | /// |
| 50 | /// 2. The slices passed are in the following order |
| 51 | /// `y,cb,cr` |
| 52 | /// |
| 53 | /// 3. `&mut [u8]` is zero initialized |
| 54 | /// |
| 55 | /// 4. `&mut usize` points to the position in the array where new values should |
| 56 | /// be used |
| 57 | /// |
| 58 | /// The pointer should |
| 59 | /// 1. Carry out color conversion |
| 60 | /// 2. Update `&mut usize` with the new position |
| 61 | |
| 62 | pub type ColorConvert16Ptrrust-analyzer cargo zune-jpeg 0.5.15 decoder/ColorConvert16Ptr# = fn(&[i16; 16], &[i16; 16], &[i16; 16], &mut [u8], &mut usize); |
| 63 | |
| 64 | /// IDCT function prototype |
| 65 | /// |
| 66 | /// This encapsulates a dequantize and IDCT function which will carry out the |
| 67 | /// following functions |
| 68 | /// |
| 69 | /// Multiply each 64 element block of `&mut [i16]` with `&Aligned32<[i32;64]>` |
| 70 | /// Carry out IDCT (type 3 dct) on ach block of 64 i16's |
| 71 | pub type IDCTPtrrust-analyzer cargo zune-jpeg 0.5.15 decoder/IDCTPtr# = fn(&mut [i32; 64], &mut [i16], usize); |
| 72 | |
| 73 | /// An encapsulation of an ICC chunk |
| 74 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) struct ICCChunkrust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk# { |
| 75 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) seq_norust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#seq_no.: u8, |
| 76 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) num_markersrust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#num_markers.: u8, |
| 77 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#data.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> |
| 78 | } |
| 79 | |
| 80 | /// A JPEG Decoder Instance. |
| 81 | #[allow(clippy::upper_case_acronyms, clippy::struct_excessive_bools)] |
| 82 | pub struct JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#<T> { |
| 83 | /// Struct to hold image information from SOI |
| 84 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info.: ImageInforust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#, |
| 85 | /// Quantization tables, will be set to none and the tables will |
| 86 | /// be moved to `components` field |
| 87 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) qt_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#qt_tables.: [Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<[i32; 64]>; MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.], |
| 88 | /// DC Huffman Tables with a maximum of 4 tables for each component |
| 89 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) dc_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#dc_huffman_tables.: [Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#>; MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.], |
| 90 | /// AC Huffman Tables with a maximum of 4 tables for each component |
| 91 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) ac_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#ac_huffman_tables.: [Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<HuffmanTablerust-analyzer cargo zune-jpeg 0.5.15 huffman/HuffmanTable#>; MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.], |
| 92 | /// Image components, holds information like DC prediction and quantization |
| 93 | /// tables of a component |
| 94 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Componentsrust-analyzer cargo zune-jpeg 0.5.15 components/Components#>, |
| 95 | /// maximum horizontal component of all channels in the image |
| 96 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max.: usize, |
| 97 | // maximum vertical component of all channels in the image |
| 98 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max.: usize, |
| 99 | /// mcu's width (interleaved scans) |
| 100 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_width.: usize, |
| 101 | /// MCU height(interleaved scans |
| 102 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) mcu_heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_height.: usize, |
| 103 | /// Number of MCU's in the x plane |
| 104 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) mcu_xrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_x.: usize, |
| 105 | /// Number of MCU's in the y plane |
| 106 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) mcu_yrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_y.: usize, |
| 107 | /// Is the image interleaved? |
| 108 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) is_interleavedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_interleaved.: bool, |
| 109 | /// Image input colorspace, should be YCbCr for a sane image, might be |
| 110 | /// grayscale too |
| 111 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace.: ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#, |
| 112 | // Progressive image details |
| 113 | /// Is the image progressive? |
| 114 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) is_progressiverust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_progressive.: bool, |
| 115 | |
| 116 | /// Start of spectral scan |
| 117 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) spec_startrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#spec_start.: u8, |
| 118 | /// End of spectral scan |
| 119 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) spec_endrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#spec_end.: u8, |
| 120 | /// Successive approximation bit position high |
| 121 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) succ_highrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#succ_high.: u8, |
| 122 | /// Successive approximation bit position low |
| 123 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) succ_lowrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#succ_low.: u8, |
| 124 | /// Number of components. |
| 125 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) num_scansrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#num_scans.: u8, |
| 126 | /// For a scan, check if any component has vertical/horizontal sampling. |
| 127 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) scan_subsampledrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#scan_subsampled.: bool, |
| 128 | // Function pointers, for pointy stuff. |
| 129 | /// Dequantize and idct function |
| 130 | // This is determined at runtime which function to run, statically it's |
| 131 | // initialized to a platform independent one and during initialization |
| 132 | // of this struct, we check if we can switch to a faster one which |
| 133 | // depend on certain CPU extensions. |
| 134 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) idct_funcrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#idct_func.: IDCTPtrrust-analyzer cargo zune-jpeg 0.5.15 decoder/IDCTPtr#, |
| 135 | /// Specialized IDCT when we can guarantee only few coefficients are non-zero. |
| 136 | /// |
| 137 | /// **The callee must uphold a contract**. See [`choose_idct_4x4_func`]. |
| 138 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) idct_4x4_funcrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#idct_4x4_func.: IDCTPtrrust-analyzer cargo zune-jpeg 0.5.15 decoder/IDCTPtr#, |
| 139 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) idct_1x1_funcrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#idct_1x1_func.: IDCTPtrrust-analyzer cargo zune-jpeg 0.5.15 decoder/IDCTPtr#, |
| 140 | // Color convert function which acts on 16 YCbCr values |
| 141 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) color_convert_16rust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#color_convert_16.: ColorConvert16Ptrrust-analyzer cargo zune-jpeg 0.5.15 decoder/ColorConvert16Ptr#, |
| 142 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) z_orderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#z_order.: [usize; MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.], |
| 143 | /// restart markers |
| 144 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) restart_intervalrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#restart_interval.: usize, |
| 145 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) todorust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#todo.: usize, |
| 146 | // decoder options |
| 147 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options.: DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#, |
| 148 | // byte-stream |
| 149 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream.: ZReaderrust-analyzer cargo zune-core 0.5.1 bytestream/reader/ZReader#<T>, |
| 150 | // Indicate whether headers have been decoded |
| 151 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded.: bool, |
| 152 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) seen_sofrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#seen_sof.: bool, |
| 153 | |
| 154 | // exif data, lifted from app2 |
| 155 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) icc_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#icc_data.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ICCChunkrust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#>, |
| 156 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) is_mjpegrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_mjpeg.: bool, |
| 157 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) coeffrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#coeff.: usize, // Solves some weird bug :) |
| 158 | /// Extended XMP segments |
| 159 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ExtendedXmpSegmentrust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#>, |
| 160 | } |
| 161 | |
| 162 | impl<T> JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#<T> |
| 163 | where |
| 164 | T: ZByteReaderTraitrust-analyzer cargo zune-core 0.5.1 bytestream/traits/ZByteReaderTrait# |
| 165 | { |
| 166 | #[allow(clippy::redundant_field_names)] |
| 167 | fn defaultrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]default().(options: DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#, buffer: T) -> Selfrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`] { |
| 168 | let color_convert = choose_ycbcr_to_rgb_convert_funcrust-analyzer cargo zune-jpeg 0.5.15 color_convert/choose_ycbcr_to_rgb_convert_func().(ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB#, &options).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 169 | JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder# { |
| 170 | inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info.: ImageInforust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#::defaultrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[ImageInfo][Default]default().(), |
| 171 | qt_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#qt_tables.: [Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#], |
| 172 | dc_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#dc_huffman_tables.: [Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#], |
| 173 | ac_huffman_tablesrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#ac_huffman_tables.: [Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#], |
| 174 | componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 175 | // Interleaved information |
| 176 | h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max.: 1, |
| 177 | v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max.: 1, |
| 178 | mcu_heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_height.: 0, |
| 179 | mcu_widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_width.: 0, |
| 180 | mcu_xrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_x.: 0, |
| 181 | mcu_yrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#mcu_y.: 0, |
| 182 | is_interleavedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_interleaved.: false, |
| 183 | is_progressiverust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_progressive.: false, |
| 184 | spec_startrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#spec_start.: 0, |
| 185 | spec_endrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#spec_end.: 0, |
| 186 | succ_highrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#succ_high.: 0, |
| 187 | succ_lowrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#succ_low.: 0, |
| 188 | num_scansrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#num_scans.: 0, |
| 189 | scan_subsampledrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#scan_subsampled.: false, |
| 190 | idct_funcrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#idct_func.: choose_idct_funcrust-analyzer cargo zune-jpeg 0.5.15 idct/choose_idct_func().(&options), |
| 191 | idct_4x4_funcrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#idct_4x4_func.: choose_idct_4x4_funcrust-analyzer cargo zune-jpeg 0.5.15 idct/choose_idct_4x4_func().(&options), |
| 192 | idct_1x1_funcrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#idct_1x1_func.: choose_idct_1x1_funcrust-analyzer cargo zune-jpeg 0.5.15 idct/choose_idct_1x1_func().(&options), |
| 193 | color_convert_16rust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#color_convert_16.: color_convert, |
| 194 | input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace.: ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::YCbCrrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#YCbCr#, |
| 195 | z_orderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#z_order.: [0; MAX_COMPONENTSrust-analyzer cargo zune-jpeg 0.5.15 decoder/MAX_COMPONENTS.], |
| 196 | restart_intervalrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#restart_interval.: 0, |
| 197 | todorust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#todo.: 0x7fff_ffff, |
| 198 | optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options.: options, |
| 199 | streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream.: ZReaderrust-analyzer cargo zune-core 0.5.1 bytestream/reader/ZReader#::newrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]new().(buffer), |
| 200 | headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded.: false, |
| 201 | seen_sofrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#seen_sof.: false, |
| 202 | icc_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#icc_data.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 203 | is_mjpegrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_mjpeg.: false, |
| 204 | coeffrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#coeff.: 1, |
| 205 | extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 206 | } |
| 207 | } |
| 208 | /// Decode a buffer already in memory |
| 209 | /// |
| 210 | /// The buffer should be a valid jpeg file, perhaps created by the command |
| 211 | /// `std:::fs::read()` or a JPEG file downloaded from the internet. |
| 212 | /// |
| 213 | /// # Errors |
| 214 | /// See DecodeErrors for an explanation |
| 215 | pub fn decoderust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]decode().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> { |
| 216 | self.decode_headersrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]decode_headers().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 217 | let size = self.output_buffer_sizerust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]output_buffer_size().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 218 | let mut out = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; size]; |
| 219 | self.decode_intorust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]decode_into().(&mut out)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 220 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(out) |
| 221 | } |
| 222 | |
| 223 | /// Create a new Decoder instance |
| 224 | /// |
| 225 | /// # Arguments |
| 226 | /// - `stream`: The raw bytes of a jpeg file. |
| 227 | #[must_use] |
| 228 | #[allow(clippy::new_without_default)] |
| 229 | pub fn newrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]new().(stream: T) -> JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#<T> { |
| 230 | JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#::defaultrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]default().(DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#::defaultrust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions][Default]default().(), stream) |
| 231 | } |
| 232 | |
| 233 | /// Returns the image information |
| 234 | /// |
| 235 | /// This **must** be called after a subsequent call to [`decode`] or [`decode_headers`] |
| 236 | /// it will return `None` |
| 237 | /// |
| 238 | /// # Returns |
| 239 | /// - `Some(info)`: Image information,width, height, number of components |
| 240 | /// - None: Indicates image headers haven't been decoded |
| 241 | /// |
| 242 | /// [`decode`]: JpegDecoder::decode |
| 243 | /// [`decode_headers`]: JpegDecoder::decode_headers |
| 244 | #[must_use] |
| 245 | pub fn inforust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]info().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ImageInforust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#> { |
| 246 | // we check for fails to that call by comparing what we have to the default, if |
| 247 | // it's default we assume that the caller failed to uphold the |
| 248 | // guarantees. We can be sure that an image cannot be the default since |
| 249 | // its a hard panic in-case width or height are set to zero. |
| 250 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded. { |
| 251 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 252 | } |
| 253 | |
| 254 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..clonerust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[ImageInfo][Clone]clone().()); |
| 255 | } |
| 256 | |
| 257 | /// Return the number of bytes required to hold a decoded image frame |
| 258 | /// decoded using the given input transformations |
| 259 | /// |
| 260 | /// # Returns |
| 261 | /// - `Some(usize)`: Minimum size for a buffer needed to decode the image |
| 262 | /// - `None`: Indicates the image was not decoded, or image dimensions would overflow a usize |
| 263 | /// |
| 264 | #[must_use] |
| 265 | pub fn output_buffer_sizerust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]output_buffer_size().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 266 | return if self.headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded. { |
| 267 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#( |
| 268 | usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(self.widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]width().()) |
| 269 | .checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(self.heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]height().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). |
| 270 | .checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_colorspace().().num_componentsrust-analyzer cargo zune-core 0.5.1 colorspace/impl#[ColorSpace]num_components().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch(). |
| 271 | ) |
| 272 | } else { |
| 273 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 274 | }; |
| 275 | } |
| 276 | |
| 277 | /// Get an immutable reference to the decoder options |
| 278 | /// for the decoder instance |
| 279 | /// |
| 280 | /// This can be used to modify options before actual decoding |
| 281 | /// but after initial creation |
| 282 | /// |
| 283 | /// # Example |
| 284 | /// ```no_run |
| 285 | /// use zune_core::bytestream::ZCursor; |
| 286 | /// use zune_jpeg::JpegDecoder; |
| 287 | /// |
| 288 | /// let mut decoder = JpegDecoder::new(ZCursor::new(&[])); |
| 289 | /// // get current options |
| 290 | /// let mut options = decoder.options(); |
| 291 | /// // modify it |
| 292 | /// let new_options = options.set_max_width(10); |
| 293 | /// // set it back |
| 294 | /// decoder.set_options(new_options); |
| 295 | /// |
| 296 | /// ``` |
| 297 | #[must_use] |
| 298 | pub const fn optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]options().(&self) -> &DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions# { |
| 299 | &self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options. |
| 300 | } |
| 301 | /// Return the input colorspace of the image |
| 302 | /// |
| 303 | /// This indicates the colorspace that is present in |
| 304 | /// the image, but this may be different to the colorspace that |
| 305 | /// the output will be transformed to |
| 306 | /// |
| 307 | /// # Returns |
| 308 | /// -`Some(Colorspace)`: Input colorspace |
| 309 | /// - None : Indicates the headers weren't decoded |
| 310 | #[must_use] |
| 311 | pub fn input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]input_colorspace().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#> { |
| 312 | return if self.headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded. { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace.) } else { Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# }; |
| 313 | } |
| 314 | /// Set decoder options |
| 315 | /// |
| 316 | /// This can be used to set new options even after initialization |
| 317 | /// but before decoding. |
| 318 | /// |
| 319 | /// This does not bear any significance after decoding an image |
| 320 | /// |
| 321 | /// # Arguments |
| 322 | /// - `options`: New decoder options |
| 323 | /// |
| 324 | /// # Example |
| 325 | /// Set maximum jpeg progressive passes to be 4 |
| 326 | /// |
| 327 | /// ```no_run |
| 328 | /// use zune_core::bytestream::ZCursor; |
| 329 | /// use zune_jpeg::JpegDecoder; |
| 330 | /// let mut decoder =JpegDecoder::new(ZCursor::new(&[])); |
| 331 | /// // this works also because DecoderOptions implements `Copy` |
| 332 | /// let options = decoder.options().jpeg_set_max_scans(4); |
| 333 | /// // set the new options |
| 334 | /// decoder.set_options(options); |
| 335 | /// // now decode |
| 336 | /// decoder.decode().unwrap(); |
| 337 | /// ``` |
| 338 | pub fn set_optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]set_options().(&mut self, options: DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#) { |
| 339 | self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options. = options; |
| 340 | } |
| 341 | fn reassemble_extended_xmprust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]reassemble_extended_xmp().(&mut self) { |
| 342 | if self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | // Sort by offset |
| 347 | self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments..sort_byrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]sort_by().(|a, b| a.offsetrust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#offset..cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][Ord]cmp().(&b.offsetrust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#offset.)); |
| 348 | |
| 349 | let guid = &self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..guidrust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#guid.; |
| 350 | let total_size = self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..total_sizerust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#total_size.; |
| 351 | |
| 352 | // Check for consistency |
| 353 | for segment in &self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments. { |
| 354 | if &segment.guidrust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#guid. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().guid || segment.total_sizerust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#total_size. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().total_size { |
| 355 | errorrust-analyzer cargo log 0.4.29 macros/error!!("Inconsistent Extended XMP segments"); |
| 356 | self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 357 | return; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | let mut rolling_offset = 0; |
| 362 | let mut complete = true; |
| 363 | |
| 364 | for segment in &self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments. { |
| 365 | if segment.offsetrust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#offset. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().rolling_offset { |
| 366 | // Gap or overlap |
| 367 | complete = false; |
| 368 | break; |
| 369 | } |
| 370 | rolling_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().segment.datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() as u32; |
| 371 | } |
| 372 | |
| 373 | if complete && rolling_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().total_size { |
| 374 | let mut result = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(total_size as usize); |
| 375 | for segment in &self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments. { |
| 376 | result.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&segment.datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#data.); |
| 377 | } |
| 378 | self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..extended_xmprust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#extended_xmp. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(result); |
| 379 | self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..extended_xmp_guidrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#extended_xmp_guid. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(guid.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Clone]clone().()); |
| 380 | self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 381 | } else if rolling_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().total_size { |
| 382 | errorrust-analyzer cargo log 0.4.29 macros/error!!("Extended XMP overflow"); |
| 383 | self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 384 | } |
| 385 | // Else: Incomplete, wait for more. |
| 386 | } |
| 387 | /// Decode Decoder headers |
| 388 | /// |
| 389 | /// This routine takes care of parsing supported headers from a Decoder |
| 390 | /// image |
| 391 | /// |
| 392 | /// # Supported Headers |
| 393 | /// - APP(0) |
| 394 | /// - SOF(O) |
| 395 | /// - DQT -> Quantization tables |
| 396 | /// - DHT -> Huffman tables |
| 397 | /// - SOS -> Start of Scan |
| 398 | /// # Unsupported Headers |
| 399 | /// - SOF(n) -> Decoder images which are not baseline/progressive |
| 400 | /// - DAC -> Images using Arithmetic tables |
| 401 | /// - JPG(n) |
| 402 | fn decode_headers_internalrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]decode_headers_internal().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> { |
| 403 | if self.headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded. { |
| 404 | tracerust-analyzer cargo log 0.4.29 macros/trace!!("Headers decoded!"); |
| 405 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 406 | } |
| 407 | |
| 408 | // match output colorspace here |
| 409 | // we know this will only be called once per image |
| 410 | // so makes sense |
| 411 | // We only care for ycbcr to rgb/rgba here |
| 412 | // in case one is using another colorspace. |
| 413 | // May god help you |
| 414 | let out_colorspace = self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_colorspace().(); |
| 415 | |
| 416 | if matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!( |
| 417 | out_colorspace, |
| 418 | ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::BGRrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGR# | ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::BGRArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#BGRA# | ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB# | ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBArust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGBA# |
| 419 | ) { |
| 420 | self.color_convert_16rust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#color_convert_16. = choose_ycbcr_to_rgb_convert_funcrust-analyzer cargo zune-jpeg 0.5.15 color_convert/choose_ycbcr_to_rgb_convert_func().( |
| 421 | self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_colorspace().(), |
| 422 | &self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options. |
| 423 | ) |
| 424 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 425 | } |
| 426 | // First two bytes should be jpeg soi marker |
| 427 | let magic_bytes = self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..get_u16_be_errrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]get_u16_be_err().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 428 | |
| 429 | let mut last_byte = 0; |
| 430 | let mut bytes_before_marker = 0; |
| 431 | |
| 432 | if magic_bytes rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]ne().0xffd8 { |
| 433 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::IllegalMagicBytesrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#IllegalMagicBytes#(magic_bytes)); |
| 434 | } |
| 435 | |
| 436 | loop { |
| 437 | // read a byte |
| 438 | let mut m = self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..read_u8_errrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]read_u8_err().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 439 | |
| 440 | // AND OF COURSE some images will have fill bytes in their marker |
| 441 | // bitstreams because why not. |
| 442 | // |
| 443 | // I am disappointed as a man. |
| 444 | if (m rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0xFF || m rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0) && last_byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0xFF { |
| 445 | // This handles the edge case where |
| 446 | // images have markers with fill bytes(0xFF) |
| 447 | // or byte stuffing (0) |
| 448 | // I.e 0xFF 0xFF 0xDA |
| 449 | // and |
| 450 | // 0xFF 0 0xDA |
| 451 | // It should ignore those fill bytes and take 0xDA |
| 452 | // I don't know why such images exist |
| 453 | // but they do. |
| 454 | // so this is for you (with love) |
| 455 | while m rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0xFF || m rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0x0 { |
| 456 | last_byte = m; |
| 457 | m = self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..read_u8_errrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]read_u8_err().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 458 | } |
| 459 | } |
| 460 | // Last byte should be 0xFF to confirm existence of a marker since markers look |
| 461 | // like OxFF(some marker data) |
| 462 | if last_byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0xFF { |
| 463 | let marker = Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::from_u8rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker]from_u8().(m); |
| 464 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(n) = marker { |
| 465 | if bytes_before_marker rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt().3 { |
| 466 | if self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..strict_moderust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]strict_mode().() |
| 467 | /*No reason to use this*/ |
| 468 | { |
| 469 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#( |
| 470 | "[strict-mode]: Extra bytes between headers" |
| 471 | )); |
| 472 | } |
| 473 | |
| 474 | errorrust-analyzer cargo log 0.4.29 macros/error!!( |
| 475 | "Extra bytes {} before marker 0xFF{:X}", |
| 476 | bytes_before_marker -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub(). 3, |
| 477 | m |
| 478 | ); |
| 479 | } |
| 480 | |
| 481 | bytes_before_marker = 0; |
| 482 | |
| 483 | self.parse_marker_innerrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]parse_marker_inner().(n)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 484 | |
| 485 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.extended_xmp_segmentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#extended_xmp_segments..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 486 | self.reassemble_extended_xmprust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]reassemble_extended_xmp().(); |
| 487 | } |
| 488 | |
| 489 | // break after reading the start of scan. |
| 490 | // what follows is the image data |
| 491 | if n rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq().Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOSrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOS# { |
| 492 | self.headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded. = true; |
| 493 | tracerust-analyzer cargo log 0.4.29 macros/trace!!("Input colorspace {:?}", self.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace.); |
| 494 | |
| 495 | // Check if image is RGB |
| 496 | // The check is weird, we need to check if ID |
| 497 | // represents R, G and B in ascii, |
| 498 | // |
| 499 | // I am not sure if this is even specified in any standard, |
| 500 | // but jpegli https://github.com/google/jpegli does encode |
| 501 | // its images that way, so this will check for that. and handle it appropriately |
| 502 | // It is spefified here so that on a successful header decode,we can at least |
| 503 | // try to attribute image colorspace correctly. |
| 504 | // |
| 505 | // It was first the issue in https://github.com/etemesi254/zune-image/issues/291 |
| 506 | // that brought it to light |
| 507 | // |
| 508 | let mut is_rgb = self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().3; |
| 509 | let chars = ['R', 'G', 'B']; |
| 510 | for (comp, single_char) in self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(chars.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) { |
| 511 | is_rgb rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitAndAssign<Self>`]bitand_assign().&=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitAndAssign<Self>`]bitand_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][`BitAndAssign<Self>`]bitand_assign().comp.idrust-analyzer cargo zune-jpeg 0.5.15 components/Components#id. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().single_char) as u8 |
| 512 | } |
| 513 | // Image is RGB, change colorspace |
| 514 | if is_rgb { |
| 515 | self.input_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#input_colorspace. = ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#::RGBrust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#RGB#; |
| 516 | } |
| 517 | |
| 518 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 519 | } |
| 520 | } else { |
| 521 | bytes_before_marker = 0; |
| 522 | |
| 523 | warnrust-analyzer cargo log 0.4.29 macros/warn!!("Marker 0xFF{:X} not known", m); |
| 524 | |
| 525 | let length = self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..get_u16_be_errrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]get_u16_be_err().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 526 | |
| 527 | if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().2 { |
| 528 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::Formatrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Format#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 529 | "Found a marker with invalid length : {length}" |
| 530 | ))); |
| 531 | } |
| 532 | |
| 533 | warnrust-analyzer cargo log 0.4.29 macros/warn!!("Skipping {} bytes", length -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub(). 2); |
| 534 | self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..skiprust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]skip().((length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().2) as usize)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 535 | } |
| 536 | } |
| 537 | last_byte = m; |
| 538 | bytes_before_marker rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1; |
| 539 | } |
| 540 | // Check if image is RGB |
| 541 | } |
| 542 | #[allow(clippy::too_many_lines)] |
| 543 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn parse_marker_innerrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]parse_marker_inner().(&mut self, m: Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> { |
| 544 | match m { |
| 545 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOFrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOF#(0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#2) => { |
| 546 | let marker = { |
| 547 | // choose marker |
| 548 | if m rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq().Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOFrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOF#(0) || m rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq().==rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq(). rust-analyzer cargo zune-jpeg 0.5.15 marker/impl#[Marker][`PartialEq<Self>`]eq().Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOFrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOF#(1) { |
| 549 | SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#::BaselineDctrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#BaselineDct# |
| 550 | } else { |
| 551 | self.is_progressiverust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_progressive. = true; |
| 552 | SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#::ProgressiveDctHuffmanrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#ProgressiveDctHuffman# |
| 553 | } |
| 554 | }; |
| 555 | |
| 556 | tracerust-analyzer cargo log 0.4.29 macros/trace!!("Image encoding scheme =`{:?}`", marker); |
| 557 | // get components |
| 558 | parse_start_of_framerust-analyzer cargo zune-jpeg 0.5.15 headers/parse_start_of_frame().(marker, self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 559 | } |
| 560 | // Start of Frame Segments not supported |
| 561 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOFrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOF#(v) => { |
| 562 | let feature = UnsupportedSchemesrust-analyzer cargo zune-jpeg 0.5.15 errors/UnsupportedSchemes#::from_intrust-analyzer cargo zune-jpeg 0.5.15 errors/impl#[UnsupportedSchemes]from_int().(v); |
| 563 | |
| 564 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(feature) = feature { |
| 565 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::Unsupportedrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Unsupported#(feature)); |
| 566 | } |
| 567 | |
| 568 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::Formatrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Format#("Unsupported image format".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 569 | } |
| 570 | //APP(0) segment |
| 571 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::APPrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#APP#(0) => { |
| 572 | let mut length = self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..get_u16_be_errrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]get_u16_be_err().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 573 | |
| 574 | if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().2 { |
| 575 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::Formatrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Format#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 576 | "Found a marker with invalid length:{length}\n" |
| 577 | ))); |
| 578 | } |
| 579 | // skip for now |
| 580 | if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt().5 { |
| 581 | let mut buffer = [0u8; 5]; |
| 582 | self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..read_exact_bytesrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]read_exact_bytes().(&mut buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 583 | if &buffer rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().b"AVI1\0" { |
| 584 | self.is_mjpegrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_mjpeg. = true; |
| 585 | } |
| 586 | length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`SubAssign<Self>`]sub_assign().5; |
| 587 | } |
| 588 | |
| 589 | self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..skiprust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]skip().(length.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_sub().(2) as usize)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 590 | |
| 591 | //parse_app(buf, m, &mut self.info)?; |
| 592 | } |
| 593 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::APPrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#APP#(1) => { |
| 594 | parse_app1rust-analyzer cargo zune-jpeg 0.5.15 headers/parse_app1().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 595 | } |
| 596 | |
| 597 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::APPrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#APP#(2) => { |
| 598 | parse_app2rust-analyzer cargo zune-jpeg 0.5.15 headers/parse_app2().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 599 | } |
| 600 | // Quantization tables |
| 601 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DQTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DQT# => { |
| 602 | parse_dqtrust-analyzer cargo zune-jpeg 0.5.15 headers/parse_dqt().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 603 | } |
| 604 | // Huffman tables |
| 605 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DHTrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DHT# => { |
| 606 | parse_huffmanrust-analyzer cargo zune-jpeg 0.5.15 headers/parse_huffman().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 607 | } |
| 608 | // Start of Scan Data |
| 609 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::SOSrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#SOS# => { |
| 610 | parse_sosrust-analyzer cargo zune-jpeg 0.5.15 headers/parse_sos().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 611 | } |
| 612 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::EOIrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#EOI# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::FormatStaticrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#FormatStatic#("Premature End of image")), |
| 613 | |
| 614 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DACrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DAC# | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DNLrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DNL# => { |
| 615 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::Formatrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Format#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 616 | "Parsing of the following header `{m:?}` is not supported,\ |
| 617 | cannot continue" |
| 618 | ))); |
| 619 | } |
| 620 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::DRIrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#DRI# => { |
| 621 | if self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..get_u16_be_errrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]get_u16_be_err().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialEq<Self>`]ne().4 { |
| 622 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::Formatrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Format#( |
| 623 | "Bad DRI length, Corrupt JPEG".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() |
| 624 | )); |
| 625 | } |
| 626 | |
| 627 | self.restart_intervalrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#restart_interval. = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u16>`]from().(self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..get_u16_be_errrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]get_u16_be_err().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().); |
| 628 | tracerust-analyzer cargo log 0.4.29 macros/trace!!("DRI marker present ({})", self.restart_intervalrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#restart_interval.); |
| 629 | |
| 630 | self.todorust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#todo. = self.restart_intervalrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#restart_interval.; |
| 631 | } |
| 632 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::APPrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#APP#(14) => { |
| 633 | parse_app14rust-analyzer cargo zune-jpeg 0.5.15 headers/parse_app14().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 634 | } |
| 635 | Markerrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#::APPrust-analyzer cargo zune-jpeg 0.5.15 marker/Marker#APP#(13) => { |
| 636 | parse_app13rust-analyzer cargo zune-jpeg 0.5.15 headers/parse_app13().(self)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 637 | } |
| 638 | _ => { |
| 639 | warnrust-analyzer cargo log 0.4.29 macros/warn!!( |
| 640 | "Capabilities for processing marker \"{:?}\" not implemented", |
| 641 | m |
| 642 | ); |
| 643 | |
| 644 | let length = self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..get_u16_be_errrust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]get_u16_be_err().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 645 | |
| 646 | if length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().2 { |
| 647 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::Formatrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#Format#(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!( |
| 648 | "Found a marker with invalid length:{length}\n" |
| 649 | ))); |
| 650 | } |
| 651 | warnrust-analyzer cargo log 0.4.29 macros/warn!!("Skipping {} bytes", length -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub(). 2); |
| 652 | self.streamrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#stream..skiprust-analyzer cargo zune-core 0.5.1 bytestream/reader/impl#[`ZReader<T>`]skip().((length rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Sub<Self>`]sub().2) as usize)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 653 | } |
| 654 | } |
| 655 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 656 | } |
| 657 | /// Get the embedded ICC profile if it exists |
| 658 | /// and is correct |
| 659 | /// |
| 660 | /// One needs not to decode the whole image to extract this, |
| 661 | /// calling [`decode_headers`] for an image with an ICC profile |
| 662 | /// allows you to decode this |
| 663 | /// |
| 664 | /// # Returns |
| 665 | /// - `Some(Vec<u8>)`: The raw ICC profile of the image |
| 666 | /// - `None`: May indicate an error in the ICC profile , non-existence of |
| 667 | /// an ICC profile, or that the headers weren't decoded. |
| 668 | /// |
| 669 | /// [`decode_headers`]:Self::decode_headers |
| 670 | #[must_use] |
| 671 | pub fn icc_profilerust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]icc_profile().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 672 | let mut marker_present: [Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&ICCChunkrust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#>; 256] = [Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; 256]; |
| 673 | |
| 674 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded. { |
| 675 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 676 | } |
| 677 | let num_markers = self.icc_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#icc_data..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 678 | |
| 679 | if num_markers rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 || num_markers rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().255 { |
| 680 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 681 | } |
| 682 | // check validity |
| 683 | for chunk in &self.icc_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#icc_data. { |
| 684 | if usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(chunk.num_markersrust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#num_markers.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().num_markers { |
| 685 | // all the lengths must match |
| 686 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 687 | } |
| 688 | if chunk.seq_norust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#seq_no. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 689 | warnrust-analyzer cargo log 0.4.29 macros/warn!!("Zero sequence number in ICC, corrupt ICC chunk"); |
| 690 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 691 | } |
| 692 | if marker_present[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(chunk.seq_norust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#seq_no.)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 693 | // duplicate seq_no |
| 694 | warnrust-analyzer cargo log 0.4.29 macros/warn!!("Duplicate sequence number in ICC, corrupt chunk"); |
| 695 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 696 | } |
| 697 | |
| 698 | marker_present[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut().usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(chunk.seq_norust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#seq_no.)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`IndexMut<I>`]index_mut(). = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(chunk); |
| 699 | } |
| 700 | let mut data = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(1000); |
| 701 | // assemble the data now |
| 702 | for chunk in marker_present.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#num_markers).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() { |
| 703 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ch) = chunk { |
| 704 | data.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&ch.datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ICCChunk#data.); |
| 705 | } else { |
| 706 | warnrust-analyzer cargo log 0.4.29 macros/warn!!("Missing icc sequence number, corrupt ICC chunk "); |
| 707 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(data) |
| 712 | } |
| 713 | /// Return the exif data for the file |
| 714 | /// |
| 715 | /// This returns the raw exif data starting at the |
| 716 | /// TIFF header |
| 717 | /// |
| 718 | /// # Returns |
| 719 | /// -`Some(data)`: The raw exif data, if present in the image |
| 720 | /// - None: May indicate the following |
| 721 | /// |
| 722 | /// 1. The image doesn't have exif data |
| 723 | /// 2. The image headers haven't been decoded |
| 724 | #[must_use] |
| 725 | pub fn exifrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]exif().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 726 | return self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..exif_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#exif_data..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(); |
| 727 | } |
| 728 | /// Return the XMP data for the file |
| 729 | /// |
| 730 | /// This returns raw XMP data starting at the XML header |
| 731 | /// One needs an XML/XMP decoder to extract valuable metadata |
| 732 | /// |
| 733 | /// |
| 734 | /// # Returns |
| 735 | /// - `Some(data)`: Raw xmp data |
| 736 | /// - `None`: May indicate the following |
| 737 | /// 1. The image does not have xmp data |
| 738 | /// 2. The image headers have not been decoded |
| 739 | /// |
| 740 | /// # Example |
| 741 | /// |
| 742 | /// ```no_run |
| 743 | /// use zune_core::bytestream::ZCursor; |
| 744 | /// use zune_jpeg::JpegDecoder; |
| 745 | /// let mut decoder = JpegDecoder::new(ZCursor::new(&[])); |
| 746 | /// // decode headers to extract xmp metadata if present |
| 747 | /// decoder.decode_headers().unwrap(); |
| 748 | /// if let Some(data) = decoder.xmp(){ |
| 749 | /// let stringified = String::from_utf8_lossy(data); |
| 750 | /// println!("XMP") |
| 751 | /// } else{ |
| 752 | /// println!("No XMP Found") |
| 753 | /// } |
| 754 | /// |
| 755 | /// ``` |
| 756 | pub fn xmprust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]xmp().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 757 | return self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..xmp_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#xmp_data..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(); |
| 758 | } |
| 759 | /// Return the IPTC data for the file |
| 760 | /// |
| 761 | /// This returns the raw IPTC data. |
| 762 | /// |
| 763 | /// # Returns |
| 764 | /// -`Some(data)`: The raw IPTC data, if present in the image |
| 765 | /// - None: May indicate the following |
| 766 | /// |
| 767 | /// 1. The image doesn't have IPTC data |
| 768 | /// 2. The image headers haven't been decoded |
| 769 | #[must_use] |
| 770 | pub fn iptcrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]iptc().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> { |
| 771 | return self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..iptc_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#iptc_data..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(); |
| 772 | } |
| 773 | /// Get the output colorspace the image pixels will be decoded into |
| 774 | /// |
| 775 | /// |
| 776 | /// # Note. |
| 777 | /// This field can only be regarded after decoding headers, |
| 778 | /// as markers such as Adobe APP14 may dictate different colorspaces |
| 779 | /// than requested. |
| 780 | /// |
| 781 | /// Calling `decode_headers` is sufficient to know what colorspace the |
| 782 | /// output is, if this is called after `decode` it indicates the colorspace |
| 783 | /// the output is currently in |
| 784 | /// |
| 785 | /// Additionally not all input->output colorspace mappings are supported |
| 786 | /// but all input colorspaces can map to RGB colorspace, so that's a safe bet |
| 787 | /// if one is handling image formats |
| 788 | /// |
| 789 | ///# Returns |
| 790 | /// - `Some(Colorspace)`: If headers have been decoded, the colorspace the |
| 791 | ///output array will be in |
| 792 | ///- `None |
| 793 | #[must_use] |
| 794 | pub fn output_colorspacerust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]output_colorspace().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ColorSpacerust-analyzer cargo zune-core 0.5.1 colorspace/ColorSpace#> { |
| 795 | return if self.headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded. { |
| 796 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options..jpeg_get_out_colorspacerust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]jpeg_get_out_colorspace().()) |
| 797 | } else { |
| 798 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 799 | }; |
| 800 | } |
| 801 | |
| 802 | /// Decode into a pre-allocated buffer |
| 803 | /// |
| 804 | /// It is an error if the buffer size is smaller than |
| 805 | /// [`output_buffer_size()`](Self::output_buffer_size) |
| 806 | /// |
| 807 | /// If the buffer is bigger than expected, we ignore the end padding bytes |
| 808 | /// |
| 809 | /// # Example |
| 810 | /// |
| 811 | /// - Read headers and then alloc a buffer big enough to hold the image |
| 812 | /// |
| 813 | /// ```no_run |
| 814 | /// use zune_core::bytestream::ZCursor; |
| 815 | /// use zune_jpeg::JpegDecoder; |
| 816 | /// let mut decoder = JpegDecoder::new(ZCursor::new(&[])); |
| 817 | /// // before we get output, we must decode the headers to get width |
| 818 | /// // height, and input colorspace |
| 819 | /// decoder.decode_headers().unwrap(); |
| 820 | /// |
| 821 | /// let mut out = vec![0;decoder.output_buffer_size().unwrap()]; |
| 822 | /// // write into out |
| 823 | /// decoder.decode_into(&mut out).unwrap(); |
| 824 | /// ``` |
| 825 | /// |
| 826 | /// |
| 827 | pub fn decode_intorust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]decode_into().(&mut self, out: &mut [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> { |
| 828 | self.decode_headers_internalrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]decode_headers_internal().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 829 | |
| 830 | let expected_size = self.output_buffer_sizerust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]output_buffer_size().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 831 | |
| 832 | if out.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().expected_size { |
| 833 | // too small of a size |
| 834 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#::TooSmallOutputrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#TooSmallOutput#(expected_size, out.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())); |
| 835 | } |
| 836 | |
| 837 | // ensure we don't touch anyone else's scratch space |
| 838 | let out_len = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(out.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), expected_size); |
| 839 | let out = &mut out[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#out_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().; |
| 840 | |
| 841 | if self.is_progressiverust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#is_progressive. { |
| 842 | self.decode_mcu_ycbcr_progressiverust-analyzer cargo zune-jpeg 0.5.15 mcu_prog/impl#[`JpegDecoder<T>`]decode_mcu_ycbcr_progressive().(out) |
| 843 | } else { |
| 844 | self.decode_mcu_ycbcr_baselinerust-analyzer cargo zune-jpeg 0.5.15 mcu/impl#[`JpegDecoder<T>`]decode_mcu_ycbcr_baseline().(out) |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | /// Read only headers from a jpeg image buffer |
| 849 | /// |
| 850 | /// This allows you to extract important information like |
| 851 | /// image width and height without decoding the full image |
| 852 | /// |
| 853 | /// # Examples |
| 854 | /// ```no_run |
| 855 | /// use zune_core::bytestream::ZCursor; |
| 856 | /// use zune_jpeg::{JpegDecoder}; |
| 857 | /// |
| 858 | /// let img_data = std::fs::read("a_valid.jpeg").unwrap(); |
| 859 | /// let mut decoder = JpegDecoder::new(ZCursor::new(&img_data)); |
| 860 | /// decoder.decode_headers().unwrap(); |
| 861 | /// |
| 862 | /// println!("Total decoder dimensions are : {:?} pixels",decoder.dimensions()); |
| 863 | /// println!("Number of components in the image are {}", decoder.info().unwrap().components); |
| 864 | /// ``` |
| 865 | /// # Errors |
| 866 | /// See DecodeErrors enum for list of possible errors during decoding |
| 867 | pub fn decode_headersrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]decode_headers().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> { |
| 868 | self.decode_headers_internalrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]decode_headers_internal().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 869 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 870 | } |
| 871 | /// Create a new decoder with the specified options to be used for decoding |
| 872 | /// an image |
| 873 | /// |
| 874 | /// # Arguments |
| 875 | /// - `buf`: The input buffer from where we will pull in compressed jpeg bytes from |
| 876 | /// - `options`: Options specific to this decoder instance |
| 877 | #[must_use] |
| 878 | pub fn new_with_optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]new_with_options().(buf: T, options: DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#) -> JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#<T> { |
| 879 | JpegDecoderrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#::defaultrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]default().(options, buf) |
| 880 | } |
| 881 | |
| 882 | /// Set up-sampling routines in case an image is down sampled |
| 883 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn set_upsamplingrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]set_upsampling().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), DecodeErrorsrust-analyzer cargo zune-jpeg 0.5.15 errors/DecodeErrors#> { |
| 884 | // no sampling, return early |
| 885 | // check if horizontal max ==1 |
| 886 | if self.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().self.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max. && self.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 { |
| 887 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 888 | } |
| 889 | |
| 890 | for comp in &mut self.componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#components. { |
| 891 | let hs = self.h_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#h_max. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().comp.horizontal_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#horizontal_sample.; |
| 892 | let vs = self.v_maxrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#v_max. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().comp.vertical_samplerust-analyzer cargo zune-jpeg 0.5.15 components/Components#vertical_sample.; |
| 893 | |
| 894 | let samp_factor = match (hs, vs) { |
| 895 | (1, 1) => { |
| 896 | comp.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio. = SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Nonerust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#None#; |
| 897 | upsample_no_oprust-analyzer cargo zune-jpeg 0.5.15 upsampler/upsample_no_op(). |
| 898 | } |
| 899 | (2, 1) => { |
| 900 | comp.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio. = SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Hrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#H#; |
| 901 | choose_horizontal_samp_functionrust-analyzer cargo zune-jpeg 0.5.15 upsampler/choose_horizontal_samp_function().(&self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options.) |
| 902 | } |
| 903 | (1, 2) => { |
| 904 | comp.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio. = SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Vrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#V#; |
| 905 | choose_v_samp_functionrust-analyzer cargo zune-jpeg 0.5.15 upsampler/choose_v_samp_function().(&self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options.) |
| 906 | } |
| 907 | (2, 2) => { |
| 908 | comp.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio. = SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::HVrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#HV#; |
| 909 | choose_hv_samp_functionrust-analyzer cargo zune-jpeg 0.5.15 upsampler/choose_hv_samp_function().(&self.optionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#options.) |
| 910 | } |
| 911 | (hs, vs) => { |
| 912 | comp.sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 components/Components#sample_ratio. = SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#::Genericrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#Generic#(hs, vs); |
| 913 | generic_samplerrust-analyzer cargo zune-jpeg 0.5.15 upsampler/generic_sampler().() |
| 914 | } |
| 915 | }; |
| 916 | comp.setup_upsample_scanlinerust-analyzer cargo zune-jpeg 0.5.15 components/impl#[Components]setup_upsample_scanline().(); |
| 917 | comp.up_samplerrust-analyzer cargo zune-jpeg 0.5.15 components/Components#up_sampler. = samp_factor; |
| 918 | } |
| 919 | |
| 920 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 921 | } |
| 922 | #[must_use] |
| 923 | /// Get the width of the image as a u16 |
| 924 | /// |
| 925 | /// The width lies between 1 and 65535 |
| 926 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]width().(&self) -> u16 { |
| 927 | self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width. |
| 928 | } |
| 929 | |
| 930 | /// Get the height of the image as a u16 |
| 931 | /// |
| 932 | /// The height lies between 1 and 65535 |
| 933 | #[must_use] |
| 934 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]height().(&self) -> u16 { |
| 935 | self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#height. |
| 936 | } |
| 937 | |
| 938 | /// Get image dimensions as a tuple of width and height |
| 939 | /// or `None` if the image hasn't been decoded. |
| 940 | /// |
| 941 | /// # Returns |
| 942 | /// - `Some(width,height)`: Image dimensions |
| 943 | /// - None : The image headers haven't been decoded |
| 944 | #[must_use] |
| 945 | pub const fn dimensionsrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[`JpegDecoder<T>`]dimensions().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, usize)> { |
| 946 | return if self.headers_decodedrust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#headers_decoded. { |
| 947 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width. as usize, self.inforust-analyzer cargo zune-jpeg 0.5.15 decoder/JpegDecoder#info..heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#height. as usize)) |
| 948 | } else { |
| 949 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 950 | }; |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 955 | pub struct GainMapInforust-analyzer cargo zune-jpeg 0.5.15 decoder/GainMapInfo# { |
| 956 | pub datarust-analyzer cargo zune-jpeg 0.5.15 decoder/GainMapInfo#data.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> |
| 957 | } |
| 958 | |
| 959 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 960 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) struct ExtendedXmpSegmentrust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment# { |
| 961 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) offsetrust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#offset.: u32, |
| 962 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) total_sizerust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#total_size.: u32, |
| 963 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) guidrust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#guid.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 964 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ExtendedXmpSegment#data.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 965 | } |
| 966 | |
| 967 | /// A struct representing Image Information |
| 968 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 969 | #[allow(clippy::module_name_repetitions)] |
| 970 | pub struct ImageInforust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo# { |
| 971 | /// Width of the image |
| 972 | pub widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width.: u16, |
| 973 | /// Height of image |
| 974 | pub heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#height.: u16, |
| 975 | /// PixelDensity |
| 976 | pub pixel_densityrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#pixel_density.: u8, |
| 977 | /// Start of frame markers |
| 978 | pub sofrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#sof.: SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#, |
| 979 | /// Horizontal sample |
| 980 | pub x_densityrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#x_density.: u16, |
| 981 | /// Vertical sample |
| 982 | pub y_densityrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#y_density.: u16, |
| 983 | /// Number of components |
| 984 | pub componentsrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#components.: u8, |
| 985 | /// Gain Map information, useful for |
| 986 | /// UHDR images |
| 987 | pub gain_map_inforust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#gain_map_info.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<GainMapInforust-analyzer cargo zune-jpeg 0.5.15 decoder/GainMapInfo#>, |
| 988 | /// Multi picture information, useful for |
| 989 | /// UHDR images |
| 990 | pub multi_picture_informationrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#multi_picture_information.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 991 | /// Exif Data |
| 992 | pub exif_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#exif_data.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 993 | /// XMP Data |
| 994 | pub xmp_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#xmp_data.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 995 | /// IPTC Data |
| 996 | pub iptc_datarust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#iptc_data.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 997 | /// Extended XMP Data |
| 998 | pub extended_xmprust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#extended_xmp.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 999 | /// Extended XMP Guid |
| 1000 | pub extended_xmp_guidrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#extended_xmp_guid.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 1001 | /// Image sub-sampling ratio |
| 1002 | pub sample_ratiorust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#sample_ratio.: SampleRatiosrust-analyzer cargo zune-jpeg 0.5.15 components/SampleRatios#, |
| 1003 | /// The offset at which Multi picture information was found |
| 1004 | pub multi_picture_information_offsetrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#multi_picture_information_offset.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u64>, |
| 1005 | } |
| 1006 | |
| 1007 | impl ImageInforust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo# { |
| 1008 | /// Set width of the image |
| 1009 | /// |
| 1010 | /// Found in the start of frame |
| 1011 | |
| 1012 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn set_widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[ImageInfo]set_width().(&mut self, width: u16) { |
| 1013 | self.widthrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#width. = width; |
| 1014 | } |
| 1015 | |
| 1016 | /// Set height of the image |
| 1017 | /// |
| 1018 | /// Found in the start of frame |
| 1019 | |
| 1020 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn set_heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[ImageInfo]set_height().(&mut self, height: u16) { |
| 1021 | self.heightrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#height. = height; |
| 1022 | } |
| 1023 | |
| 1024 | /// Set the image density |
| 1025 | /// |
| 1026 | /// Found in the start of frame |
| 1027 | |
| 1028 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn set_densityrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[ImageInfo]set_density().(&mut self, density: u8) { |
| 1029 | self.pixel_densityrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#pixel_density. = density; |
| 1030 | } |
| 1031 | |
| 1032 | /// Set image Start of frame marker |
| 1033 | /// |
| 1034 | /// found in the Start of frame header |
| 1035 | |
| 1036 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn set_sof_markerrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[ImageInfo]set_sof_marker().(&mut self, marker: SOFMarkersrust-analyzer cargo zune-jpeg 0.5.15 misc/SOFMarkers#) { |
| 1037 | self.sofrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#sof. = marker; |
| 1038 | } |
| 1039 | |
| 1040 | /// Set image x-density(dots per pixel) |
| 1041 | /// |
| 1042 | /// Found in the APP(0) marker |
| 1043 | #[allow(dead_code)] |
| 1044 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn set_xrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[ImageInfo]set_x().(&mut self, sample: u16) { |
| 1045 | self.x_densityrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#x_density. = sample; |
| 1046 | } |
| 1047 | |
| 1048 | /// Set image y-density |
| 1049 | /// |
| 1050 | /// Found in the APP(0) marker |
| 1051 | #[allow(dead_code)] |
| 1052 | pub(craterust-analyzer cargo zune-jpeg 0.5.15 crate/) fn set_yrust-analyzer cargo zune-jpeg 0.5.15 decoder/impl#[ImageInfo]set_y().(&mut self, sample: u16) { |
| 1053 | self.y_densityrust-analyzer cargo zune-jpeg 0.5.15 decoder/ImageInfo#y_density. = sample; |
| 1054 | } |
| 1055 | } |