예제 #1
0
파일: PsdFile.cs 프로젝트: timgaunt/resizer
        ///////////////////////////////////////////////////////////////////////////

        private void SaveLayers(BinaryReverseWriter writer)
        {
            Debug.WriteLine("SaveLayers started at " + writer.BaseStream.Position.ToString());

            using (new LengthWriter(writer))
            {
                short numberOfLayers = (short)m_layers.Count;
                if (AbsoluteAlpha)
                {
                    numberOfLayers = (short)-numberOfLayers;
                }

                writer.Write(numberOfLayers);

                // Finish compute-bound operations before embarking on the sequential save
                PrivateThreadPool threadPool = new PrivateThreadPool();
                foreach (Layer layer in m_layers)
                {
                    layer.PrepareSave(threadPool);
                }
                threadPool.Drain();

                foreach (Layer layer in m_layers)
                {
                    layer.Save(writer);
                }

                foreach (Layer layer in m_layers)
                {
                    foreach (Layer.Channel channel in layer.Channels)
                    {
                        channel.SavePixelData(writer);
                    }
                }

                if (writer.BaseStream.Position % 2 == 1)
                {
                    writer.Write((byte)0);
                }
            }
        }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////////
        private void SaveLayers(BinaryReverseWriter writer)
        {
            Debug.WriteLine("SaveLayers started at " + writer.BaseStream.Position.ToString());

              using (new LengthWriter(writer))
              {
            short numberOfLayers = (short)m_layers.Count;
            if (AbsoluteAlpha)
              numberOfLayers = (short)-numberOfLayers;

            writer.Write(numberOfLayers);

            // Finish compute-bound operations before embarking on the sequential save
            PrivateThreadPool threadPool = new PrivateThreadPool();
            foreach (Layer layer in m_layers)
            {
              layer.PrepareSave(threadPool);
            }
            threadPool.Drain();

            foreach (Layer layer in m_layers)
            {
              layer.Save(writer);
            }

            foreach (Layer layer in m_layers)
            {
              foreach (Layer.Channel channel in layer.Channels)
              {
            channel.SavePixelData(writer);
              }
            }

            if (writer.BaseStream.Position % 2 == 1)
              writer.Write((byte)0);
              }
        }
예제 #3
0
        ///////////////////////////////////////////////////////////////////////////
        private void LoadLayers(BinaryReverseReader reader)
        {
            Debug.WriteLine("LoadLayers started at " + reader.BaseStream.Position.ToString());

              uint layersInfoSectionLength = reader.ReadUInt32();

              if (layersInfoSectionLength <= 0)
            return;

              long startPosition = reader.BaseStream.Position;

              short numberOfLayers = reader.ReadInt16();

              // If <0, then number of layers is absolute value,
              // and the first alpha channel contains the transparency data for
              // the merged result.
              if (numberOfLayers < 0)
              {
            AbsoluteAlpha = true;
            numberOfLayers = Math.Abs(numberOfLayers);
              }

              m_layers.Clear();

              if (numberOfLayers == 0)
            return;

              for (int i = 0; i < numberOfLayers; i++)
              {
            m_layers.Add(new Layer(reader, this));
              }

              PrivateThreadPool threadPool = new PrivateThreadPool();

              foreach (Layer layer in m_layers)
              {
            foreach (Layer.Channel channel in layer.Channels)
            {
              if (channel.ID != -2)
              {
            channel.LoadPixelData(reader);
            DecompressChannelContext dcc = new DecompressChannelContext(channel);
            WaitCallback waitCallback = new WaitCallback(dcc.DecompressChannel);
            threadPool.QueueUserWorkItem(waitCallback);
              }
            }

            layer.MaskData.LoadPixelData(reader);
              }

              threadPool.Drain();

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

              if (reader.BaseStream.Position % 2 == 1)
            reader.ReadByte();

              //-----------------------------------------------------------------------
              // make sure we are not on a wrong offset, so set the stream position
              // manually
              reader.BaseStream.Position = startPosition + layersInfoSectionLength;
        }
예제 #4
0
파일: PsdFile.cs 프로젝트: timgaunt/resizer
        ///////////////////////////////////////////////////////////////////////////

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

            uint layersInfoSectionLength = reader.ReadUInt32();

            if (layersInfoSectionLength <= 0)
            {
                return;
            }

            long startPosition = reader.BaseStream.Position;

            short numberOfLayers = reader.ReadInt16();

            // If <0, then number of layers is absolute value,
            // and the first alpha channel contains the transparency data for
            // the merged result.
            if (numberOfLayers < 0)
            {
                AbsoluteAlpha  = true;
                numberOfLayers = Math.Abs(numberOfLayers);
            }

            m_layers.Clear();

            if (numberOfLayers == 0)
            {
                return;
            }

            for (int i = 0; i < numberOfLayers; i++)
            {
                m_layers.Add(new Layer(reader, this));
            }

            PrivateThreadPool threadPool = new PrivateThreadPool();

            foreach (Layer layer in m_layers)
            {
                foreach (Layer.Channel channel in layer.Channels)
                {
                    if (channel.ID != -2)
                    {
                        channel.LoadPixelData(reader);
                        DecompressChannelContext dcc          = new DecompressChannelContext(channel);
                        WaitCallback             waitCallback = new WaitCallback(dcc.DecompressChannel);
                        threadPool.QueueUserWorkItem(waitCallback);
                    }
                }

                layer.MaskData.LoadPixelData(reader);
            }

            threadPool.Drain();


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

            if (reader.BaseStream.Position % 2 == 1)
            {
                reader.ReadByte();
            }

            //-----------------------------------------------------------------------
            // make sure we are not on a wrong offset, so set the stream position
            // manually
            reader.BaseStream.Position = startPosition + layersInfoSectionLength;
        }