protected override void WriteData(PsdBinaryWriter writer) { writer.Write(Version); writer.Write(HasRealMergedData); writer.WriteUnicodeString(ReaderName); writer.WriteUnicodeString(WriterName); writer.Write(FileVersion); }
private void SaveColorModeData(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, ColorModeData"); writer.Write((UInt32)ColorModeData.Length); writer.Write(ColorModeData); Util.DebugMessage(writer.BaseStream, "Save, End, ColorModeData"); }
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); } } }
/////////////////////////////////////////////////////////////////////////// public void Save(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, MaskInfo"); 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); } } Util.DebugMessage(writer.BaseStream, "Save, End, MaskInfo"); }
public void Write(PsdBinaryWriter writer, bool isLargeDocument) { for (int i = 0; i < Values.Length; i++) { if (isLargeDocument) { writer.Write(Values[i]); } else { writer.Write((UInt16)Values[i]); } } }
/////////////////////////////////////////////////////////////////////////// public void Save(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, BlendingRanges"); if (Data == null) { writer.Write((UInt32)0); return; } writer.Write((UInt32)Data.Length); writer.Write(Data); Util.DebugMessage(writer.BaseStream, "Save, End, BlendingRanges"); }
/////////////////////////////////////////////////////////////////////////// private void SaveGlobalLayerMask(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, GlobalLayerMask"); if (AdditionalInfo.Exists(x => x.Key == "LMsk")) { writer.Write((UInt32)0); Util.DebugMessage(writer.BaseStream, "Save, End, GlobalLayerMask"); return; } writer.Write((UInt32)_globalLayerMaskData.Length); writer.Write(_globalLayerMaskData); Util.DebugMessage(writer.BaseStream, "Save, End, GlobalLayerMask"); }
internal void Save(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, Channel"); writer.Write(ID); if (Layer.PsdFile.IsLargeDocument) { writer.Write(Length); } else { writer.Write((Int32)Length); } Util.DebugMessage(writer.BaseStream, "Save, End, Channel, {0}", ID); }
public void Write() { var endPosition = _writer.BaseStream.Position; _writer.BaseStream.Position = _lengthPosition; long length = endPosition - _startPosition; if (_hasLongLength) { _writer.Write(length); } else { _writer.Write((UInt32)length); } _writer.BaseStream.Position = endPosition; }
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); }
internal void SavePixelData(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, Channel image"); writer.Write((Int16)ImageCompression); if (ImageDataRaw == null) { return; } if (ImageCompression == ImageCompression.Rle) { RleRowLengths.Write(writer, Layer.PsdFile.IsLargeDocument); } writer.Write(ImageDataRaw); Util.DebugMessage(writer.BaseStream, "Save, End, Channel image, {0}", ID, Layer.Name); }
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; }
/////////////////////////////////////////////////////////////////////////// private void SaveImage(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, Composite image"); writer.Write((short)this.ImageCompression); if (this.ImageCompression == Memoria.PSD.ImageCompression.Rle) { foreach (var channel in this.BaseLayer.Channels) { Util.DebugMessage(writer.BaseStream, "Save, Begin, RLE header"); channel.RleRowLengths.Write(writer, IsLargeDocument); Util.DebugMessage(writer.BaseStream, "Save, End, RLE header"); } } foreach (var channel in this.BaseLayer.Channels) { Util.DebugMessage(writer.BaseStream, "Save, Begin, Channel image data"); writer.Write(channel.ImageDataRaw); Util.DebugMessage(writer.BaseStream, "Save, End, Channel image data"); } Util.DebugMessage(writer.BaseStream, "Save, End, Composite image"); }
/// <summary> /// Saves the layer data, excluding headers and padding. /// </summary> /// <param name="writer">The PSD writer.</param> internal void SaveLayersData(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, Layers"); var numLayers = (Int16)Layers.Count; if (AbsoluteAlpha) { numLayers = (Int16)(-numLayers); } // Photoshop will not load files that have a layer count of 0 in the // compatible Layers section. Instead, the Layers section must be // entirely empty. if (numLayers == 0) { return; } writer.Write(numLayers); foreach (var layer in Layers) { layer.Save(writer); } foreach (var layer in Layers) { Util.DebugMessage(writer.BaseStream, $"Save, Begin, Layer image, {layer.Name}"); foreach (var channel in layer.Channels) { channel.SavePixelData(writer); } Util.DebugMessage(writer.BaseStream, $"Save, End, Layer image, {layer.Name}"); } // The caller is responsible for padding. Photoshop writes padded // lengths for compatible layers, but unpadded lengths for Additional // Info layers. Util.DebugMessage(writer.BaseStream, "Save, End, Layers"); }
/////////////////////////////////////////////////////////////////////////// private void SaveHeader(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, File header"); string signature = "8BPS"; writer.WriteAsciiChars(signature); writer.Write((Int16)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); Util.DebugMessage(writer.BaseStream, "Save, End, File header"); }
/// <summary> /// Write out the image resource block: header and data. /// </summary> public void Save(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, ImageResource"); writer.WriteAsciiChars(Signature); writer.Write((UInt16)ID); writer.WritePascalString(Name, 2); // Length is unpadded, but data is even-padded var startPosition = writer.BaseStream.Position; using (new PsdBlockLengthWriter(writer)) { WriteData(writer); } writer.WritePadding(startPosition, 2); Util.DebugMessage(writer.BaseStream, "Save, End, ImageResource, {0}", ID); }
public void Save(PsdBinaryWriter writer) { Util.DebugMessage(writer.BaseStream, "Save, Begin, Layer"); writer.Write(Rect); //----------------------------------------------------------------------- writer.Write((Int16)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, globalLayerInfo: false, isLargeDocument: PsdFile.IsLargeDocument); } } Util.DebugMessage(writer.BaseStream, "Save, End, Layer, {0}", Name); }
protected override void WriteData(PsdBinaryWriter writer) { writer.Write(Data); }