/// <summary> /// Compresses any image described as ICompressSource to JPEG /// </summary> /// <param name="source">Contains description of input image</param> /// <param name="output">Stream for output of compressed JPEG</param> public void Compress(IRawImage source, Stream output) { if (source == null) { throw new ArgumentNullException("source"); } if (output == null) { throw new ArgumentNullException("output"); } m_compressor.Image_width = source.Width; m_compressor.Image_height = source.Height; m_compressor.In_color_space = (J_COLOR_SPACE)source.Colorspace; m_compressor.Input_components = source.ComponentsPerPixel; //m_compressor.Data_precision = source.DataPrecision; m_compressor.jpeg_set_defaults(); //we need to set density parameters after setting of default jpeg parameters //m_compressor.Density_unit = source.DensityUnit; //m_compressor.X_density = (short)source.DensityX; //m_compressor.Y_density = (short)source.DensityY; applyParameters(m_compressionParameters); // Specify data destination for compression m_compressor.jpeg_stdio_dest(output); // Start compression m_compressor.jpeg_start_compress(true); // Process pixels source.BeginRead(); while (m_compressor.Next_scanline < m_compressor.Image_height) { byte[] row = source.GetPixelRow(); if (row == null) { #if !SILVERLIGHT throw new InvalidDataException("Row of pixels is null"); #else // System.IO.InvalidDataException is not available in Silverlight throw new IOException("Row of pixels is null"); #endif } byte[][] rowForDecompressor = new byte[1][]; rowForDecompressor[0] = row; m_compressor.jpeg_write_scanlines(rowForDecompressor, 1); } source.EndRead(); // Finish compression and release memory m_compressor.jpeg_finish_compress(); }
/// <summary> /// Compresses any image described as ICompressSource to JPEG /// </summary> /// <param name="source">Contains description of input image</param> /// <param name="output">Stream for output of compressed JPEG</param> public void Compress(IRawImage source, Stream output) { if (source is null) { throw new ArgumentNullException(nameof(source)); } if (output is null) { throw new ArgumentNullException(nameof(output)); } ClassicCompressor.Image_width = source.Width; ClassicCompressor.Image_height = source.Height; ClassicCompressor.In_color_space = (JColorSpace)source.Colorspace; ClassicCompressor.Input_components = source.ComponentsPerPixel; //m_compressor.Data_precision = source.DataPrecision; ClassicCompressor.JpegSetDefaults(); //we need to set density parameters after setting of default jpeg parameters //m_compressor.Density_unit = source.DensityUnit; //m_compressor.X_density = (short)source.DensityX; //m_compressor.Y_density = (short)source.DensityY; applyParameters(m_compressionParameters); // Specify data destination for compression ClassicCompressor.JpegStdioDest(output); // Start compression ClassicCompressor.JpegStartCompression(true); // Process pixels source.BeginRead(); while (ClassicCompressor.Next_scanline < ClassicCompressor.Image_height) { var row = source.GetPixelRow(); var rowForDecompressor = new byte[1][]; rowForDecompressor[0] = row ?? throw new InvalidDataException("Row of pixels is null"); ClassicCompressor.JpegWriteScanlines(rowForDecompressor, 1); } source.EndRead(); // Finish compression and release memory ClassicCompressor.JpegFinishCompress(); }
/// <summary> /// Compresses any image described as ICompressSource to JPEG /// </summary> /// <param name="source">Contains description of input image</param> /// <param name="output">Stream for output of compressed JPEG</param> public void Compress(IRawImage source, Stream output) { if (source == null) throw new ArgumentNullException("source"); if (output == null) throw new ArgumentNullException("output"); m_compressor.Image_width = source.Width; m_compressor.Image_height = source.Height; m_compressor.In_color_space = (J_COLOR_SPACE)source.Colorspace; m_compressor.Input_components = source.ComponentsPerPixel; //m_compressor.Data_precision = source.DataPrecision; // TODO: This method call is messy. It doesn't so much set blind defaults, because a number of the calls it makes // react to class fields/properties set by CompressionParameters. // This is even odder because many of the "defaults" are then overridden in applyParameters, below. // Why does this method exist? Seems like all calls that overlap with applyParameters should be removed. m_compressor.jpeg_set_defaults(); //we need to set density parameters after setting of default jpeg parameters //m_compressor.Density_unit = source.DensityUnit; //m_compressor.X_density = (short)source.DensityX; //m_compressor.Y_density = (short)source.DensityY; applyParameters(m_compressionParameters); // Specify data destination for compression m_compressor.jpeg_stdio_dest(output); // Start compression m_compressor.jpeg_start_compress(true); // Process pixels source.BeginRead(); while (m_compressor.Next_scanline < m_compressor.Image_height) { byte[] row = source.GetPixelRow(); if (row == null) { #if !SILVERLIGHT throw new InvalidDataException("Row of pixels is null"); #else // System.IO.InvalidDataException is not available in Silverlight throw new IOException("Row of pixels is null"); #endif } byte[][] rowForDecompressor = new byte[1][]; rowForDecompressor[0] = row; m_compressor.jpeg_write_scanlines(rowForDecompressor, 1); } source.EndRead(); // Finish compression and release memory m_compressor.jpeg_finish_compress(); }
/// <summary> /// Compresses any image described as ICompressSource to JPEG /// </summary> /// <param name="source">Contains description of input image</param> /// <param name="output">Stream for output of compressed JPEG</param> public void Compress(IRawImage source, Stream output) { if (source == null) throw new ArgumentNullException("source"); if (output == null) throw new ArgumentNullException("output"); m_compressor.Image_width = source.Width; m_compressor.Image_height = source.Height; m_compressor.In_color_space = (J_COLOR_SPACE)source.Colorspace; m_compressor.Input_components = source.ComponentsPerPixel; //m_compressor.Data_precision = source.DataPrecision; m_compressor.jpeg_set_defaults(); //we need to set density parameters after setting of default jpeg parameters //m_compressor.Density_unit = source.DensityUnit; //m_compressor.X_density = (short)source.DensityX; //m_compressor.Y_density = (short)source.DensityY; applyParameters(m_compressionParameters); // Specify data destination for compression m_compressor.jpeg_stdio_dest(output); // Start compression m_compressor.jpeg_start_compress(true); // Process pixels source.BeginRead(); while (m_compressor.Next_scanline < m_compressor.Image_height) { byte[] row = source.GetPixelRow(); if (row == null) { #if !SILVERLIGHT throw new InvalidDataException("Row of pixels is null"); #else // System.IO.InvalidDataException is not available in Silverlight throw new IOException("Row of pixels is null"); #endif } byte[][] rowForDecompressor = new byte[1][]; rowForDecompressor[0] = row; m_compressor.jpeg_write_scanlines(rowForDecompressor, 1); } source.EndRead(); // Finish compression and release memory m_compressor.jpeg_finish_compress(); }
/// <summary> /// Compresses any image described as ICompressSource to JPEG /// </summary> /// <param name="source">Contains description of input image</param> /// <param name="output">Stream for output of compressed JPEG</param> public void Compress(IRawImage source, Stream output) { if (source == null) { throw new ArgumentNullException("source"); } if (output == null) { throw new ArgumentNullException("output"); } m_compressor.Image_width = source.Width; m_compressor.Image_height = source.Height; m_compressor.In_color_space = (J_COLOR_SPACE)source.Colorspace; m_compressor.Input_components = source.ComponentsPerPixel; //m_compressor.Data_precision = source.DataPrecision; // TODO: This method call is messy. It doesn't so much set blind defaults, because a number of the calls it makes // react to class fields/properties set by CompressionParameters. // This is even odder because many of the "defaults" are then overridden in applyParameters, below. // Why does this method exist? Seems like all calls that overlap with applyParameters should be removed. m_compressor.jpeg_set_defaults(); //we need to set density parameters after setting of default jpeg parameters //m_compressor.Density_unit = source.DensityUnit; //m_compressor.X_density = (short)source.DensityX; //m_compressor.Y_density = (short)source.DensityY; applyParameters(m_compressionParameters); // Specify data destination for compression m_compressor.jpeg_stdio_dest(output); // Start compression m_compressor.jpeg_start_compress(true); // Process pixels source.BeginRead(); while (m_compressor.Next_scanline < m_compressor.Image_height) { byte[] row = source.GetPixelRow(); if (row == null) { #if !SILVERLIGHT throw new InvalidDataException("Row of pixels is null"); #else // System.IO.InvalidDataException is not available in Silverlight throw new IOException("Row of pixels is null"); #endif } byte[][] rowForDecompressor = new byte[1][]; rowForDecompressor[0] = row; m_compressor.jpeg_write_scanlines(rowForDecompressor, 1); } source.EndRead(); // Finish compression and release memory m_compressor.jpeg_finish_compress(); }