public static new FloatBitmapGtk FromPPM(RawLoader ppm, ProgressReporter callback)
        {
            FloatBitmapGtk fbg = new FloatBitmapGtk();

            if (fbg.LoadDataFromPPM(ppm, callback))
                return fbg;
            else
                return null;
        }
Beispiel #2
0
        public unsafe static RawLoader FromFile(string filename, bool divide_by_2, ProgressReporter callback)
        {
            IntPtr eximg_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SSRLWrapper.ExtractedRawImage)));
            int    err       = SSRLWrapper.ExtractRawImageFromFile(filename, divide_by_2, eximg_ptr, delegate(float progress) {
                return(callback(progress));
            });

#if DEBUG
            Console.WriteLine("ExtractRawImageFromFile returned " + err);
#endif
            if (err != 0)
            {
                return(null);
            }

            SSRLWrapper.ExtractedRawImage eximg = (SSRLWrapper.ExtractedRawImage)Marshal.PtrToStructure(eximg_ptr, typeof(SSRLWrapper.ExtractedRawImage));

            RawLoader ppml = new RawLoader(eximg.width, eximg.height);

            if (eximg.bitsPerChannel == 16)
            {
                // Handling
                short[] rgb_data = new short[eximg.width * eximg.height * 3];
                Marshal.Copy(eximg.data, rgb_data, 0, rgb_data.Length);

                for (int i = 0; i < eximg.width; i++)
                {
                    for (int j = 0; j < eximg.height; j++)
                    {
                        ppml.r_channel[i, j] = (ushort)rgb_data[3 * (i + eximg.width * j)];
                        ppml.g_channel[i, j] = (ushort)rgb_data[3 * (i + eximg.width * j) + 1];
                        ppml.b_channel[i, j] = (ushort)rgb_data[3 * (i + eximg.width * j) + 2];
                    }
                }
            }
            else if (eximg.bitsPerChannel == 8)
            {
                throw new Exception("Can't handle 8 bit");
            }
            else
            {
                throw new Exception("incorrect or unsupported bitsPerChannel value: " + eximg.bitsPerChannel);
            }


            SSRLWrapper.FreeExtractedRawImage(eximg);

            return(ppml);
        }
Beispiel #3
0
        public static unsafe RawLoader FromFile(string filename, bool divide_by_2, ProgressReporter callback)
        {
            IntPtr eximg_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SSRLWrapper.ExtractedRawImage)));
            int err = SSRLWrapper.ExtractRawImageFromFile(filename, divide_by_2, eximg_ptr, delegate (float progress) {
                return callback(progress);
            });
            #if DEBUG
            Console.WriteLine("ExtractRawImageFromFile returned " + err);
            #endif
            if (err != 0)
            {
                return null;
            }

            SSRLWrapper.ExtractedRawImage eximg = (SSRLWrapper.ExtractedRawImage)Marshal.PtrToStructure(eximg_ptr, typeof(SSRLWrapper.ExtractedRawImage));

            RawLoader ppml = new RawLoader(eximg.width, eximg.height);

            if (eximg.bitsPerChannel == 16)
            {
                // Handling
                short[] rgb_data = new short[eximg.width * eximg.height * 3];
                Marshal.Copy(eximg.data, rgb_data, 0, rgb_data.Length);

                for (int i = 0; i < eximg.width; i++)
                for (int j = 0; j < eximg.height; j++)
                {
                     ppml.r_channel[i, j] = (ushort)rgb_data[3 * (i + eximg.width * j)];
                     ppml.g_channel[i, j] = (ushort)rgb_data[3 * (i + eximg.width * j) + 1];
                     ppml.b_channel[i, j] = (ushort)rgb_data[3 * (i + eximg.width * j) + 2];
                }
            }
            else if (eximg.bitsPerChannel == 8)
            {
                throw new Exception("Can't handle 8 bit");
            }
            else
            {
                throw new Exception("incorrect or unsupported bitsPerChannel value: " + eximg.bitsPerChannel);
            }

            SSRLWrapper.FreeExtractedRawImage(eximg);

            return ppml;
        }
Beispiel #4
0
        public IBitmapCore LoadRaw(string filename, int downscale_by)
        {
            // Checkig if downscale divides by 2
            bool div_by_2 = false;

            if (downscale_by % 2 == 0)
            {
                div_by_2      = true;
                downscale_by /= 2;
            }

            mCancelLoadingPending = false;
            RawLoader ppl = RawLoader.FromFile(filename, div_by_2, delegate(double progress) {
                OnProgressMessageReport(true, 6 * progress / 8, "1 of 3: Parsing image...", false);
                return(!mCancelLoadingPending);
            });

            if (ppl == null)
            {
                return(null);
            }
            else
            {
                if (downscale_by != 1)
                {
                    bool dsres = ppl.Downscale(downscale_by, delegate(double progress) {
                        OnProgressMessageReport(true, 6.0 / 8 + progress / 8, "2 of 3: Downscaling...", false);
                        return(!mCancelLoadingPending);
                    });

                    if (dsres == false)
                    {
                        ppl = null;
                        return(null);
                    }
                }

                return(mBitmapCoreFactory(ppl,
                                          delegate(double progress) {
                    OnProgressMessageReport(true, 7.0 / 8 + progress / 8, "3 of 3: Converting to editable format...", false);
                    return !mCancelLoadingPending;
                }
                                          ));
            }
        }
Beispiel #5
0
        private static string[] OtherRawsSameDirectory(string rawFileName)
        {
            string path = Path.GetDirectoryName(rawFileName);
            string name = Path.GetFileNameWithoutExtension(rawFileName);

            string[]      alts   = System.IO.Directory.GetFiles(path, "*");
            List <string> others = new List <string> ();

            for (int i = 0; i < alts.Length; i++)
            {
                if (alts[i] != rawFileName && RawLoader.IsRaw(alts[i]))
                {
                    others.Add(alts[i]);
                    Console.WriteLine(alts[i]);
                }
            }
            return(others.ToArray());
        }
Beispiel #6
0
        protected bool LoadDataFromPPM(RawLoader ppm, ProgressReporter callback)
        {
            mWidth = ppm.RChannel.GetLength(0);
            mHeight = ppm.RChannel.GetLength(1);

            r_chan = new float[mWidth, mHeight];
            g_chan = new float[mWidth, mHeight];
            b_chan = new float[mWidth, mHeight];
            hl_chan = new float[mWidth, mHeight];

            for (int i = 0; i < mWidth; i++)
            {
                if (i % REPORT_EVERY_NTH_LINE == 0 && callback != null)
                {
                    if (!callback((double)i / mWidth / 2))
                        return false;
                }
                lock (this)
                {
                    for (int j = 0; j < mHeight; j++)
                    {
                        r_chan[i, j] = ppm.RChannel[i, j];
                        g_chan[i, j] = ppm.GChannel[i, j];
                        b_chan[i, j] = ppm.BChannel[i, j];
                    }
                }
            }

            double maxLight = CalcMaxLight();

            // Normalizing to 0..1
            for (int i = 0; i < mWidth; i++)
            {
                if (i % REPORT_EVERY_NTH_LINE == 0 && callback != null)
                {
                    if (!callback(0.5 + (double)i / mWidth / 2))
                        return false;
                }
                lock (this)
                {
                    for (int j = 0; j < mHeight; j++)
                    {
                        r_chan[i, j] /= (float)maxLight;
                        g_chan[i, j] /= (float)maxLight;
                        b_chan[i, j] /= (float)maxLight;
                    }
                }
            }

            return true;
        }
Beispiel #7
0
 public static IBitmapCore FloatBitmapGtkFactory(RawLoader ppl, ProgressReporter callback)
 {
     return FloatBitmapGtk.FromPPM(ppl, callback);
 }