コード例 #1
0
        /// <summary>
        /// Creates <see cref="JpegImage"/> from file with an arbitrary image
        /// </summary>
        /// <param name="fileName">Path to file with image in
        /// arbitrary format (BMP, Jpeg, GIF, PNG, TIFF, e.t.c)</param>
        //public JpegImage(string fileName)
        //{
        //	if (fileName == null)
        //		throw new ArgumentNullException("fileName");

        //	using (FileStream input = new FileStream(fileName, FileMode.Open))
        //		createFromStream(input);
        //}

        /// <summary>
        /// Creates <see cref="JpegImage"/> from pixels
        /// </summary>
        /// <param name="sampleData">Description of pixels.</param>
        /// <param name="colorspace">Colorspace of image.</param>
        /// <seealso cref="SampleRow"/>
        public JpegImage(SampleRow[] sampleData, Colorspace colorspace)
        {
            if (sampleData == null)
            {
                throw new ArgumentNullException("sampleData");
            }

            if (sampleData.Length == 0)
            {
                throw new ArgumentException("sampleData must be no empty");
            }

            if (colorspace == Colorspace.Unknown)
            {
                throw new ArgumentException("Unknown colorspace");
            }

            m_rows = new List <SampleRow>(sampleData);

            SampleRow firstRow = m_rows[0];

            m_width  = firstRow.Length;
            m_height = m_rows.Count;

            Sample firstSample = firstRow[0];

            m_bitsPerComponent    = firstSample.BitsPerComponent;
            m_componentsPerSample = firstSample.ComponentCount;
            m_colorspace          = colorspace;
        }
コード例 #2
0
        /// <inheritdoc/>
        public void Encode(ImageBase image, Stream stream)
        {
            Guard.NotNull(image, nameof(image));
            Guard.NotNull(stream, nameof(stream));

            int imageWidth = image.Width;
            int imageHeight = image.Height;

            SampleRow[] rows = new SampleRow[imageHeight];

            Parallel.For(
                0,
                imageHeight,
                y =>
                    {
                        byte[] samples = new byte[imageWidth * 3];

                        for (int x = 0; x < imageWidth; x++)
                        {
                            Bgra32 color = Color.ToNonPremultiplied(image[x, y]);

                            int start = x * 3;
                            samples[start] = color.R;
                            samples[start + 1] = color.G;
                            samples[start + 2] = color.B;
                        }

                        rows[y] = new SampleRow(samples, imageWidth, 8, 3);
                    });

            using (JpegImage jpg = new JpegImage(rows, Colorspace.RGB))
            {
                jpg.WriteJpeg(stream, new CompressionParameters { Quality = this.Quality });
            }
        }
コード例 #3
0
        public void Encode(Image image, Stream stream)
        {
            int pixelWidth  = image.Width;
            int pixelHeight = image.Height;

            byte[] sourcePixels = image.Pixels;

            SampleRow[] rows = new SampleRow[pixelHeight];

            for (int y = 0; y < pixelHeight; y++)
            {
                byte[] samples = new byte[pixelWidth * 3];

                for (int x = 0; x < pixelWidth; x++)
                {
                    int start = x * 3;
                    int source = (y * pixelWidth + x) * 4;

                    samples[start] = sourcePixels[source + 2];
                    samples[start + 1] = sourcePixels[source + 1];
                    samples[start + 2] = sourcePixels[source];
                }

                rows[y] = new SampleRow(samples, pixelWidth, 8, 3);
            }

            JpegImage jpg = new JpegImage(rows, Colorspace.RGB);
            jpg.WriteJpeg(stream, new CompressionParameters { Quality = Quality });
        }
コード例 #4
0
        /// <summary>
        /// Needs for DecompressorToJpegImage class
        /// </summary>
        internal void addSampleRow(SampleRow row)
        {
            if (row == null)
            {
                throw new ArgumentNullException("row");
            }

            m_rows.Add(row);
        }
コード例 #5
0
ファイル: JpegImage.cs プロジェクト: Chapmania/Juniper
        /// <summary>
        /// Needs for DecompressorToJpegImage class
        /// </summary>
        internal void AddSampleRow(SampleRow row)
        {
            if (row is null)
            {
                throw new ArgumentNullException(nameof(row));
            }

            m_rows.Add(row);
        }
コード例 #6
0
        public void ProcessPixelsRow(byte[] row)
        {
            SampleRow samplesRow = new SampleRow(row,
                m_jpegImage.Width,
                m_jpegImage.BitsPerComponent,
                m_jpegImage.ComponentsPerSample);

            m_jpegImage.addSampleRow(samplesRow);
        }
コード例 #7
0
        public void ProcessPixelsRow(byte[] row)
        {
            SampleRow samplesRow = new SampleRow(row,
                                                 m_jpegImage.Width,
                                                 m_jpegImage.BitsPerComponent,
                                                 m_jpegImage.ComponentsPerSample);

            m_jpegImage.addSampleRow(samplesRow);
        }
コード例 #8
0
        public byte[] GetPixelRow()
        {
            SampleRow   row    = _samples[m_currentRow];
            List <byte> result = new List <byte>();

            for (int i = 0; i < row.Length; ++i)
            {
                //Sample sample = row[i];
                row.WriteToList(result);

                //for (int j = 0; j < sample.ComponentCount; ++j)
                //    result.Add((byte)sample[j]);
            }
            ++m_currentRow;
            return(result.ToArray());
        }
コード例 #9
0
        /// <summary>
        /// Creates <see cref="JpegImage"/> from pixels
        /// </summary>
        /// <param name="sampleData">Description of pixels.</param>
        /// <param name="colorspace">Colorspace of image.</param>
        /// <seealso cref="SampleRow"/>
        public JpegImage(SampleRow[] sampleData, Colorspace colorspace)
        {
            if (sampleData == null)
                throw new ArgumentNullException("sampleData");

            if (sampleData.Length == 0)
                throw new ArgumentException("sampleData must be no empty");

            if (colorspace == Colorspace.Unknown)
                throw new ArgumentException("Unknown colorspace");

            m_rows = new List<SampleRow>(sampleData);

            SampleRow firstRow = m_rows[0];
            m_width = firstRow.Length;
            m_height = m_rows.Count;

            Sample firstSample = firstRow[0];
            m_bitsPerComponent = firstSample.BitsPerComponent;
            m_componentsPerSample = firstSample.ComponentCount;
            m_colorspace = colorspace;
        }
コード例 #10
0
ファイル: JpegImage.cs プロジェクト: prepare/HTML-Renderer
        /// <summary>
        /// Needs for DecompressorToJpegImage class
        /// </summary>
        internal void addSampleRow(SampleRow row)
        {
            if (row == null)
                throw new ArgumentNullException("row");

            m_rows.Add(row);
        }
コード例 #11
0
ファイル: JpegImage.cs プロジェクト: lygroup/libjpeg.net
        private static JpegImage createImageFromPixels()
        {
            byte[] rowData = new byte[96];
            for (int i = 0; i < rowData.Length; ++i)
            {
                if (i < 5)
                    rowData[i] = 0xE4;
                else if (i < 15)
                    rowData[i] = 0xAB;
                else if (i < 35)
                    rowData[i] = 0x00;
                else if (i < 55)
                    rowData[i] = 0x65;
                else
                    rowData[i] = 0xF0;
            }

            const int width = 24;
            const int height = 25;
            const byte bitsPerComponent = 8;
            const byte componentsPerSample = 4;
            const Colorspace colorspace = Colorspace.CMYK;

            SampleRow row = new SampleRow(rowData, width, bitsPerComponent, componentsPerSample);
            SampleRow[] rows = new SampleRow[height];
            for (int i = 0; i < rows.Length; ++i)
                rows[i] = row;

            JpegImage jpegImage = new JpegImage(rows, colorspace);
            Assert.AreEqual(jpegImage.Width, width);
            Assert.AreEqual(jpegImage.Height, rows.Length);
            Assert.AreEqual(jpegImage.BitsPerComponent, bitsPerComponent);
            Assert.AreEqual(jpegImage.ComponentsPerSample, componentsPerSample);
            Assert.AreEqual(jpegImage.Colorspace, colorspace);
            return jpegImage;
        }