| 1 | use tiffrust-analyzer cargo tiff 0.11.3 crate/::decoderrust-analyzer cargo tiff 0.11.3 decoder/::{BufferLayoutPreferencerust-analyzer cargo tiff 0.11.3 decoder/BufferLayoutPreference#, Decoderrust-analyzer cargo tiff 0.11.3 decoder/Decoder#, DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#, DecodingResultrust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#}; |
| 2 | |
| 3 | fn mainrust-analyzer cargo tiff 0.11.3 main().() -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#>> { |
| 4 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(image) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::args_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/args_os().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(1) else { |
| 5 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Usage: decode FILE"); |
| 6 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 7 | }; |
| 8 | |
| 9 | let file = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(image)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 10 | let io = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(file); |
| 11 | let mut reader = Decoderrust-analyzer cargo tiff 0.11.3 decoder/Decoder#::newrust-analyzer cargo tiff 0.11.3 decoder/impl#[`Decoder<R>`]new().(io)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 12 | |
| 13 | let mut data = DecodingResultrust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#::I8rust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#I8#(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]); |
| 14 | |
| 15 | for i in 0u32..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom# { |
| 16 | let colortype = reader.colortyperust-analyzer cargo tiff 0.11.3 decoder/impl#[`Decoder<R>`]colortype().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 17 | let dimensions = reader.dimensionsrust-analyzer cargo tiff 0.11.3 decoder/impl#[`Decoder<R>`]dimensions().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 18 | let layout = reader.read_image_to_bufferrust-analyzer cargo tiff 0.11.3 decoder/impl#[`Decoder<R>`]read_image_to_buffer().(&mut data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 19 | |
| 20 | debug_planesrust-analyzer cargo tiff 0.11.3 debug_planes().(i, &mut data, &layout, &colortype, dimensions); |
| 21 | |
| 22 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().reader.more_imagesrust-analyzer cargo tiff 0.11.3 decoder/impl#[`Decoder<R>`]more_images().() { |
| 23 | break; |
| 24 | } |
| 25 | |
| 26 | reader.next_imagerust-analyzer cargo tiff 0.11.3 decoder/impl#[`Decoder<R>`]next_image().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 27 | } |
| 28 | |
| 29 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 30 | } |
| 31 | |
| 32 | fn debug_planesrust-analyzer cargo tiff 0.11.3 debug_planes().( |
| 33 | index: u32, |
| 34 | data: &mut DecodingResultrust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#, |
| 35 | layout: &BufferLayoutPreferencerust-analyzer cargo tiff 0.11.3 decoder/BufferLayoutPreference#, |
| 36 | colortype: &tiffrust-analyzer cargo tiff 0.11.3 crate/::ColorTyperust-analyzer cargo tiff 0.11.3 ColorType#, |
| 37 | (width, height): (u32, u32), |
| 38 | ) { |
| 39 | let (depth, mut tupltype) = match colortype { |
| 40 | // Note: we will expand, so this is in fact not BLACKANDWHITE |
| 41 | tiffrust-analyzer cargo tiff 0.11.3 crate/::ColorTyperust-analyzer cargo tiff 0.11.3 ColorType#::Grayrust-analyzer cargo tiff 0.11.3 ColorType#Gray#(_) => (1, "GRAYSCALE"), |
| 42 | tiffrust-analyzer cargo tiff 0.11.3 crate/::ColorTyperust-analyzer cargo tiff 0.11.3 ColorType#::RGBrust-analyzer cargo tiff 0.11.3 ColorType#RGB#(_) => (3, "RGB"), |
| 43 | tiffrust-analyzer cargo tiff 0.11.3 crate/::ColorTyperust-analyzer cargo tiff 0.11.3 ColorType#::RGBArust-analyzer cargo tiff 0.11.3 ColorType#RGBA#(_) => (4, "RGB_ALPHA"), |
| 44 | tiffrust-analyzer cargo tiff 0.11.3 crate/::ColorTyperust-analyzer cargo tiff 0.11.3 ColorType#::Paletterust-analyzer cargo tiff 0.11.3 ColorType#Palette#(_) => (1, "PALETTE"), |
| 45 | tiffrust-analyzer cargo tiff 0.11.3 crate/::ColorTyperust-analyzer cargo tiff 0.11.3 ColorType#::CMYKrust-analyzer cargo tiff 0.11.3 ColorType#CMYK#(_) => (4, "CMYK"), |
| 46 | tiffrust-analyzer cargo tiff 0.11.3 crate/::ColorTyperust-analyzer cargo tiff 0.11.3 ColorType#::Multibandrust-analyzer cargo tiff 0.11.3 ColorType#Multiband# { num_samplesrust-analyzer cargo tiff 0.11.3 ColorType#Multiband#num_samples.: 2, .. } => (2, "GRAYSCALE_ALPHA"), |
| 47 | _ => { |
| 48 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("Unsupported color type for PAM output: {:?}", colortype); |
| 49 | return; |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | // Number of samples in a line and number of sample lines in the image, depending on whether |
| 54 | // they are planar or not. This determines the layout of the image buffer when expanding bit |
| 55 | // packed samples to a full byte (we support power-of-two sample sizes, positive and negative, |
| 56 | // but only those). |
| 57 | let (swidth, sheight) = if layout.planesrust-analyzer cargo tiff 0.11.3 decoder/BufferLayoutPreference#planes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 { |
| 58 | ( |
| 59 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(width) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u16>`]from().(colortype.num_samplesrust-analyzer cargo tiff 0.11.3 impl#[ColorType]num_samples().()), |
| 60 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(height), |
| 61 | ) |
| 62 | } else { |
| 63 | ( |
| 64 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(width), |
| 65 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(height) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u16>`]from().(colortype.num_samplesrust-analyzer cargo tiff 0.11.3 impl#[ColorType]num_samples().()), |
| 66 | ) |
| 67 | }; |
| 68 | |
| 69 | let mut fallback_buffer; |
| 70 | let maxval = match data.as_bufferrust-analyzer cargo tiff 0.11.3 decoder/impl#[DecodingResult]as_buffer().(0) { |
| 71 | // `U8` is also our representation of bit-packed color. PAM uses the smallest number of |
| 72 | // *bytes* needed to represent a sample but we must also adhere to maxval. We could explode |
| 73 | // them here (e.g. represent 1-bit as `{0, 1}`) but we'd also set `maxval` accordingly and |
| 74 | // this requires tupltype to be `BLACKANDWHITE` so introducing a bunch of complexity. If |
| 75 | // you want to do that in your real code, go ahead. |
| 76 | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::U8rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#U8#(buf) => match colortype.bit_depthrust-analyzer cargo tiff 0.11.3 impl#[ColorType]bit_depth().() { |
| 77 | 8 => u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(u8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]MAX.), |
| 78 | 4 => { |
| 79 | fallback_buffer = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; (swidth *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). sheight) as usize]; |
| 80 | expand_4bitrust-analyzer cargo tiff 0.11.3 expand_4bit().(buf, swidth, &mut fallback_buffer); |
| 81 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().data = DecodingResultrust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#::U8rust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#U8#(fallback_buffer); |
| 82 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(u8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]MAX.) |
| 83 | } |
| 84 | 2 => { |
| 85 | fallback_buffer = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; (swidth *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). sheight) as usize]; |
| 86 | expand_2bitrust-analyzer cargo tiff 0.11.3 expand_2bit().(buf, swidth, &mut fallback_buffer); |
| 87 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().data = DecodingResultrust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#::U8rust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#U8#(fallback_buffer); |
| 88 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(u8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]MAX.) |
| 89 | } |
| 90 | 1 => { |
| 91 | fallback_buffer = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; (swidth *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). sheight) as usize]; |
| 92 | expand_1bitrust-analyzer cargo tiff 0.11.3 expand_1bit().(buf, swidth, &mut fallback_buffer); |
| 93 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().data = DecodingResultrust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#::U8rust-analyzer cargo tiff 0.11.3 decoder/DecodingResult#U8#(fallback_buffer); |
| 94 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(u8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]MAX.) |
| 95 | } |
| 96 | _ => { |
| 97 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!( |
| 98 | "Unsupported bit depth for U8 buffer: {}", |
| 99 | colortype.bit_depthrust-analyzer cargo tiff 0.11.3 impl#[ColorType]bit_depth().() |
| 100 | ); |
| 101 | return; |
| 102 | } |
| 103 | }, |
| 104 | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::U16rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#U16#(_) => u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u16>`]from().(u16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]MAX.), |
| 105 | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::U32rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#U32#(_) => u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(u32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]MAX.), |
| 106 | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::U64rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#U64#(_) => u64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]MAX., |
| 107 | // Eh, this is a good effort I guess. |
| 108 | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::I8rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#I8#(items) => { |
| 109 | items.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]for_each().(|v| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v = 0.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v)); |
| 110 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u8>`]from().(i8::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]MAX. as u8) |
| 111 | } |
| 112 | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::I16rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#I16#(items) => { |
| 113 | items.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]for_each().(|v| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v = 0.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v)); |
| 114 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u16>`]from().(i16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i16]MAX. as u16) |
| 115 | } |
| 116 | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::I32rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#I32#(items) => { |
| 117 | items.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]for_each().(|v| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v = 0.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v)); |
| 118 | u64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u64][`From<u32>`]from().(i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX. as u32) |
| 119 | } |
| 120 | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::I64rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#I64#(items) => { |
| 121 | items.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]for_each().(|v| *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v = 0.maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#max().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().v)); |
| 122 | i64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]MAX. as u64 |
| 123 | } |
| 124 | // Not supported by PAM. |
| 125 | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::F16rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#F16#(_) | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::F32rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#F32#(_) | DecodingBufferrust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#::F64rust-analyzer cargo tiff 0.11.3 decoder/DecodingBuffer#F64#(_) => return, |
| 126 | }; |
| 127 | |
| 128 | let byte_len = if layout.planesrust-analyzer cargo tiff 0.11.3 decoder/BufferLayoutPreference#planes. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 { |
| 129 | tupltype = "GRAYSCALE"; |
| 130 | layout.plane_striderust-analyzer cargo tiff 0.11.3 decoder/BufferLayoutPreference#plane_stride..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/nonzero/impl#[`NonZero<T>`]get().() |
| 131 | } else { |
| 132 | data.as_bufferrust-analyzer cargo tiff 0.11.3 decoder/impl#[DecodingResult]as_buffer().(0).byte_lenrust-analyzer cargo tiff 0.11.3 decoder/impl#[`DecodingBuffer<'a>`]byte_len().() |
| 133 | }; |
| 134 | |
| 135 | // Write out this image's planes to PAM files. |
| 136 | let header = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("P7\nWIDTH {width}\nHEIGHT {height}\nDEPTH {depth}\nMAXVAL {maxval}\nTUPLTYPE {tupltype}\nENDHDR\n"); |
| 137 | |
| 138 | for (plane, plane_data) in data |
| 139 | .as_bufferrust-analyzer cargo tiff 0.11.3 decoder/impl#[DecodingResult]as_buffer().(0) |
| 140 | .as_bytes_mutrust-analyzer cargo tiff 0.11.3 decoder/impl#[`DecodingBuffer<'a>`]as_bytes_mut().() |
| 141 | .chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(byte_len) |
| 142 | .enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() |
| 143 | { |
| 144 | let filename = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("image_{index:03}_plane_{plane:03}.pam"); |
| 145 | let mut file = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(filename).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to create output file"); |
| 146 | |
| 147 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#; |
| 148 | file.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(header.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()) |
| 149 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to write PAM header"); |
| 150 | file.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(plane_data) |
| 151 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Failed to write PAM data"); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /// Put exactly the ith `SCALE`-bit chunk of `val` into the least significant bits. |
| 156 | #[inline(always)] |
| 157 | fn bits_extractrust-analyzer cargo tiff 0.11.3 bits_extract().<const SCALE: u8>(val: u8, i: u8) -> u8 { |
| 158 | // Shift left to discard high bits, then right to bring desired bits down. This way also |
| 159 | // conveniently avoids all cases of overflow. |
| 160 | (val rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shl<Self>`]shl().(i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul().SCALE)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shr<Self>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shr<Self>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`Shr<Self>`]shr().(8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().SCALE) |
| 161 | } |
| 162 | |
| 163 | fn expand_1bitrust-analyzer cargo tiff 0.11.3 expand_1bit().(from: &[u8], samples_per_padded: u64, into: &mut [u8]) { |
| 164 | let stride = samples_per_padded.div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]div_ceil().(8); |
| 165 | |
| 166 | let from_row = from.chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(stride as usize); |
| 167 | let into_row = into.chunks_exact_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact_mut().(samples_per_padded as usize); |
| 168 | |
| 169 | for (from_row, into_row) in from_row.ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(into_row) { |
| 170 | for (into, &from) in into_row.chunks_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_mut().(8).ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(from_row) { |
| 171 | let data = |
| 172 | corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::arrayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/from_fn().::<u8, 8, _>(|i| 0xff rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul().bits_extractrust-analyzer cargo tiff 0.11.3 bits_extract().::<1>(from, i as u8)); |
| 173 | into.copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(&data[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#into.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 array/impl#[`[T; N]`][`Index<I>`]index().); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | fn expand_2bitrust-analyzer cargo tiff 0.11.3 expand_2bit().(from: &[u8], samples_per_padded: u64, into: &mut [u8]) { |
| 179 | let stride = samples_per_padded.div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]div_ceil().(4); |
| 180 | |
| 181 | let from_row = from.chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(stride as usize); |
| 182 | let into_row = into.chunks_exact_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact_mut().(samples_per_padded as usize); |
| 183 | |
| 184 | for (from_row, into_row) in from_row.ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(into_row) { |
| 185 | for (into, &from) in into_row.chunks_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_mut().(4).ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(from_row) { |
| 186 | let data = |
| 187 | corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::arrayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/from_fn().::<u8, 4, _>(|i| 0xaa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul().bits_extractrust-analyzer cargo tiff 0.11.3 bits_extract().::<2>(from, i as u8)); |
| 188 | into.copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(&data[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#into.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 array/impl#[`[T; N]`][`Index<I>`]index().); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | fn expand_4bitrust-analyzer cargo tiff 0.11.3 expand_4bit().(from: &[u8], samples_per_padded: u64, into: &mut [u8]) { |
| 194 | let stride = samples_per_padded.div_ceilrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]div_ceil().(2); |
| 195 | |
| 196 | let from_row = from.chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(stride as usize); |
| 197 | let into_row = into.chunks_exact_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact_mut().(samples_per_padded as usize); |
| 198 | |
| 199 | for (from_row, into_row) in from_row.ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(into_row) { |
| 200 | for (into, &from) in into_row.chunks_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_mut().(2).ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(from_row) { |
| 201 | let data = |
| 202 | corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::arrayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/from_fn().::<u8, 2, _>(|i| 0x88 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Mul<Self>`]mul().bits_extractrust-analyzer cargo tiff 0.11.3 bits_extract().::<4>(from, i as u8)); |
| 203 | into.copy_from_slicerust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]copy_from_slice().(&data[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#into.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 array/impl#[`[T; N]`][`Index<I>`]index().); |
| 204 | } |
| 205 | } |
| 206 | } |