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

        private void LoadImage(BinaryReverseReader reader)
        {
            Debug.WriteLine("LoadImage started at " + reader.BaseStream.Position);

            m_imageCompression = (ImageCompression)reader.ReadInt16();

            m_imageData = new byte[m_channels][];

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

            if (m_imageCompression == ImageCompression.Rle)
            {
                // The RLE-compressed data is proceeded by a 2-byte data count for each row in the data,
                // which we're going to just skip.
                reader.BaseStream.Position += m_rows * m_channels * 2;
            }

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

            int bytesPerRow = 0;

            switch (m_depth)
            {
            case 1:
                bytesPerRow = m_columns;     //NOT Shure
                break;

            case 8:
                bytesPerRow = m_columns;
                break;

            case 16:
                bytesPerRow = m_columns * 2;
                break;
            }

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

            for (int ch = 0; ch < m_channels; ch++)
            {
                m_imageData[ch] = new byte[m_rows * bytesPerRow];

                switch (m_imageCompression)
                {
                case ImageCompression.Raw:
                    reader.Read(m_imageData[ch], 0, m_imageData[ch].Length);
                    break;

                case ImageCompression.Rle:
                {
                    for (int i = 0; i < m_rows; i++)
                    {
                        int rowIndex = i * m_columns;
                        RleHelper.DecodedRow(reader.BaseStream, m_imageData[ch], rowIndex, bytesPerRow);
                    }
                }
                break;
                }
            }
        }
Exemple #2
0
            //////////////////////////////////////////////////////////////////

            internal void LoadPixelData(BinaryReverseReader reader)
            {
                Debug.WriteLine("Channel.LoadPixelData started at " + reader.BaseStream.Position);

                m_data = reader.ReadBytes(Length);

                using (BinaryReverseReader readerImg = DataReader)
                {
                    m_imageCompression = (ImageCompression)readerImg.ReadInt16();

                    int bytesPerRow = 0;

                    switch (m_layer.PsdFile.Depth)
                    {
                    case 1:
                        bytesPerRow = m_layer.m_rect.Width;     //NOT Shure
                        break;

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

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

                    m_imageData = new byte[m_layer.m_rect.Height * bytesPerRow];

                    switch (m_imageCompression)
                    {
                    case ImageCompression.Raw:
                        readerImg.Read(m_imageData, 0, m_imageData.Length);
                        break;

                    case ImageCompression.Rle:
                    {
                        var rowLenghtList = new int[m_layer.m_rect.Height];
                        for (int i = 0; i < rowLenghtList.Length; i++)
                        {
                            rowLenghtList[i] = readerImg.ReadInt16();
                        }

                        for (int i = 0; i < m_layer.m_rect.Height; i++)
                        {
                            var rowIndex = i * m_layer.m_rect.Width;
                            RleHelper.DecodedRow(readerImg.BaseStream, m_imageData, rowIndex, bytesPerRow);

                            //if (rowLenghtList[i] % 2 == 1)
                            //  readerImg.ReadByte();
                        }
                    }
                    break;
                    }
                }
            }
Exemple #3
0
            public void DecompressImageData()
            {
                MemoryStream stream = new MemoryStream(m_data);

                for (int i = 0; i < m_layer.m_rect.Height; i++)
                {
                    int rowIndex = i * m_layer.m_rect.Width;
                    RleHelper.DecodedRow(stream, m_imageData, rowIndex, m_bytesPerRow);
                }
            }
Exemple #4
0
        internal void LoadPixelData(BinaryReverseReader reader)
        {
            Data = reader.ReadBytes(Length);

            using (BinaryReverseReader dataReader = DataReader)
            {
                //从文档 五 - 5 读取信息
                ImageCompression = (ImageCompression)dataReader.ReadInt16();
                int columns = 0;
                switch (Layer.PsdFile.Depth)
                {
                case 1:
                    columns = (int)Layer.Rect.width;
                    break;

                case 8:
                    columns = (int)Layer.Rect.width;
                    break;

                case 16:
                    columns = (int)Layer.Rect.width * 2;
                    break;
                }

                ImageData = new byte[(int)Layer.Rect.height * columns];
                switch (ImageCompression)
                {
                case ImageCompression.Raw:
                    dataReader.Read(ImageData, 0, ImageData.Length);
                    break;

                case ImageCompression.Rle:
                    int[] nums = new int[(int)Layer.Rect.height];

                    for (int i = 0; i < Layer.Rect.height; i++)
                    {
                        nums[i] = dataReader.ReadInt16();
                    }

                    for (int index = 0; index < Layer.Rect.height; ++index)
                    {
                        int startIdx = index * (int)Layer.Rect.width;
                        RleHelper.DecodedRow(dataReader.BaseStream, ImageData, startIdx, columns);
                    }

                    break;
                }
            }
        }
Exemple #5
0
        private void LoadImage(BinaryReverseReader reader)
        {
            _imageCompression = (ImageCompression)reader.ReadInt16();
            _imageData        = new byte[_channels][];
            if (_imageCompression == ImageCompression.Rle)
            {
                reader.BaseStream.Position += _height * _channels * 2;
            }

            int columns = 0;

            switch (_depth)
            {
            case 1:
                columns = _width;
                break;

            case 8:
                columns = _width;
                break;

            case 16:
                columns = _width * 2;
                break;
            }

            for (int index1 = 0; index1 < (int)_channels; ++index1)
            {
                _imageData[index1] = new byte[_height * columns];
                switch (_imageCompression)
                {
                case ImageCompression.Raw:
                    reader.Read(_imageData[index1], 0, _imageData[index1].Length);
                    break;

                case ImageCompression.Rle:
                    for (int index2 = 0; index2 < _height; ++index2)
                    {
                        int startIdx = index2 * _width;
                        RleHelper.DecodedRow(reader.BaseStream, _imageData[index1], startIdx, columns);
                    }

                    break;
                }
            }
        }
Exemple #6
0
            internal void LoadPixelData(BinaryReverseReader reader)
            {
                Debug.WriteLine("Mask.LoadPixelData started at " + reader.BaseStream.Position.ToString());

                if (m_rect.IsEmpty || m_layer.SortedChannels.ContainsKey(-2) == false)
                {
                    return;
                }

                Channel maskChannel = m_layer.SortedChannels[-2];


                maskChannel.Data = reader.ReadBytes((int)maskChannel.Length);


                using (BinaryReverseReader readerImg = maskChannel.DataReader)
                {
                    maskChannel.ImageCompression = (ImageCompression)readerImg.ReadInt16();

                    int bytesPerRow = 0;

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

                    case 8:
                        bytesPerRow = m_rect.Width;
                        break;

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

                    maskChannel.ImageData = new byte[m_rect.Height * bytesPerRow];
                    // Fill Array
                    for (int i = 0; i < maskChannel.ImageData.Length; i++)
                    {
                        maskChannel.ImageData[i] = 0xAB;
                    }

                    m_imageData = (byte[])maskChannel.ImageData.Clone();

                    switch (maskChannel.ImageCompression)
                    {
                    case ImageCompression.Raw:
                        readerImg.Read(maskChannel.ImageData, 0, maskChannel.ImageData.Length);
                        break;

                    case ImageCompression.Rle:
                    {
                        uint[] rowLengthList = new uint[m_rect.Height];

                        for (int i = 0; i < rowLengthList.Length; i++)
                        {
                            rowLengthList[i] = readerImg.ReadUInt16();
                        }

                        for (int i = 0; i < m_rect.Height; i++)
                        {
                            int rowIndex = i * m_rect.Width;
                            RleHelper.DecodedRow(readerImg.BaseStream, maskChannel.ImageData, rowIndex, bytesPerRow);
                        }
                    }
                    break;

                    default:
                        break;
                    }

                    m_imageData = (byte[])maskChannel.ImageData.Clone();
                }
            }
Exemple #7
0
        /// <summary>
        /// Reads the pixel data from a reader.
        /// </summary>
        /// <param name="reader">The reader to use to read the pixel data.</param>
        internal void LoadPixelData(BinaryReverseReader reader)
        {
            if (rect.width <= 0 || !Layer.SortedChannels.ContainsKey(-2))
            {
                return;
            }

            Channel channel = Layer.SortedChannels[-2];

            channel.Data = reader.ReadBytes(channel.Length);
            using (BinaryReverseReader dataReader = channel.DataReader)
            {
                channel.ImageCompression = (ImageCompression)dataReader.ReadInt16();
                int columns = 0;
                switch (Layer.PsdFile.Depth)
                {
                case 1:
                    columns = (int)rect.width;
                    break;

                case 8:
                    columns = (int)rect.width;
                    break;

                case 16:
                    columns = (int)rect.width * 2;
                    break;
                }

                channel.ImageData = new byte[(int)rect.height * columns];
                for (int index = 0; index < channel.ImageData.Length; ++index)
                {
                    channel.ImageData[index] = 171;
                }

                ImageData = (byte[])channel.ImageData.Clone();
                switch (channel.ImageCompression)
                {
                case ImageCompression.Raw:
                    dataReader.Read(channel.ImageData, 0, channel.ImageData.Length);
                    break;

                case ImageCompression.Rle:
                    int[] nums = new int[(int)rect.height];
                    for (int i = 0; i < (int)rect.height; i++)
                    {
                        nums[i] = dataReader.ReadInt16();
                    }

                    for (int index = 0; index < (int)rect.height; ++index)
                    {
                        int startIdx = index * (int)rect.width;
                        RleHelper.DecodedRow(dataReader.BaseStream, channel.ImageData, startIdx, columns);
                    }

                    break;
                }

                ImageData = (byte[])channel.ImageData.Clone();
            }
        }