Beispiel #1
0
		/// <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();
		}
Beispiel #2
0
        /// <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();
        }
Beispiel #3
0
        /// <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();
        }
Beispiel #4
0
        /// <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();
        }
Beispiel #5
0
        private void compress(IRawImage source, CompressionParameters parameters)
        {
            Debug.Assert(source != null);

            if (!needCompressWith(parameters))
            {
                return;
            }

            m_compressedData        = new MemoryStream();
            m_compressionParameters = new CompressionParameters(parameters);

            Jpeg jpeg = new Jpeg();

            jpeg.CompressionParameters = m_compressionParameters;
            jpeg.Compress(source, m_compressedData);
        }
Beispiel #6
0
        private void Compress(IRawImage source, CompressionParameters parameters)
        {
            Debug.Assert(source is object);

            if (!NeedCompressWith(parameters))
            {
                return;
            }

            m_compressedData        = new MemoryStream();
            m_compressionParameters = new CompressionParameters(parameters);

            var jpeg = new Jpeg
            {
                CompressionParameters = m_compressionParameters
            };

            jpeg.Compress(source, m_compressedData);
        }
Beispiel #7
0
        /// <summary>
        /// Display a Image on the Display
        /// </summary>
        /// <param name="rawImage">Bitmap that should be displayed</param>
        /// <param name="dithering"></param>
        public void DisplayImage(IRawImage rawImage, bool dithering)
        {
            SendCommand(StartDataTransmissionCommand);

            if (dithering)
            {
                SendDitheredBitmapToDevice(rawImage.ScanLine, rawImage.Stride, rawImage.Width, rawImage.Height);
            }
            else
            {
                SendBitmapToDevice(rawImage.ScanLine, rawImage.Stride, rawImage.Width, rawImage.Height);
            }

            if (StopDataTransmissionCommand < byte.MaxValue)
            {
                SendCommand(StopDataTransmissionCommand);
            }

            TurnOnDisplay();
        }
Beispiel #8
0
        private void compress(IRawImage source, CompressionParameters parameters)
        {
            Debug.Assert(source != null);

            if (!needCompressWith(parameters))
                return;

            m_compressedData = new MemoryStream();
            m_compressionParameters = new CompressionParameters(parameters);

            Jpeg jpeg = new Jpeg();
            jpeg.CompressionParameters = m_compressionParameters;
            jpeg.Compress(source, m_compressedData);
        }
Beispiel #9
0
        /// <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();
        }