コード例 #1
0
ファイル: ImageDecoder.cs プロジェクト: HaKDMoDz/eStd
		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;
		}
コード例 #2
0
ファイル: Layer.cs プロジェクト: HaKDMoDz/eStd
		public Layer(PsdFile psdFile)
		{
			AdjustmentInfo = new List<AdjusmentLayerInfo>();
			SortedChannels = new SortedList<Int16, Channel>();
			Channels = new List<Channel>();
			Rect = Rectangle.Empty;
			PsdFile = psdFile;
		}
コード例 #3
0
ファイル: Layer.cs プロジェクト: HaKDMoDz/eStd
		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;
		}
コード例 #4
0
ファイル: ImageDecoder.cs プロジェクト: HaKDMoDz/eStd
		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;
		}