Exemplo n.º 1
0
        private ManagedCuda.NPP.NPPImage_8uC4 CudaHelper(Bitmap map)
        {
            NppiSize size = new NppiSize(map.Width, map.Height);

            ManagedCuda.NPP.NPPImage_8uC4 source = new NPPImage_8uC4(size);

            source.CopyToDevice(map);

            return source;
        }
Exemplo n.º 2
0
        private void btn_open_Click(object sender, EventArgs e)
        {
            if (!_nppOK) return;

            CleanUp();

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Images|*.jpg;*.bmp;*.png;*.tif";
            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

            Bitmap src = new Bitmap(ofd.FileName);

            switch (src.PixelFormat)
            {
                case PixelFormat.Format24bppRgb:
                    _colorChannels = 3;
                    break;
                case PixelFormat.Format32bppArgb:
                    _colorChannels = 4;
                    break;
                case PixelFormat.Format32bppRgb:
                    _colorChannels = 4;
                    break;
                case PixelFormat.Format8bppIndexed:
                    _colorChannels = 1;
                    break;
                default:
                    _colorChannels = 0;
                    txt_info.AppendText(ofd.FileName + " has an unsupported pixel format.\n");
                    break;
            }

            try
            {
                switch (_colorChannels)
                {
                    case 1:
                        //Allocate memory on device for one channel images...
                        src_c1 = new NPPImage_8uC1(src.Width, src.Height);
                        dest_c1 = new NPPImage_8uC1(src.Width, src.Height);
                        src_c1.CopyToDevice(src);
                        txt_info.AppendText("Info: Loaded image '" + ofd.FileName + "' succesfully (Size: " + src.Width.ToString() + " x " + src.Height.ToString() + ", color channels: " + _colorChannels.ToString() + ")\n");
                        break;
                    case 3:
                        //As of version 5, NPP has new histogram and LUT functions for three channel images, no more need to convert first to 4 channels.
                        //Allocate memory on device for four channel images...
                        src_c3 = new NPPImage_8uC3(src.Width, src.Height);
                        dest_c3 = new NPPImage_8uC3(src.Width, src.Height);

                        //Fill 3 channel image in device memory
                        src_c3.CopyToDevice(src);

                        txt_info.AppendText("Info: Loaded image '" + ofd.FileName + "' succesfully (Size: " + src.Width.ToString() + " x " + src.Height.ToString() + ", color channels: " + _colorChannels.ToString() + ")\n");
                        break;
                    case 4:
                        //Allocate memory on device for four channel images...
                        src_c4 = new NPPImage_8uC4(src.Width, src.Height);
                        dest_c4 = new NPPImage_8uC4(src.Width, src.Height);
                        src_c4.CopyToDevice(src);
                        txt_info.AppendText("Info: Loaded image '" + ofd.FileName + "' succesfully (Size: " + src.Width.ToString() + " x " + src.Height.ToString() + ", color channels: " + _colorChannels.ToString() + ")\n");
                        break;
                }
            }
            catch (Exception ex)
            {
                if (ex is NPPException)
                {
                    txt_info.AppendText("NPPException: " + ex.Message + "\n");
                    CleanUp();
                }
                else if (ex is CudaException)
                {
                    txt_info.AppendText("CudaException: " + ex.Message + "\n");
                    CleanUp();
                }
                else throw;
            }
            //Show original image
            pictureBox_src.Image = src;
        }