/** * Instantiates a new psd descriptor. * * @param stream the stream * @throws IOException Signals that an I/O exception has occurred. */ public PsdDescriptor(BinaryReverseReader stream) { int unicstrlength = stream.ReadInt32() * 2; string unicstr = Encoding.Unicode.GetString(stream.ReadBytes(unicstrlength)); int classlength = stream.ReadInt32(); if (classlength != 0) { classId = Encoding.Default.GetString(stream.ReadBytes(classlength)); } else { classId = Encoding.Default.GetString(stream.ReadBytes(4)); } int itemsCount = stream.ReadInt32(); for (int i = 0; i < itemsCount; i++) { int size = stream.ReadInt32(); if (size == 0) { size = 4; } String key = Encoding.Default.GetString(stream.ReadBytes(size)); objects.Add(key, PsdObjectFactory.loadPsdObject(stream)); } }
/// <summary> /// Initializes a new instance of the <see cref="ImageResource"/> class using a reader. /// </summary> /// <param name="reader">The reader to use to create the instance.</param> public ImageResource(BinaryReverseReader reader) { // read the OS type string osType = new string(reader.ReadChars(4)); if (osType != "8BIM" && osType != "MeSa") { throw new InvalidOperationException("Could not read an image resource"); } // read the ID ID = reader.ReadInt16(); // read the name Name = string.Empty; Name = reader.ReadPascalString(); // read the length of the data in bytes uint length = reader.ReadUInt32(); // read the actual data Data = reader.ReadBytes((int)length); if (reader.BaseStream.Position % 2L != 1L) { return; } reader.ReadByte(); }
/// <summary> /// Initializes a new instance of the <see cref="ImageResource"/> class using a reader. /// </summary> /// <param name="reader">The reader to use to create the instance.</param> public ImageResource(BinaryReverseReader reader) { // read the OS type string osType = new string(reader.ReadChars(4)); if (osType != "8BIM" && osType != "MeSa") { throw new InvalidOperationException("Could not read an image resource"); } // read the ID ID = reader.ReadInt16(); // read the name Name = string.Empty; Name = reader.ReadPascalString(); // read the length of the data in bytes uint length = reader.ReadUInt32(); // read the actual data Data = reader.ReadBytes((int)length); if (reader.BaseStream.Position % 2L != 1L) { return; } reader.ReadByte(); }
////////////////////////////////////////////////////////////////// internal void LoadPixelData(BinaryReverseReader reader) { Debug.WriteLine("Channel.LoadPixelData started at " + reader.BaseStream.Position); m_data = reader.ReadBytes(Length); using (BinaryReverseReader readerImg = DataReader) { m_imageCompression = (ImageCompression)readerImg.ReadInt16(); int bytesPerRow = 0; switch (m_layer.PsdFile.Depth) { case 1: bytesPerRow = m_layer.m_rect.Width; //NOT Shure break; case 8: bytesPerRow = m_layer.m_rect.Width; break; case 16: bytesPerRow = m_layer.m_rect.Width * 2; break; } m_imageData = new byte[m_layer.m_rect.Height * bytesPerRow]; switch (m_imageCompression) { case ImageCompression.Raw: readerImg.Read(m_imageData, 0, m_imageData.Length); break; case ImageCompression.Rle: { var rowLenghtList = new int[m_layer.m_rect.Height]; for (int i = 0; i < rowLenghtList.Length; i++) { rowLenghtList[i] = readerImg.ReadInt16(); } for (int i = 0; i < m_layer.m_rect.Height; i++) { var rowIndex = i * m_layer.m_rect.Width; RleHelper.DecodedRow(readerImg.BaseStream, m_imageData, rowIndex, bytesPerRow); //if (rowLenghtList[i] % 2 == 1) // readerImg.ReadByte(); } } break; } } }
private void LoadColorModeData(BinaryReverseReader reader) { uint num = reader.ReadUInt32(); if (num <= 0U) { return; } ColorModeData = reader.ReadBytes((int)num); }
private void LoadGlobalLayerMask(BinaryReverseReader reader) { uint num = reader.ReadUInt32(); if (num <= 0U) { return; } reader.ReadBytes((int)num); }
private void LoadColorModeData(BinaryReverseReader reader) { Debug.WriteLine("LoadColorModeData started at " + reader.BaseStream.Position.ToString()); uint paletteLength = reader.ReadUInt32(); if (paletteLength > 0) { ColorModeData = reader.ReadBytes((int)paletteLength); } }
public BlendingRanges(BinaryReverseReader reader) { //读文档 五 - 4 - 15) 到 五 - 4 - 20) int count = reader.ReadInt32(); if (count <= 0) { return; } byte[] data = reader.ReadBytes(count); }
public PsdTextData(BinaryReverseReader stream) { int size = stream.ReadInt32(); byte[] array = new byte[size]; offset = stream.BaseStream.Position; array = stream.ReadBytes(size); Stream str = new MemoryStream(array); BinaryReverseReader br = new BinaryReverseReader(str); properties = readMap(br); }
/// <summary> /// Reads the color mode data from the reader. /// </summary> /// <param name="reader">The reader to use to read the color mode data.</param> private void LoadColorModeData(BinaryReverseReader reader) { uint num = reader.ReadUInt32(); // Debug.Log(Time.time + "LoadColorModeData number=" + num); if (num <= 0U) { return; } ColorModeData = reader.ReadBytes((int)num); }
private void LoadGlobalLayerMask(BinaryReverseReader reader) { Debug.WriteLine("LoadGlobalLayerMask started at " + reader.BaseStream.Position.ToString()); uint maskLength = reader.ReadUInt32(); if (maskLength <= 0) { return; } GlobalLayerMaskData = reader.ReadBytes((int)maskLength); }
/////////////////////////////////////////////////////////////////////////// public BlendingRanges(BinaryReverseReader reader, Layer layer) { Debug.WriteLine("BlendingRanges started at " + reader.BaseStream.Position.ToString()); m_layer = layer; int dataLength = reader.ReadInt32(); if (dataLength <= 0) { return; } m_data = reader.ReadBytes(dataLength); }
internal void LoadPixelData(BinaryReverseReader reader) { Data = reader.ReadBytes(Length); using (BinaryReverseReader dataReader = DataReader) { //从文档 五 - 5 读取信息 ImageCompression = (ImageCompression)dataReader.ReadInt16(); int columns = 0; switch (Layer.PsdFile.Depth) { case 1: columns = (int)Layer.Rect.width; break; case 8: columns = (int)Layer.Rect.width; break; case 16: columns = (int)Layer.Rect.width * 2; break; } ImageData = new byte[(int)Layer.Rect.height * columns]; switch (ImageCompression) { case ImageCompression.Raw: dataReader.Read(ImageData, 0, ImageData.Length); break; case ImageCompression.Rle: int[] nums = new int[(int)Layer.Rect.height]; for (int i = 0; i < Layer.Rect.height; i++) { nums[i] = dataReader.ReadInt16(); } for (int index = 0; index < Layer.Rect.height; ++index) { int startIdx = index * (int)Layer.Rect.width; RleHelper.DecodedRow(dataReader.BaseStream, ImageData, startIdx, columns); } break; } } }
/// <summary> /// Initializes a new instance of the <see cref="AdjustmentLayerInfo"/> class. /// </summary> /// <param name="reader">The reader containing the PSD file data</param> /// <param name="layer">The layer that this adjustment info belongs to</param> public AdjustmentLayerInfo(BinaryReverseReader reader, Layer layer) { if (new string(reader.ReadChars(4)) != "8BIM") { throw new IOException("Could not read an image resource"); } Key = new string(reader.ReadChars(4)); if (Key == "lfx2" || Key == "lrFX") { layer.HasEffects = true; } uint length = reader.ReadUInt32(); Data = reader.ReadBytes((int)length); }
/// <summary> /// Initializes a new instance of the <see cref="AdjustmentLayerInfo"/> class. /// </summary> /// <param name="reader">The reader containing the PSD file data</param> /// <param name="layer">The layer that this adjustment info belongs to</param> public AdjustmentLayerInfo(BinaryReverseReader reader, Layer layer) { if (new string(reader.ReadChars(4)) != "8BIM") { throw new IOException("Could not read an image resource"); } Key = new string(reader.ReadChars(4)); if (Key == "lfx2" || Key == "lrFX") { layer.HasEffects = true; } uint length = reader.ReadUInt32(); Data = reader.ReadBytes((int)length); }
public AdjustmentLayerInfo(BinaryReverseReader reader, Layer layer) { Debug.WriteLine("AdjustmentLayerInfo started at " + reader.BaseStream.Position.ToString()); m_layer = layer; string signature = new string(reader.ReadChars(4)); if (signature != "8BIM") { throw new IOException("Could not read an image resource"); } m_key = new string(reader.ReadChars(4)); uint dataLength = reader.ReadUInt32(); m_data = reader.ReadBytes((int)dataLength); }
////////////////////////////////////////////////////////////////// public ImageResource(BinaryReverseReader reader) { m_osType = new string(reader.ReadChars(4)); if (m_osType != "8BIM" && m_osType != "MeSa") { throw new InvalidOperationException("Could not read an image resource"); } m_id = reader.ReadInt16(); m_name = reader.ReadPascalString(); uint settingLength = reader.ReadUInt32(); m_data = reader.ReadBytes((int)settingLength); if (reader.BaseStream.Position % 2 == 1) { reader.ReadByte(); } }
/// <summary> /// Initializes a new instance of the <see cref="BlendingRanges"/> class. /// </summary> /// <param name="reader">The reader containing the PSD file data</param> public BlendingRanges(BinaryReverseReader reader) { // read the data length int count = reader.ReadInt32(); if (count <= 0) { return; } // read the data byte [] data = reader.ReadBytes(count); //string info = "BlendingRanges data=\n"; //for (int index = 0; index < data.Length; index++) //{ // info += "data[" + index + "]=" + data[index] + "\n"; //} //Debug.Log(info); }
public AdjustmentLayerInfo(BinaryReverseReader reader, Layer layer) { // 从文档 五 - 4 - 22) 开始读取 string head = reader.ReadStringNew(4); if (head != "8BIM") { throw new IOException("Could not read an image resource"); } Key = reader.ReadStringNew(4); if (Key == "lfx2" || Key == "lrFX") { layer.HasEffects = true; } uint length = reader.ReadUInt32(); Data = reader.ReadBytes((int)length); }
public Thumbnail(ImageResource imgRes) : base(imgRes) { using (BinaryReverseReader reader = DataReader) { int format = reader.ReadInt32(); int width = reader.ReadInt32(); int height = reader.ReadInt32(); int widthBytes = reader.ReadInt32(); int size = reader.ReadInt32(); int compressedSize = reader.ReadInt32(); short bitPerPixel = reader.ReadInt16(); short planes = reader.ReadInt16(); if (format == 1) { byte[] imgData = reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)); using (MemoryStream strm = new MemoryStream(imgData)) { m_thumbnailImage = (Bitmap)(Bitmap.FromStream(strm).Clone()); } if (this.ID == 1033) { //// BGR //for(int y=0;y<m_thumbnailImage.Height;y++) // for (int x = 0; x < m_thumbnailImage.Width; x++) // { // Color c=m_thumbnailImage.GetPixel(x,y); // Color c2=Color.FromArgb(c.B, c.G, c.R); // m_thumbnailImage.SetPixel(x, y, c); // } } } else { m_thumbnailImage = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); } } }
public static PsdObject loadPsdObject(BinaryReverseReader stream) { string type = Encoding.Default.GetString(stream.ReadBytes(4)); switch (type) { case "Objc": return(new PsdDescriptor(stream)); case "GlbO": return(new PsdDescriptor(stream)); case "VlLs": return(new PsdList(stream)); case "doub": return(new PsdDouble(stream)); case "long": return(new PsdLong(stream)); case "bool": return(new PsdBoolean(stream)); case "UntF": return(new PsdUnitFloat(stream)); case "enum": return(new PsdEnum(stream)); case "TEXT": return(new PsdText(stream)); case "tdta": return(new PsdTextData(stream)); default: return(new PsdObject()); } }
/// <summary> /// Initializes a new instance of the <see cref="AdjustmentLayerInfo"/> class. /// </summary> /// <param name="reader">The reader containing the PSD file data</param> /// <param name="layer">The layer that this adjustment info belongs to</param> public AdjustmentLayerInfo(BinaryReverseReader reader, Layer layer) { string head = reader.readStringNew(4); if (head != "8BIM") { throw new IOException("Could not read an image resource"); } Key = reader.readStringNew(4); if (Key == "lfx2" || Key == "lrFX") { layer.HasEffects = true; } //int readlength = byte.MaxValue; uint length = reader.ReadUInt32(); Data = reader.ReadBytes((int)length); //Debug.Log(Time.time + ",new AdjustmentLayerInfo key=" + Key +",strdata="+Stringdata); }
public Layer(BinaryReverseReader reader, PsdFile psdFile) { Debug.WriteLine("Layer started at " + reader.BaseStream.Position); m_psdFile = psdFile; m_rect = new Rectangle { Y = reader.ReadInt32(), X = reader.ReadInt32() }; m_rect.Height = reader.ReadInt32() - m_rect.Y; m_rect.Width = reader.ReadInt32() - m_rect.X; //----------------------------------------------------------------------- int numberOfChannels = reader.ReadUInt16(); m_channels.Clear(); for (int channel = 0; channel < numberOfChannels; channel++) { var ch = new Channel(reader, this); m_channels.Add(ch); m_sortedChannels.Add(ch.ID, ch); } //----------------------------------------------------------------------- var signature = new string(reader.ReadChars(4)); if (signature != LayerConstants.EightBimSignature) throw (new IOException("Layer Channelheader error!")); m_blendModeKey = new string(reader.ReadChars(4)); m_opacity = reader.ReadByte(); m_clipping = reader.ReadByte() > 0; //----------------------------------------------------------------------- byte flags = reader.ReadByte(); m_flags = new BitVector32(flags); //----------------------------------------------------------------------- reader.ReadByte(); //padding //----------------------------------------------------------------------- Debug.WriteLine("Layer extraDataSize started at " + reader.BaseStream.Position); // this is the total size of the MaskData, the BlendingRangesData, the // Name and the AdjustmenLayerInfo uint extraDataSize = reader.ReadUInt32(); // remember the start position for calculation of the // AdjustmenLayerInfo size long extraDataStartPosition = reader.BaseStream.Position; m_maskData = new Mask(reader, this); m_blendingRangesData = new BlendingRanges(reader, this); //----------------------------------------------------------------------- var namePosition = reader.BaseStream.Position; m_name = reader.ReadPascalString(); var paddingBytes = (int)((reader.BaseStream.Position - namePosition) % 4); Debug.Print("Layer {0} padding bytes after name", paddingBytes); reader.ReadBytes(paddingBytes); //----------------------------------------------------------------------- m_adjustmentInfo.Clear(); long adjustmenLayerEndPos = extraDataStartPosition + extraDataSize; while (reader.BaseStream.Position < adjustmenLayerEndPos) { try { m_adjustmentInfo.Add(new AdjusmentLayerInfo(reader, this)); } catch { reader.BaseStream.Position = adjustmenLayerEndPos; } } //----------------------------------------------------------------------- // make shure we are not on a wrong offset, so set the stream position // manually reader.BaseStream.Position = adjustmenLayerEndPos; }
/// <summary> /// Reads the color mode data from the reader. /// </summary> /// <param name="reader">The reader to use to read the color mode data.</param> private void LoadColorModeData(BinaryReverseReader reader) { uint num = reader.ReadUInt32(); if (num <= 0U) { return; } ColorModeData = reader.ReadBytes((int)num); }
internal void LoadPixelData(BinaryReverseReader reader) { Debug.WriteLine("Mask.LoadPixelData started at " + reader.BaseStream.Position.ToString()); if (m_rect.IsEmpty || m_layer.SortedChannels.ContainsKey(-2) == false) { return; } Channel maskChannel = m_layer.SortedChannels[-2]; maskChannel.Data = reader.ReadBytes((int)maskChannel.Length); using (BinaryReverseReader readerImg = maskChannel.DataReader) { maskChannel.ImageCompression = (ImageCompression)readerImg.ReadInt16(); int bytesPerRow = 0; switch (m_layer.PsdFile.Depth) { case 1: bytesPerRow = ImageDecoder.BytesFromBits(m_layer.m_rect.Width); break; case 8: bytesPerRow = m_rect.Width; break; case 16: bytesPerRow = m_rect.Width * 2; break; } maskChannel.ImageData = new byte[m_rect.Height * bytesPerRow]; // Fill Array for (int i = 0; i < maskChannel.ImageData.Length; i++) { maskChannel.ImageData[i] = 0xAB; } m_imageData = (byte[])maskChannel.ImageData.Clone(); switch (maskChannel.ImageCompression) { case ImageCompression.Raw: readerImg.Read(maskChannel.ImageData, 0, maskChannel.ImageData.Length); break; case ImageCompression.Rle: { uint[] rowLengthList = new uint[m_rect.Height]; for (int i = 0; i < rowLengthList.Length; i++) { rowLengthList[i] = readerImg.ReadUInt16(); } for (int i = 0; i < m_rect.Height; i++) { int rowIndex = i * m_rect.Width; RleHelper.DecodedRow(readerImg.BaseStream, maskChannel.ImageData, rowIndex, bytesPerRow); } } break; default: break; } m_imageData = (byte[])maskChannel.ImageData.Clone(); } }
/// <summary> /// Reads the text information for the layer. /// </summary> /// <param name="dataReader">The reader to use to read the text data.</param> private void ReadTextLayer(BinaryReverseReader dataReader) { IsTextLayer = true; // read the text layer's text string dataReader.Seek("/Text"); dataReader.ReadBytes(4); Text = dataReader.ReadString(); // read the text justification dataReader.Seek("/Justification "); int justification = dataReader.ReadByte() - 48; Justification = TextJustification.Left; if (justification == 1) { Justification = TextJustification.Right; } else if (justification == 2) { Justification = TextJustification.Center; } // read the font size dataReader.Seek("/FontSize "); FontSize = dataReader.ReadFloat(); // read the font fill color dataReader.Seek("/FillColor"); dataReader.Seek("/Values [ "); float alpha = dataReader.ReadFloat(); dataReader.ReadByte(); float red = dataReader.ReadFloat(); dataReader.ReadByte(); float green = dataReader.ReadFloat(); dataReader.ReadByte(); float blue = dataReader.ReadFloat(); FillColor = new Color(red * byte.MaxValue, green * byte.MaxValue, blue * byte.MaxValue, alpha * byte.MaxValue); // read the font name dataReader.Seek("/FontSet "); dataReader.Seek("/Name"); dataReader.ReadBytes(4); FontName = dataReader.ReadString(); // read the warp style dataReader.Seek("warpStyle"); dataReader.Seek("warpStyle"); dataReader.ReadBytes(3); int num13 = dataReader.ReadByte(); WarpStyle = string.Empty; for (; num13 > 0; --num13) { string str = WarpStyle + dataReader.ReadChar(); WarpStyle = str; } }
/// <summary> /// Reads the pixel data from a reader. /// </summary> /// <param name="reader">The reader to use to read the pixel data.</param> internal void LoadPixelData(BinaryReverseReader reader) { if (rect.width <= 0 || !Layer.SortedChannels.ContainsKey(-2)) { return; } Channel channel = Layer.SortedChannels[-2]; channel.Data = reader.ReadBytes(channel.Length); using (BinaryReverseReader dataReader = channel.DataReader) { channel.ImageCompression = (ImageCompression)dataReader.ReadInt16(); int columns = 0; switch (Layer.PsdFile.Depth) { case 1: columns = (int)rect.width; break; case 8: columns = (int)rect.width; break; case 16: columns = (int)rect.width * 2; break; } channel.ImageData = new byte[(int)rect.height * columns]; for (int index = 0; index < channel.ImageData.Length; ++index) { channel.ImageData[index] = 171; } ImageData = (byte[])channel.ImageData.Clone(); switch (channel.ImageCompression) { case ImageCompression.Raw: dataReader.Read(channel.ImageData, 0, channel.ImageData.Length); break; case ImageCompression.Rle: int[] nums = new int[(int)rect.height]; for (int i = 0; i < (int)rect.height; i++) { nums[i] = dataReader.ReadInt16(); } for (int index = 0; index < (int)rect.height; ++index) { int startIdx = index * (int)rect.width; RleHelper.DecodedRow(dataReader.BaseStream, channel.ImageData, startIdx, columns); } break; } ImageData = (byte[])channel.ImageData.Clone(); } }
private void ParseLrfxKeyword(AdjustmentLayerInfo adjustmentLayerInfo) { BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; int version = dataReader.ReadInt16(); int effectCount = dataReader.ReadInt16(); for (int index = 0; index < effectCount; index++) { string sigNature = dataReader.ReadStringNew(4); string type = dataReader.ReadStringNew(4); switch (type) { case "cmnS": //OK int cmnsSize = dataReader.ReadInt32(); int cmnsVersion = dataReader.ReadInt32(); bool cmnsBool = dataReader.ReadBoolean(); int cmnsUnused = dataReader.ReadInt16(); break; case "dsdw": // 投影效果 byte[] testbyte2 = dataReader.ReadBytes(55); break; case "isdw": //内阴影效果 int dropSize = dataReader.ReadInt32(); int dropVersion = dataReader.ReadInt32(); int dropBlurValue = dataReader.ReadInt32(); int Intensityasapercent = dataReader.ReadInt32(); int angleindegrees = dataReader.ReadInt32(); int distanceinp = dataReader.ReadInt32(); byte[] colortest = dataReader.ReadBytes(10); dataReader.ReadBytes(4); string dropBlendmode = dataReader.ReadStringNew(4); bool dropeffectEnable = dataReader.ReadBoolean(); byte usethisangle = dataReader.ReadByte(); int dropOpacity = dataReader.ReadByte(); int dropSpace11 = dataReader.ReadInt16(); int color111 = dataReader.ReadInt16(); int color211 = dataReader.ReadInt16(); int color311 = dataReader.ReadInt16(); int color411 = dataReader.ReadInt16(); dataReader.ReadBytes(4); dataReader.ReadBytes(4); dataReader.ReadBytes(4); dataReader.ReadBytes(4); dataReader.ReadBytes(4); dataReader.ReadBytes(4); dataReader.ReadBytes(10); string sign1 = dataReader.ReadStringNew(4); string key1 = dataReader.ReadStringNew(4); dataReader.ReadBytes(1); dataReader.ReadBytes(1); dataReader.ReadBytes(1); if (dropVersion == 2) { dataReader.ReadBytes(10); } break; case "oglw": //有用:字体的描边! int sizeofRemainItems = dataReader.ReadInt32(); int oglwversion = dataReader.ReadInt32(); byte[] blurdata = dataReader.ReadBytes(4); _outLineDis = Convert.ToInt32(blurdata[1]); //也是小坑,四个故意放在第二个字节 也不说明( ▼-▼ ) //int blurvalue = dataReader.ReadInt32(); int intensityPercent = dataReader.ReadInt32(); byte outline_r = 0; byte outline_g = 0; byte outline_b = 0; byte outline_a = 0; dataReader.ReadBytes(2); outline_r = dataReader.ReadByte(); dataReader.ReadByte(); outline_g = dataReader.ReadByte(); dataReader.ReadByte(); outline_b = dataReader.ReadByte(); dataReader.ReadByte(); outline_a = dataReader.ReadByte(); dataReader.ReadByte(); string curSign = dataReader.ReadStringNew(4); string key = dataReader.ReadStringNew(4); bool effectEnable = dataReader.ReadBoolean(); //yanruTODO 不可靠,如果整个effect 层 禁用了,子字段可能依然为true,暂时找不到上层effect开关 byte opacityPercent = dataReader.ReadByte(); //描边透明度 if (oglwversion == 2) { byte[] oglwColor2 = dataReader.ReadBytes(10); } if (!effectEnable) //指明了没有描边 { TextOutlineColor = new Color(0, 0, 0, 0); } else { TextOutlineColor = new Color(outline_r / 255f, outline_g / 255f, outline_b / 255f, opacityPercent / 255f); } break; case "iglw": byte[] testdata5 = dataReader.ReadBytes(47); //effectStr += "\n" + printbytes(testdata5, "iglw"); //dataReader.ReadBytes(4); //dataReader.ReadBytes(4); //dataReader.ReadBytes(4); //dataReader.ReadBytes(4); //dataReader.ReadBytes(10); //dataReader.ReadBytes(8); //dataReader.ReadBytes(1); //dataReader.ReadBytes(1); //dataReader.ReadBytes(1); //dataReader.ReadBytes(10); break; case "bevl": int bevelSizeofRemain = dataReader.ReadInt32(); //.ReadBytes(4); int bevelversion = dataReader.ReadInt32(); //dataReader.ReadBytes(4); dataReader.ReadBytes(4); dataReader.ReadBytes(4); dataReader.ReadBytes(4); dataReader.ReadBytes(8); dataReader.ReadBytes(8); dataReader.ReadBytes(10); dataReader.ReadBytes(10); dataReader.ReadBytes(1); dataReader.ReadBytes(1); dataReader.ReadBytes(1); dataReader.ReadBytes(1); dataReader.ReadBytes(1); dataReader.ReadBytes(1); if (bevelversion == 2) { dataReader.ReadBytes(10); dataReader.ReadBytes(10); } break; case "sofi": int solidSize = dataReader.ReadInt32(); //.ReadBytes(4); int solidVersion = dataReader.ReadInt32(); // (4); string sign = dataReader.ReadStringNew(4); string solidBlendmode = dataReader.ReadStringNew(4); //.ReadBytes(4); byte[] solidColor = dataReader.ReadBytes(10); byte opacity = dataReader.ReadByte(); byte solidenable = dataReader.ReadByte(); dataReader.ReadBytes(10); break; } } }
private void LoadColorModeData(BinaryReverseReader reader) { Debug.WriteLine("LoadColorModeData started at " + reader.BaseStream.Position); uint paletteLength = reader.ReadUInt32(); if (paletteLength > 0) { ColorModeData = reader.ReadBytes((int) paletteLength); } }
/// <summary> /// Reads the pixel data from a reader. /// </summary> /// <param name="reader">The reader to use to read the pixel data.</param> internal void LoadPixelData(BinaryReverseReader reader) { Data = reader.ReadBytes(Length); using (BinaryReverseReader dataReader = DataReader) { ImageCompression = (ImageCompression)dataReader.ReadInt16(); int columns = 0; switch (Layer.PsdFile.Depth) { case 1: columns = (int)Layer.Rect.width; break; case 8: columns = (int)Layer.Rect.width; break; case 16: columns = (int)Layer.Rect.width * 2; break; } ImageData = new byte[(int)Layer.Rect.height * columns]; switch (ImageCompression) { case ImageCompression.Raw: dataReader.Read(ImageData, 0, ImageData.Length); break; case ImageCompression.Rle: int[] nums = new int[(int)Layer.Rect.height]; for (int i = 0; i < Layer.Rect.height; i++) { nums[i] = dataReader.ReadInt16(); } for (int index = 0; index < Layer.Rect.height; ++index) { int startIdx = index * (int)Layer.Rect.width; RleHelper.DecodedRow(dataReader.BaseStream, ImageData, startIdx, columns); } break; } } }
/// <summary> /// Reads the text information for the layer. /// </summary> /// <param name="dataReader">The reader to use to read the text data.</param> private void ReadTextLayer(BinaryReverseReader dataReader) { IsTextLayer = true; // read the text layer's text string dataReader.Seek("/Text"); dataReader.ReadBytes(4); Text = dataReader.ReadString(); // read the text justification dataReader.Seek("/Justification "); int justification = dataReader.ReadByte() - 48; Justification = TextJustification.Left; if (justification == 1) { Justification = TextJustification.Right; } else if (justification == 2) { Justification = TextJustification.Center; } // read the font size dataReader.Seek("/FontSize "); FontSize = dataReader.ReadFloat(); // read the font fill color dataReader.Seek("/FillColor"); dataReader.Seek("/Values [ "); float alpha = dataReader.ReadFloat(); dataReader.ReadByte(); float red = dataReader.ReadFloat(); dataReader.ReadByte(); float green = dataReader.ReadFloat(); dataReader.ReadByte(); float blue = dataReader.ReadFloat(); FillColor = new Color(red * byte.MaxValue, green * byte.MaxValue, blue * byte.MaxValue, alpha * byte.MaxValue); // read the font name dataReader.Seek("/FontSet "); dataReader.Seek("/Name"); dataReader.ReadBytes(4); FontName = dataReader.ReadString(); // read the warp style dataReader.Seek("warpStyle"); dataReader.Seek("warpStyle"); dataReader.ReadBytes(3); int num13 = dataReader.ReadByte(); WarpStyle = string.Empty; for (; num13 > 0; --num13) { string str = WarpStyle + dataReader.ReadChar(); WarpStyle = str; } }
////////////////////////////////////////////////////////////////// internal void LoadPixelData(BinaryReverseReader reader) { Debug.WriteLine("Channel.LoadPixelData started at " + reader.BaseStream.Position); m_data = reader.ReadBytes(Length); using (BinaryReverseReader readerImg = DataReader) { m_imageCompression = (ImageCompression) readerImg.ReadInt16(); int bytesPerRow = 0; switch (m_layer.PsdFile.Depth) { case 1: bytesPerRow = m_layer.m_rect.Width; //NOT Shure break; case 8: bytesPerRow = m_layer.m_rect.Width; break; case 16: bytesPerRow = m_layer.m_rect.Width*2; break; } m_imageData = new byte[m_layer.m_rect.Height*bytesPerRow]; switch (m_imageCompression) { case ImageCompression.Raw: readerImg.Read(m_imageData, 0, m_imageData.Length); break; case ImageCompression.Rle: { var rowLenghtList = new int[m_layer.m_rect.Height]; for (int i = 0; i < rowLenghtList.Length; i++) rowLenghtList[i] = readerImg.ReadInt16(); for (int i = 0; i < m_layer.m_rect.Height; i++) { var rowIndex = i * m_layer.m_rect.Width; RleHelper.DecodedRow(readerImg.BaseStream, m_imageData, rowIndex, bytesPerRow); //if (rowLenghtList[i] % 2 == 1) // readerImg.ReadByte(); } } break; } } }
/////////////////////////////////////////////////////////////////////////// public BlendingRanges(BinaryReverseReader reader, Layer layer) { Debug.WriteLine("BlendingRanges started at " + reader.BaseStream.Position); m_layer = layer; int dataLength = reader.ReadInt32(); if (dataLength <= 0) return; m_data = reader.ReadBytes(dataLength); }
internal void LoadPixelData(BinaryReverseReader reader) { Debug.WriteLine("Mask.LoadPixelData started at " + reader.BaseStream.Position); if (m_rect.IsEmpty || m_layer.SortedChannels.ContainsKey(-2) == false) return; Channel maskChannel = m_layer.SortedChannels[-2]; maskChannel.Data = reader.ReadBytes(maskChannel.Length); using (BinaryReverseReader readerImg = maskChannel.DataReader) { maskChannel.ImageCompression = (ImageCompression) readerImg.ReadInt16(); int bytesPerRow = 0; switch (m_layer.PsdFile.Depth) { case 1: bytesPerRow = m_rect.Width; //NOT Shure break; case 8: bytesPerRow = m_rect.Width; break; case 16: bytesPerRow = m_rect.Width*2; break; } maskChannel.ImageData = new byte[m_rect.Height*bytesPerRow]; // Fill Array for (int i = 0; i < maskChannel.ImageData.Length; i++) { maskChannel.ImageData[i] = 0xAB; } m_imageData = (byte[]) maskChannel.ImageData.Clone(); switch (maskChannel.ImageCompression) { case ImageCompression.Raw: readerImg.Read(maskChannel.ImageData, 0, maskChannel.ImageData.Length); break; case ImageCompression.Rle: { var rowLenghtList = new int[m_rect.Height]; for (int i = 0; i < rowLenghtList.Length; i++) rowLenghtList[i] = readerImg.ReadInt16(); for (int i = 0; i < m_rect.Height; i++) { int rowIndex = i*m_rect.Width; RleHelper.DecodedRow(readerImg.BaseStream, maskChannel.ImageData, rowIndex, bytesPerRow); } } break; } m_imageData = (byte[]) maskChannel.ImageData.Clone(); } }
public Layer(BinaryReverseReader reader, PsdFile psdFile) { Debug.WriteLine("Layer started at " + reader.BaseStream.Position.ToString()); m_psdFile = psdFile; m_rect = new Rectangle(); m_rect.Y = reader.ReadInt32(); m_rect.X = reader.ReadInt32(); m_rect.Height = reader.ReadInt32() - m_rect.Y; m_rect.Width = reader.ReadInt32() - m_rect.X; //----------------------------------------------------------------------- int numberOfChannels = reader.ReadUInt16(); this.m_channels.Clear(); for (int channel = 0; channel < numberOfChannels; channel++) { Channel ch = new Channel(reader, this); m_channels.Add(ch); m_sortedChannels.Add(ch.ID, ch); } //----------------------------------------------------------------------- string signature = new string(reader.ReadChars(4)); if (signature != "8BIM") { throw (new IOException("Layer Channelheader error!")); } m_blendModeKey = new string(reader.ReadChars(4)); m_opacity = reader.ReadByte(); m_clipping = reader.ReadByte() > 0; //----------------------------------------------------------------------- byte flags = reader.ReadByte(); m_flags = new BitVector32(flags); //----------------------------------------------------------------------- reader.ReadByte(); //padding //----------------------------------------------------------------------- Debug.WriteLine("Layer extraDataSize started at " + reader.BaseStream.Position.ToString()); // this is the total size of the MaskData, the BlendingRangesData, the // Name and the AdjustmentLayerInfo uint extraDataSize = reader.ReadUInt32(); // remember the start position for calculation of the // AdjustmentLayerInfo size long extraDataStartPosition = reader.BaseStream.Position; m_maskData = new Mask(reader, this); m_blendingRangesData = new BlendingRanges(reader, this); //----------------------------------------------------------------------- long namePosition = reader.BaseStream.Position; m_name = reader.ReadPascalString(); int paddingBytes = (int)((reader.BaseStream.Position - namePosition) % 4); Debug.Print("Layer {0} padding bytes after name", paddingBytes); reader.ReadBytes(paddingBytes); //----------------------------------------------------------------------- m_adjustmentInfo.Clear(); long adjustmentLayerEndPos = extraDataStartPosition + extraDataSize; while (reader.BaseStream.Position < adjustmentLayerEndPos) { try { AdjustmentLayerInfo ali = new AdjustmentLayerInfo(reader, this); if (ali.Key.Equals("lrFX")) { //A sub-key - we want to merge its sub-layer info items with this dict. m_adjustmentInfo.AddRange(new Effects(ali)._resources.Values); } else { m_adjustmentInfo.Add(ali); // Just add the items } } catch { reader.BaseStream.Position = adjustmentLayerEndPos; } } //----------------------------------------------------------------------- // make sure we are not on a wrong offset, so set the stream position // manually reader.BaseStream.Position = adjustmentLayerEndPos; }
public Layer(BinaryReverseReader reader, PsdFile psdFile) { Debug.WriteLine("Layer started at " + reader.BaseStream.Position.ToString()); m_psdFile = psdFile; m_rect = new Rectangle(); m_rect.Y = reader.ReadInt32(); m_rect.X = reader.ReadInt32(); m_rect.Height = reader.ReadInt32() - m_rect.Y; m_rect.Width = reader.ReadInt32() - m_rect.X; //----------------------------------------------------------------------- int numberOfChannels = reader.ReadUInt16(); this.m_channels.Clear(); for (int channel = 0; channel < numberOfChannels; channel++) { Channel ch = new Channel(reader, this); m_channels.Add(ch); m_sortedChannels.Add(ch.ID, ch); } //----------------------------------------------------------------------- string signature = new string(reader.ReadChars(4)); if (signature != "8BIM") throw (new IOException("Layer Channelheader error!")); m_blendModeKey = new string(reader.ReadChars(4)); m_opacity = reader.ReadByte(); m_clipping = reader.ReadByte() > 0; //----------------------------------------------------------------------- byte flags = reader.ReadByte(); m_flags = new BitVector32(flags); //----------------------------------------------------------------------- reader.ReadByte(); //padding //----------------------------------------------------------------------- Debug.WriteLine("Layer extraDataSize started at " + reader.BaseStream.Position.ToString()); // this is the total size of the MaskData, the BlendingRangesData, the // Name and the AdjustmentLayerInfo uint extraDataSize = reader.ReadUInt32(); // remember the start position for calculation of the // AdjustmentLayerInfo size long extraDataStartPosition = reader.BaseStream.Position; m_maskData = new Mask(reader, this); m_blendingRangesData = new BlendingRanges(reader, this); //----------------------------------------------------------------------- long namePosition = reader.BaseStream.Position; m_name = reader.ReadPascalString(); int paddingBytes =(int)((reader.BaseStream.Position - namePosition) % 4); Debug.Print("Layer {0} padding bytes after name", paddingBytes); reader.ReadBytes(paddingBytes); //----------------------------------------------------------------------- m_adjustmentInfo.Clear(); long adjustmentLayerEndPos = extraDataStartPosition + extraDataSize; while (reader.BaseStream.Position < adjustmentLayerEndPos) { try { AdjustmentLayerInfo ali = new AdjustmentLayerInfo(reader, this); if (ali.Key.Equals("lrFX")) { //A sub-key - we want to merge its sub-layer info items with this dict. m_adjustmentInfo.AddRange(new Effects(ali)._resources.Values); } else m_adjustmentInfo.Add(ali); // Just add the items } catch { reader.BaseStream.Position = adjustmentLayerEndPos; } } //----------------------------------------------------------------------- // make sure we are not on a wrong offset, so set the stream position // manually reader.BaseStream.Position = adjustmentLayerEndPos; }
//public BitVector32 Flags //{ // get { return flags; } //} /// <summary> /// Initializes a new instance of the <see cref="Layer"/> class using the provided reader containing the PSD file data. /// </summary> /// <param name="reader">The reader containing the PSD file data.</param> /// <param name="psdFile">The PSD file to set as the parent.</param> public Layer(BinaryReverseReader reader, PsdFile psdFile) { Children = new List<Layer>(); PsdFile = psdFile; // read the rect Rect rect = new Rect(); rect.y = reader.ReadInt32(); rect.x = reader.ReadInt32(); rect.height = reader.ReadInt32() - rect.y; rect.width = reader.ReadInt32() - rect.x; Rect = rect; // read the channels int channelCount = reader.ReadUInt16(); Channels = new List<Channel>(); SortedChannels = new SortedList<short, Channel>(); for (int index = 0; index < channelCount; ++index) { Channel channel = new Channel(reader, this); Channels.Add(channel); SortedChannels.Add(channel.ID, channel); } // read the header and verify it if (new string(reader.ReadChars(4)) != "8BIM") { throw new IOException("Layer Channelheader error!"); } // read the blend mode key (unused) (defaults to "norm") reader.ReadChars(4); // read the opacity Opacity = reader.ReadByte(); // read the clipping (unused) (< 0 = base, > 0 = non base) reader.ReadByte(); // read all of the flags (protectTrans, visible, obsolete, ver5orLater, pixelDataIrrelevant) flags = new BitVector32(reader.ReadByte()); // skip a padding byte reader.ReadByte(); uint num3 = reader.ReadUInt32(); long position1 = reader.BaseStream.Position; MaskData = new Mask(reader, this); BlendingRangesData = new BlendingRanges(reader); long position2 = reader.BaseStream.Position; // read the name Name = reader.ReadPascalString(); // read the adjustment info int count = (int)((reader.BaseStream.Position - position2) % 4L); reader.ReadBytes(count); AdjustmentInfo = new List<AdjustmentLayerInfo>(); long num4 = position1 + num3; while (reader.BaseStream.Position < num4) { try { AdjustmentInfo.Add(new AdjustmentLayerInfo(reader, this)); } catch { reader.BaseStream.Position = num4; } } foreach (AdjustmentLayerInfo adjustmentLayerInfo in AdjustmentInfo) { if (adjustmentLayerInfo.Key == "TySh") { ReadTextLayer(adjustmentLayerInfo.DataReader); } else if (adjustmentLayerInfo.Key == "luni") { // read the unicode name BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; dataReader.ReadBytes(3); dataReader.ReadByte(); Name = dataReader.ReadString().TrimEnd(new char[1]); } } reader.BaseStream.Position = num4; }
public Layer(BinaryReverseReader reader, PsdFile psdFile) { Debug.WriteLine("Layer started at " + reader.BaseStream.Position); m_psdFile = psdFile; m_rect = new Rectangle { Y = reader.ReadInt32(), X = reader.ReadInt32() }; m_rect.Height = reader.ReadInt32() - m_rect.Y; m_rect.Width = reader.ReadInt32() - m_rect.X; //----------------------------------------------------------------------- int numberOfChannels = reader.ReadUInt16(); m_channels.Clear(); for (int channel = 0; channel < numberOfChannels; channel++) { var ch = new Channel(reader, this); m_channels.Add(ch); m_sortedChannels.Add(ch.ID, ch); } //----------------------------------------------------------------------- var signature = new string(reader.ReadChars(4)); if (signature != LayerConstants.EightBimSignature) { throw (new IOException("Layer Channelheader error!")); } m_blendModeKey = new string(reader.ReadChars(4)); m_opacity = reader.ReadByte(); m_clipping = reader.ReadByte() > 0; //----------------------------------------------------------------------- byte flags = reader.ReadByte(); m_flags = new BitVector32(flags); //----------------------------------------------------------------------- reader.ReadByte(); //padding //----------------------------------------------------------------------- Debug.WriteLine("Layer extraDataSize started at " + reader.BaseStream.Position); // this is the total size of the MaskData, the BlendingRangesData, the // Name and the AdjustmenLayerInfo uint extraDataSize = reader.ReadUInt32(); // remember the start position for calculation of the // AdjustmenLayerInfo size long extraDataStartPosition = reader.BaseStream.Position; m_maskData = new Mask(reader, this); m_blendingRangesData = new BlendingRanges(reader, this); //----------------------------------------------------------------------- var namePosition = reader.BaseStream.Position; m_name = reader.ReadPascalString(); var paddingBytes = (int)((reader.BaseStream.Position - namePosition) % 4); Debug.Print("Layer {0} padding bytes after name", paddingBytes); reader.ReadBytes(paddingBytes); //----------------------------------------------------------------------- m_adjustmentInfo.Clear(); long adjustmenLayerEndPos = extraDataStartPosition + extraDataSize; while (reader.BaseStream.Position < adjustmenLayerEndPos) { try { m_adjustmentInfo.Add(new AdjusmentLayerInfo(reader, this)); } catch { reader.BaseStream.Position = adjustmenLayerEndPos; } } //----------------------------------------------------------------------- // make shure we are not on a wrong offset, so set the stream position // manually reader.BaseStream.Position = adjustmenLayerEndPos; }
public Layer(BinaryReverseReader reader, PsdFile psdFile) { //从文档 五 - 4 - 1) 开始读 Children = new List <Layer>(); PsdFile = psdFile; Rect rect = new Rect(); rect.y = reader.ReadInt32(); rect.x = reader.ReadInt32(); rect.height = reader.ReadInt32() - rect.y; rect.width = reader.ReadInt32() - rect.x; Rect = rect; int channelCount = reader.ReadUInt16(); Channels = new List <Channel>(); SortedChannels = new SortedList <short, Channel>(); for (int index = 0; index < channelCount; ++index) { Channel channel = new Channel(reader, this); Channels.Add(channel); SortedChannels.Add(channel.ID, channel); } string head = reader.ReadStringNew(4); if (head != "8BIM") { throw new IOException("Layer Channelheader error!"); } string layerRecordsBlendModeKey = reader.ReadStringNew(4); Opacity = reader.ReadByte(); int Clipping = reader.ReadByte(); _flags = new BitVector32(reader.ReadByte()); int Filler = reader.ReadByte(); _imageTransparent = Convert.ToSingle(Opacity) / byte.MaxValue; //文档 五 - 4 - 13) uint num3 = reader.ReadUInt32(); long position1 = reader.BaseStream.Position; MaskData = new Mask(reader, this); _blendingRangesData = new BlendingRanges(reader); long position2 = reader.BaseStream.Position; // 文档 五 - 4 - 21) Name = reader.ReadPascalString(); // read the adjustment info int count = (int)((reader.BaseStream.Position - position2) % 4L); reader.ReadBytes(count); _adjustmentInfo = new List <AdjustmentLayerInfo>(); long num4 = position1 + num3; while (reader.BaseStream.Position < num4) { try { _adjustmentInfo.Add(new AdjustmentLayerInfo(reader, this)); } catch { reader.BaseStream.Position = num4; } } foreach (AdjustmentLayerInfo adjustmentLayerInfo in _adjustmentInfo) { if (adjustmentLayerInfo.Key == "TySh") { ReadTextLayer(adjustmentLayerInfo.DataReader); } else if (adjustmentLayerInfo.Key == "luni") { // read the unicode name BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; byte[] temp1 = dataReader.ReadBytes(3); byte charCount = dataReader.ReadByte(); //本来 charCount 是文本串的长度,可以传入ReadString()限定读取长度,但Text除串头无文本长度信息,因此改为读一段Unicode字符串 Name = dataReader.ReadString(); if (Name == "") { Name = DefaultLayerName; } } //此处针对字体 图层样式 else if (adjustmentLayerInfo.Key == "lrFX") //样式 相关,对于字体来说,就是描边之类的 { ParseLrfxKeyword(adjustmentLayerInfo); //yanruTODO测试屏蔽 } //仅对于图片的 else if (adjustmentLayerInfo.Key == "lspf") { BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; byte[] data = dataReader.ReadBytes(4); } else if (adjustmentLayerInfo.Key == "lclr") { BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; byte[] data = dataReader.ReadBytes(10); } } reader.BaseStream.Position = num4; int deltaL = (int)(MaskData.Rect.x - Rect.x); int deltaR = (int)(Rect.xMax - MaskData.Rect.xMax); int deltaT = (int)(MaskData.Rect.y - Rect.y); int deltaB = (int)(Rect.yMax - MaskData.Rect.yMax); int l = deltaL > 0 ? deltaL : 0; int r = deltaR > 0 ? deltaR : 0; int t = deltaT > 0 ? deltaT : 0; int b = deltaB > 0 ? deltaB : 0; //Unity Document TextureImporter.spriteBorder X=left, Y=bottom, Z=right, W=top. _border = new Vector4(l, b, r, t); //_is9Slice = SLICE_REG.Match(_name).Success; _is9Slice = _name.Contains(SLICE_HEAD); }
////////////////////////////////////////////////////////////////// public ImageResource(BinaryReverseReader reader) { m_osType = new string(reader.ReadChars(4)); if (m_osType != "8BIM" && m_osType != "MeSa") { throw new InvalidOperationException("Could not read an image resource"); } m_id = reader.ReadInt16(); m_name = reader.ReadPascalString(); uint settingLength = reader.ReadUInt32(); m_data = reader.ReadBytes((int) settingLength); if (reader.BaseStream.Position%2 == 1) reader.ReadByte(); }
private void ReadTextLayer(BinaryReverseReader dataReader) { //文档 五 - 4 - 22) -d - 15 IsTextLayer = true; dataReader.Seek("/Text"); byte[] temp = dataReader.ReadBytes(4); Text = dataReader.ReadString();// ( true); dataReader.Seek("/Justification"); int justification = dataReader.ReadByte();// - 48; Justification = TextJustification.Left; if (justification == 1) { Justification = TextJustification.Right; } else if (justification == 2) { Justification = TextJustification.Center; } dataReader.Seek("/FontSize "); FontSize = dataReader.ReadFloat(); // read the font fill color dataReader.Seek("/FillColor"); dataReader.Seek("/Values [ "); float alpha = dataReader.ReadFloat(); dataReader.ReadByte(); float red = dataReader.ReadFloat(); dataReader.ReadByte(); float green = dataReader.ReadFloat(); dataReader.ReadByte(); float blue = dataReader.ReadFloat(); FillColor = new Color(red, green, blue, alpha); // read the font name dataReader.Seek("/FontSet "); dataReader.Seek("/Name"); FontName = dataReader.ReadString(); // read the warp style dataReader.Seek("warpStyle"); dataReader.Seek("warpStyle"); byte[] wrapBytes = dataReader.ReadBytes(3); int num13 = dataReader.ReadByte(); WarpStyle = string.Empty; for (; num13 > 0; --num13) { string str = WarpStyle + dataReader.ReadChar(); WarpStyle = str; } }
public PsdUnitFloat(BinaryReverseReader stream) { unit = Encoding.Default.GetString(stream.ReadBytes(4)); value = stream.ReadDouble(); }
private void LoadGlobalLayerMask(BinaryReverseReader reader) { Debug.WriteLine("LoadGlobalLayerMask started at " + reader.BaseStream.Position); uint maskLength = reader.ReadUInt32(); if (maskLength <= 0) return; GlobalLayerMaskData = reader.ReadBytes((int) maskLength); }
////////////////////////////////////////////////////////////////// internal void LoadPixelData(BinaryReverseReader reader) { Debug.WriteLine("Channel.LoadPixelData started at " + reader.BaseStream.Position.ToString()); m_data = reader.ReadBytes((int)Length); using (BinaryReverseReader readerImg = DataReader) { m_imageCompression = (ImageCompression)readerImg.ReadInt16(); m_bytesPerRow = 0; switch (m_layer.PsdFile.Depth) { case 1: m_bytesPerRow = ImageDecoder.BytesFromBits(m_layer.m_rect.Width); break; case 8: m_bytesPerRow = m_layer.m_rect.Width; break; case 16: m_bytesPerRow = m_layer.m_rect.Width * 2; break; } m_imageData = new byte[m_layer.m_rect.Height * m_bytesPerRow]; switch (m_imageCompression) { case ImageCompression.Raw: readerImg.Read(m_imageData, 0, m_imageData.Length); break; case ImageCompression.Rle: { m_rowLengthList = new uint[m_layer.m_rect.Height]; uint totalRleLength = 0; for (int i = 0; i < m_rowLengthList.Length; i++) { m_rowLengthList[i] = readerImg.ReadUInt16(); totalRleLength += m_rowLengthList[i]; } m_data = new byte[totalRleLength]; uint idxData = 0; for (int i = 0; i < m_layer.m_rect.Height; i++) { readerImg.Read(m_data, (int)idxData, (int)m_rowLengthList[i]); idxData += m_rowLengthList[i]; // The PSD specification states that rows are padded to even sizes. // However, PSD files generated by Photoshop CS4 do not actually // follow this stipulation. } } break; default: break; } } }
/// <summary> /// Initializes a new instance of the <see cref="Layer"/> class using the provided reader containing the PSD file data. /// </summary> /// <param name="reader">The reader containing the PSD file data.</param> /// <param name="psdFile">The PSD file to set as the parent.</param> public Layer(BinaryReverseReader reader, PsdFile psdFile) { Children = new List <Layer>(); PsdFile = psdFile; // read the rect Rect rect = new Rect(); rect.y = reader.ReadInt32(); rect.x = reader.ReadInt32(); rect.height = reader.ReadInt32() - rect.y; rect.width = reader.ReadInt32() - rect.x; Rect = rect; // read the channels int channelCount = reader.ReadUInt16(); Channels = new List <Channel>(); SortedChannels = new SortedList <short, Channel>(); for (int index = 0; index < channelCount; ++index) { Channel channel = new Channel(reader, this); Channels.Add(channel); SortedChannels.Add(channel.ID, channel); } // read the header and verify it if (new string(reader.ReadChars(4)) != "8BIM") { throw new IOException("Layer Channelheader error!"); } // read the blend mode key (unused) (defaults to "norm") reader.ReadChars(4); // read the opacity Opacity = reader.ReadByte(); // read the clipping (unused) (< 0 = base, > 0 = non base) reader.ReadByte(); // read all of the flags (protectTrans, visible, obsolete, ver5orLater, pixelDataIrrelevant) flags = new BitVector32(reader.ReadByte()); // skip a padding byte reader.ReadByte(); uint num3 = reader.ReadUInt32(); long position1 = reader.BaseStream.Position; MaskData = new Mask(reader, this); BlendingRangesData = new BlendingRanges(reader); long position2 = reader.BaseStream.Position; // read the name Name = reader.ReadPascalString(); // read the adjustment info int count = (int)((reader.BaseStream.Position - position2) % 4L); reader.ReadBytes(count); AdjustmentInfo = new List <AdjustmentLayerInfo>(); long num4 = position1 + num3; while (reader.BaseStream.Position < num4) { try { AdjustmentInfo.Add(new AdjustmentLayerInfo(reader, this)); } catch { reader.BaseStream.Position = num4; } } foreach (AdjustmentLayerInfo adjustmentLayerInfo in AdjustmentInfo) { if (adjustmentLayerInfo.Key == "TySh") { ReadTextLayer(adjustmentLayerInfo.DataReader); } else if (adjustmentLayerInfo.Key == "luni") { // read the unicode name BinaryReverseReader dataReader = adjustmentLayerInfo.DataReader; dataReader.ReadBytes(3); dataReader.ReadByte(); Name = dataReader.ReadString().TrimEnd(new char[1]); } } reader.BaseStream.Position = num4; }
////////////////////////////////////////////////////////////////// internal void LoadPixelData(BinaryReverseReader reader) { Debug.WriteLine("Channel.LoadPixelData started at " + reader.BaseStream.Position.ToString()); m_data = reader.ReadBytes((int)Length); using (BinaryReverseReader readerImg = DataReader) { m_imageCompression = (ImageCompression)readerImg.ReadInt16(); m_bytesPerRow = 0; switch (m_layer.PsdFile.Depth) { case 1: m_bytesPerRow = ImageDecoder.BytesFromBits(m_layer.m_rect.Width); break; case 8: m_bytesPerRow = m_layer.m_rect.Width; break; case 16: m_bytesPerRow = m_layer.m_rect.Width * 2; break; } m_imageData = new byte[m_layer.m_rect.Height * m_bytesPerRow]; switch (m_imageCompression) { case ImageCompression.Raw: readerImg.Read(m_imageData, 0, m_imageData.Length); break; case ImageCompression.Rle: { m_rowLengthList = new uint[m_layer.m_rect.Height]; uint totalRleLength = 0; for (int i = 0; i < m_rowLengthList.Length; i++) { m_rowLengthList[i] = readerImg.ReadUInt16(); totalRleLength += m_rowLengthList[i]; } m_data = new byte[totalRleLength]; uint idxData = 0; for (int i = 0; i < m_layer.m_rect.Height; i++) { readerImg.Read(m_data, (int)idxData, (int)m_rowLengthList[i]); idxData += m_rowLengthList[i]; // The PSD specification states that rows are padded to even sizes. // However, PSD files generated by Photoshop CS4 do not actually // follow this stipulation. } } break; default: break; } } }
public AdjusmentLayerInfo(BinaryReverseReader reader, Layer layer) { Debug.WriteLine("AdjusmentLayerInfo started at " + reader.BaseStream.Position); m_layer = layer; var signature = new string(reader.ReadChars(4)); if (signature != LayerConstants.EightBimSignature) { throw new IOException("Could not read an image resource"); } m_key = new string(reader.ReadChars(4)); uint dataLength = reader.ReadUInt32(); m_data = reader.ReadBytes((int) dataLength); }
/// <summary> /// Reads the global layer mask from the reader. /// </summary> /// <param name="reader">The reader to use to read the global layer mask.</param> private void LoadGlobalLayerMask(BinaryReverseReader reader) { uint num = reader.ReadUInt32(); if (num <= 0U) { return; } // read the global mask data reader.ReadBytes((int)num); }