Example #1
0
            public FontInfo(BinaryReverseReader r)
            {
                this.Mark           = r.ReadUInt16();
                this.FontType       = r.ReadUInt32();
                this.FontName       = r.ReadPascalString();
                this.FontFamilyName = r.ReadPascalString();
                this.FontStyleName  = r.ReadPascalString();
                this.Script         = r.ReadUInt16();

                ushort NumDesignAxesVectors = r.ReadUInt16();

                this.DesignVectors = new List <uint>();
                for (int vectorNum = 0; vectorNum < NumDesignAxesVectors; vectorNum++)
                {
                    this.DesignVectors.Add(r.ReadUInt32());
                }
            }
Example #2
0
 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();
 }
Example #3
0
        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();
            }
        }
Example #4
0
        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
            }
        }
Example #5
0
        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 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();
		}
Example #7
0
		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;
		}