Beispiel #1
0
        public Channel(BinaryReverseReader reader, Layer layer)
        {
            this._usage = reader.ReadInt16();

            this._length = (long)reader.ReadUInt32();
            this._layer = layer;
        }
Beispiel #2
0
        public Mask(BinaryReverseReader reader, Layer layer)
        {
            this._layer = layer;

            int nLength = (int)reader.ReadUInt32();
            if (nLength == 0)
                return;

            long nStart = reader.BaseStream.Position;

            this.Rectangle = new ERectangle();
            this.Rectangle.Y = reader.ReadInt32();
            this.Rectangle.X = reader.ReadInt32();
            this.Rectangle.Height = reader.ReadInt32() - Rectangle.Y;
            this.Rectangle.Width = reader.ReadInt32() - Rectangle.X;

            byte color = reader.ReadByte();

            byte flags = reader.ReadByte();

            if (nLength == 36)
            {
                int someOtherFlags = reader.ReadByte();

                byte maskBg = reader.ReadByte();

                ERectangle rect = new ERectangle();
                rect.Y = reader.ReadInt32();
                rect.X = reader.ReadInt32();
                rect.Height = reader.ReadInt32() - rect.Y;
                rect.Width = reader.ReadInt32() - rect.X;
            }

            reader.BaseStream.Position = nStart + nLength;
        }
Beispiel #3
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();
        }