Exemple #1
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveImageRLE(BinaryReverseWriter writer)
        {
            // we will write the correct lengths later, so remember
            // the position
            var lengthPosition = writer.BaseStream.Position;

            var rleRowLenghs = new int[m_rows * m_channels];

            if (m_imageCompression == ImageCompression.Rle)
            {
                for (int i = 0; i < rleRowLenghs.Length; i++)
                {
                    writer.Write((short)0x1234);
                }
            }

            //---------------------------------------------------------------

            for (int ch = 0; ch < m_channels; ch++)
            {
                var startIdx = ch * m_rows;

                for (int row = 0; row < m_rows; row++)
                {
                    rleRowLenghs[row + startIdx] = RleHelper.EncodedRow(writer.BaseStream, m_imageData[ch],
                                                                        row * m_columns, m_columns);
                }
            }

            //---------------------------------------------------------------

            long endPosition = writer.BaseStream.Position;

            writer.BaseStream.Position = lengthPosition;

            for (var i = 0; i < rleRowLenghs.Length; i++)
            {
                writer.Write((short)rleRowLenghs[i]);
            }

            writer.BaseStream.Position = endPosition;

            //---------------------------------------------------------------
        }
Exemple #2
0
            public void CompressImageData()
            {
                if (m_imageCompression == ImageCompression.Rle)
                {
                    MemoryStream        dataStream = new MemoryStream();
                    BinaryReverseWriter writer     = new BinaryReverseWriter(dataStream);

                    // we will write the correct lengths later, so remember
                    // the position
                    long lengthPosition = writer.BaseStream.Position;

                    int[] rleRowLengths = new int[m_layer.m_rect.Height];
                    for (int i = 0; i < rleRowLengths.Length; i++)
                    {
                        writer.Write((short)0x1234);
                    }

                    //---------------------------------------------------------------

                    int bytesPerRow = 0;

                    switch (m_layer.PsdFile.Depth)
                    {
                    case 1:
                        bytesPerRow = ImageDecoder.BytesFromBits(m_layer.m_rect.Width);
                        break;

                    case 8:
                        bytesPerRow = m_layer.m_rect.Width;
                        break;

                    case 16:
                        bytesPerRow = m_layer.m_rect.Width * 2;
                        break;
                    }

                    //---------------------------------------------------------------

                    for (int row = 0; row < m_layer.m_rect.Height; row++)
                    {
                        int rowIndex = row * m_layer.m_rect.Width;
                        rleRowLengths[row] = RleHelper.EncodedRow(writer.BaseStream, m_imageData, rowIndex, bytesPerRow);
                    }

                    //---------------------------------------------------------------

                    long endPosition = writer.BaseStream.Position;

                    writer.BaseStream.Position = lengthPosition;

                    for (int i = 0; i < rleRowLengths.Length; i++)
                    {
                        writer.Write((short)rleRowLengths[i]);
                    }

                    writer.BaseStream.Position = endPosition;

                    dataStream.Close();

                    m_data = dataStream.ToArray();

                    dataStream.Dispose();
                }
                else
                {
                    m_data = (byte[])m_imageData.Clone();
                }
            }