pub fn encode_image<I: GenericImageView>(&mut self, image: &I) -> ImageResult<()> {
        let n = I::Pixel::CHANNEL_COUNT;
        let num_components = if n == 1 || n == 2 { 1 } else { 3 };

        self.writer.write_marker(SOI)?;

        let mut buf = Vec::new();

        build_jfif_header(&mut buf, self.pixel_density);
        self.writer.write_segment(APP0, &buf)?;

        // memex adaption
        // this will write the data from the reader in consecutive segments
        let data_len = self.config.data_len();
        let segment_len = self.config.segment_data_len();
        loop {
            let mut buf = Vec::with_capacity(segment_len);
            buf.extend_from_slice(self.config.vendor.as_bytes());
            let read = self
                .reader
                .by_ref()
                .take(data_len as u64)
                .read_to_end(&mut buf)?;
            self.writer.write_segment(self.config.marker, &buf)?;
            if read == 0 {
                break;
            }
        }

        build_frame_header(
            &mut buf,
            8,
            // TODO: not idiomatic yet. Should be an EncodingError and mention jpg. Further it
            // should check dimensions prior to writing.
            u16::try_from(image.width()).map_err(|_| {
                ImageError::Parameter(ParameterError::from_kind(
                    ParameterErrorKind::DimensionMismatch,
                ))
            })?,
            u16::try_from(image.height()).map_err(|_| {
                ImageError::Parameter(ParameterError::from_kind(
                    ParameterErrorKind::DimensionMismatch,
                ))
            })?,
            &self.components[..num_components],
        );
        self.writer.write_segment(SOF0, &buf)?;

        assert_eq!(self.tables.len(), 2);
        let numtables = if num_components == 1 { 1 } else { 2 };

        for (i, table) in self.tables[..numtables].iter().enumerate() {
            build_quantization_segment(&mut buf, 8, i as u8, table);
            self.writer.write_segment(DQT, &buf)?;
        }

        build_huffman_segment(
            &mut buf,
            DCCLASS,
            LUMADESTINATION,
            &STD_LUMA_DC_CODE_LENGTHS,
            &STD_LUMA_DC_VALUES,
        );
        self.writer.write_segment(DHT, &buf)?;

        build_huffman_segment(
            &mut buf,
            ACCLASS,
            LUMADESTINATION,
            &STD_LUMA_AC_CODE_LENGTHS,
            &STD_LUMA_AC_VALUES,
        );
        self.writer.write_segment(DHT, &buf)?;

        if num_components == 3 {
            build_huffman_segment(
                &mut buf,
                DCCLASS,
                CHROMADESTINATION,
                &STD_CHROMA_DC_CODE_LENGTHS,
                &STD_CHROMA_DC_VALUES,
            );
            self.writer.write_segment(DHT, &buf)?;

            build_huffman_segment(
                &mut buf,
                ACCLASS,
                CHROMADESTINATION,
                &STD_CHROMA_AC_CODE_LENGTHS,
                &STD_CHROMA_AC_VALUES,
            );
            self.writer.write_segment(DHT, &buf)?;
        }

        build_scan_header(&mut buf, &self.components[..num_components]);
        self.writer.write_segment(SOS, &buf)?;

        if I::Pixel::COLOR_TYPE.has_color() {
            self.encode_rgb(image)
        } else {
            self.encode_gray(image)
        }?;

        self.writer.pad_byte()?;
        self.writer.write_marker(EOI)?;
        Ok(())
    }
/// Encodes the given image.
///
/// As a special feature this does not require the whole image to be present in memory at the
/// same time such that it may be computed on the fly, which is why this method exists on this
/// encoder but not on others. Instead the encoder will iterate over 8-by-8 blocks of pixels at
/// a time, inspecting each pixel exactly once. You can rely on this behaviour when calling
/// this method.
///
/// The Image in encoded with subsampling ratio 4:2:2
Encodes the given image.
As a special feature this does not require the whole image to be present in memory at the
same time such that it may be computed on the fly, which is why this method exists on this
encoder but not on others. Instead the encoder will iterate over 8-by-8 blocks of pixels at
a time, inspecting each pixel exactly once. You can rely on this behaviour when calling
this method.

The Image in encoded with subsampling ratio 4:2:2
Encodes the given image . As a special feature this does not require the whole image to be present in memory at the same time such that it may be computed on the fly which is why this method exists on this encoder but not on others . Instead the encoder will iterate over 8 - by - 8 blocks of pixels at a time inspecting each pixel exactly once . You can rely on this behaviour when calling this method . The Image in encoded with subsampling ratio 4 : 2 : 2
pub fn encode_image<I: GenericImageView>(&mut self, image: &I) -> ImageResult<()> {
        let n = I::Pixel::CHANNEL_COUNT;
        let num_components = if n == 1 || n == 2 { 1 } else { 3 };
        self.writer.write_marker(SOI)?;
        let mut buf = Vec::new();
        build_jfif_header(&mut buf, self.pixel_density);
        self.writer.write_segment(APP0, &buf)?;
        // memex adaption
        // this will write the data from the reader in consecutive segments
        let data_len = self.config.data_len();
        let segment_len = self.config.segment_data_len();
        loop {
            let mut buf = Vec::with_capacity(segment_len);
            buf.extend_from_slice(self.config.vendor.as_bytes());
            let read = self
                .reader
                .by_ref()
                .take(data_len as u64)
                .read_to_end(&mut buf)?;
            self.writer.write_segment(self.config.marker, &buf)?;
            if read == 0 {
                break;
            }
        }
        build_frame_header(
            &mut buf,
            8,
            // TODO: not idiomatic yet. Should be an EncodingError and mention jpg. Further it
            // should check dimensions prior to writing.
            u16::try_from(image.width()).map_err(|_| {
                ImageError::Parameter(ParameterError::from_kind(
                    ParameterErrorKind::DimensionMismatch,
                ))
            })?,
            u16::try_from(image.height()).map_err(|_| {
                ImageError::Parameter(ParameterError::from_kind(
                    ParameterErrorKind::DimensionMismatch,
                ))
            })?,
            &self.components[..num_components],
        );
        self.writer.write_segment(SOF0, &buf)?;
        assert_eq!(self.tables.len(), 2);
        let numtables = if num_components == 1 { 1 } else { 2 };
        for (i, table) in self.tables[..numtables].iter().enumerate() {
            build_quantization_segment(&mut buf, 8, i as u8, table);
            self.writer.write_segment(DQT, &buf)?;
        }
        build_huffman_segment(
            &mut buf,
            DCCLASS,
            LUMADESTINATION,
            &STD_LUMA_DC_CODE_LENGTHS,
            &STD_LUMA_DC_VALUES,
        );
        self.writer.write_segment(DHT, &buf)?;
        build_huffman_segment(
            &mut buf,
            ACCLASS,
            LUMADESTINATION,
            &STD_LUMA_AC_CODE_LENGTHS,
            &STD_LUMA_AC_VALUES,
        );
        self.writer.write_segment(DHT, &buf)?;
        if num_components == 3 {
            build_huffman_segment(
                &mut buf,
                DCCLASS,
                CHROMADESTINATION,
                &STD_CHROMA_DC_CODE_LENGTHS,
                &STD_CHROMA_DC_VALUES,
            );
            self.writer.write_segment(DHT, &buf)?;
            build_huffman_segment(
                &mut buf,
                ACCLASS,
                CHROMADESTINATION,
                &STD_CHROMA_AC_CODE_LENGTHS,
                &STD_CHROMA_AC_VALUES,
            );
            self.writer.write_segment(DHT, &buf)?;
        }
        build_scan_header(&mut buf, &self.components[..num_components]);
        self.writer.write_segment(SOS, &buf)?;
        if I::Pixel::COLOR_TYPE.has_color() {
            self.encode_rgb(image)
        } else {
            self.encode_gray(image)
        }?;
        self.writer.pad_byte()?;
        self.writer.write_marker(EOI)?;
        Ok(())
    }
pub fn encode_image < I : GenericImageView > ( & mut self , image : & I ) -> ImageResult < ( ) > { let n = I :: Pixel :: CHANNEL_COUNT ; let num_components = if n == 1 || n == 2 { 1 } else { 3 } ; self . writer . write_marker ( SOI ) ? ; let mut buf = Vec :: new ( ) ; build_jfif_header ( & mut buf , self . pixel_density ) ; self . writer . write_segment ( APP0 , & buf ) ? ; // memex adaption // this will write the data from the reader in consecutive segments let data_len = self . config . data_len ( ) ; let segment_len = self . config . segment_data_len ( ) ; loop { let mut buf = Vec :: with_capacity ( segment_len ) ; buf . extend_from_slice ( self . config . vendor . as_bytes ( ) ) ; let read = self . reader . by_ref ( ) . take ( data_len as u64 ) . read_to_end ( & mut buf ) ? ; self . writer . write_segment ( self . config . marker , & buf ) ? ; if read == 0 { break ; } } build_frame_header ( & mut buf , 8 , // TODO: not idiomatic yet. Should be an EncodingError and mention jpg. Further it // should check dimensions prior to writing. u16 :: try_from ( image . width ( ) ) . map_err ( | _ | { ImageError :: Parameter ( ParameterError :: from_kind ( ParameterErrorKind :: DimensionMismatch , ) ) } ) ? , u16 :: try_from ( image . height ( ) ) . map_err ( | _ | { ImageError :: Parameter ( ParameterError :: from_kind ( ParameterErrorKind :: DimensionMismatch , ) ) } ) ? , & self . components [ .. num_components ] , ) ; self . writer . write_segment ( SOF0 , & buf ) ? ; assert_eq ! ( self tables len ( ) 2 ) ; let numtables = if num_components == 1 { 1 } else { 2 } ; for ( i , table ) in self . tables [ .. numtables ] . iter ( ) . enumerate ( ) { build_quantization_segment ( & mut buf , 8 , i as u8 , table ) ; self . writer . write_segment ( DQT , & buf ) ? ; } build_huffman_segment ( & mut buf , DCCLASS , LUMADESTINATION , & STD_LUMA_DC_CODE_LENGTHS , & STD_LUMA_DC_VALUES , ) ; self . writer . write_segment ( DHT , & buf ) ? ; build_huffman_segment ( & mut buf , ACCLASS , LUMADESTINATION , & STD_LUMA_AC_CODE_LENGTHS , & STD_LUMA_AC_VALUES , ) ; self . writer . write_segment ( DHT , & buf ) ? ; if num_components == 3 { build_huffman_segment ( & mut buf , DCCLASS , CHROMADESTINATION , & STD_CHROMA_DC_CODE_LENGTHS , & STD_CHROMA_DC_VALUES , ) ; self . writer . write_segment ( DHT , & buf ) ? ; build_huffman_segment ( & mut buf , ACCLASS , CHROMADESTINATION , & STD_CHROMA_AC_CODE_LENGTHS , & STD_CHROMA_AC_VALUES , ) ; self . writer . write_segment ( DHT , & buf ) ? ; } build_scan_header ( & mut buf , & self . components [ .. num_components ] ) ; self . writer . write_segment ( SOS , & buf ) ? ; if I :: Pixel :: COLOR_TYPE . has_color ( ) { self . encode_rgb ( image ) } else { self . encode_gray ( image ) } ? ; self . writer . pad_byte ( ) ? ; self . writer . write_marker ( EOI ) ? ; Ok ( ( ) ) }
Encodes the given image.
Encodes the given image .
&mut self
image
&I