Exemplo n.º 1
0
        /// <summary>
        /// Create a new blank image
        /// </summary>
        /// <param name="width">width</param>
        /// <param name="height">height</param>
        /// <param name="channels">channel flags</param>
        public ManagedImage(int width, int height, ImageChannels channels)
        {
            Width    = width;
            Height   = height;
            Channels = channels;

            int n = width * height;

            if ((channels & ImageChannels.Gray) != 0)
            {
                Red = new byte[n];
            }
            else if ((channels & ImageChannels.Color) != 0)
            {
                Red   = new byte[n];
                Green = new byte[n];
                Blue  = new byte[n];
            }

            if ((channels & ImageChannels.Alpha) != 0)
            {
                Alpha = new byte[n];
            }

            if ((channels & ImageChannels.Bump) != 0)
            {
                Bump = new byte[n];
            }
        }
Exemplo n.º 2
0
        public static void *ImageLoadData(IntPtr handle, ImageChannels channels)
        {
            byte *data;

            _ImageLoadData(handle.ToPointer(), &data, channels);
            return(data);
        }
Exemplo n.º 3
0
        public static void *ImageGetLoadedData(IntPtr handle, out ImageChannels channels)
        {
            byte *        data;
            ImageChannels c;

            _ImageGetLoadedData(handle.ToPointer(), &data, &c);
            channels = c;
            return(data);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Convert the channels in the image. Channels are created or destroyed as required.
        /// </summary>
        /// <param name="channels">new channel flags</param>
        public void ConvertChannels(ImageChannels channels)
        {
            if (Channels == channels)
            {
                return;
            }

            int           n   = Width * Height;
            ImageChannels add = Channels ^ channels & channels;
            ImageChannels del = Channels ^ channels & Channels;

            if ((add & ImageChannels.Color) != 0)
            {
                Red   = new byte[n];
                Green = new byte[n];
                Blue  = new byte[n];
            }
            else if ((del & ImageChannels.Color) != 0)
            {
                Red   = null;
                Green = null;
                Blue  = null;
            }

            if ((add & ImageChannels.Alpha) != 0)
            {
                Alpha = new byte[n];
                FillArray(Alpha, 255);
            }
            else if ((del & ImageChannels.Alpha) != 0)
            {
                Alpha = null;
            }

            if ((add & ImageChannels.Bump) != 0)
            {
                Bump = new byte[n];
            }
            else if ((del & ImageChannels.Bump) != 0)
            {
                Bump = null;
            }

            Channels = channels;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a new blank image
        /// </summary>
        /// <param name="width">width</param>
        /// <param name="height">height</param>
        /// <param name="channels">channel flags</param>
        public Image(int width, int height, ImageChannels channels)
        {
            Width = width;
            Height = height;
            Channels = channels;

            int n = width * height;

            if ((channels & ImageChannels.Color) != 0)
            {
                Red = new byte[n];
                Green = new byte[n];
                Blue = new byte[n];
            }

            if ((channels & ImageChannels.Bump) != 0) Bump = new byte[n];

            if ((channels & ImageChannels.Alpha) != 0)
                Alpha = new byte[n];
        }
Exemplo n.º 6
0
        /// <summary>
        /// Convert the channels in the image. Channels are created or destroyed as required.
        /// </summary>
        /// <param name="channels">new channel flags</param>
        public void ConvertChannels(ImageChannels channels)
        {
            if (Channels == channels)
                return;

            int n = Width * Height;
            ImageChannels add = Channels ^ channels & channels;
            ImageChannels del = Channels ^ channels & Channels;

            if ((add & ImageChannels.Color) != 0)
            {
                Red = new byte[n];
                Green = new byte[n];
                Blue = new byte[n];
            }
            else if ((del & ImageChannels.Color) != 0)
            {
                Red = null;
                Green = null;
                Blue = null;
            }

            if ((add & ImageChannels.Alpha) != 0)
            {
                Alpha = new byte[n];
                FillArray(Alpha, 255);
            }
            else if ((del & ImageChannels.Alpha) != 0)
                Alpha = null;

            if ((add & ImageChannels.Bump) != 0)
                Bump = new byte[n];
            else if ((del & ImageChannels.Bump) != 0)
                Bump = null;

            Channels = channels;
        }
Exemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bitmap"></param>
        public ManagedImage(System.Drawing.Bitmap bitmap)
        {
            Width = bitmap.Width;
            Height = bitmap.Height;

            int pixelCount = Width * Height;

            if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            {
                Channels = ImageChannels.Alpha | ImageChannels.Color;
                Red = new byte[pixelCount];
                Green = new byte[pixelCount];
                Blue = new byte[pixelCount];
                Alpha = new byte[pixelCount];

                System.Drawing.Imaging.BitmapData bd = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height),
                    System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                unsafe
                {
                    byte* pixel = (byte*)bd.Scan0;

                    for (int i = 0; i < pixelCount; i++)
                    {
                        // GDI+ gives us BGRA and we need to turn that in to RGBA
                        Blue[i] = *(pixel++);
                        Green[i] = *(pixel++);
                        Red[i] = *(pixel++);
                        Alpha[i] = *(pixel++);
                    }
                }

                bitmap.UnlockBits(bd);
            }
            else if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format16bppGrayScale)
            {
                Channels = ImageChannels.Gray;
                Red = new byte[pixelCount];

                throw new NotImplementedException("16bpp grayscale image support is incomplete");
            }
            else if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            {
                Channels = ImageChannels.Color;
                Red = new byte[pixelCount];
                Green = new byte[pixelCount];
                Blue = new byte[pixelCount];

                System.Drawing.Imaging.BitmapData bd = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height),
                        System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                unsafe
                {
                    byte* pixel = (byte*)bd.Scan0;

                    for (int i = 0; i < pixelCount; i++)
                    {
                        // GDI+ gives us BGR and we need to turn that in to RGB
                        Blue[i] = *(pixel++);
                        Green[i] = *(pixel++);
                        Red[i] = *(pixel++);
                    }
                }

                bitmap.UnlockBits(bd);
            }
            else if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppRgb)
            {
                Channels = ImageChannels.Color;
                Red = new byte[pixelCount];
                Green = new byte[pixelCount];
                Blue = new byte[pixelCount];

                System.Drawing.Imaging.BitmapData bd = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height),
                        System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

                unsafe
                {
                    byte* pixel = (byte*)bd.Scan0;

                    for (int i = 0; i < pixelCount; i++)
                    {
                        // GDI+ gives us BGR and we need to turn that in to RGB
                        Blue[i] = *(pixel++);
                        Green[i] = *(pixel++);
                        Red[i] = *(pixel++);
                        pixel++;	// Skip over the empty byte where the Alpha info would normally be
                    }
                }

                bitmap.UnlockBits(bd);
            }
            else
            {
                throw new NotSupportedException("Unrecognized pixel format: " + bitmap.PixelFormat.ToString());
            }
        }
Exemplo n.º 8
0
 private void StartChannelButton_MouseDown(object sender, MouseButtonEventArgs e)
 {
     ImageChannels.GetChannels(_sourceImagePath, _resultFolderPath);
     MessageBox.Show("Finished!", "Result", MessageBoxButtons.OK);
 }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bitmap"></param>
        public ManagedImage(System.Drawing.Bitmap bitmap)
        {
            Width  = bitmap.Width;
            Height = bitmap.Height;

            int pixelCount = Width * Height;

            if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            {
                Channels = ImageChannels.Alpha | ImageChannels.Color;
                Red      = new byte[pixelCount];
                Green    = new byte[pixelCount];
                Blue     = new byte[pixelCount];
                Alpha    = new byte[pixelCount];

                System.Drawing.Imaging.BitmapData bd = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height),
                                                                       System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                unsafe
                {
                    byte *pixel = (byte *)bd.Scan0;

                    for (int i = 0; i < pixelCount; i++)
                    {
                        // GDI+ gives us BGRA and we need to turn that in to RGBA
                        Blue[i]  = *(pixel++);
                        Green[i] = *(pixel++);
                        Red[i]   = *(pixel++);
                        Alpha[i] = *(pixel++);
                    }
                }

                bitmap.UnlockBits(bd);
            }
            else if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format16bppGrayScale)
            {
                Channels = ImageChannels.Gray;
                Red      = new byte[pixelCount];

                throw new NotImplementedException("16bpp grayscale image support is incomplete");
            }
            else if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            {
                Channels = ImageChannels.Color;
                Red      = new byte[pixelCount];
                Green    = new byte[pixelCount];
                Blue     = new byte[pixelCount];

                System.Drawing.Imaging.BitmapData bd = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height),
                                                                       System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                unsafe
                {
                    byte *pixel = (byte *)bd.Scan0;

                    for (int i = 0; i < pixelCount; i++)
                    {
                        // GDI+ gives us BGR and we need to turn that in to RGB
                        Blue[i]  = *(pixel++);
                        Green[i] = *(pixel++);
                        Red[i]   = *(pixel++);
                    }
                }

                bitmap.UnlockBits(bd);
            }
            else if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppRgb)
            {
                Channels = ImageChannels.Color;
                Red      = new byte[pixelCount];
                Green    = new byte[pixelCount];
                Blue     = new byte[pixelCount];

                System.Drawing.Imaging.BitmapData bd = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height),
                                                                       System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

                unsafe
                {
                    byte *pixel = (byte *)bd.Scan0;

                    for (int i = 0; i < pixelCount; i++)
                    {
                        // GDI+ gives us BGR and we need to turn that in to RGB
                        Blue[i]  = *(pixel++);
                        Green[i] = *(pixel++);
                        Red[i]   = *(pixel++);
                        pixel++;                                // Skip over the empty byte where the Alpha info would normally be
                    }
                }

                bitmap.UnlockBits(bd);
            }
            else
            {
                throw new NotSupportedException("Unrecognized pixel format: " + bitmap.PixelFormat.ToString());
            }
        }