Beispiel #1
0
        /*static public double StarSigma( IImage image, PointF current )
         * {
         *  int width = image.LoadThumbnail().Width;
         *  Color[] pixels = image.GetThumbnailRgbPixels();
         *  Point center = new Point( (int) Math.Round( current.X ), (int) Math.Round( current.Y ) );
         *  double ddx = center.X - current.X;
         *  double ddy = center.Y - current.Y;
         *  double sqrdev = 0.0;
         *  double sum = 0.0;
         *  int N = 7;
         *  Color sky = LocalSky( image, center );
         *  for( int dy = -N; dy <= N; dy++ ) {
         *      for( int dx = -N; dx <= N; dx++ ) {
         *          int offset = ( center.Y + dy ) * width + center.X + dx;
         *          int r = pixels[offset].R;
         *          int g = pixels[offset].G;
         *          int b = pixels[offset].B;
         *          double s = ( r + g + b ) - sky.R - sky.G - sky.B;
         *          if( s < 0 ) {
         *              continue;
         *          }
         *          if( dy == -N ) {
         *              s *= 0.5 + ddy;
         *          }
         *          if( dy == N ) {
         *              s *= 0.5 - ddy;
         *          }
         *          if( dx == -N ) {
         *              s *= 0.5 + ddx;
         *          }
         *          if( dx == N ) {
         *              s *= 0.5 - ddx;
         *          }
         *          double rx = dx + ddx;
         *          double ry = dy + ddy;
         *          sqrdev += ( rx * rx + ry * ry ) * s ;
         *          sum += s;
         *      }
         *  }
         *  return Math.Sqrt( sqrdev / sum );
         * }*/

        static public void CalcStackStatistics(AstroPhoto.LibRaw.Instance libraw, string currentImagePath)
        {
            /*int width, height;
             * float[] stack = ImageTools.CreateDarkAvg( libraw, currentImagePath, out width, out height );
             * string msg = "";
             * for( int ch = 0; ch < 4; ch++ ) {
             *  double mean, sigma;
             *  libraw.CalcStatistics( width, height, stack, ch, currentZoomRect.X, currentZoomRect.Y, currentZoomRect.Width, currentZoomRect.Height, out mean, out sigma );
             *  msg += string.Format( "{2}: Mean={0:0.00} Sigma={1:0.00}\n", mean, sigma, ch );
             * }
             * System.Windows.Forms.MessageBox.Show( msg, "Avg Dark" );
             * string path = currentImagePath;
             * if( !System.IO.File.Exists( path ) ) {
             *  var stackFiles = System.IO.Directory.GetFiles( currentImagePath + "\\RAW" );
             *  path = stackFiles[currentStackIndex];
             * }
             * libraw.open_file( path );
             * short[] pixels  = libraw.GetPixels();
             * for( int i = 0; i < pixels.Length; i++ ) {
             *  stack[i] = pixels[i] - stack[i];
             * }
             * msg = "";
             * for( int ch = 0; ch < 4; ch++ ) {
             *  double mean, sigma;
             *  libraw.CalcStatistics( width, height, stack, ch, currentZoomRect.X, currentZoomRect.Y, currentZoomRect.Width, currentZoomRect.Height, out mean, out sigma );
             *  msg += string.Format( "{2}: Mean={0:0.00} Sigma={1:0.00}\n", mean, sigma, ch );
             * }
             *
             * MessageBox.Show( msg, "Dark Subtracted Avg Dark" );*/

            throw new NotImplementedException();
        }
Beispiel #2
0
        static public ushort[] CreateDarkMedian(AstroPhoto.LibRaw.Instance libraw, string path)
        {
            var rawDir     = System.IO.Path.Combine(path, "RAW");
            var stackFiles = System.IO.Directory.GetFiles(rawDir, "*.arw");

            ushort[][] pixels = new ushort[stackFiles.Length][];
            int        size   = -1;

            for (int i = 0; i < stackFiles.Length; i++)
            {
                using (var rawImage = libraw.load_raw(stackFiles[i])) {
                    size      = rawImage.Height * rawImage.Width;
                    pixels[i] = rawImage.GetRawPixels();
                }
            }
            ushort[] median = new ushort[size];
            for (int i = 0; i < size; i++)
            {
                ushort[] line = new ushort[stackFiles.Length];
                for (int j = 0; j < stackFiles.Length; j++)
                {
                    line[j] = pixels[j][i];
                }
                Array.Sort(line);
                if (stackFiles.Length % 2 == 0)
                {
                    median[i] = (ushort)((line[stackFiles.Length / 2 - 1] + line[stackFiles.Length / 2]) / 2);
                }
                else
                {
                    median[i] = line[stackFiles.Length / 2];
                }
            }
            return(median);
        }
Beispiel #3
0
        public void CreateStack(AstroPhoto.LibRaw.Instance libraw, string name)
        {
            string dir = session.CreateStack(name, selectedImages);

            SuspendLayout();
            for (int i = Controls.Count - 1; i >= 0; i--)
            {
                Control control = Controls[i];
                Panel   panel   = (Panel)control;
                string  path    = (string)panel.Tag;
                if (selectedImages.Contains(path))
                {
                    if (path == currentObjectPath)
                    {
                        panel.Tag = dir;
                        ThumbnailData data = loadThumbnailData(libraw, dir);
                        panel.Height = buildThumbnail((Panel)(panel.Controls[0]), data).Height;
                    }
                    else
                    {
                        Controls.Remove(control);
                    }
                }
            }
            ResumeLayout();

            selectedImages.Clear();
            selectedImages.Add(dir);
            currentObjectPath = dir;
            updateThumbnails();
        }
Beispiel #4
0
        static public IImage LoadImage(AstroPhoto.LibRaw.Instance libraw, string path, Session session)
        {
            var ext = System.IO.Path.GetExtension(path).ToLower();

            if (ext == ".jpg" || ext == ".png")
            {
                return(new PreviewOnlyImage(path));
            }
            else
            {
                return(new RawImageWrapper(libraw, path, session));
            }
        }
Beispiel #5
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            using (var libraw = new AstroPhoto.LibRaw.Instance()) {
                var dirs  = System.IO.Directory.GetDirectories(session.RootPath);
                var files = System.IO.Directory.GetFiles(session.RootPath);

                var thumbnailsToLoad = new string[dirs.Length + files.Length];
                Array.Copy(dirs, 0, thumbnailsToLoad, 0, dirs.Length);
                Array.Copy(files, 0, thumbnailsToLoad, dirs.Length, files.Length);

                int count        = 0;
                int delta        = 1;
                int nextToReport = 0;
                foreach (var path in thumbnailsToLoad)
                {
                    if (System.IO.Directory.Exists(path) ||
                        ".arw;.cr2;.jpg;.png;.fit;".Contains(System.IO.Path.GetExtension(path).ToLower()))
                    {
                        var thumbnailData = loadThumbnailData(libraw, path);
                        lock ( thumbnailsData ) {
                            thumbnailsData.Enqueue(thumbnailData);
                        }
                        if (count == nextToReport)
                        {
                            backgroundWorker.ReportProgress(100 * count / thumbnailsToLoad.Length);
                            if (delta < 5)
                            {
                                delta = delta + 1;
                            }
                            nextToReport = count + delta;
                        }
                        count++;
                    }
                    if (backgroundWorker.CancellationPending)
                    {
                        return;
                    }
                }
            }
        }
Beispiel #6
0
        static public float[] CreateDarkAvg(AstroPhoto.LibRaw.Instance libraw, string path, out int width, out int height)
        {
            var rawDir     = System.IO.Path.Combine(path, "RAW");
            var stackFiles = System.IO.Directory.GetFiles(rawDir, "*.arw");

            float[] sum  = null;
            int     size = 0;

            width  = 0;
            height = 0;
            for (int i = 0; i < stackFiles.Length; i++)
            {
                using (var rawImage = libraw.load_raw(stackFiles[i])) {
                    if (sum == null)
                    {
                        width  = rawImage.Width;
                        height = rawImage.Height;
                        size   = width * height;
                        sum    = new float[size];
                        for (int j = 0; j < size; j++)
                        {
                            sum[j] = 0.0f;
                        }
                    }
                    ushort[] _pixels = rawImage.GetRawPixels();
                    for (int j = 0; j < size; j++)
                    {
                        sum[j] += _pixels[j];
                    }
                }
            }
            for (int j = 0; j < sum.Length; j++)
            {
                sum[j] /= stackFiles.Length;
            }
            return(sum);
        }
Beispiel #7
0
 public RawImageWrapper(AstroPhoto.LibRaw.Instance _libraw, string _filePath, Session _session)
 {
     filePath = _filePath;
     libraw   = _libraw;
     session  = _session;
 }
Beispiel #8
0
        private static ThumbnailData loadThumbnailData(AstroPhoto.LibRaw.Instance libraw, string path)
        {
            var thumbnailData = new ThumbnailData();

            thumbnailData.path = path;

            string ext = "";

            string[] stackFiles = null;
            if (System.IO.Directory.Exists(path))
            {
                var rawDir = System.IO.Path.Combine(path, "RAW");
                if (System.IO.Directory.Exists(rawDir))
                {
                    stackFiles = System.IO.Directory.GetFiles(rawDir, "*.arw");
                    ext        = ".arw";
                    if (stackFiles.Length == 0)
                    {
                        stackFiles = System.IO.Directory.GetFiles(rawDir, "*.cr2");
                        ext        = ".cr2";
                    }
                    if (stackFiles.Length == 0)
                    {
                        stackFiles = System.IO.Directory.GetFiles(rawDir, "*.cfa");
                        ext        = ".cfa";
                    }
                    if (stackFiles.Length == 0)
                    {
                        stackFiles = System.IO.Directory.GetFiles(rawDir, "*.fit");
                        ext        = ".fit";
                    }
                }
            }
            else
            {
                ext = System.IO.Path.GetExtension(path).ToLower();
            }

            if (ext.Length > 0)
            {
                if (ext == ".arw" || ext == ".cr2")
                {
                    string filePath = stackFiles == null ? path : stackFiles[0];
                    using (RawImage rawImage = libraw.load_thumbnail(filePath)) {
                        thumbnailData.image = createScaledImage(rawImage.Preview);
                        string shutter = rawImage.Shutter > 1 ? string.Format("{0:0}s", rawImage.Shutter) :
                                         string.Format("1/{0:0}s", 1 / rawImage.Shutter);
                        if (stackFiles == null)
                        {
                            thumbnailData.label = "ISO" + rawImage.IsoSpeed.ToString("0") + " - " + shutter;
                        }
                        else
                        {
                            thumbnailData.label = System.IO.Path.GetFileName(path) +
                                                  "\nISO" + rawImage.IsoSpeed.ToString("0") + " - " + shutter
                                                  + (stackFiles == null ? "" : " (" + stackFiles.Length + ")");
                        }
                    }
                }
                else if (ext == ".cfa" || ext == ".fit")
                {
                    string filePath = stackFiles == null ? path : stackFiles[0];
                    using (RawImage rawImage = new RawImage(filePath)) {
                        thumbnailData.image = createScaledImage(rawImage.Preview);
                        string shutter = rawImage.Shutter > 1 ? string.Format("{0:0}s", rawImage.Shutter) :
                                         string.Format("1/{0:0}s", 1 / rawImage.Shutter);
                        if (stackFiles == null)
                        {
                            thumbnailData.label = "ISO" + rawImage.IsoSpeed.ToString("0") + " - " + shutter;
                        }
                        else
                        {
                            thumbnailData.label = System.IO.Path.GetFileName(path) +
                                                  "\nISO" + rawImage.IsoSpeed.ToString("0") + " - " + shutter
                                                  + (stackFiles == null ? "" : " (" + stackFiles.Length + ")");
                        }
                    }
                }
                else if (ext == ".jpg" || ext == ".png")
                {
                    using (Image preview = Image.FromFile(path)) {
                        thumbnailData.image = createScaledImage(preview);
                    }
                    thumbnailData.label = System.IO.Path.GetFileName(path);
                }
            }
            else
            {
                thumbnailData.label = System.IO.Path.GetFileName(path);
            }
            return(thumbnailData);
        }