コード例 #1
0
        ///////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Returns the alpha value of the mask at the specified coordinates
        /// </summary>
        /// <param name="mask"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private static int GetMaskValue(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);
        }
コード例 #2
0
        ///////////////////////////////////////////////////////////////////////////

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

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

#if true // fix remove unsafeness (admittedly slower)
            // TODO: fast mode
            for (var y = 0; y < mask.Rect.Height; y++)
            {
                var rowIndex = y * mask.Rect.Width;
                for (var x = 0; x < mask.Rect.Width; x++)
                {
                    var pos = rowIndex + x;

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

                    // TODO: why is alpha ignored
                    bitmap.SetPixel(x, y, Color.FromArgb(255, pixelColor));
                }
            }
#else
            Layer      layer = mask.Layer;
            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);
#endif

            return(bitmap);
        }
コード例 #3
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);

            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);
        }
コード例 #4
0
 public LayerWrapper(Layer l)
 {
     colorMode = l.PsdFile.ColorMode;
     hasalpha = l.SortedChannels.ContainsKey(-1);
     hasmask = l.SortedChannels.ContainsKey(-2);
     hasch0 = l.SortedChannels.ContainsKey(0);
     hasch1 = l.SortedChannels.ContainsKey(1);
     hasch2 = l.SortedChannels.ContainsKey(2);
     hasch3 = l.SortedChannels.ContainsKey(3);
     if (hasalpha) alphabytes = l.SortedChannels[-1].ImageData;
     if (hasmask) mask = l.MaskData;
     if (hasch0) ch0bytes = l.SortedChannels[0].ImageData;
     if (hasch1) ch1bytes = l.SortedChannels[1].ImageData;
     if (hasch2) ch2bytes = l.SortedChannels[2].ImageData;
     if (hasch3) ch3bytes = l.SortedChannels[3].ImageData;
     colorModeData = l.PsdFile.ColorModeData;
 }