示例#1
0
            internal Mask(BinaryReverseReader reader, Layer layer)
            {
                Debug.WriteLine("Mask started at " + reader.BaseStream.Position.ToString());

                m_layer = layer;

                uint maskLength = reader.ReadUInt32();

                if (maskLength <= 0)
                    return;

                long startPosition = reader.BaseStream.Position;

                //-----------------------------------------------------------------------

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

                m_defaultColor = reader.ReadByte();

                //-----------------------------------------------------------------------

                byte flags = reader.ReadByte();
                m_flags = new BitVector32(flags);

                //-----------------------------------------------------------------------

                if (maskLength == 36)
                {
                    BitVector32 realFlags = new BitVector32(reader.ReadByte());

                    byte realUserMaskBackground = reader.ReadByte();

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

                // there is other stuff following, but we will ignore this.
                reader.BaseStream.Position = startPosition + maskLength;
            }
示例#2
0
 internal Mask(Layer layer)
 {
     m_layer = layer;
     m_layer.MaskData = this;
 }
示例#3
0
 internal Channel(short id, Layer layer)
 {
     m_id = id;
     m_layer = layer;
     m_layer.Channels.Add(this);
     m_layer.SortedChannels.Add(this.ID, this);
 }
示例#4
0
            internal Channel(BinaryReverseReader reader, Layer layer)
            {
                Debug.WriteLine("Channel started at " + reader.BaseStream.Position.ToString());

                m_id = reader.ReadInt16();
                Length = reader.ReadInt32();

                m_layer = layer;
            }
示例#5
0
            public BlendingRanges(BinaryReverseReader reader, Layer layer)
            {
                Debug.WriteLine("BlendingRanges started at " + reader.BaseStream.Position.ToString());

                m_layer = layer;
                int dataLength = reader.ReadInt32();
                if (dataLength <= 0)
                    return;

                m_data = reader.ReadBytes(dataLength);
            }
示例#6
0
 public BlendingRanges(Layer layer)
 {
     m_layer = layer;
     m_layer.BlendingRangesData = this;
 }
示例#7
0
 public AdjusmentLayerInfo(string key, Layer layer)
 {
     m_key = key;
     m_layer = layer;
     m_layer.AdjustmentInfo.Add(this);
 }
示例#8
0
            public AdjusmentLayerInfo(BinaryReverseReader reader, Layer layer)
            {
                Debug.WriteLine("AdjusmentLayerInfo started at " + reader.BaseStream.Position.ToString());

                m_layer = layer;

                string signature = new string(reader.ReadChars(4));
                if (signature != "8BIM")
                {
                    throw new IOException("Could not read an image resource");
                }

                m_key = new string(reader.ReadChars(4));

                uint dataLength = reader.ReadUInt32();
                m_data = reader.ReadBytes((int)dataLength);
            }
        private static int GetColor(Layer.Mask mask, int x, int y)
        {
            int c = 255;

            if (mask.PositionIsRelative)
            {
                x -= mask.Rect.X;
                y -= mask.Rect.Y;
            }
            else
            {
                x = (x + mask.Layer.Rect.X) - mask.Rect.X;
                y = (y + mask.Layer.Rect.Y) - mask.Rect.Y;
            }

            if (y >= 0 && y < mask.Rect.Height &&
                 x >= 0 && x < mask.Rect.Width)
            {
                int pos = y * mask.Rect.Width + x;
                if (pos < mask.ImageData.Length)
                    c = mask.ImageData[pos];
                else
                    c = 255;
            }

            return c;
        }
示例#10
0
        private static Color GetColor(Layer layer, int pos)
        {
            Color c = Color.White;

            switch (layer.PsdFile.ColorMode)
            {
                case PsdFile.ColorModes.RGB:
                    c = Color.FromArgb(layer.SortedChannels[0].ImageData[pos],
                                       layer.SortedChannels[1].ImageData[pos],
                                       layer.SortedChannels[2].ImageData[pos]);
                    break;
                case PsdFile.ColorModes.CMYK:
                    c = CMYKToRGB(layer.SortedChannels[0].ImageData[pos],
                                  layer.SortedChannels[1].ImageData[pos],
                                  layer.SortedChannels[2].ImageData[pos],
                                  layer.SortedChannels[3].ImageData[pos]);
                    break;
                case PsdFile.ColorModes.Multichannel:
                    c = CMYKToRGB(layer.SortedChannels[0].ImageData[pos],
                                  layer.SortedChannels[1].ImageData[pos],
                                  layer.SortedChannels[2].ImageData[pos],
                                  0);
                    break;
                case PsdFile.ColorModes.Grayscale:
                case PsdFile.ColorModes.Duotone:
                    c = Color.FromArgb(layer.SortedChannels[0].ImageData[pos],
                                       layer.SortedChannels[0].ImageData[pos],
                                       layer.SortedChannels[0].ImageData[pos]);
                    break;
                case PsdFile.ColorModes.Indexed:
                    {
                        int index = (int)layer.SortedChannels[0].ImageData[pos];
                        c = Color.FromArgb((int)layer.PsdFile.ColorModeData[index],
                                         layer.PsdFile.ColorModeData[index + 256],
                                         layer.PsdFile.ColorModeData[index + 2 * 256]);
                    }
                    break;
                case PsdFile.ColorModes.Lab:
                    {
                        c = LabToRGB(layer.SortedChannels[0].ImageData[pos],
                                     layer.SortedChannels[1].ImageData[pos],
                                     layer.SortedChannels[2].ImageData[pos]);
                    }
                    break;
            }

            if (layer.SortedChannels.ContainsKey(-1))
                c = Color.FromArgb(layer.SortedChannels[-1].ImageData[pos], c);

            return c;
        }
示例#11
0
        public static Bitmap DecodeImage(Layer.Mask mask)
        {
            if (mask.Rect.Width == 0 || mask.Rect.Height == 0)
            {
                return null;
            }

            Bitmap bitmap = new Bitmap(mask.Rect.Width, mask.Rect.Height, PixelFormat.Format32bppArgb);

            Rectangle r = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            BitmapData bd = bitmap.LockBits(r, ImageLockMode.ReadWrite, bitmap.PixelFormat);

            unsafe
            {
                byte* pCurrRowPixel = (byte*)bd.Scan0.ToPointer();

                for (int y = 0; y < mask.Rect.Height; y++)
                {
                    int rowIndex = y * mask.Rect.Width;
                    PixelData* pCurrPixel = (PixelData*)pCurrRowPixel;
                    for (int x = 0; x < mask.Rect.Width; x++)
                    {
                        int pos = rowIndex + x;

                        Color pixelColor = Color.FromArgb(mask.ImageData[pos], mask.ImageData[pos], mask.ImageData[pos]);

                        pCurrPixel->Alpha = 255;
                        pCurrPixel->Red = pixelColor.R;
                        pCurrPixel->Green = pixelColor.G;
                        pCurrPixel->Blue = pixelColor.B;

                        pCurrPixel += 1;
                    }
                    pCurrRowPixel += bd.Stride;
                }
            }

            bitmap.UnlockBits(bd);

            return bitmap;
        }
示例#12
0
        public static Bitmap DecodeImage(Layer layer)
        {
            if (layer.Rect.Width == 0 || layer.Rect.Height == 0)
                return null;

            Bitmap bitmap = new Bitmap(layer.Rect.Width, layer.Rect.Height, PixelFormat.Format32bppArgb);

#if TEST

      for (int y = 0; y < layer.Rect.Height; y++)
      {
        int rowIndex = y * layer.Rect.Width;

        for (int x = 0; x < layer.Rect.Width; x++)
        {
          int pos = rowIndex + x;

          //Color pixelColor=GetColor(psdFile,pos);
          Color pixelColor = Color.FromArgb(x % 255, Color.ForestGreen);// 255, 128, 0);

          bitmap.SetPixel(x, y, pixelColor);
        }
      }

#else

            Rectangle r = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            BitmapData bd = bitmap.LockBits(r, ImageLockMode.ReadWrite, bitmap.PixelFormat);

            unsafe
            {
                byte* pCurrRowPixel = (byte*)bd.Scan0.ToPointer();

                for (int y = 0; y < layer.Rect.Height; y++)
                {
                    int rowIndex = y * layer.Rect.Width;
                    PixelData* pCurrPixel = (PixelData*)pCurrRowPixel;
                    for (int x = 0; x < layer.Rect.Width; x++)
                    {
                        int pos = rowIndex + x;

                        Color pixelColor = GetColor(layer, pos);

                        if (layer.SortedChannels.ContainsKey(-2))
                        {
                            int maskAlpha = GetColor(layer.MaskData, x, y);
                            int oldAlpha = pixelColor.A;

                            int newAlpha = (oldAlpha * maskAlpha) / 255;
                            pixelColor = Color.FromArgb(newAlpha, pixelColor);
                        }

                        pCurrPixel->Alpha = pixelColor.A;
                        pCurrPixel->Red = pixelColor.R;
                        pCurrPixel->Green = pixelColor.G;
                        pCurrPixel->Blue = pixelColor.B;

                        pCurrPixel += 1;
                    }
                    pCurrRowPixel += bd.Stride;
                }
            }

            bitmap.UnlockBits(bd);
#endif

            return bitmap;
        }
示例#13
0
        ///////////////////////////////////////////////////////////////////////////

        public static Bitmap DecodeImage(Layer layer)
        {
            if (layer.Rect.Width == 0 || layer.Rect.Height == 0)
            {
                return(null);
            }

            Bitmap bitmap = new Bitmap(layer.Rect.Width, layer.Rect.Height, PixelFormat.Format32bppArgb);

#if TEST
            for (int y = 0; y < layer.Rect.Height; y++)
            {
                int rowIndex = y * layer.Rect.Width;

                for (int x = 0; x < layer.Rect.Width; x++)
                {
                    int pos = rowIndex + x;

                    //Color pixelColor=GetColor(psdFile,pos);
                    Color pixelColor = Color.FromArgb(x % 255, Color.ForestGreen);// 255, 128, 0);

                    bitmap.SetPixel(x, y, pixelColor);
                }
            }
#else
            Rectangle  r  = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            BitmapData bd = bitmap.LockBits(r, ImageLockMode.ReadWrite, bitmap.PixelFormat);

            unsafe
            {
                byte *pCurrRowPixel = (byte *)bd.Scan0.ToPointer();

                for (int y = 0; y < layer.Rect.Height; y++)
                {
                    int        rowIndex   = y * layer.Rect.Width;
                    PixelData *pCurrPixel = (PixelData *)pCurrRowPixel;
                    for (int x = 0; x < layer.Rect.Width; x++)
                    {
                        int pos = rowIndex + x;

                        Color pixelColor = GetColor(layer, pos);

                        if (layer.SortedChannels.ContainsKey(-2))
                        {
                            int maskAlpha = GetColor(layer.MaskData, x, y);
                            int oldAlpha  = pixelColor.A;

                            int newAlpha = (oldAlpha * maskAlpha) / 255;
                            pixelColor = Color.FromArgb(newAlpha, pixelColor);
                        }

                        pCurrPixel->Alpha = pixelColor.A;
                        pCurrPixel->Red   = pixelColor.R;
                        pCurrPixel->Green = pixelColor.G;
                        pCurrPixel->Blue  = pixelColor.B;

                        pCurrPixel += 1;
                    }
                    pCurrRowPixel += bd.Stride;
                }
            }

            bitmap.UnlockBits(bd);
#endif

            return(bitmap);
        }