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

            writer.WriteUnicodeString(Name);
            writer.WritePadding(startPosition, 4);
        }
Beispiel #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);
        }
Beispiel #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);
   }
 }
 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);
   }
 }
Beispiel #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;
        }
Beispiel #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);
                }
            }
        }
Beispiel #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);
            }
        }
Beispiel #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}");
        }
Beispiel #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;
        }
Beispiel #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);
            }
        }
Beispiel #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);
        }
 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);
 }
Beispiel #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);
        }
Beispiel #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);
            }
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #20
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     writer.Write(Data);
 }
Beispiel #21
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     throw new System.NotImplementedException();
 }
Beispiel #22
0
 public PsdBlockLengthWriter(PsdBinaryWriter writer)
     : this(writer, false)
 {
 }
        ///////////////////////////////////////////////////////////////////////////

        private void SaveGlobalLayerMask(PsdBinaryWriter writer) {
            writer.Write((UInt32)GlobalLayerMaskData.Length);
            writer.Write(GlobalLayerMaskData);
        }
 private void SaveColorModeData(PsdBinaryWriter writer) {
     writer.Write((UInt32)ColorModeData.Length);
     writer.Write(ColorModeData);
 }
        ///////////////////////////////////////////////////////////////////////////

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

        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);
            }
        }
Beispiel #27
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     throw new NotImplementedException("LayerTextType not implemented!");
 }
        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);
        }
        ///////////////////////////////////////////////////////////////////////////

        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);
            }
        }
Beispiel #30
0
 internal void Save(PsdBinaryWriter writer)
 {
     writer.Write(ID);
     writer.Write(Length);
 }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #34
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     PsdFile.SaveLayersData(writer);
 }
Beispiel #35
0
 public override void WriteData(PsdBinaryWriter writer)
 {
     writer.WriteAsciiChars(Key);
     writer.WriteUnicodeString(Text);
 }
Beispiel #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);
            }
        }
Beispiel #37
0
 public abstract void WriteData(PsdBinaryWriter writer);
 /// <summary>
 /// Write the data for this image resource.
 /// </summary>
 protected abstract void WriteData(PsdBinaryWriter writer);
        ///////////////////////////////////////////////////////////////////////////

        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);
        }
Beispiel #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);
 }
Beispiel #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);
            }
        }
Beispiel #43
0
 private void SaveColorModeData(PsdBinaryWriter writer)
 {
     writer.Write((UInt32)ColorModeData.Length);
     writer.Write(ColorModeData);
 }
Beispiel #44
0
 public override void WriteData(PsdBinaryWriter writer)
 {
     writer.WriteAsciiChars(Key);
     writer.Write(Data.Length);
     writer.Write(Data);
 }
Beispiel #45
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveGlobalLayerMask(PsdBinaryWriter writer)
        {
            writer.Write((UInt32)GlobalLayerMaskData.Length);
            writer.Write(GlobalLayerMaskData);
        }
Beispiel #46
0
 protected abstract void WriteData(PsdBinaryWriter writer);
    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);
        }
      }
    }
Beispiel #48
0
        ///////////////////////////////////////////////////////////////////////////
        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);
                }
            }
        }
    ///////////////////////////////////////////////////////////////////////////

    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);
        }
      }
    }
Beispiel #50
0
 public override void WriteData(PsdBinaryWriter writer)
 {
     writer.WriteAsciiChars(Key);
     writer.Write(Value);
 }
        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);
            }
        }