Пример #1
0
        public static Bitmap DecodeImage(Layer.Mask mask)
        {
            Layer layer = mask.Layer;

            if (mask.Rect.Width == 0 || mask.Rect.Height == 0) return null;

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

            Parallel.For(0, layer.Rect.Height, y =>
            {
                Int32 rowIndex = y * layer.Rect.Width;

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

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

                    lock (bitmap)
                    {
                        bitmap.SetPixel(x, y, pixelColor);
                    }
                }
            });
            return bitmap;
        }
Пример #2
0
			internal Channel(Int16 id, Layer layer)
			{
				ID = id;
				Layer = layer;
				Layer.Channels.Add(this);
				Layer.SortedChannels.Add(ID, this);
			}
Пример #3
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);

            Parallel.For(0, layer.Rect.Height, y =>
            {
                Int32 rowIndex = y * layer.Rect.Width;

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

                    Color pixelColor = GetColor(layer, pos);

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

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

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

            return bitmap;
        }
Пример #4
0
			internal Channel(BinaryReverseReader reverseReader, Layer layer)
			{
				Debug.WriteLine("Channel started at " + reverseReader.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

				ID = reverseReader.ReadInt16();
				Length = reverseReader.ReadInt32();

				Layer = layer;
			}
Пример #5
0
			public BlendingRanges(BinaryReverseReader reader, Layer layer)
			{
				Data = new Byte[0];
				Debug.WriteLine("BlendingRanges started at " + reader.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

				Layer = layer;
				Int32 dataLength = reader.ReadInt32();
				if (dataLength <= 0) return;

				Data = reader.ReadBytes(dataLength);
			}
Пример #6
0
			public AdjusmentLayerInfo(BinaryReverseReader reader, Layer layer)
			{
				Debug.WriteLine("AdjusmentLayerInfo started at " + reader.BaseStream.Position.ToString(CultureInfo.InvariantCulture));

				Layer = layer;

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

				Key = new String(reader.ReadChars(4));

				UInt32 dataLength = reader.ReadUInt32();
				Data = reader.ReadBytes((Int32)dataLength);
			}
Пример #7
0
			public BlendingRanges(Layer layer)
			{
				Data = new Byte[0];
				Layer = layer;
				Layer.BlendingRangesData = this;
			}
Пример #8
0
			public AdjusmentLayerInfo(String key, Layer layer)
			{
				Key = key;
				Layer = layer;
				Layer.AdjustmentInfo.Add(this);
			}
Пример #9
0
		private static Int32 GetColor(Layer.Mask mask, Int32 x, Int32 y)
		{
			Int32 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)
			{
				Int32 pos = y * mask.Rect.Width + x;
				c = pos < mask.ImageData.Length ? mask.ImageData[pos] : 255;
			}

			return c;
		}
Пример #10
0
		private static Color GetColor(Layer layer, Int32 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:
					{
						Int32 index = layer.SortedChannels[0].ImageData[pos];
						c = Color.FromArgb(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;
		}