public CopyrightInfo(ImageResource imgRes) { BinaryReverseReader reader = imgRes.GetDataReader(); this.Copyrighted = reader.ReadByte() == 0?false:true; reader.Close(); }
/// <summary> /// Initializes a new instance of the <see cref="ResolutionInfo"/> class using the <see cref="ImageResource"/>. /// </summary> /// <param name="imgRes">The image resource to use.</param> public ResolutionInfo(ImageResource imgRes) : base(imgRes) { BinaryReverseReader dataReader = imgRes.DataReader; // read horizontal resolution dataReader.ReadInt16(); // read horizontal resolution units (1=pixels per inch, 2=pixels per centimeter) dataReader.ReadInt32(); // read the width units (1=inches, 2=cm, 3=pt, 4=picas, 5=columns) dataReader.ReadInt16(); // read vertical resolution dataReader.ReadInt16(); // read vertical resolution units (1=pixels per inch, 2=pixels per centimeter) dataReader.ReadInt32(); // read the height units (1=inches, 2=cm, 3=pt, 4=picas, 5=columns) dataReader.ReadInt16(); dataReader.Close(); }
public ResolutionInfo(ImageResource imgRes) : base(imgRes) { //m_bResolutionInfoFilled = true; BinaryReverseReader reader = imgRes.GetDataReader(); this.hRes = reader.ReadInt16(); this.hResUnit = reader.ReadInt32(); this.widthUnit = reader.ReadInt16(); this.vRes = reader.ReadInt16(); this.vResUnit = reader.ReadInt32(); this.heightUnit = reader.ReadInt16(); reader.Close(); //int ppm_x = 3780; // 96 dpi //int ppm_y = 3780; // 96 dpi //if (psd.ResolutionInfo != null) //{ // int nHorzResolution = (int)psd.ResolutionInfo.hRes; // int nVertResolution = (int)psd.ResolutionInfo.vRes; // ppm_x = (nHorzResolution * 10000) / 254; // ppm_y = (nVertResolution * 10000) / 254; //} }
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(); }
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(); }
/// <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(); }
public ResolutionInfo(ImageResource imgRes) : base(imgRes) { //文档 四 - 1 ID 1005 BinaryReverseReader dataReader = imgRes.DataReader; //这里解析是错的, 但解的字节数没错,反正这些数据没用,就没修改了,要用的时候参考文档修改 dataReader.ReadInt16(); dataReader.ReadInt32(); dataReader.ReadInt16(); dataReader.ReadInt16(); dataReader.ReadInt32(); dataReader.ReadInt16(); dataReader.Close(); }
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 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 Bevel(Effect effect) : base(effect) { BinaryReverseReader reader = base.GetDataReader(); this.Angle = reader.ReadUInt32(); this.Strength = reader.ReadUInt32(); this.Blur = reader.ReadUInt32(); this.BlendModeSignature = reader.ReadUInt32(); this.BlendModeKey = reader.ReadUInt32(); this.ShadowBlendModeSignature = reader.ReadUInt32(); this.ShadowBlendModeKey = reader.ReadUInt32(); this.Color = this.ReadColorWithAlpha(reader); this.ShadowColor = this.ReadColorWithAlpha(reader); this.Enabled = reader.ReadBoolean(); this.UseGlobalAngle = reader.ReadBoolean(); this.Inverted = reader.ReadBoolean(); reader.Close(); }
public Document(string a_sFilename) { FileStream stream = new FileStream(a_sFilename, FileMode.Open, FileAccess.Read); //stream. BinaryReverseReader reader = new BinaryReverseReader(stream); //, System.Text.Encoding.UTF8); //System.Text.Encoding.BigEndianUnicode); string signature = new string(reader.ReadChars(4)); if (signature != "8BPS") return; #region Header this.Version = reader.ReadUInt16(); if (Version != 1) throw new Exception("Can not read .psd version " + Version); byte[] buf = new byte[256]; reader.Read(buf, (int)reader.BaseStream.Position, 6); //6 bytes reserved this.Channels = reader.ReadInt16(); this.Rows = reader.ReadUInt32(); this.Columns = reader.ReadUInt32(); this.BitsPerPixel = (int)reader.ReadUInt16(); this.ColorMode = (ColorModes)reader.ReadInt16(); #endregion #region Palette uint nPaletteLength = reader.ReadUInt32(); if (nPaletteLength > 0) { this.ColorData = reader.ReadBytes((int)nPaletteLength); if (this.ColorMode == ColorModes.Duotone) { } else { } } #endregion #region ImageResource section uint nResLength = reader.ReadUInt32(); ResourceIDs resID = ResourceIDs.Undefined; if (nResLength > 0) { //read settings while (true) { long nBefore = reader.BaseStream.Position; string settingSignature = new string(reader.ReadChars(4)); if (settingSignature != "8BIM") { reader.BaseStream.Position = nBefore; //TODO: it SHOULD be 4 bytes back - but sometimes ReadChars(4) advances 5 positions. WHY?!? // reader.BaseStream.Position-=4; break; } ImageResource imgRes = new ImageResource(reader); resID = (ResourceIDs)imgRes.ID; switch (resID) //imgRes.ID) { case ResourceIDs.ResolutionInfo: this.ResolutionInfo = new Endogine.Serialization.Photoshop.ImageResources.ResolutionInfo(imgRes); break; case ResourceIDs.DisplayInfo: ImageResources.DisplayInfo displayInfo = new Endogine.Serialization.Photoshop.ImageResources.DisplayInfo(imgRes); break; case ResourceIDs.CopyrightInfo: ImageResources.CopyrightInfo copyright = new Endogine.Serialization.Photoshop.ImageResources.CopyrightInfo(imgRes); break; case ResourceIDs.Thumbnail1: case ResourceIDs.Thumbnail2: ImageResources.Thumbnail thumbnail = new Endogine.Serialization.Photoshop.ImageResources.Thumbnail(imgRes); break; case ResourceIDs.GlobalAngle: //m_nGlobalAngle = reader.ReadInt32(); break; case ResourceIDs.IndexedColorTableCount: this.NumColors = reader.ReadInt16(); break; case ResourceIDs.TransparentIndex: //m_nTransparentIndex = reader.ReadInt16(); break; case ResourceIDs.Slices://Slices. What's that..? //Leftlong, Botmlong etc etc break; case ResourceIDs.XMLInfo: break; case ResourceIDs.Unknown: //Seems to be very common... break; } } } #endregion if (resID == ResourceIDs.Unknown4) { //it seems this one is } //reader.JumpToEvenNthByte(4); int nTotalLayersBytes = reader.ReadInt32(); long nAfterLayersDefinitions = reader.BaseStream.Position + nTotalLayersBytes; //TODO: ?? if (nTotalLayersBytes == 8) stream.Position+=nTotalLayersBytes; uint nSize = reader.ReadUInt32(); long nLayersEndPos = reader.BaseStream.Position + nSize; short nNumLayers = reader.ReadInt16(); bool bSkipFirstAlpha = false; if (nNumLayers < 0) { bSkipFirstAlpha = true; nNumLayers = (short)-nNumLayers; } List<Layer> loadOrderLayers = new List<Layer>(); this._layers = new Dictionary<int, Layer>(); for (int nLayerNum = 0; nLayerNum < nNumLayers; nLayerNum++) { Layer layerInfo = new Layer(reader, this); if (this._layers.ContainsKey(layerInfo.LayerID)) throw(new Exception("Duplicate layer IDs! " + layerInfo.LayerID.ToString())); else this._layers.Add(layerInfo.LayerID, layerInfo); loadOrderLayers.Add(layerInfo); } //I have no idea what this is: // ushort nWhat = reader.ReadUInt16(); // reader.BaseStream.Position+=(long)this.Header.Rows*2*2; //this.Header.Channels; //*bitsperpixel for (int layerNum = 0; layerNum < nNumLayers; layerNum++) { Layer layer = (Layer)loadOrderLayers[layerNum]; layer.ReadPixels(reader); } reader.BaseStream.Position = nAfterLayersDefinitions; if (false) { //the big merged bitmap (which is how the photoshop document looked when it was saved) //TODO: read! //Bitmap bmp = null; //if (bmp != null) //{ // Sprite sp = new Sprite(); // MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); // sp.Member = mb; //} } reader.Close(); stream.Close(); }
public Document(string a_sFilename) { FileStream stream = new FileStream(a_sFilename, FileMode.Open, FileAccess.Read); //stream. BinaryReverseReader reader = new BinaryReverseReader(stream); //, System.Text.Encoding.UTF8); //System.Text.Encoding.BigEndianUnicode); string signature = new string(reader.ReadChars(4)); if (signature != "8BPS") { return; } #region Header this.Version = reader.ReadUInt16(); if (Version != 1) { throw new Exception("Can not read .psd version " + Version); } byte[] buf = new byte[256]; reader.Read(buf, (int)reader.BaseStream.Position, 6); //6 bytes reserved this.Channels = reader.ReadInt16(); this.Rows = reader.ReadUInt32(); this.Columns = reader.ReadUInt32(); this.BitsPerPixel = (int)reader.ReadUInt16(); this.ColorMode = (ColorModes)reader.ReadInt16(); #endregion #region Palette uint nPaletteLength = reader.ReadUInt32(); if (nPaletteLength > 0) { this.ColorData = reader.ReadBytes((int)nPaletteLength); if (this.ColorMode == ColorModes.Duotone) { } else { } } #endregion #region ImageResource section uint nResLength = reader.ReadUInt32(); ResourceIDs resID = ResourceIDs.Undefined; if (nResLength > 0) { //read settings while (true) { long nBefore = reader.BaseStream.Position; string settingSignature = new string(reader.ReadChars(4)); if (settingSignature != "8BIM") { reader.BaseStream.Position = nBefore; //TODO: it SHOULD be 4 bytes back - but sometimes ReadChars(4) advances 5 positions. WHY?!? // reader.BaseStream.Position-=4; break; } ImageResource imgRes = new ImageResource(reader); resID = (ResourceIDs)imgRes.ID; switch (resID) //imgRes.ID) { case ResourceIDs.ResolutionInfo: this.ResolutionInfo = new Endogine.Serialization.Photoshop.ImageResources.ResolutionInfo(imgRes); break; case ResourceIDs.DisplayInfo: ImageResources.DisplayInfo displayInfo = new Endogine.Serialization.Photoshop.ImageResources.DisplayInfo(imgRes); break; case ResourceIDs.CopyrightInfo: ImageResources.CopyrightInfo copyright = new Endogine.Serialization.Photoshop.ImageResources.CopyrightInfo(imgRes); break; case ResourceIDs.Thumbnail1: case ResourceIDs.Thumbnail2: ImageResources.Thumbnail thumbnail = new Endogine.Serialization.Photoshop.ImageResources.Thumbnail(imgRes); break; case ResourceIDs.GlobalAngle: //m_nGlobalAngle = reader.ReadInt32(); break; case ResourceIDs.IndexedColorTableCount: this.NumColors = reader.ReadInt16(); break; case ResourceIDs.TransparentIndex: //m_nTransparentIndex = reader.ReadInt16(); break; case ResourceIDs.Slices: //Slices. What's that..? //Leftlong, Botmlong etc etc break; case ResourceIDs.XMLInfo: break; case ResourceIDs.Unknown: //Seems to be very common... break; } } } #endregion if (resID == ResourceIDs.Unknown4) { //it seems this one is } //reader.JumpToEvenNthByte(4); int nTotalLayersBytes = reader.ReadInt32(); long nAfterLayersDefinitions = reader.BaseStream.Position + nTotalLayersBytes; //TODO: ?? if (nTotalLayersBytes == 8) { stream.Position += nTotalLayersBytes; } uint nSize = reader.ReadUInt32(); long nLayersEndPos = reader.BaseStream.Position + nSize; short nNumLayers = reader.ReadInt16(); bool bSkipFirstAlpha = false; if (nNumLayers < 0) { bSkipFirstAlpha = true; nNumLayers = (short)-nNumLayers; } List <Layer> loadOrderLayers = new List <Layer>(); this._layers = new Dictionary <int, Layer>(); for (int nLayerNum = 0; nLayerNum < nNumLayers; nLayerNum++) { Layer layerInfo = new Layer(reader, this); if (this._layers.ContainsKey(layerInfo.LayerID)) { throw(new Exception("Duplicate layer IDs! " + layerInfo.LayerID.ToString())); } else { this._layers.Add(layerInfo.LayerID, layerInfo); } loadOrderLayers.Add(layerInfo); } //I have no idea what this is: // ushort nWhat = reader.ReadUInt16(); // reader.BaseStream.Position+=(long)this.Header.Rows*2*2; //this.Header.Channels; //*bitsperpixel for (int layerNum = 0; layerNum < nNumLayers; layerNum++) { Layer layer = (Layer)loadOrderLayers[layerNum]; layer.ReadPixels(reader); } reader.BaseStream.Position = nAfterLayersDefinitions; if (false) { //the big merged bitmap (which is how the photoshop document looked when it was saved) //TODO: read! //Bitmap bmp = null; //if (bmp != null) //{ // Sprite sp = new Sprite(); // MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp); // sp.Member = mb; //} } reader.Close(); stream.Close(); }