Beispiel #1
0
        unsafe void CreateDistortionMap(string settings, string path)
        {
            DistortionMap DM = new DistortionMap();

            DM.Deserialize(settings);
            float[] fData = DM.GenerateMap();
            byte[]  bData = new byte[fData.Length * 4 + 8];
            using (FileStream FS = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                fixed(float *sfData = &fData[0])
                fixed(byte *sbData = &bData[0])
                {
                    float *pfData = sfData;
                    float *pbData = (float *)sbData + 2;
                    int *  piData = (int *)sbData;

                    *piData++ = DM.Width;
                    *piData++ = DM.Height;
                    for (int i = 0; i < fData.Length; i++)
                    {
                        *pbData++ = *pfData++;
                    }
                }
            }
            File.WriteAllBytes(path, bData);
        }
Beispiel #2
0
 private void BCalculate_Click(object sender, EventArgs e)
 {
     if (DM.Width <= 0)
     {
         MessageBox.Show("Map width must be greater than zero.");
         return;
     }
     if (DM.Height <= 0)
     {
         MessageBox.Show("Map height must be greater than zero.");
         return;
     }
     if (DM.OriginalWidth <= 0)
     {
         MessageBox.Show("Original width must be greater than zero.");
         return;
     }
     if (DM.OriginalHeight <= 0)
     {
         MessageBox.Show("Original height must be greater than zero.");
         return;
     }
     if (DM.FX <= 0 || DM.FY <= 0)
     {
         MessageBox.Show("Focal length must be greater than zero.");
         return;
     }
     float[] Map = DM.GenerateMap();
     if (SFD.ShowDialog() == DialogResult.OK)
     {
         try
         {
             using (FileStream FS = new FileStream(SFD.FileName, FileMode.Create, FileAccess.Write))
                 using (BinaryWriter BW = new BinaryWriter(FS))
                 {
                     BW.Write(DM.Width);
                     BW.Write(DM.Height);
                     for (int i = 0; i < Map.Length; i++)
                     {
                         BW.Write(Map[i]);
                     }
                     BW.Flush();
                     BW.Close();
                 }
         }
         catch
         {
             MessageBox.Show("Save was unsuccesful!");
         }
     }
 }