public Mask(BinaryReverseReader reader, Layer layer) { this._layer = layer; int nLength = (int)reader.ReadUInt32(); if (nLength == 0) return; long nStart = reader.BaseStream.Position; this.Rectangle = new ERectangle(); this.Rectangle.Y = reader.ReadInt32(); this.Rectangle.X = reader.ReadInt32(); this.Rectangle.Height = reader.ReadInt32() - Rectangle.Y; this.Rectangle.Width = reader.ReadInt32() - Rectangle.X; byte color = reader.ReadByte(); byte flags = reader.ReadByte(); if (nLength == 36) { int someOtherFlags = reader.ReadByte(); byte maskBg = reader.ReadByte(); ERectangle rect = new ERectangle(); rect.Y = reader.ReadInt32(); rect.X = reader.ReadInt32(); rect.Height = reader.ReadInt32() - rect.Y; rect.Width = reader.ReadInt32() - rect.X; } reader.BaseStream.Position = nStart + nLength; }
public ImageResource(BinaryReverseReader reader) { this.ID = reader.ReadUInt16(); this.Name = reader.ReadPascalString(); uint settingLength = reader.ReadUInt32(); this.Data = reader.ReadBytes((int)settingLength); if (reader.BaseStream.Position % 2 == 1) reader.ReadByte(); }
public ImageResource(BinaryReverseReader reader) { this.ID = reader.ReadUInt16(); this.Name = reader.ReadPascalString(); uint settingLength = reader.ReadUInt32(); this.Data = reader.ReadBytes((int)settingLength); if (reader.BaseStream.Position % 2 == 1) { reader.ReadByte(); } }
public Thumbnail(ImageResource imgRes) { BinaryReverseReader reader = imgRes.GetDataReader(); //m_bThumbnailFilled = true; this.nFormat = reader.ReadInt32(); this.nWidth = reader.ReadInt32(); this.nHeight = reader.ReadInt32(); this.nWidthBytes = reader.ReadInt32(); this.nSize = reader.ReadInt32(); this.nCompressedSize = reader.ReadInt32(); this.nBitPerPixel = reader.ReadInt16(); this.nPlanes = reader.ReadInt16(); int nTotalData = this.nSize - 28; // header byte [] buffer = new byte[nTotalData]; if (this.ID == 1033) { // BGR for (int n = 0; n < nTotalData; n = n + 3) { buffer[n + 2] = reader.ReadByte(); buffer[n + 1] = reader.ReadByte(); buffer[n + 0] = reader.ReadByte(); } } else if (this.ID == 1036) { // RGB for (int n = 0; n < nTotalData; ++n) { buffer[n] = reader.ReadByte(); } } reader.Close(); }
public Mask(BinaryReverseReader reader, Layer layer) { this._layer = layer; int nLength = (int)reader.ReadUInt32(); if (nLength == 0) { return; } long nStart = reader.BaseStream.Position; this.Rectangle = new ERectangle(); this.Rectangle.Y = reader.ReadInt32(); this.Rectangle.X = reader.ReadInt32(); this.Rectangle.Height = reader.ReadInt32() - Rectangle.Y; this.Rectangle.Width = reader.ReadInt32() - Rectangle.X; byte color = reader.ReadByte(); byte flags = reader.ReadByte(); if (nLength == 36) { int someOtherFlags = reader.ReadByte(); byte maskBg = reader.ReadByte(); ERectangle rect = new ERectangle(); rect.Y = reader.ReadInt32(); rect.X = reader.ReadInt32(); rect.Height = reader.ReadInt32() - rect.Y; rect.Width = reader.ReadInt32() - rect.X; } reader.BaseStream.Position = nStart + nLength; }
private byte readByte(BinaryReverseReader stream) { if (useCachedByte) { Debug.Assert(cachedByte != -1); useCachedByte = false; return((byte)cachedByte); } else { cachedByte = stream.ReadByte(); return((byte)cachedByte); } }
public Glow(PhotoshopFile.Layer.AdjustmentLayerInfo info) { this.m_data = info.Data; this.m_key = info.Key; this.m_layer = info.Layer; BinaryReverseReader r = this.DataReader; //string blendModeSignature = null; uint version = r.ReadUInt32(); //two version specifications?!? switch (version) { case 0: this.Blur = r.ReadUInt32(); this.Data = null; break; case 2: this.Blur = (uint)r.ReadUInt16(); this.Intensity = r.ReadUInt32(); ushort something = r.ReadUInt16(); this.Color = r.ReadPSDColor(16, false); //Inner color (no alpha) this.BlendModeKey = this.ReadBlendKey(r); this.Enabled = r.ReadBoolean(); this.Opacity = r.ReadByte(); //TODO! if (this.Inner) { this.Unknown = r.ReadByte(); } this.UnknownColor = r.ReadPSDColor(16, false); //unknown color(no alpha) this.Data = r.ReadBytes((int)r.BytesToEnd); break; } }
public bool kind; // selected = false, protected = true public DisplayInfo(ImageResource imgRes) { BinaryReverseReader reader = imgRes.GetDataReader(); this.ColorSpace = (ColorModes)reader.ReadInt16(); for (int i = 0; i < 4; i++) { this.Color[i] = reader.ReadInt16(); } this.Opacity = (short)Math.Max(0, Math.Min(100, (int)reader.ReadInt16())); this.kind = reader.ReadByte() == 0?false:true; reader.Close(); }
public AlphaChannels(ImageResource imgRes) : base(imgRes) { // 文档 四 - 2 ID 1006 BinaryReverseReader dataReader = imgRes.DataReader; while (dataReader.BaseStream.Length - dataReader.BaseStream.Position > 0L) { byte length = dataReader.ReadByte(); dataReader.ReadChars(length); } dataReader.Close(); }
/// <summary> /// Initializes a new instance of the <see cref="AlphaChannels" /> class. /// </summary> /// <param name="imgRes">The image resource.</param> public AlphaChannels(ImageResource imgRes) : base(imgRes) { BinaryReverseReader dataReader = imgRes.DataReader; while (dataReader.BaseStream.Length - dataReader.BaseStream.Position > 0L) { // read the length of the string byte length = dataReader.ReadByte(); // read the string dataReader.ReadChars(length); } dataReader.Close(); }
/// <summary> /// Reads bytes until a unescaped closing parenthesis in found. Unescapes escaped parenthesis. /// Leaves reader on the char following the closing parenthesis. /// </summary> /// <param name="r"></param> /// <returns></returns> public static byte[] parseBinary(BinaryReverseReader r) { MemoryStream ms = new MemoryStream(128); //For writing the decoded binary byte b = 0; byte lastb = 0; bool hasLastByte = false; //Read bytes, keeping a two-byte shifting buffer so we can decode escaped chars. while (r.CanReadByte()) { b = r.ReadByte(); //Look for closing parenthesis if ((char)b == ')') { if (hasLastByte && (char)lastb == '\\') { //Escaped parenthesis, skip slash lastb = 0; hasLastByte = false; } else { //Unescaped closing parenthesis! We hit the end! if (hasLastByte) { ms.WriteByte(lastb); //If we still have a byte in the buffer. } return(ms.ToArray()); //We hit the end, an unescaped closng parenthesis. } } //Far as I know, nothing else is escaped. //Write lastb if present. if (hasLastByte) { ms.WriteByte(lastb); } //Shift buffer lastb = b; hasLastByte = true; } throw new TdTaParseException("Hit end of stream without finding closing parenthesis!"); }
public Shadow(Effect effect) : base(effect) { BinaryReverseReader reader = base.GetDataReader(); this.Blur = reader.ReadUInt32(); this.Angle = reader.ReadUInt32(); this.Distance = reader.ReadUInt32(); this.Color = this.ReadColor(reader); this.BlendModeSignature = reader.ReadUInt32(); this.BlendModeKey = reader.ReadUInt32(); this.Enabled = reader.ReadBoolean(); this.UseGlobalAngle = reader.ReadBoolean(); this.Opacity = reader.ReadByte(); reader.Close(); }
public Glow(Effect effect) : base(effect) { BinaryReverseReader reader = base.GetDataReader(); uint version = reader.ReadUInt32(); //two version specifications?!? this.Blur = reader.ReadUInt32(); this.Intensity = reader.ReadUInt32(); this.Color = this.ReadColorWithAlpha(reader); this.BlendModeSignature = reader.ReadUInt32(); this.BlendModeKey = reader.ReadUInt32(); this.Enabled = reader.ReadBoolean(); this.UseGlobalAngle = reader.ReadBoolean(); this.Opacity = reader.ReadByte(); reader.Close(); }
public Layer(BinaryReverseReader reader, Document document) { this._document = document; this._rect = new ERectangle(); this._rect.Y = reader.ReadInt32(); this._rect.X = reader.ReadInt32(); this._rect.Height = reader.ReadInt32() - this._rect.Y; this._rect.Width = reader.ReadInt32() - this._rect.X; this.NumChannels = reader.ReadUInt16(); this._channels = new Dictionary <int, Channel>(); for (int channelNum = 0; channelNum < this.NumChannels; channelNum++) { Channel ch = new Channel(reader, this); this._channels.Add(ch.Usage, ch); } string sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") { throw(new Exception("Layer Channelheader error!")); } this.BlendKey = new string(reader.ReadChars(4)); int nBlend = -1; try { nBlend = (int)Enum.Parse(typeof(_blendKeysPsd), this.BlendKey); } catch { } if (nBlend >= 0) { BlendKeys key = (BlendKeys)nBlend; this.BlendKey = Enum.GetName(typeof(BlendKeys), key); } this.Opacity = reader.ReadByte(); //(byte)(255 - (int)reader.ReadByte()); //paLayerInfo[#Opacity] = 256 - m_oReader.readUC() --256-ScaleCharToQuantum(ReadBlobByte(image)) this.Clipping = reader.ReadByte(); this.Flags = reader.ReadByte(); reader.ReadByte(); //padding uint nSize = reader.ReadUInt32(); long nChannelEndPos = reader.BaseStream.Position + (long)nSize; if (nSize > 0) { uint nLength; //uint nCombinedlength = 0; this._mask = new Mask(reader, this); if (this._mask.Rectangle == null) { this._mask = null; } //reader.BaseStream.Position+=nLength-16; //nCombinedlength+= nLength + 4; //blending ranges nLength = reader.ReadUInt32(); for (uint i = 0; i < nLength / 8; i++) { uint color1 = reader.ReadUInt32(); uint color2 = reader.ReadUInt32(); } //nCombinedlength+= nLength + 4; //Name nLength = (uint)reader.ReadByte(); reader.BaseStream.Position -= 1; this.Name = reader.ReadPascalString(); //nCombinedlength+= nLength + 4; #region Adjustment etc layers //TODO: there's probably a 2-byte padding here sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") { reader.BaseStream.Position -= 2; sHeader = new string(reader.ReadChars(4)); } reader.BaseStream.Position -= 4; do { try { this.ReadPSDChannelTag(reader); } catch { //dunno what the last bytes are for, just skip them: reader.BaseStream.Position = nChannelEndPos; } }while(reader.BaseStream.Position < nChannelEndPos); #endregion } }
public Layer(BinaryReverseReader reader, Document document) { this._document = document; this._rect = new ERectangle(); this._rect.Y = reader.ReadInt32(); this._rect.X = reader.ReadInt32(); this._rect.Height = reader.ReadInt32() - this._rect.Y; this._rect.Width = reader.ReadInt32() - this._rect.X; this.NumChannels = reader.ReadUInt16(); this._channels = new Dictionary<int, Channel>(); for (int channelNum = 0; channelNum < this.NumChannels; channelNum++) { Channel ch = new Channel(reader, this); this._channels.Add(ch.Usage, ch); } string sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") throw(new Exception("Layer Channelheader error!")); this.BlendKey = new string(reader.ReadChars(4)); int nBlend = -1; try { nBlend = (int)Enum.Parse(typeof(_blendKeysPsd), this.BlendKey); } catch { } if (nBlend >= 0) { BlendKeys key = (BlendKeys)nBlend; this.BlendKey = Enum.GetName(typeof(BlendKeys), key); } this.Opacity = reader.ReadByte(); //(byte)(255 - (int)reader.ReadByte()); //paLayerInfo[#Opacity] = 256 - m_oReader.readUC() --256-ScaleCharToQuantum(ReadBlobByte(image)) this.Clipping = reader.ReadByte(); this.Flags = reader.ReadByte(); reader.ReadByte(); //padding uint nSize = reader.ReadUInt32(); long nChannelEndPos = reader.BaseStream.Position + (long)nSize; if (nSize > 0) { uint nLength; //uint nCombinedlength = 0; this._mask = new Mask(reader, this); if (this._mask.Rectangle == null) this._mask = null; //reader.BaseStream.Position+=nLength-16; //nCombinedlength+= nLength + 4; //blending ranges nLength = reader.ReadUInt32(); for (uint i = 0; i < nLength/8; i++) { uint color1 = reader.ReadUInt32(); uint color2 = reader.ReadUInt32(); } //nCombinedlength+= nLength + 4; //Name nLength = (uint)reader.ReadByte(); reader.BaseStream.Position-=1; this.Name = reader.ReadPascalString(); //nCombinedlength+= nLength + 4; #region Adjustment etc layers //TODO: there's probably a 2-byte padding here sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") { reader.BaseStream.Position-=2; sHeader = new string(reader.ReadChars(4)); } reader.BaseStream.Position-=4; do { try { this.ReadPSDChannelTag(reader); } catch { //dunno what the last bytes are for, just skip them: reader.BaseStream.Position = nChannelEndPos; } } while(reader.BaseStream.Position < nChannelEndPos); #endregion } }
private void ReadPSDChannelTag(BinaryReverseReader reader) { string sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") { reader.BaseStream.Position-=4; //back it up before throwing exception throw(new Exception("Effect header incorrect")); } string sKey = new string(reader.ReadChars(4)); uint nLength = reader.ReadUInt32(); long nPosStart = reader.BaseStream.Position; switch (sKey) { case "lyid": this.LayerID = (int)reader.ReadUInt32(); break; case "fxrp": this.ReferencePoint = new EPointF(); this.ReferencePoint.X = reader.ReadPSD8BitSingle(); this.ReferencePoint.Y = reader.ReadPSD8BitSingle(); break; case "clbl": //blend clipping this.BlendClipping = reader.ReadBoolean(); reader.BaseStream.Position+=3; //padding break; case "infx": //blend interior elements this.Blend = reader.ReadBoolean(); reader.BaseStream.Position+=3; //padding break; case "knko": //Knockout setting this.Knockout = reader.ReadBoolean(); reader.BaseStream.Position+=3; //padding break; case "lspf": //Protected settings //TODO: reader.ReadBytes(4); //nLength? //bits 0-2 = Transparency, composite and position break; case "lclr": //Sheet Color setting this.SheetColor = System.Drawing.Color.FromArgb( reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); reader.BaseStream.Position+=2; //padding break; case "lnsr": //Layer Name Source setting string sWhatIsThis = new string(reader.ReadChars((int)nLength)); //this.NameSourceSetting = reader.ReadUInt32(); break; case "luni": //Unicode Layer name uint nUnicodeLength = reader.ReadUInt32(); this.UnicodeName = new string(reader.ReadChars((int)nUnicodeLength*2)); break; case "lrFX": //Effects Layer info reader.BaseStream.Position+=2; //unused ushort nNumEffects = reader.ReadUInt16(); // aEffectsInfo = [] // paInfo[#EffectsInfo] = aEffectsInfo for (int nEffectNum = 0; nEffectNum < nNumEffects; nEffectNum++) { sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") throw(new Exception("Effect header incorrect")); EffectLayers.Effect effectForReading = new Endogine.Serialization.Photoshop.EffectLayers.Effect(reader); //reader.JumpToEvenNthByte(2); EffectLayers.Effect effect = null; //long nEffectEndPos = reader.BaseStream.Position + effect.Size; switch (effectForReading.Name) { case "cmnS": //common state BinaryReverseReader subreader = effectForReading.GetDataReader(); bool bVisible = subreader.ReadBoolean(); //reader.BaseStream.Position+=2; //unused break; case "dsdw": case "isdw": //drop/inner shadow if (effectForReading.Version == 0) effect = new Endogine.Serialization.Photoshop.EffectLayers.Shadow(effectForReading); else { //TODO: } break; case "oglw": case "iglw": //outer/inner glow if (effectForReading.Version == 0) effect = new Endogine.Serialization.Photoshop.EffectLayers.Glow(effectForReading); else { //TODO: } break; case "bevl": //bevel if (effectForReading.Version == 0) effect = new Endogine.Serialization.Photoshop.EffectLayers.Bevel(effectForReading); else { //TODO: } break; case "sofi": //unknown break; } this.Effects.Add(effect); //reader.BaseStream.Position = nEffectEndPos; } break; case "lsct": //TODO: what is this? reader.BaseStream.Position+=4; break; case "TySh": case "lfx2": //TODO: what are these? break; default: string sMsg = "Unknown layer setting: " + sKey + " Length:" + nLength.ToString() + " Pos: "+reader.BaseStream.Position.ToString(); //EH.Put(sMsg); break; } //add to nLength so it's padded to 4 int nLengthMod = (int)(nLength % (long)4); if (nLengthMod > 0) nLength+= 4-(uint)nLengthMod; reader.BaseStream.Position = nPosStart + nLength; reader.JumpToEvenNthByte(2); }
/// <summary> /// Reads bytes until a unescaped closing parenthesis in found. Unescapes escaped parenthesis. /// Leaves reader on the char following the closing parenthesis. /// </summary> /// <param name="r"></param> /// <returns></returns> public static byte[] parseBinary(BinaryReverseReader r) { MemoryStream ms = new MemoryStream(128); //For writing the decoded binary byte b = 0; byte lastb = 0; bool hasLastByte = false; //Read bytes, keeping a two-byte shifting buffer so we can decode escaped chars. while (r.CanReadByte()) { b = r.ReadByte(); //Look for closing parenthesis if ((char)b == ')') { if (hasLastByte && (char)lastb == '\\') { //Escaped parenthesis, skip slash lastb = 0; hasLastByte = false; } else { //Unescaped closing parenthesis! We hit the end! if (hasLastByte) ms.WriteByte(lastb); //If we still have a byte in the buffer. return ms.ToArray();//We hit the end, an unescaped closng parenthesis. } } //Far as I know, nothing else is escaped. //Write lastb if present. if (hasLastByte) ms.WriteByte(lastb); //Shift buffer lastb = b; hasLastByte = true; } throw new TdTaParseException("Hit end of stream without finding closing parenthesis!"); }
private void ReadPSDChannelTag(BinaryReverseReader reader) { string sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") { reader.BaseStream.Position -= 4; //back it up before throwing exception throw(new Exception("Effect header incorrect")); } string sKey = new string(reader.ReadChars(4)); uint nLength = reader.ReadUInt32(); long nPosStart = reader.BaseStream.Position; switch (sKey) { case "lyid": this.LayerID = (int)reader.ReadUInt32(); break; case "fxrp": this.ReferencePoint = new EPointF(); this.ReferencePoint.X = reader.ReadPSD8BitSingle(); this.ReferencePoint.Y = reader.ReadPSD8BitSingle(); break; case "clbl": //blend clipping this.BlendClipping = reader.ReadBoolean(); reader.BaseStream.Position += 3; //padding break; case "infx": //blend interior elements this.Blend = reader.ReadBoolean(); reader.BaseStream.Position += 3; //padding break; case "knko": //Knockout setting this.Knockout = reader.ReadBoolean(); reader.BaseStream.Position += 3; //padding break; case "lspf": //Protected settings //TODO: reader.ReadBytes(4); //nLength? //bits 0-2 = Transparency, composite and position break; case "lclr": //Sheet Color setting this.SheetColor = System.Drawing.Color.FromArgb( reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte()); reader.BaseStream.Position += 2; //padding break; case "lnsr": //Layer Name Source setting string sWhatIsThis = new string(reader.ReadChars((int)nLength)); //this.NameSourceSetting = reader.ReadUInt32(); break; case "luni": //Unicode Layer name uint nUnicodeLength = reader.ReadUInt32(); this.UnicodeName = new string(reader.ReadChars((int)nUnicodeLength * 2)); break; case "lrFX": //Effects Layer info reader.BaseStream.Position += 2; //unused ushort nNumEffects = reader.ReadUInt16(); // aEffectsInfo = [] // paInfo[#EffectsInfo] = aEffectsInfo for (int nEffectNum = 0; nEffectNum < nNumEffects; nEffectNum++) { sHeader = new string(reader.ReadChars(4)); if (sHeader != "8BIM") { throw(new Exception("Effect header incorrect")); } EffectLayers.Effect effectForReading = new Endogine.Serialization.Photoshop.EffectLayers.Effect(reader); //reader.JumpToEvenNthByte(2); EffectLayers.Effect effect = null; //long nEffectEndPos = reader.BaseStream.Position + effect.Size; switch (effectForReading.Name) { case "cmnS": //common state BinaryReverseReader subreader = effectForReading.GetDataReader(); bool bVisible = subreader.ReadBoolean(); //reader.BaseStream.Position+=2; //unused break; case "dsdw": case "isdw": //drop/inner shadow if (effectForReading.Version == 0) { effect = new Endogine.Serialization.Photoshop.EffectLayers.Shadow(effectForReading); } else { //TODO: } break; case "oglw": case "iglw": //outer/inner glow if (effectForReading.Version == 0) { effect = new Endogine.Serialization.Photoshop.EffectLayers.Glow(effectForReading); } else { //TODO: } break; case "bevl": //bevel if (effectForReading.Version == 0) { effect = new Endogine.Serialization.Photoshop.EffectLayers.Bevel(effectForReading); } else { //TODO: } break; case "sofi": //unknown break; } this.Effects.Add(effect); //reader.BaseStream.Position = nEffectEndPos; } break; case "lsct": //TODO: what is this? reader.BaseStream.Position += 4; break; case "TySh": case "lfx2": //TODO: what are these? break; default: string sMsg = "Unknown layer setting: " + sKey + " Length:" + nLength.ToString() + " Pos: " + reader.BaseStream.Position.ToString(); //EH.Put(sMsg); break; } //add to nLength so it's padded to 4 int nLengthMod = (int)(nLength % (long)4); if (nLengthMod > 0) { nLength += 4 - (uint)nLengthMod; } reader.BaseStream.Position = nPosStart + nLength; reader.JumpToEvenNthByte(2); }
public Layer(BinaryReverseReader reverseReader, PsdFile psdFile) { AdjustmentInfo = new List<AdjusmentLayerInfo>(); SortedChannels = new SortedList<Int16, Channel>(); Channels = new List<Channel>(); Debug.WriteLine("Layer started at " + reverseReader.BaseStream.Position.ToString(CultureInfo.InvariantCulture)); PsdFile = psdFile; Rectangle localRectangle = new Rectangle { Y = reverseReader.ReadInt32(), X = reverseReader.ReadInt32() }; localRectangle.Height = reverseReader.ReadInt32() - localRectangle.Y; localRectangle.Width = reverseReader.ReadInt32() - localRectangle.X; Rect = localRectangle; Int32 numberOfChannels = reverseReader.ReadUInt16(); Channels.Clear(); for (Int32 channel = 0; channel < numberOfChannels; channel++) { Channel ch = new Channel(reverseReader, this); Channels.Add(ch); SortedChannels.Add(ch.ID, ch); } String signature = new String(reverseReader.ReadChars(4)); if (signature != "8BIM") throw (new IOException("Layer Channelheader error")); _blendModeKeyStr = new String(reverseReader.ReadChars(4)); Opacity = reverseReader.ReadByte(); Clipping = reverseReader.ReadByte() > 0; Byte flags = reverseReader.ReadByte(); _flags = new BitVector32(flags); reverseReader.ReadByte(); //padding Debug.WriteLine("Layer extraDataSize started at " + reverseReader.BaseStream.Position.ToString(CultureInfo.InvariantCulture)); // this is the total size of the MaskData, the BlendingRangesData, the // Name and the AdjustmenLayerInfo UInt32 extraDataSize = reverseReader.ReadUInt32(); // remember the start position for calculation of the // AdjustmenLayerInfo size Int64 extraDataStartPosition = reverseReader.BaseStream.Position; MaskData = new Mask(reverseReader, this); BlendingRangesData = new BlendingRanges(reverseReader, this); Int64 namePosition = reverseReader.BaseStream.Position; Name = reverseReader.ReadPascalString(); Int32 paddingBytes = (Int32)((reverseReader.BaseStream.Position - namePosition) % 4); Debug.Print("Layer {0} padding bytes after name", paddingBytes); reverseReader.ReadBytes(paddingBytes); AdjustmentInfo.Clear(); Int64 adjustmenLayerEndPos = extraDataStartPosition + extraDataSize; while (reverseReader.BaseStream.Position < adjustmenLayerEndPos) { try { AdjustmentInfo.Add(new AdjusmentLayerInfo(reverseReader, this)); } catch { reverseReader.BaseStream.Position = adjustmenLayerEndPos; } } // make shure we are not on a wrong offset, so set the stream position // manually reverseReader.BaseStream.Position = adjustmenLayerEndPos; }
internal Mask(BinaryReverseReader reader, Layer layer) { Debug.WriteLine("Mask started at " + reader.BaseStream.Position.ToString(CultureInfo.InvariantCulture)); Layer = layer; uint maskLength = reader.ReadUInt32(); if (maskLength <= 0) return; long startPosition = reader.BaseStream.Position; Rectangle localRectangle = new Rectangle { Y = reader.ReadInt32(), X = reader.ReadInt32() }; localRectangle.Height = reader.ReadInt32() - localRectangle.Y; localRectangle.Width = reader.ReadInt32() - localRectangle.X; Rect = localRectangle; DefaultColor = reader.ReadByte(); byte flags = reader.ReadByte(); _flags = new BitVector32(flags); if (maskLength == 36) { #pragma warning disable 168 BitVector32 realFlags = new BitVector32(reader.ReadByte()); byte realUserMaskBackground = reader.ReadByte(); Rectangle rect = new Rectangle { Y = reader.ReadInt32(), X = reader.ReadInt32(), Height = reader.ReadInt32() - Rect.Y, Width = reader.ReadInt32() - Rect.X }; #pragma warning restore 168 } // there is other stuff following, but we will ignore this. reader.BaseStream.Position = startPosition + maskLength; }
public TypeTooltySh(BinaryReverseReader areader) { ushort Version = areader.ReadUInt16(); //1= Photoshop 5.0 for (int i = 0; i < 6; i++) //2D transform matrix { ReadPSDDouble(areader); } //Font info: ushort FontVersion = areader.ReadUInt16(); //6 = Photoshop 5.0 ushort FaceCount = areader.ReadUInt16(); this.FontInfos = new List <FontInfo>(); for (int i = 0; i < FaceCount; i++) { this.FontInfos.Add(new FontInfo(areader)); } //TODO: make classes of styles as well... ushort StyleCount = areader.ReadUInt16(); for (int i = 0; i < StyleCount; i++) { ushort Mark = areader.ReadUInt16(); ushort FaceMark = areader.ReadUInt16(); uint Size = areader.ReadUInt32(); uint Tracking = areader.ReadUInt32(); uint Kerning = areader.ReadUInt32(); uint Leading = areader.ReadUInt32(); uint BaseShift = areader.ReadUInt32(); byte AutoKern = areader.ReadByte(); byte Extra = 0; if (Version <= 5) { Extra = areader.ReadByte(); } byte Rotate = areader.ReadByte(); } //Text information ushort Type = areader.ReadUInt16(); uint ScalingFactor = areader.ReadUInt32(); uint CharacterCount = areader.ReadUInt32(); uint HorizontalPlacement = areader.ReadUInt32(); uint VerticalPlacement = areader.ReadUInt32(); uint SelectStart = areader.ReadUInt32(); uint SelectEnd = areader.ReadUInt32(); ushort LineCount = areader.ReadUInt16(); for (int i = 0; i < LineCount; i++) { uint CharacterCountLine = areader.ReadUInt32(); ushort Orientation = areader.ReadUInt16(); ushort Alignment = areader.ReadUInt16(); ushort DoubleByteChar = areader.ReadUInt16(); ushort Style = areader.ReadUInt16(); } ushort ColorSpace = areader.ReadUInt16(); for (int i = 0; i < 4; i++) { areader.ReadUInt16(); //Color compensation } byte AntiAlias = areader.ReadByte(); }
public ImageResource(BinaryReverseReader reverseReader) { Name = String.Empty; OSType = new String(reverseReader.ReadChars(4)); if (OSType != "8BIM" && OSType != "MeSa") { throw new InvalidOperationException("Could not read an image resource"); } ID = reverseReader.ReadInt16(); Name = reverseReader.ReadPascalString(); UInt32 settingLength = reverseReader.ReadUInt32(); Data = reverseReader.ReadBytes((Int32)settingLength); if (reverseReader.BaseStream.Position % 2 == 1) reverseReader.ReadByte(); }
} //end Load() /// <summary> /// Loads up the Layers of the supplied PSD file /// </summary> private void LoadLayers(BinaryReverseReader reader) { Debug.WriteLine("LoadLayers started at " + reader.BaseStream.Position.ToString(CultureInfo.InvariantCulture)); UInt32 layersInfoSectionLength = reader.ReadUInt32(); if (layersInfoSectionLength <= 0) return; Int64 startPosition = reader.BaseStream.Position; Int16 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); } _layers.Clear(); if (numberOfLayers == 0) return; for (Int32 i = 0; i < numberOfLayers; i++) { _layers.Add(new Layer(reader, this)); } foreach (Layer layer in Layers) { foreach (Layer.Channel channel in layer.Channels.Where(c => c.ID != -2)) { channel.LoadPixelData(reader); } layer.MaskData.LoadPixelData(reader); } 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; }
public TypeTool(PhotoshopFile.Layer.AdjustmentLayerInfo info) { this.m_data = info.Data; this.m_key = info.Key; this.m_layer = info.Layer; BinaryReverseReader reader = this.DataReader; ushort Version = reader.ReadUInt16(); //1= Photoshop 5.0 //2D transform matrix (6 doubles) Transform = new Matrix2D(reader); //Font info: ushort FontVersion = reader.ReadUInt16(); //6 = Photoshop 5.0 ushort FaceCount = reader.ReadUInt16(); this.FontInfos = new List <FontInfo>(); for (int i = 0; i < FaceCount; i++) { this.FontInfos.Add(new FontInfo(reader)); } //TODO: make classes of styles as well... ushort StyleCount = reader.ReadUInt16(); for (int i = 0; i < StyleCount; i++) { ushort Mark = reader.ReadUInt16(); ushort FaceMark = reader.ReadUInt16(); uint Size = reader.ReadUInt32(); uint Tracking = reader.ReadUInt32(); uint Kerning = reader.ReadUInt32(); uint Leading = reader.ReadUInt32(); uint BaseShift = reader.ReadUInt32(); byte AutoKern = reader.ReadByte(); byte Extra = 0; if (Version <= 5) { Extra = reader.ReadByte(); } byte Rotate = reader.ReadByte(); } //Text information ushort Type = reader.ReadUInt16(); uint ScalingFactor = reader.ReadUInt32(); uint CharacterCount = reader.ReadUInt32(); uint HorizontalPlacement = reader.ReadUInt32(); uint VerticalPlacement = reader.ReadUInt32(); uint SelectStart = reader.ReadUInt32(); uint SelectEnd = reader.ReadUInt32(); ushort LineCount = reader.ReadUInt16(); for (int i = 0; i < LineCount; i++) { uint CharacterCountLine = reader.ReadUInt32(); ushort Orientation = reader.ReadUInt16(); ushort Alignment = reader.ReadUInt16(); ushort DoubleByteChar = reader.ReadUInt16(); ushort Style = reader.ReadUInt16(); } ushort ColorSpace = reader.ReadUInt16(); for (int i = 0; i < 4; i++) { reader.ReadUInt16(); //Color compensation } byte AntiAlias = reader.ReadByte(); }