Пример #1
0
        public TypeToolTyShPH6(BinaryReverseReader r)
        {
            ushort Version = r.ReadUInt16(); //1= Photoshop 5.0

            this.Transform = new Matrix2D(r);

            ushort TextDescriptorVersion = r.ReadUInt16(); //=50. For Photoshop 6.0.

            if (TextDescriptorVersion == 50)
            {
                uint XTextDescriptorVersion = r.ReadUInt32(); //=16. For Photoshop 6.0.

                this.TxtDescriptor = new PsdDescriptor(r);

                ushort WarpVersion           = r.ReadUInt16(); //2 bytes, =1. For Photoshop 6.0.
                uint   WarpDescriptorVersion = r.ReadUInt32(); //4 bytes, =16. For Photoshop 6.0.
                var    a = (PsdTextData)TxtDescriptor.getObjects()["EngineData"];
                engine           = (object)a.getProperties();
                engineData       = (Dictionary <string, object>)engine;
                StylesheetReader = new TdTaStylesheetReader(engineData);

                //string desc = this.TxtDescriptor.getString();

                this.WarpDescriptor = new PsdDescriptor(r);           //Warp descriptor
                this.Data           = r.ReadBytes((int)r.BytesToEnd); //17 bytes???? All zeroes?
                if (Data.Length != 17 || !(Array.TrueForAll(Data, b => b == 0)))
                {
                    string s = ReadableBinary.CreateHexEditorString(Data);
                }
            }
        }
Пример #2
0
 public Color ReadColor(BinaryReverseReader reader)
 {
     reader.BaseStream.Position+=2; //padding
     ushort r = reader.ReadUInt16();
     ushort g = reader.ReadUInt16();
     ushort b = reader.ReadUInt16();
     return Color.FromArgb((int)r,(int)g,(int)b);
 }
Пример #3
0
        public Color ReadColor(BinaryReverseReader reader)
        {
            reader.BaseStream.Position += 2;           //padding
            ushort r = reader.ReadUInt16();
            ushort g = reader.ReadUInt16();
            ushort b = reader.ReadUInt16();

            return(Color.FromArgb((int)r, (int)g, (int)b));
        }
Пример #4
0
        public Shadow(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;

            int version = r.ReadInt32();

            switch (version)
            {
            case 0:
                this.Blur      = r.ReadUInt32();
                this.Intensity = r.ReadUInt32();

                this.Angle    = r.ReadUInt32();
                this.Distance = r.ReadUInt32();

                this.Color = r.ReadPSDColor(16, true);

                this.BlendModeKey = this.ReadBlendKey(r);
                //this.BlendModeSignature = r.ReadUInt32();
                //this.BlendModeKey = r.ReadUInt32();
                this.Enabled        = r.ReadBoolean();
                this.UseGlobalAngle = r.ReadBoolean();
                this.Opacity        = r.ReadByte();
                break;

            case 2:
                this.Blur      = (uint)r.ReadUInt16();
                this.Intensity = r.ReadUInt32();

                this.Angle    = r.ReadUInt32();
                this.Distance = r.ReadUInt32();

                ushort something = r.ReadUInt16();    //TODO:?

                this.Color = r.ReadPSDColor(16, true);

                this.BlendModeKey   = this.ReadBlendKey(r);
                this.Enabled        = r.ReadBoolean();
                this.UseGlobalAngle = r.ReadBoolean();
                this.Opacity        = r.ReadByte();
                //TODO: 10 unknown bytes!
                break;
            }

            this.Data = null;
        }
Пример #5
0
        public Bevel(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();

            switch (version)
            {
            case 0:
                this.Blur = r.ReadUInt32();
                this.Data = null;
                break;

            case 2:
                this.Angle    = (uint)r.ReadUInt16();
                this.Strength = (uint)r.ReadUInt16();
                this.Blur     = (uint)r.ReadUInt16();

                this.Unknown1 = r.ReadByte();
                this.Unknown2 = r.ReadByte();
                this.Unknown3 = r.ReadUInt16();
                this.Unknown4 = r.ReadUInt16();

                this.BlendModeKey       = this.ReadBlendKey(r);
                this.ShadowBlendModeKey = this.ReadBlendKey(r);

                this.Color       = r.ReadPSDColor(16, true);
                this.ShadowColor = r.ReadPSDColor(16, true);

                this.BevelStyle    = r.ReadByte();
                this.Opacity       = r.ReadByte();
                this.ShadowOpacity = r.ReadByte();

                this.Enabled        = r.ReadBoolean();
                this.UseGlobalAngle = r.ReadBoolean();
                this.Inverted       = r.ReadBoolean();

                System.Drawing.Color someColor  = r.ReadPSDColor(16, true);
                System.Drawing.Color someColor2 = r.ReadPSDColor(16, true);
                break;
            }
            this.Data = null;
        }
Пример #6
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());
                }
            }
Пример #7
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();
 }
Пример #8
0
        public TypeToolObject(PhotoshopFile.Layer.AdjustmentLayerInfo info)
        {
            this.m_data  = info.Data;
            this.m_key   = info.Key;
            this.m_layer = info.Layer;

            BinaryReverseReader r = this.DataReader;

            ushort PhotshopVersion = r.ReadUInt16();   //2 bytes, =1 Photoshop 6 (not 5)

            this.Transform = new Matrix2D(r);          //six doubles (48 bytes)

            ushort TextVersion       = r.ReadUInt16(); //2 bytes, =50. For Photoshop 6.0.
            uint   DescriptorVersion = r.ReadUInt32(); //4 bytes,=16. For Photoshop 6.0.


            this.TxtDescriptor = DynVal.ReadDescriptor(r); //Text descriptor

            ushort WarpVersion           = r.ReadUInt16(); //2 bytes, =1. For Photoshop 6.0.
            uint   WarpDescriptorVersion = r.ReadUInt32(); //4 bytes, =16. For Photoshop 6.0.

            engineData       = (Dictionary <string, object>)TxtDescriptor.Children.Find(c => c.Name == "EngineData").Value;
            StylesheetReader = new TdTaStylesheetReader(engineData);

            //string desc = this.TxtDescriptor.getString();

            this.WarpDescriptor = DynVal.ReadDescriptor(r);       //Warp descriptor
            this.Data           = r.ReadBytes((int)r.BytesToEnd); //17 bytes???? All zeroes?
            if (Data.Length != 17 || !(Array.TrueForAll(Data, b => b == 0)))
            {
                string s = ReadableBinary.CreateHexEditorString(Data);
                Debug.Write(s);
            }

            //this.WarpRect = new RectangleF();
            //WarpRect.X = (float)r.ReadDouble();
            //WarpRect.Y = (float)r.ReadDouble();
            //this.Data.
            //WarpRect.Width = (float)r.ReadDouble() - WarpRect.X;
            //WarpRect.Height = (float)r.ReadDouble() - WarpRect.Y;

            //this.Data = r.ReadBytes((int)r.BytesToEnd);
        }
Пример #9
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();
            }
        }
Пример #10
0
        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;
            }
        }
Пример #11
0
        public Effects(PhotoshopFile.Layer.AdjustmentLayerInfo info)
        {
            this.m_data  = info.Data;
            this.m_key   = info.Key;
            this.m_layer = info.Layer;

            BinaryReverseReader r = this.DataReader;

            r.BaseStream.Position += 2; //unused
            ushort nNumEffects = r.ReadUInt16();

            this._resources = new Dictionary <string, PhotoshopFile.Layer.AdjustmentLayerInfo>();
            for (int nEffectNum = 0; nEffectNum < nNumEffects; nEffectNum++)
            {
                PhotoshopFile.Layer.AdjustmentLayerInfo res = new PhotoshopFile.Layer.AdjustmentLayerInfo(r, info.Layer);
                //if (res.Tag != "cmnS")
                //  continue;
                this._resources.Add(res.Key, res);
                //    case "sofi": //unknown
            }

            this.Data = null;
        }
Пример #12
0
        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();
        }
Пример #13
0
        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);
        }
Пример #14
0
        public override Endogine.ColorEx.Palette Load(string filename)
        {
            Serialization.BinaryReverseReader reader = new BinaryReverseReader(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            //Serialization.BinaryReaderEx reader = new BinaryReaderEx(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            ushort version = reader.ReadUInt16();
            ushort numColors = reader.ReadUInt16();

            if (version > 2)
            {
                throw new Exception("Can't parse .ACO palettes with version > 2: "+filename);
            }

            Endogine.ColorEx.Palette palette = new Endogine.ColorEx.Palette();
            for (int colorNum = 0; colorNum < numColors; colorNum++)
            {
                ushort colorSpaceId = reader.ReadUInt16();

                ushort[] vals = new ushort[4];
                for (int i = 0; i < 4; i++)
                    vals[i] = reader.ReadUInt16();

                string name = colorNum.ToString();
                if (version == 2)
                {
                    reader.ReadUInt16(); //padded
                    int nameLength = reader.ReadUInt16();

                    if (reader.BaseStream.Position % 2 == 1) // ?
                        reader.ReadUInt16(); //padded

                    for (int letterNum = 0; letterNum < nameLength; letterNum++)
                    {
                        char c = (char)reader.ReadUInt16();
                        name+=c.ToString();
                    }
                }

                ColorEx.ColorBase color;
                //TODO; uses 16 bits per channel, but here I truncate it to 8 bits
                switch (colorSpaceId)
                {
                    case 0: //RGB
                        ColorEx.ColorRgb rgb = new Endogine.ColorEx.ColorRgb();
                        rgb.R = vals[0] / 256;
                        rgb.G = vals[1] / 256;
                        rgb.B = vals[2] / 256;
                        color = rgb;
                        break;
                    case 1: //HSB
                        ColorEx.ColorHsb hsb = new Endogine.ColorEx.ColorHsb();
                        hsb.H = (float)vals[0] / 182.04f;
                        hsb.S = (float)vals[1] / 655.35f / 100f;
                        hsb.B = (float)vals[2] / 655.35f / 100f;
                        color = hsb;
                        break;
                    case 2: //CMYK
                        ColorEx.ColorCmyk cmyk = new Endogine.ColorEx.ColorCmyk();
                        cmyk.C = (float)vals[0] / 256;
                        cmyk.M = (float)vals[1] / 256;
                        cmyk.Y = (float)vals[2] / 256;
                        cmyk.K = (float)vals[3] / 256;
                        color = cmyk;
                        break;
                    case 7: //Lab
                        float[] ab = new float[2];
                        for (int i = 1; i < 3; i++)
                        {
                            if (vals[i] <= 12000) ab[i - 1] = (float)vals[i] / 100;
                            else ab[i - 1] = (float)(65536 - vals[i]) / 100;
                        }
                        ColorEx.ColorLab lab = new Endogine.ColorEx.ColorLab();
                        lab.L = (float)vals[0]/100;
                        lab.a = vals[1];
                        lab.b = vals[2];
                        //Angle:2, Observer:D65
                        color = lab;
                        break;
                    case 8: //Grayscale
                        ColorEx.ColorRgb rgbGray = new Endogine.ColorEx.ColorRgb();
                        int gray = (int)((float)vals[0] / 39.0625f);
                        rgbGray.R = gray;
                        rgbGray.G = gray;
                        rgbGray.B = gray;
                        color = rgbGray;
                        break;
                    case 9: //Wide CMYK
                    default:
                        throw new Exception("Can't read colorspace "+colorSpaceId+" in "+filename);
                }
                palette.Add(name, color);
            }
            return palette;
        }
Пример #15
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;
		}
Пример #16
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
            }
        }
Пример #17
0
        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);
        }
Пример #18
0
        public override Endogine.ColorEx.Palette Load(string filename)
        {
            Serialization.BinaryReverseReader reader = new BinaryReverseReader(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            //Serialization.BinaryReaderEx reader = new BinaryReaderEx(new System.IO.FileStream(filename, System.IO.FileMode.Open));
            ushort version   = reader.ReadUInt16();
            ushort numColors = reader.ReadUInt16();

            if (version > 2)
            {
                throw new Exception("Can't parse .ACO palettes with version > 2: " + filename);
            }

            Endogine.ColorEx.Palette palette = new Endogine.ColorEx.Palette();
            for (int colorNum = 0; colorNum < numColors; colorNum++)
            {
                ushort colorSpaceId = reader.ReadUInt16();

                ushort[] vals = new ushort[4];
                for (int i = 0; i < 4; i++)
                {
                    vals[i] = reader.ReadUInt16();
                }

                string name = colorNum.ToString();
                if (version == 2)
                {
                    reader.ReadUInt16(); //padded
                    int nameLength = reader.ReadUInt16();

                    if (reader.BaseStream.Position % 2 == 1) // ?
                    {
                        reader.ReadUInt16();                 //padded
                    }
                    for (int letterNum = 0; letterNum < nameLength; letterNum++)
                    {
                        char c = (char)reader.ReadUInt16();
                        name += c.ToString();
                    }
                }

                ColorEx.ColorBase color;
                //TODO; uses 16 bits per channel, but here I truncate it to 8 bits
                switch (colorSpaceId)
                {
                case 0:     //RGB
                    ColorEx.ColorRgb rgb = new Endogine.ColorEx.ColorRgb();
                    rgb.R = vals[0] / 256;
                    rgb.G = vals[1] / 256;
                    rgb.B = vals[2] / 256;
                    color = rgb;
                    break;

                case 1:     //HSB
                    ColorEx.ColorHsb hsb = new Endogine.ColorEx.ColorHsb();
                    hsb.H = (float)vals[0] / 182.04f;
                    hsb.S = (float)vals[1] / 655.35f / 100f;
                    hsb.B = (float)vals[2] / 655.35f / 100f;
                    color = hsb;
                    break;

                case 2:     //CMYK
                    ColorEx.ColorCmyk cmyk = new Endogine.ColorEx.ColorCmyk();
                    cmyk.C = (float)vals[0] / 256;
                    cmyk.M = (float)vals[1] / 256;
                    cmyk.Y = (float)vals[2] / 256;
                    cmyk.K = (float)vals[3] / 256;
                    color  = cmyk;
                    break;

                case 7:     //Lab
                    float[] ab = new float[2];
                    for (int i = 1; i < 3; i++)
                    {
                        if (vals[i] <= 12000)
                        {
                            ab[i - 1] = (float)vals[i] / 100;
                        }
                        else
                        {
                            ab[i - 1] = (float)(65536 - vals[i]) / 100;
                        }
                    }
                    ColorEx.ColorLab lab = new Endogine.ColorEx.ColorLab();
                    lab.L = (float)vals[0] / 100;
                    lab.a = vals[1];
                    lab.b = vals[2];
                    //Angle:2, Observer:D65
                    color = lab;
                    break;

                case 8:     //Grayscale
                    ColorEx.ColorRgb rgbGray = new Endogine.ColorEx.ColorRgb();
                    int gray = (int)((float)vals[0] / 39.0625f);
                    rgbGray.R = gray;
                    rgbGray.G = gray;
                    rgbGray.B = gray;
                    color     = rgbGray;
                    break;

                case 9:     //Wide CMYK
                default:
                    throw new Exception("Can't read colorspace " + colorSpaceId + " in " + filename);
                }
                palette.Add(name, color);
            }
            return(palette);
        }
Пример #19
0
        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();
        }
Пример #20
0
        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();
        }
Пример #21
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
            }
        }
Пример #22
0
        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();
        }