Example #1
0
        private void LoadPanorama(String FileName)
        {
            if (!FileName.Substring(FileName.Length - 4, 4).Equals(".hdr"))
            {
                MessageBox.Show("Wrong filename. Make sure it's an .hdr file");
                return;
            }

            generate_cubemap_button.Enabled = true;

            CubemapLibrary.open_hdri(FileName);
            IntPtr p_pixels = CubemapLibrary.get_pixels();
            int    width    = CubemapLibrary.get_width();
            int    height   = CubemapLibrary.get_height();

            float[] data = new float[width * height * 3];

            Marshal.Copy(p_pixels, data, 0, width * height * 3);

            Bitmap bm = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            System.Drawing.Imaging.BitmapData bm_data = bm.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bm.PixelFormat);

            IntPtr Iptr = bm_data.Scan0;

            byte[] pixels = new byte[width * height * 3];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    int   index = 3 * (i + j * width);
                    float r     = data[index + 0]; if (r > 1.0f)
                    {
                        r = 1.0f;
                    }
                    r *= 255;
                    float g = data[index + 1]; if (g > 1.0f)
                    {
                        g = 1.0f;
                    }
                    g *= 255;
                    float b = data[index + 2]; if (b > 1.0f)
                    {
                        b = 1.0f;
                    }
                    b *= 255;

                    pixels[index]     = (byte)b;
                    pixels[index + 1] = (byte)g;
                    pixels[index + 2] = (byte)r;
                }
            }

            Marshal.Copy(pixels, 0, Iptr, width * height * 3);
            bm.UnlockBits(bm_data);

            panorama_picture_box.BackgroundImage = bm;
            input_file_text_box.Text             = FileName;
        }
Example #2
0
        private Bitmap AddSquare(int cube_edge_i, Bitmap bm, int x, int y, Surface k, int turns = 0)
        {
            IntPtr p_pixels = CubemapLibrary.get_edge_t((int)k, turns);

            float[] data = new float[cube_edge_i * cube_edge_i * 3];
            Marshal.Copy(p_pixels, data, 0, cube_edge_i * cube_edge_i * 3);

            for (int i = 0; i < cube_edge_i; i++)
            {
                for (int j = 0; j < cube_edge_i; j++)
                {
                    float r = data[3 * (i + j * cube_edge_i) + 0]; if (r > 1.0f)
                    {
                        r = 1.0f;
                    }
                    r *= 255;
                    float g = data[3 * (i + j * cube_edge_i) + 1]; if (g > 1.0f)
                    {
                        g = 1.0f;
                    }
                    g *= 255;
                    float b = data[3 * (i + j * cube_edge_i) + 2]; if (b > 1.0f)
                    {
                        b = 1.0f;
                    }
                    b *= 255;
                    bm.SetPixel(i + x * cube_edge_i, j + y * cube_edge_i, Color.FromArgb((int)r, (int)g, (int)b));
                }
            }
            return(bm);
        }
Example #3
0
        private void UpdateCubemap()
        {
            cube_edge_i = Int32.Parse(edge_size_text_box.Text);

            CubemapLibrary.make_cube(cube_edge_i, rotate_z_track_bar.Value * 10);
            CubemapLibrary.blur(blur_track_bar.Value);
            DrawCubemap();
            DrawPreview();

            EnableCubemapEditing(true);
        }
Example #4
0
 private void save_cubemap_button_Click(object sender, EventArgs e)
 {
     if (save_to_input_check_box.Checked)
     {
         CubemapLibrary.save_cube_dds(MakeDDSName(open_file_dialog.FileName), cube_edge_i);
         MessageBox.Show("Successfully saved!");
     }
     else
     {
         if (save_file_dialog.ShowDialog() == DialogResult.OK)
         {
             CubemapLibrary.save_cube_dds(save_file_dialog.FileName, cube_edge_i);
             return;
         }
     }
 }
Example #5
0
        private void DrawCubemap()
        {
            int height = cube_edge_i;
            int width  = height * 6;

            Bitmap bm = new Bitmap(width, height);

            for (int k = 0; k < 6; k++)
            {
                IntPtr p_pixels = CubemapLibrary.get_blurred_edge(k);

                float[] data = new float[height * height * 3];

                Marshal.Copy(p_pixels, data, 0, height * height * 3);

                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        float r = data[3 * (i + j * height) + 0]; if (r > 1.0f)
                        {
                            r = 1.0f;
                        }
                        r *= 255;
                        float g = data[3 * (i + j * height) + 1]; if (g > 1.0f)
                        {
                            g = 1.0f;
                        }
                        g *= 255;
                        float b = data[3 * (i + j * height) + 2]; if (b > 1.0f)
                        {
                            b = 1.0f;
                        }
                        b *= 255;
                        bm.SetPixel(i + k * height, j, Color.FromArgb((int)r, (int)g, (int)b));
                    }
                }
            }

            cubemap_picture_box.BackgroundImage = bm;

            tabs_image.SelectTab(tab_cubemap);
        }
Example #6
0
        private void process_batch_button_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(input_folder_text_box.Text))
            {
                MessageBox.Show("Input directory doesn't exist");
                return;
            }

            if (!Directory.Exists(output_folder_text_box.Text))
            {
                MessageBox.Show("Output directory doesn't exist");
                return;
            }

            DirectoryInfo          InputInfo = new DirectoryInfo(input_folder_text_box.Text);
            IEnumerable <FileInfo> Files     = InputInfo.EnumerateFiles("*.hdr");

            foreach (FileInfo Info in Files)
            {
                LoadPanorama(Info.FullName);
                UpdateCubemap();
                CubemapLibrary.save_cube_dds(output_folder_text_box.Text + MakeDDSName(Info.Name), cube_edge_i);
            }
        }
Example #7
0
        private void DrawPreview()
        {
            Stopwatch sw1 = new Stopwatch();
            Stopwatch sw2 = new Stopwatch();

            sw1.Start();
            IntPtr render = CubemapLibrary.render(rotate_z_track_bar.Value);

            sw1.Stop();


            sw2.Start();
            int width  = 1024;
            int height = 1024;

            float[] render_p = new float[width * height * 3];
            Marshal.Copy(render, render_p, 0, width * height * 3);

            Bitmap bm = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Drawing.Imaging.BitmapData bm_data = bm.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bm.PixelFormat);

            IntPtr Iptr = bm_data.Scan0;

            byte[] pixels = new byte[width * height * 4];

            Random rand = new Random();

            unsafe
            {
                byte *pixel_begin = (byte *)Iptr;
                for (int i = 0; i < height; i++)
                {
                    byte *pixel_cur_line = pixel_begin + i * bm_data.Stride;
                    for (int j = 0; j < width; j++)
                    {
                        //int index = 4 * (i + j * width);
                        float r = render_p[(j + (height - i - 1) * width) * 3]; if (r > 1)
                        {
                            r = 1.0f;
                        }
                        float g = render_p[(j + (height - i - 1) * width) * 3 + 1]; if (g > 1)
                        {
                            g = 1.0f;
                        }
                        float b = render_p[(j + (height - i - 1) * width) * 3 + 2]; if (b > 1)
                        {
                            b = 1.0f;
                        }
                        //
                        pixel_cur_line[4 * j]     = (byte)(255 * b);
                        pixel_cur_line[4 * j + 1] = (byte)(255 * g);
                        pixel_cur_line[4 * j + 2] = (byte)(255 * r);
                        pixel_cur_line[4 * j + 3] = 255;
                    }
                }
            }


            //Marshal.Copy(pixels, 0, Iptr, width * height * 4);
            bm.UnlockBits(bm_data);

            preview_picture_box.BackgroundImage = bm;
            sw2.Stop();

            String sw1_s = sw1.Elapsed.ToString();
            String sw2_s = sw2.Elapsed.ToString();

            String x = "";
        }
Example #8
0
 private void Main_Form_FormClosing(object sender, FormClosingEventArgs e)
 {
     CubemapLibrary.deinit();
 }
Example #9
0
 public Main_Form()
 {
     InitializeComponent();
     CubemapLibrary.init();
 }