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

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

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

        private void SaveImageResources(PsdBinaryWriter writer) {
            using (new PsdBlockLengthWriter(writer)) {
                foreach (var imgRes in ImageResources)
                    imgRes.Save(writer);
            }
        }
Esempio 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);
            }
        }
Esempio n. 27
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     throw new NotImplementedException("LayerTextType not implemented!");
 }
Esempio 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);
        }
Esempio 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);
            }
        }
Esempio n. 30
0
 internal void Save(PsdBinaryWriter writer)
 {
     writer.Write(ID);
     writer.Write(Length);
 }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio n. 34
0
 protected override void WriteData(PsdBinaryWriter writer)
 {
     PsdFile.SaveLayersData(writer);
 }
Esempio n. 35
0
 public override void WriteData(PsdBinaryWriter writer)
 {
     writer.WriteAsciiChars(Key);
     writer.WriteUnicodeString(Text);
 }
Esempio 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);
            }
        }
Esempio n. 37
0
 public abstract void WriteData(PsdBinaryWriter writer);
Esempio n. 38
0
 /// <summary>
 /// Write the data for this image resource.
 /// </summary>
 protected abstract void WriteData(PsdBinaryWriter writer);
Esempio 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);
        }
Esempio 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);
 }
Esempio 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);
            }
        }
Esempio n. 43
0
 private void SaveColorModeData(PsdBinaryWriter writer)
 {
     writer.Write((UInt32)ColorModeData.Length);
     writer.Write(ColorModeData);
 }
Esempio n. 44
0
 public override void WriteData(PsdBinaryWriter writer)
 {
     writer.WriteAsciiChars(Key);
     writer.Write(Data.Length);
     writer.Write(Data);
 }
Esempio n. 45
0
        ///////////////////////////////////////////////////////////////////////////

        private void SaveGlobalLayerMask(PsdBinaryWriter writer)
        {
            writer.Write((UInt32)GlobalLayerMaskData.Length);
            writer.Write(GlobalLayerMaskData);
        }
Esempio n. 46
0
 protected abstract void WriteData(PsdBinaryWriter writer);
Esempio 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);
        }
      }
    }
Esempio n. 48
0
File: Mask.cs Progetto: 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);
                }
            }
        }
Esempio 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);
        }
      }
    }
Esempio n. 50
0
 public override void WriteData(PsdBinaryWriter writer)
 {
     writer.WriteAsciiChars(Key);
     writer.Write(Value);
 }
Esempio 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);
            }
        }