Exemplo n.º 1
0
 public void Write(PsdBinaryWriter writer)
 {
   for (int i = 0; i < Values.Length; i++)
   {
     writer.Write((UInt16)Values[i]);
   }
 }
Exemplo n.º 2
0
        protected override void WriteData(PsdBinaryWriter writer)
        {
            var startPosition = writer.BaseStream.Position;

            writer.WriteUnicodeString(Name);
            writer.WritePadding(startPosition, 4);
        }
Exemplo n.º 3
0
        ///////////////////////////////////////////////////////////////////////////
        public void Save(PsdBinaryWriter writer)
        {
            Debug.WriteLine("BlendingRanges Save started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            writer.Write((UInt32)Data.Length);
            writer.Write(Data);
        }
Exemplo n.º 4
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     foreach (var channelName in ChannelNames)
     {
         writer.WriteUnicodeString(channelName);
     }
 }
 protected override void WriteData(PsdBinaryWriter writer)
 {
   foreach (var channelName in ChannelNames)
   {
     writer.WritePascalString(channelName, 1);
   }
 }
Exemplo n.º 6
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
   writer.Write(Version);
   writer.Write(HasRealMergedData);
   writer.WriteUnicodeString(ReaderName);
   writer.WriteUnicodeString(WriterName);
   writer.Write(FileVersion);
 }
 protected override void WriteData(PsdBinaryWriter writer)
 {
   writer.Write((Int32)SectionType);
   if (BlendModeKey != null)
   {
     writer.WriteAsciiChars("8BIM");
     writer.WriteAsciiChars(BlendModeKey);
     if (subtype != null)
       writer.Write((Int32)Subtype);
   }
 }
Exemplo n.º 8
0
        public PsdBlockLengthWriter(PsdBinaryWriter writer)
        {
            this.writer = writer;

            // Store position so that we can return to it when the length is known.
            lengthPosition = writer.BaseStream.Position;

            // Write a sentinel value as a placeholder for the length.
            writer.Write((UInt32)0xFEEDFEED);

            // Store the start position of the data block so that we can calculate
            // its length when we're done writing.
            startPosition = writer.BaseStream.Position;
        }
Exemplo n.º 9
0
        public void Save(PsdBinaryWriter writer)
        {
            Debug.WriteLine("Layer Save started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            writer.Write(Rect);

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

            writer.Write((short)Channels.Count);
            foreach (var ch in Channels)
            {
                ch.Save(writer);
            }

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

            writer.WriteAsciiChars("8BIM");
            writer.WriteAsciiChars(BlendModeKey);
            writer.Write(Opacity);
            writer.Write(Clipping);

            writer.Write((byte)flags.Data);

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

            writer.Write((byte)0);

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

            using (new PsdBlockLengthWriter(writer))
            {
                Masks.Save(writer);
                BlendingRangesData.Save(writer);

                var namePosition = writer.BaseStream.Position;

                // Legacy layer name is limited to 31 bytes.  Unicode layer name
                // can be much longer.
                writer.WritePascalString(Name, 4, 31);

                foreach (LayerInfo info in AdditionalInfo)
                {
                    info.Save(writer);
                }
            }
        }
Exemplo n.º 10
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveImage(PsdBinaryWriter writer)
        {
            Debug.WriteLine("SaveImage started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            writer.Write((short)this.ImageCompression);
            if (this.ImageCompression == PhotoshopFile.ImageCompression.Rle)
            {
                foreach (var channel in this.BaseLayer.Channels)
                {
                    writer.Write(channel.RleHeader);
                }
            }
            foreach (var channel in this.BaseLayer.Channels)
            {
                writer.Write(channel.Data);
            }
        }
Exemplo n.º 11
0
        internal void SavePixelData(PsdBinaryWriter writer)
        {
            Util.DebugMessage(writer.BaseStream, "Save, Begin, Channel image");

            writer.Write((short)ImageCompression);
            if (ImageDataRaw == null)
            {
                return;
            }

            if (ImageCompression == PhotoshopFile.ImageCompression.Rle)
            {
                RleRowLengths.Write(writer, Layer.PsdFile.IsLargeDocument);
            }
            writer.Write(ImageDataRaw);

            Util.DebugMessage(writer.BaseStream, $"Save, End, Channel image, {ID}");
        }
Exemplo n.º 12
0
        public PsdBlockLengthWriter(PsdBinaryWriter writer, bool hasLongLength)
        {
            this.writer        = writer;
            this.hasLongLength = hasLongLength;

            // Store position so that we can return to it when the length is known.
            lengthPosition = writer.BaseStream.Position;

            // Write a sentinel value as a placeholder for the length.
            writer.Write((UInt32)0xFEEDFEED);
            if (hasLongLength)
            {
                writer.Write((UInt32)0xFEEDFEED);
            }

            // Store the start position of the data block so that we can calculate
            // its length when we're done writing.
            startPosition = writer.BaseStream.Position;
        }
Exemplo n.º 13
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveLayerAndMaskInfo(PsdBinaryWriter writer)
        {
            Debug.WriteLine("SaveLayerAndMaskInfo started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            using (new PsdBlockLengthWriter(writer))
            {
                var startPosition = writer.BaseStream.Position;

                SaveLayers(writer);
                SaveGlobalLayerMask(writer);

                foreach (var info in AdditionalInfo)
                {
                    info.Save(writer);
                }

                writer.WritePadding(startPosition, 2);
            }
        }
Exemplo n.º 14
0
        public void Save(Stream stream, Encoding encoding)
        {
            if (BitDepth != 8)
            {
                throw new NotImplementedException("Only 8-bit color has been implemented for saving.");
            }

            var writer = new PsdBinaryWriter(stream, encoding);

            writer.AutoFlush = true;

            PrepareSave();

            SaveHeader(writer);
            SaveColorModeData(writer);
            SaveImageResources(writer);
            SaveLayerAndMaskInfo(writer);
            SaveImage(writer);
        }
Exemplo n.º 15
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     writer.Write(Version);
     writer.Write(xx);
     writer.Write(xy);
     writer.Write(yx);
     writer.Write(yy);
     writer.Write(tx);
     writer.Write(ty);
     writer.Write(TextVersion);
     writer.Write(TextDescriptorVestion);
     TextData.WriteData(writer);
     writer.Write(WarpVersion);
     writer.Write(WarpDescriptorVestion);
     WarpData.WriteData(writer);
     writer.Write(left);
     writer.Write(top);
     writer.Write(right);
     writer.Write(bottom);
 }
Exemplo n.º 16
0
        public void Save(PsdBinaryWriter writer)
        {
            Debug.WriteLine("LayerInfo.Save started at " + writer.BaseStream.Position);

            writer.WriteAsciiChars("8BIM");
            writer.WriteAsciiChars(Key);

            var startPosition = writer.BaseStream.Position;
            using (var lengthWriter = new PsdBlockLengthWriter(writer))
            {
                // Depending on the key, the length may be unpadded, 2-padded, or
                // 4-padded.  Thus, it is up to each implementation of WriteData to
                // pad the length correctly.
                WriteData(writer);
            }

            // Regardless of how the length is padded, the data is always padded to
            // a multiple of 4.
            writer.WritePadding(startPosition, 4);
        }
Exemplo n.º 17
0
        private void SaveLayers(PsdBinaryWriter writer)
        {
            Debug.WriteLine("SaveLayers started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            using (new PsdBlockLengthWriter(writer))
            {
                var numLayers = (Int16)Layers.Count;
                if (AbsoluteAlpha)
                {
                    numLayers = (Int16)(-numLayers);
                }

                // Layers section must be empty if the color mode doesn't allow layers.
                // Photoshop will refuse to load indexed and multichannel images if
                // there is a nonempty layers section with a layer count of 0.
                if (numLayers == 0)
                {
                    return;
                }

                var startPosition = writer.BaseStream.Position;
                writer.Write(numLayers);

                foreach (var layer in Layers)
                {
                    layer.Save(writer);
                }

                foreach (var layer in Layers)
                {
                    foreach (var channel in layer.Channels)
                    {
                        channel.SavePixelData(writer);
                    }
                }

                // Documentation states that the Layers Info section is even-padded,
                // but it is actually padded to a multiple of 4.
                writer.WritePadding(startPosition, 4);
            }
        }
Exemplo n.º 18
0
        public void Save(PsdBinaryWriter writer)
        {
            Debug.WriteLine("LayerInfo.Save started at " + writer.BaseStream.Position);

            writer.WriteAsciiChars("8BIM");
            writer.WriteAsciiChars(Key);

            var startPosition = writer.BaseStream.Position;

            using (var lengthWriter = new PsdBlockLengthWriter(writer))
            {
                // Depending on the key, the length may be unpadded, 2-padded, or
                // 4-padded.  Thus, it is up to each implementation of WriteData to
                // pad the length correctly.
                WriteData(writer);
            }

            // Regardless of how the length is padded, the data is always padded to
            // a multiple of 4.
            writer.WritePadding(startPosition, 4);
        }
Exemplo n.º 19
0
        ///////////////////////////////////////////////////////////////////////////
        private void SaveHeader(PsdBinaryWriter writer)
        {
            Debug.WriteLine("SaveHeader started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            string signature = "8BPS";
            writer.WriteAsciiChars(signature);
            writer.Write(Version);
            writer.Write(new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, });
            writer.Write(ChannelCount);
            writer.Write(RowCount);
            writer.Write(ColumnCount);
            writer.Write((Int16)BitDepth);
            writer.Write((Int16)ColorMode);
        }
Exemplo n.º 20
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     writer.Write(Data);
 }
Exemplo n.º 21
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 22
0
 public PsdBlockLengthWriter(PsdBinaryWriter writer)
     : this(writer, false)
 {
 }
Exemplo n.º 23
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveGlobalLayerMask(PsdBinaryWriter writer) {
            writer.Write((UInt32)GlobalLayerMaskData.Length);
            writer.Write(GlobalLayerMaskData);
        }
Exemplo n.º 24
0
 private void SaveColorModeData(PsdBinaryWriter writer) {
     writer.Write((UInt32)ColorModeData.Length);
     writer.Write(ColorModeData);
 }
Exemplo n.º 25
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveImageResources(PsdBinaryWriter writer) {
            using (new PsdBlockLengthWriter(writer)) {
                foreach (var imgRes in ImageResources)
                    imgRes.Save(writer);
            }
        }
Exemplo n.º 26
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveLayerAndMaskInfo(PsdBinaryWriter writer) {
            using (new PsdBlockLengthWriter(writer)) {
                var startPosition = writer.BaseStream.Position;

                SaveLayers(writer);
                SaveGlobalLayerMask(writer);

                foreach (var info in AdditionalInfo)
                    info.Save(writer);

                writer.WritePadding(startPosition, 2);
            }
        }
Exemplo n.º 27
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     throw new NotImplementedException("LayerTextType not implemented!");
 }
Exemplo n.º 28
0
        public void Save(Stream stream, Encoding encoding) {
            if (BitDepth != 8)
                throw new NotImplementedException("Only 8-bit color has been implemented for saving.");

            var writer = new PsdBinaryWriter(stream, encoding);
            writer.AutoFlush = true;

            PrepareSave();

            SaveHeader(writer);
            SaveColorModeData(writer);
            SaveImageResources(writer);
            SaveLayerAndMaskInfo(writer);
            SaveImage(writer);
        }
Exemplo n.º 29
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveImage(PsdBinaryWriter writer) {
            writer.Write((short)this.ImageCompression);
            if (this.ImageCompression == PhotoshopFile.ImageCompression.Rle) {
                foreach (var channel in this.BaseLayer.Channels)
                    channel.RleRowLengths.Write(writer);
            }
            foreach (var channel in this.BaseLayer.Channels) {
                writer.Write(channel.ImageDataRaw);
            }
        }
Exemplo n.º 30
0
 internal void Save(PsdBinaryWriter writer)
 {
     writer.Write(ID);
     writer.Write(Length);
 }
Exemplo n.º 31
0
        protected override void WriteData(PsdBinaryWriter writer)
        {
            writer.Write(HDpi.Integer);
            writer.Write(HDpi.Fraction);
            writer.Write((Int16)HResDisplayUnit);
            writer.Write((Int16)WidthDisplayUnit);

            writer.Write(VDpi.Integer);
            writer.Write(VDpi.Fraction);
            writer.Write((Int16)VResDisplayUnit);
            writer.Write((Int16)HeightDisplayUnit);
        }
Exemplo n.º 32
0
        ///////////////////////////////////////////////////////////////////////////
        private void SaveGlobalLayerMask(PsdBinaryWriter writer)
        {
            Debug.WriteLine("SaveGlobalLayerMask started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            writer.Write((UInt32)GlobalLayerMaskData.Length);
            writer.Write(GlobalLayerMaskData);
        }
Exemplo n.º 33
0
        private void SaveColorModeData(PsdBinaryWriter writer)
        {
            Debug.WriteLine("SaveColorModeData started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            writer.Write((UInt32)ColorModeData.Length);
            writer.Write(ColorModeData);
        }
Exemplo n.º 34
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     PsdFile.SaveLayersData(writer);
 }
Exemplo n.º 35
0
 public override void WriteData(PsdBinaryWriter writer)
 {
     writer.WriteAsciiChars(Key);
     writer.WriteUnicodeString(Text);
 }
Exemplo n.º 36
0
        ///////////////////////////////////////////////////////////////////////////
        private void SaveLayerAndMaskInfo(PsdBinaryWriter writer)
        {
            Debug.WriteLine("SaveLayerAndMaskInfo started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            using (new PsdBlockLengthWriter(writer))
            {
                var startPosition = writer.BaseStream.Position;

                SaveLayers(writer);
                SaveGlobalLayerMask(writer);

                foreach (var info in AdditionalInfo)
                    info.Save(writer);

                writer.WritePadding(startPosition, 2);
            }
        }
Exemplo n.º 37
0
 public abstract void WriteData(PsdBinaryWriter writer);
Exemplo n.º 38
0
 /// <summary>
 /// Write the data for this image resource.
 /// </summary>
 protected abstract void WriteData(PsdBinaryWriter writer);
Exemplo n.º 39
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveHeader(PsdBinaryWriter writer) {
            string signature = "8BPS";
            writer.WriteAsciiChars(signature);
            writer.Write(Version);
            writer.Write(new byte[] { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, });
            writer.Write(ChannelCount);
            writer.Write(RowCount);
            writer.Write(ColumnCount);
            writer.Write((Int16)BitDepth);
            writer.Write((Int16)ColorMode);
        }
Exemplo n.º 40
0
        ///////////////////////////////////////////////////////////////////////////
        private void SaveImageResources(PsdBinaryWriter writer)
        {
            Debug.WriteLine("SaveImageResources started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            using (new PsdBlockLengthWriter(writer))
            {
                foreach (var imgRes in ImageResources)
                    imgRes.Save(writer);
            }
        }
 protected override void WriteData(PsdBinaryWriter writer)
 {
   writer.Write(Data);
 }
Exemplo n.º 42
0
        ///////////////////////////////////////////////////////////////////////////
        private void SaveImage(PsdBinaryWriter writer)
        {
            Debug.WriteLine("SaveImage started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            writer.Write((short)this.ImageCompression);
            if (this.ImageCompression == PhotoshopFile.ImageCompression.Rle)
            {
                foreach (var channel in this.BaseLayer.Channels)
                    writer.Write(channel.RleHeader);
            }
            foreach (var channel in this.BaseLayer.Channels)
            {
                writer.Write(channel.Data);
            }
        }
Exemplo n.º 43
0
 private void SaveColorModeData(PsdBinaryWriter writer)
 {
     writer.Write((UInt32)ColorModeData.Length);
     writer.Write(ColorModeData);
 }
Exemplo n.º 44
0
 public override void WriteData(PsdBinaryWriter writer)
 {
     writer.WriteAsciiChars(Key);
     writer.Write(Data.Length);
     writer.Write(Data);
 }
Exemplo n.º 45
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveGlobalLayerMask(PsdBinaryWriter writer)
        {
            writer.Write((UInt32)GlobalLayerMaskData.Length);
            writer.Write(GlobalLayerMaskData);
        }
Exemplo n.º 46
0
 protected abstract void WriteData(PsdBinaryWriter writer);
Exemplo n.º 47
0
    public void Save(PsdBinaryWriter writer)
    {
      writer.Write(Rect);

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

      writer.Write((short)Channels.Count);
      foreach (var ch in Channels)
        ch.Save(writer);

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

      writer.WriteAsciiChars("8BIM");
      writer.WriteAsciiChars(BlendModeKey);
      writer.Write(Opacity);
      writer.Write(Clipping);

      writer.Write((byte)flags.Data);

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

      writer.Write((byte)0);

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

      using (new PsdBlockLengthWriter(writer))
      {
        Masks.Save(writer);
        BlendingRangesData.Save(writer);

        var namePosition = writer.BaseStream.Position;

        // Legacy layer name is limited to 31 bytes.  Unicode layer name
        // can be much longer.
        writer.WritePascalString(Name, 4, 31);

        foreach (LayerInfo info in AdditionalInfo)
        {
          info.Save(writer);
        }
      }
    }
Exemplo n.º 48
0
Arquivo: Mask.cs Projeto: hgrandry/Mgx
        ///////////////////////////////////////////////////////////////////////////
        public void Save(PsdBinaryWriter writer)
        {
            Debug.WriteLine("MaskInfo Save started at " + writer.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

            if (LayerMask == null)
            {
                writer.Write((UInt32)0);
                return;
            }

            using (new PsdBlockLengthWriter(writer))
            {
                writer.Write(LayerMask.Rect);
                writer.Write(LayerMask.BackgroundColor);
                writer.Write((byte)LayerMask.Flags.Data);

                if (UserMask == null)
                {
                    // Pad by 2 bytes to make the block length 20
                    writer.Write((UInt16)0);
                }
                else
                {
                    writer.Write((byte)UserMask.Flags.Data);
                    writer.Write(UserMask.BackgroundColor);
                    writer.Write(UserMask.Rect);
                }
            }
        }
Exemplo n.º 49
0
    ///////////////////////////////////////////////////////////////////////////

    public void Save(PsdBinaryWriter writer)
    {
      if (LayerMask == null)
      {
        writer.Write((UInt32)0);
        return;
      }

      using (new PsdBlockLengthWriter(writer))
      {
        writer.Write(LayerMask.Rect);
        writer.Write(LayerMask.BackgroundColor);
        writer.Write((byte)LayerMask.Flags.Data);

        if (UserMask == null)
        {
          // Pad by 2 bytes to make the block length 20
          writer.Write((UInt16)0);
        }
        else
        {
          writer.Write((byte)UserMask.Flags.Data);
          writer.Write(UserMask.BackgroundColor);
          writer.Write(UserMask.Rect);
        }
      }
    }
Exemplo n.º 50
0
 public override void WriteData(PsdBinaryWriter writer)
 {
     writer.WriteAsciiChars(Key);
     writer.Write(Value);
 }
Exemplo n.º 51
0
        private void SaveLayers(PsdBinaryWriter writer) {
            using (new PsdBlockLengthWriter(writer)) {
                var numLayers = (Int16)Layers.Count;
                if (AbsoluteAlpha)
                    numLayers = (Int16)(-numLayers);

                // Layers section must be empty if the color mode doesn't allow layers.
                // Photoshop will refuse to load indexed and multichannel images if
                // there is a nonempty layers section with a layer count of 0.
                if (numLayers == 0)
                    return;

                var startPosition = writer.BaseStream.Position;
                writer.Write(numLayers);

                foreach (var layer in Layers) {
                    layer.Save(writer);
                }

                foreach (var layer in Layers) {
                    foreach (var channel in layer.Channels) {
                        channel.SavePixelData(writer);
                    }
                }

                // Documentation states that the Layers Info section is even-padded,
                // but it is actually padded to a multiple of 4.
                writer.WritePadding(startPosition, 4);
            }
        }