/////////////////////////////////////////////////////////////////////////// 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); 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); return bitmap; }
public void DrawLayer(Layer layer, GameObject parent) { throw new NotImplementedException(); }
/////////////////////////////////////////////////////////////////////////// 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; }
/////////////////////////////////////////////////////////////////////////// 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); 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; }
/////////////////////////////////////////////////////////////////////////// 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; }
/////////////////////////////////////////////////////////////////////////// internal Mask(Layer layer) { m_layer = layer; m_layer.MaskData = this; }
/////////////////////////////////////////////////////////////////////////// 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; }
////////////////////////////////////////////////////////////////// internal Channel(short id, Layer layer) { Id = id; _layer = layer; _layer.Channels.Add(this); _layer.SortedChannels.Add(this.Id, this); }
internal Channel(BinaryReverseReader reader, Layer layer) { Debug.WriteLine("Channel started at " + reader.BaseStream.Position); Id = reader.ReadInt16(); Length = reader.ReadInt32(); _layer = layer; }
/////////////////////////////////////////////////////////////////////////// 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); }
/////////////////////////////////////////////////////////////////////////// public BlendingRanges(Layer layer) { m_layer = layer; m_layer.BlendingRangesData = this; }
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); }
public AdjusmentLayerInfo(string key, Layer layer) { m_key = key; m_layer = layer; m_layer.AdjustmentInfo.Add(this); }
public static void Flatten(this Layer layer, Layer destinationLayer, Color[] layerData0, Color[] layerData1) { for (int i = 0; i < layerData1.Length; i++) layerData1[i] = Blend(layerData0[i], layerData1[i]); }