Esempio n. 1
0
 public Layer(PsdFile psdFile)
 {
     AdjustmentInfo = new List <AdjusmentLayerInfo>();
     SortedChannels = new SortedList <Int16, Channel>();
     Channels       = new List <Channel>();
     Rect           = Rectangle.Empty;
     PsdFile        = psdFile;
 }
        private static Color GetColor(PsdFile psdFile, Int32 pos)
        {
            Color c = Color.White;

            byte red   = psdFile.ImageData[0][pos];
            byte green = psdFile.ImageData[1][pos];
            byte blue  = psdFile.ImageData[2][pos];

            byte alpha = 255;

            if (psdFile.ImageData.Length > 3)
            {
                alpha = psdFile.ImageData[3][pos];
            }

            switch (psdFile.ColorMode)
            {
            case PsdFile.ColorModes.RGB:
                c = Color.FromArgb(alpha, red, green, blue);
                break;

            case PsdFile.ColorModes.CMYK:
                c = CMYKToRGB(red, green, blue, alpha);
                break;

            case PsdFile.ColorModes.Multichannel:
                c = CMYKToRGB(red, green, blue, 0);
                break;

            case PsdFile.ColorModes.Grayscale:
            case PsdFile.ColorModes.Duotone:
                c = Color.FromArgb(red, red, red);
                break;

            case PsdFile.ColorModes.Indexed:
                Int32 index = red;
                c = Color.FromArgb(psdFile.ColorModeData[index], psdFile.ColorModeData[index + 256], psdFile.ColorModeData[index + 2 * 256]);
                break;

            case PsdFile.ColorModes.Lab:
                c = LabToRGB(red, green, blue);
                break;
            }

            return(c);
        }
Esempio n. 3
0
        private static Color GetColor(PsdFile psdFile, int pos)
        {
            var result = Color.White;
            var b      = psdFile.ImageData[0][pos];
            var b2     = psdFile.ImageData[1][pos];
            var b3     = psdFile.ImageData[2][pos];
            var b4     = byte.MaxValue;

            if (psdFile.ImageData.Length > 3)
            {
                b4 = psdFile.ImageData[3][pos];
            }
            switch (psdFile.ColorMode)
            {
            case PsdFile.ColorModes.Grayscale:
            case PsdFile.ColorModes.Duotone:
                result = Color.FromArgb(b, b, b);
                break;

            case PsdFile.ColorModes.Indexed:
            {
                var num = (int)b;
                result = Color.FromArgb(psdFile.ColorModeData[num], psdFile.ColorModeData[num + 256],
                                        psdFile.ColorModeData[num + 512]);
                break;
            }

            case PsdFile.ColorModes.RGB:
                result = Color.FromArgb(b4, b, b2, b3);
                break;

            case PsdFile.ColorModes.CMYK:
                result = CMYKToRGB(b, b2, b3, b4);
                break;

            case PsdFile.ColorModes.Multichannel:
                result = CMYKToRGB(b, b2, b3, 0);
                break;

            case PsdFile.ColorModes.Lab:
                result = LabToRGB(b, b2, b3);
                break;
            }
            return(result);
        }
Esempio n. 4
0
        public static Bitmap DecodeImage(PsdFile psdFile)
        {
            var bitmap = new Bitmap(psdFile.Columns, psdFile.Rows, PixelFormat.Format32bppArgb);

            Parallel.For(0, psdFile.Rows, delegate(int y)
            {
                var num = y * psdFile.Columns;
                for (var i = 0; i < psdFile.Columns; i++)
                {
                    var pos   = num + i;
                    var color = GetColor(psdFile, pos);
                    lock (bitmap)
                    {
                        bitmap.SetPixel(i, y, color);
                    }
                }
            });
            return(bitmap);
        }
Esempio n. 5
0
        private static Color GetColor(PsdFile psdFile, Int32 pos)
        {
            Color c = Color.White;

            switch (psdFile.ColorMode)
            {
            case PsdFile.ColorModes.RGB:
                c = Color.FromArgb(psdFile.ImageData[0][pos], psdFile.ImageData[1][pos], psdFile.ImageData[2][pos]);
                break;

            case PsdFile.ColorModes.CMYK:
                c = CMYKToRGB(psdFile.ImageData[0][pos], psdFile.ImageData[1][pos], psdFile.ImageData[2][pos], psdFile.ImageData[3][pos]);
                break;

            case PsdFile.ColorModes.Multichannel:
                c = CMYKToRGB(psdFile.ImageData[0][pos], psdFile.ImageData[1][pos], psdFile.ImageData[2][pos], 0);
                break;

            case PsdFile.ColorModes.Grayscale:
            case PsdFile.ColorModes.Duotone:
                c = Color.FromArgb(psdFile.ImageData[0][pos], psdFile.ImageData[0][pos], psdFile.ImageData[0][pos]);
                break;

            case PsdFile.ColorModes.Indexed:
            {
                Int32 index = psdFile.ImageData[0][pos];
                c = Color.FromArgb(psdFile.ColorModeData[index], psdFile.ColorModeData[index + 256], psdFile.ColorModeData[index + 2 * 256]);
            }
            break;

            case PsdFile.ColorModes.Lab:
                c = LabToRGB(psdFile.ImageData[0][pos], psdFile.ImageData[1][pos], psdFile.ImageData[2][pos]);
                break;
            }

            return(c);
        }
Esempio n. 6
0
        public static Bitmap DecodeImage(PsdFile psdFile)
        {
            Bitmap bitmap = new Bitmap(psdFile.Columns, psdFile.Rows, PixelFormat.Format32bppArgb);

            //Parallel load each row
            Parallel.For(0, psdFile.Rows, y =>
            {
                Int32 rowIndex = y * psdFile.Columns;

                for (Int32 x = 0; x < psdFile.Columns; x++)
                {
                    Int32 pos = rowIndex + x;

                    Color pixelColor = GetColor(psdFile, pos);

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

            return(bitmap);
        }
Esempio n. 7
0
		public static Bitmap DecodeImage(PsdFile psdFile)
		{
			Bitmap bitmap = new Bitmap(psdFile.Columns, psdFile.Rows, PixelFormat.Format32bppArgb);

			//Parallel load each row
			Parallel.For(0, psdFile.Rows, y =>
										  {
											  Int32 rowIndex = y * psdFile.Columns;

											  for (Int32 x = 0; x < psdFile.Columns; x++)
											  {
												  Int32 pos = rowIndex + x;

												  Color pixelColor = GetColor(psdFile, pos);

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

			return bitmap;
		}
Esempio n. 8
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;
        }
Esempio n. 9
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;
		}
Esempio n. 10
0
		public Layer(PsdFile psdFile)
		{
			AdjustmentInfo = new List<AdjusmentLayerInfo>();
			SortedChannels = new SortedList<Int16, Channel>();
			Channels = new List<Channel>();
			Rect = Rectangle.Empty;
			PsdFile = psdFile;
		}
Esempio n. 11
0
		private static Color GetColor(PsdFile psdFile, Int32 pos)
		{
			Color c = Color.White;

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

			return c;
		}