Ejemplo n.º 1
0
        public void LoadHistogram(FileItem item)
        {
            try
            {
                var fileInfo = item.FileInfo;
                if (fileInfo != null)
                {
                    if (fileInfo.IsLoading)
                    {
                        return;
                    }
                    fileInfo.IsLoading = true;
                }
                if (fileInfo == null || fileInfo.ExifTags == null || fileInfo.ExifTags.Items.Count == 0)
                {
                    GetMetadata(item);
                    fileInfo           = item.FileInfo;
                    fileInfo.IsLoading = true;
                }
                if (!File.Exists(item.SmallThumb))
                {
                    fileInfo.IsLoading = false;
                    return;
                }

                using (MagickImage image = new MagickImage(item.SmallThumb))
                {
                    var Blue      = new int[256];
                    var Green     = new int[256];
                    var Red       = new int[256];
                    var Luminance = new int[256];
                    Dictionary <IMagickColor <byte>, int> h = image.Histogram();
                    foreach (var i in h)
                    {
                        byte R = i.Key.R;
                        byte G = i.Key.G;
                        byte B = i.Key.B;
                        Blue[B]  += i.Value;
                        Green[G] += i.Value;
                        Red[R]   += i.Value;
                        int lum = (R + R + R + B + G + G + G + G) >> 3;
                        Luminance[lum] += i.Value;
                    }
                    fileInfo.HistogramBlue      = Blue;
                    fileInfo.HistogramGreen     = Green;
                    fileInfo.HistogramRed       = Red;
                    fileInfo.HistogramLuminance = Luminance;
                    fileInfo.IsLoading          = false;
                    item.FileInfo = fileInfo;
                }
                item.SaveInfo();
                if (ServiceProvider.Settings.SelectedBitmap.FileItem == item)
                {
                    SetData(ServiceProvider.Settings.SelectedBitmap,
                            ServiceProvider.Settings.SelectedBitmap.FileItem);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Unable to load histogram", ex);
            }

            //item.FileInfo.HistogramBlue = SmoothHistogram(item.FileInfo.HistogramBlue);
            //item.FileInfo.HistogramGreen = SmoothHistogram(item.FileInfo.HistogramGreen);
            //item.FileInfo.HistogramRed = SmoothHistogram(item.FileInfo.HistogramRed);
            //item.FileInfo.HistogramLuminance = SmoothHistogram(item.FileInfo.HistogramLuminance);
        }
Ejemplo n.º 2
0
        public void GenerateCache(FileItem fileItem)
        {
            bool deleteFile = false;
            if (fileItem == null)
                return;
            if (!File.Exists(fileItem.FileName))
                return;

            if ((File.Exists(fileItem.LargeThumb) && File.Exists(fileItem.SmallThumb)) && File.Exists(fileItem.InfoFile))
                return;

            if (fileItem.Loading)
                return;

            fileItem.Loading = true;

            PhotoUtils.WaitForFile(fileItem.FileName);
            string filename = fileItem.FileName;
            if (fileItem.IsMovie)
            {
                try
                {
                    string ffmpeg_exe = Path.Combine(Settings.ApplicationFolder, "ffmpeg.exe");
                    if (File.Exists(ffmpeg_exe))
                    {
                        string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                            Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        PhotoUtils.RunAndWait(ffmpeg_exe, String.Format("-i \"{0}\" -ss 00:00:01.000 -f image2 -vframes 1 \"{1}\"", fileItem.FileName, thumb));
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get video thumb", exception);
                }
            }
            if (fileItem.IsRaw)
            {
                try
                {
                    string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                    if (File.Exists(dcraw_exe))
                    {
                        string thumb = Path.Combine(Path.GetTempPath(),
                            Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        PhotoUtils.RunAndWait(dcraw_exe,
                            string.Format(" -e -O \"{0}\" \"{1}\"", thumb, fileItem.FileName));
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get dcraw thumb", exception);
                }
            }

            GetMetadata(fileItem);
            try
            {
                using (MagickImage image = new MagickImage(filename))
                {
                    fileItem.FileInfo.SetSize(image.Width, image.Height);

                    double dw = (double)LargeThumbSize / image.Width;
                    image.FilterType = FilterType.Box;
                    image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw));

                    if (!ServiceProvider.Settings.DisableHardwareAccelerationNew)
                        image.UnsharpMask(1, 1, 0.5, 0.1);

                    PhotoUtils.CreateFolder(fileItem.LargeThumb);
                    image.Write(fileItem.LargeThumb);
                    fileItem.IsLoaded = true;
                    fileItem.Loading = false;

                    dw = (double)SmallThumbSize / image.Width;
                    image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw));

                    if (!ServiceProvider.Settings.DisableHardwareAccelerationNew)
                        image.UnsharpMask(1, 1, 0.5, 0.1);

                    PhotoUtils.CreateFolder(fileItem.SmallThumb);
                    image.Write(fileItem.SmallThumb);

                    fileItem.Thumbnail = LoadImage(fileItem.SmallThumb);
                }
                fileItem.SaveInfo();
                SetImageInfo(fileItem);
                if (deleteFile)
                    File.Delete(filename);
                OnMetaDataUpdated(fileItem);
            }
            catch (Exception exception)
            {
                Log.Error("Error generating cache " + fileItem.FileName, exception);
            }
            fileItem.Loading = false;
        }
Ejemplo n.º 3
0
        public void GenerateCache(FileItem fileItem)
        {
            bool deleteFile = false;

            if (fileItem == null)
            {
                return;
            }
            if (!File.Exists(fileItem.FileName))
            {
                return;
            }

            if ((File.Exists(fileItem.LargeThumb) && File.Exists(fileItem.SmallThumb)) && File.Exists(fileItem.InfoFile))
            {
                return;
            }

            if (fileItem.Loading)
            {
                return;
            }

            fileItem.Loading = true;

            PhotoUtils.WaitForFile(fileItem.FileName);
            string filename = fileItem.FileName;

            if (fileItem.IsMovie)
            {
                try
                {
                    string ffmpeg_exe = Path.Combine(Settings.ApplicationFolder, "ffmpeg.exe");
                    if (File.Exists(ffmpeg_exe))
                    {
                        string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                                                    Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        PhotoUtils.RunAndWait(ffmpeg_exe, String.Format("-i \"{0}\" -ss 00:00:01.000 -f image2 -vframes 1 \"{1}\"", fileItem.FileName, thumb));
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename   = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get video thumb", exception);
                }
            }
            if (fileItem.IsRaw)
            {
                try
                {
                    string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                    if (File.Exists(dcraw_exe))
                    {
                        string thumb = Path.Combine(Path.GetTempPath(),
                                                    Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        PhotoUtils.RunAndWait(dcraw_exe,
                                              string.Format(" -e -O \"{0}\" \"{1}\"", thumb, fileItem.FileName));
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename   = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get dcraw thumb", exception);
                }
            }

            GetMetadata(fileItem);
            try
            {
                using (MagickImage image = new MagickImage(filename))
                {
                    fileItem.FileInfo.SetSize(image.Width, image.Height);

                    double dw = (double)LargeThumbSize / image.Width;
                    image.FilterType = FilterType.Box;
                    image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw));

                    if (!ServiceProvider.Settings.DisableHardwareAccelerationNew)
                    {
                        image.UnsharpMask(1, 1, 0.5, 0.1);
                    }

                    PhotoUtils.CreateFolder(fileItem.LargeThumb);
                    image.Write(fileItem.LargeThumb);
                    fileItem.IsLoaded = true;
                    fileItem.Loading  = false;

                    dw = (double)SmallThumbSize / image.Width;
                    image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw));

                    if (!ServiceProvider.Settings.DisableHardwareAccelerationNew)
                    {
                        image.UnsharpMask(1, 1, 0.5, 0.1);
                    }

                    PhotoUtils.CreateFolder(fileItem.SmallThumb);
                    image.Write(fileItem.SmallThumb);

                    fileItem.Thumbnail = LoadImage(fileItem.SmallThumb);
                }
                fileItem.SaveInfo();
                SetImageInfo(fileItem);
                if (deleteFile)
                {
                    File.Delete(filename);
                }
                OnMetaDataUpdated(fileItem);
            }
            catch (Exception exception)
            {
                Log.Error("Error generating cache " + fileItem.FileName, exception);
            }
            fileItem.Loading = false;
        }
Ejemplo n.º 4
0
        public void GenerateCache(FileItem fileItem)
        {
            bool deleteFile = false;

            if (fileItem == null)
            {
                return;
            }
            if (!File.Exists(fileItem.FileName))
            {
                return;
            }

            if ((File.Exists(fileItem.LargeThumb) && File.Exists(fileItem.SmallThumb)) && File.Exists(fileItem.InfoFile))
            {
                return;
            }

            string filename = fileItem.FileName;

            if (fileItem.IsMovie)
            {
                try
                {
                    string ffmpeg_exe = Path.Combine(Settings.ApplicationFolder, "ffmpeg.exe");
                    if (File.Exists(ffmpeg_exe))
                    {
                        string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                                                    Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        PhotoUtils.RunAndWait(ffmpeg_exe, String.Format("-i \"{0}\" -ss 00:00:01.000 -f image2 -vframes 1 \"{1}\"", fileItem.FileName, thumb));
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename   = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get video thumb", exception);
                }
            }
            if (fileItem.IsRaw)
            {
                try
                {
                    string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                    if (File.Exists(dcraw_exe))
                    {
                        PhotoUtils.RunAndWait(dcraw_exe, string.Format(" -e \"{0}\"", fileItem.FileName));
                        string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                                                    Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename   = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get dcraw thumb", exception);
                }
            }


            GetMetadata(fileItem);
            try
            {
                var rotation = 0;

                if (fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation"))
                {
                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                    {
                        rotation = 180;
                    }

                    //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                    //    writeableBitmap = writeableBitmap.Rotate(180);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                    {
                        rotation = 90;
                    }

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                    {
                        rotation = 270;
                    }
                }

                using (MemoryStream fileStream = new MemoryStream(File.ReadAllBytes(filename)))
                {
                    BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
                                                                BitmapCreateOptions.PreservePixelFormat,
                                                                BitmapCacheOption.OnLoad);

                    bmpDec.DownloadProgress += (o, args) => StaticHelper.Instance.LoadingProgress = args.Progress;

                    if (rotation == 90 || rotation == 270)
                    {
                        fileItem.FileInfo.SetSize(bmpDec.Frames[0].PixelHeight, bmpDec.Frames[0].PixelWidth);
                    }
                    else
                    {
                        fileItem.FileInfo.SetSize(bmpDec.Frames[0].PixelWidth, bmpDec.Frames[0].PixelHeight);
                    }

                    double          dw = (double)LargeThumbSize / bmpDec.Frames[0].PixelWidth;
                    WriteableBitmap writeableBitmap =
                        BitmapFactory.ConvertToPbgra32Format(GetBitmapFrame(bmpDec.Frames[0],
                                                                            (int)(bmpDec.Frames[0].PixelWidth * dw),
                                                                            (int)(bmpDec.Frames[0].PixelHeight * dw),
                                                                            BitmapScalingMode.Linear));

                    LoadHistogram(fileItem, writeableBitmap);
                    Save2Jpg(writeableBitmap, fileItem.LargeThumb);

                    dw = (double)SmallThumbSize / writeableBitmap.PixelWidth;
                    writeableBitmap = writeableBitmap.Resize((int)(writeableBitmap.PixelWidth * dw),
                                                             (int)(writeableBitmap.PixelHeight * dw),
                                                             WriteableBitmapExtensions.Interpolation.Bilinear);

                    if (rotation > 0)
                    {
                        writeableBitmap = writeableBitmap.Rotate(rotation);
                    }

                    Save2Jpg(writeableBitmap, fileItem.SmallThumb);
                    //var thumb = LoadSmallImage(fileItem);
                    //thumb.Freeze();
                    fileItem.Thumbnail = LoadImage(fileItem.SmallThumb);
                }

                //using (MagickImage image = new MagickImage(filename))
                //{
                //    if (rotation == 90 || rotation == 270)
                //        fileItem.FileInfo.SetSize(image.Height, image.Width);
                //    else
                //        fileItem.FileInfo.SetSize(image.Width, image.Height);

                //    double dw = (double)LargeThumbSize / image.Width;
                //    image.Thumbnail(dw*100);
                //    LoadHistogram(fileItem, image);
                //    image.Write(fileItem.LargeThumb);
                //    dw = (double)LargeThumbSize / image.Width;
                //    image.Thumbnail(dw * 100);
                //    image.Write(fileItem.SmallThumb);
                //    fileItem.Thumbnail = LoadImage(fileItem.SmallThumb);
                //}

                fileItem.IsLoaded = true;
                fileItem.SaveInfo();
                if (deleteFile)
                {
                    File.Delete(filename);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error generating cache " + fileItem.FileName, exception);
            }
        }
Ejemplo n.º 5
0
        public void GenerateCache(FileItem fileItem)
        {
            bool deleteFile = false;
            if (fileItem == null)
                return;
            if (!File.Exists(fileItem.FileName))
                return;

            if ((File.Exists(fileItem.LargeThumb) && File.Exists(fileItem.SmallThumb)) && File.Exists(fileItem.InfoFile))
                return;

            string filename = fileItem.FileName;
            if (fileItem.IsMovie)
            {
                try
                {
                    string ffmpeg_exe = Path.Combine(Settings.ApplicationFolder, "ffmpeg.exe");
                    if (File.Exists(ffmpeg_exe))
                    {
                        string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                            Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        PhotoUtils.RunAndWait(ffmpeg_exe,  String.Format("-i \"{0}\" -ss 00:00:01.000 -f image2 -vframes 1 \"{1}\"",fileItem.FileName, thumb));
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get video thumb", exception);
                }
            }
            if (fileItem.IsRaw)
            {
                try
                {
                    string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                    if (File.Exists(dcraw_exe))
                    {
                        PhotoUtils.RunAndWait(dcraw_exe, string.Format(" -e \"{0}\"", fileItem.FileName));
                        string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                            Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get dcraw thumb", exception);
                }
            }

            GetMetadata(fileItem);
            try
            {
                var rotation = 0;

                if (fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation"))
                {
                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                        rotation = 180;

                    //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                    //    writeableBitmap = writeableBitmap.Rotate(180);

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                        rotation = 90;

                    if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                        rotation = 270;
                }

                using (MemoryStream fileStream = new MemoryStream(File.ReadAllBytes(filename)))
                {
                    BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
                                                                BitmapCreateOptions.PreservePixelFormat,
                                                                BitmapCacheOption.OnLoad);

                    bmpDec.DownloadProgress += (o, args) => StaticHelper.Instance.LoadingProgress = args.Progress;

                    if (rotation == 90 || rotation == 270)
                        fileItem.FileInfo.SetSize(bmpDec.Frames[0].PixelHeight, bmpDec.Frames[0].PixelWidth);
                    else
                        fileItem.FileInfo.SetSize(bmpDec.Frames[0].PixelWidth, bmpDec.Frames[0].PixelHeight);

                    double dw = (double)LargeThumbSize / bmpDec.Frames[0].PixelWidth;
                    WriteableBitmap writeableBitmap =
                        BitmapFactory.ConvertToPbgra32Format(GetBitmapFrame(bmpDec.Frames[0],
                                                                            (int)(bmpDec.Frames[0].PixelWidth * dw),
                                                                            (int)(bmpDec.Frames[0].PixelHeight * dw),
                                                                            BitmapScalingMode.Linear));

                    LoadHistogram(fileItem, writeableBitmap);
                    Save2Jpg(writeableBitmap, fileItem.LargeThumb);

                    dw = (double)SmallThumbSize / writeableBitmap.PixelWidth;
                    writeableBitmap = writeableBitmap.Resize((int)(writeableBitmap.PixelWidth * dw),
                                                             (int)(writeableBitmap.PixelHeight * dw),
                                                             WriteableBitmapExtensions.Interpolation.Bilinear);

                    if (rotation > 0)
                        writeableBitmap = writeableBitmap.Rotate(rotation);

                    Save2Jpg(writeableBitmap, fileItem.SmallThumb);
                    //var thumb = LoadSmallImage(fileItem);
                    //thumb.Freeze();
                    fileItem.Thumbnail = LoadImage(fileItem.SmallThumb);
                }

                //using (MagickImage image = new MagickImage(filename))
                //{
                //    if (rotation == 90 || rotation == 270)
                //        fileItem.FileInfo.SetSize(image.Height, image.Width);
                //    else
                //        fileItem.FileInfo.SetSize(image.Width, image.Height);

                //    double dw = (double)LargeThumbSize / image.Width;
                //    image.Thumbnail(dw*100);
                //    LoadHistogram(fileItem, image);
                //    image.Write(fileItem.LargeThumb);
                //    dw = (double)LargeThumbSize / image.Width;
                //    image.Thumbnail(dw * 100);
                //    image.Write(fileItem.SmallThumb);
                //    fileItem.Thumbnail = LoadImage(fileItem.SmallThumb);
                //}

                fileItem.IsLoaded = true;
                fileItem.SaveInfo();
                if (deleteFile)
                    File.Delete(filename);
            }
            catch (Exception exception)
            {
                Log.Error("Error generating cache " + fileItem.FileName, exception);
            }
        }
Ejemplo n.º 6
0
        public void GenerateCache(FileItem fileItem)
        {
            bool deleteFile = false;
            if (fileItem == null)
                return;
            if (!File.Exists(fileItem.FileName))
                return;
            
            if ((File.Exists(fileItem.LargeThumb) && File.Exists(fileItem.SmallThumb)) && File.Exists(fileItem.InfoFile))
                return;

            string filename = fileItem.FileName;
            if (fileItem.IsRaw)
            {
                string s = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                                        Path.GetFileNameWithoutExtension(fileItem.FileName) + ".jpg");
                if (File.Exists(s))
                {
                    filename = s;
                }
                else
                {
                    try
                    {
                        string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                        if (File.Exists(dcraw_exe))
                        {
                            PhotoUtils.RunAndWait(dcraw_exe, string.Format(" -e {0}", fileItem.FileName));
                            string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                                        Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                            if (File.Exists(thumb))
                            {
                                deleteFile = true;
                                filename = thumb;
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }
            }

            GetMetadata(fileItem);
            try
            {
                using (MemoryStream fileStream = new MemoryStream(File.ReadAllBytes(filename)))
                {
                    BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
                                                                BitmapCreateOptions.PreservePixelFormat,
                                                                BitmapCacheOption.OnLoad);

                    bmpDec.DownloadProgress += (o, args) => StaticHelper.Instance.LoadingProgress = args.Progress;

                    fileItem.FileInfo.Width = bmpDec.Frames[0].PixelWidth;
                    fileItem.FileInfo.Height = bmpDec.Frames[0].PixelHeight;

                    double dw = (double) LargeThumbSize/bmpDec.Frames[0].PixelWidth;
                    WriteableBitmap writeableBitmap =
                        BitmapFactory.ConvertToPbgra32Format(GetBitmapFrame(bmpDec.Frames[0],
                                                                            (int) (bmpDec.Frames[0].PixelWidth*dw),
                                                                            (int) (bmpDec.Frames[0].PixelHeight*dw),
                                                                            BitmapScalingMode.Linear));

                    LoadHistogram(fileItem, writeableBitmap);
                    Save2Jpg(writeableBitmap, fileItem.LargeThumb);

                    dw = (double) SmallThumbSize/writeableBitmap.PixelWidth;
                    writeableBitmap = writeableBitmap.Resize((int) (writeableBitmap.PixelWidth*dw),
                                                             (int) (writeableBitmap.PixelHeight*dw),
                                                             WriteableBitmapExtensions.Interpolation.Bilinear);

                    if (fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation") )
                    {
                        if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                            writeableBitmap = writeableBitmap.Rotate(180);

                        //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                        //    writeableBitmap = writeableBitmap.Rotate(180);

                        if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                            writeableBitmap = writeableBitmap.Rotate(90);

                        if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                            writeableBitmap = writeableBitmap.Rotate(270);
                    }

                    Save2Jpg(writeableBitmap, fileItem.SmallThumb);
                    fileItem.Thumbnail = LoadSmallImage(fileItem);
                    fileItem.IsLoaded = true;
                    fileItem.SaveInfo();
                    if (deleteFile)
                        File.Delete(filename);
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error generating cache", exception);
            }
        }
Ejemplo n.º 7
0
        public void GenerateCache(FileItem fileItem)
        {
            if (fileItem == null)
            {
                return;
            }
            if (!File.Exists(fileItem.FileName))
            {
                return;
            }
            string filename = fileItem.FileName;

            if (fileItem.IsRaw)
            {
                string s = Path.Combine(Path.GetFullPath(fileItem.FileName),
                                        Path.GetFileNameWithoutExtension(fileItem.FileName) + ".jpg");
                if (File.Exists(s))
                {
                    filename = s;
                }
            }
            if ((File.Exists(fileItem.LargeThumb) && File.Exists(fileItem.SmallThumb)) && File.Exists(fileItem.InfoFile))
            {
                return;
            }
            GetMetadata(fileItem);
            try
            {
                using (MemoryStream fileStream = new MemoryStream(File.ReadAllBytes(filename)))
                {
                    BitmapDecoder bmpDec = BitmapDecoder.Create(fileStream,
                                                                BitmapCreateOptions.PreservePixelFormat,
                                                                BitmapCacheOption.OnLoad);

                    bmpDec.DownloadProgress += (o, args) => StaticHelper.Instance.LoadingProgress = args.Progress;

                    fileItem.FileInfo.Width  = bmpDec.Frames[0].PixelWidth;
                    fileItem.FileInfo.Height = bmpDec.Frames[0].PixelHeight;

                    double          dw = (double)LargeThumbSize / bmpDec.Frames[0].PixelWidth;
                    WriteableBitmap writeableBitmap =
                        BitmapFactory.ConvertToPbgra32Format(GetBitmapFrame(bmpDec.Frames[0],
                                                                            (int)(bmpDec.Frames[0].PixelWidth * dw),
                                                                            (int)(bmpDec.Frames[0].PixelHeight * dw),
                                                                            BitmapScalingMode.Linear));

                    LoadHistogram(fileItem, writeableBitmap);
                    Save2Jpg(writeableBitmap, fileItem.LargeThumb);

                    dw = (double)SmallThumbSize / writeableBitmap.PixelWidth;
                    writeableBitmap = writeableBitmap.Resize((int)(writeableBitmap.PixelWidth * dw),
                                                             (int)(writeableBitmap.PixelHeight * dw),
                                                             WriteableBitmapExtensions.Interpolation.Bilinear);

                    if (fileItem.FileInfo.ExifTags.ContainName("Exif.Image.Orientation") && !fileItem.IsRaw)
                    {
                        if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "bottom, right")
                        {
                            writeableBitmap = writeableBitmap.Rotate(180);
                        }

                        //if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "top, left")
                        //    writeableBitmap = writeableBitmap.Rotate(180);

                        if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "right, top")
                        {
                            writeableBitmap = writeableBitmap.Rotate(90);
                        }

                        if (fileItem.FileInfo.ExifTags["Exif.Image.Orientation"] == "left, bottom")
                        {
                            writeableBitmap = writeableBitmap.Rotate(270);
                        }
                    }

                    Save2Jpg(writeableBitmap, fileItem.SmallThumb);
                    fileItem.Thumbnail = LoadSmallImage(fileItem);
                    fileItem.IsLoaded  = true;
                    fileItem.SaveInfo();
                }
            }
            catch (Exception exception)
            {
                Log.Error("Error generating cache", exception);
            }
        }
Ejemplo n.º 8
-1
        public void LoadHistogram(FileItem item)
        {
            try
            {
                var fileInfo = item.FileInfo;
                if (fileInfo!=null)
                {
                    if (fileInfo.IsLoading)
                        return;
                    fileInfo.IsLoading = true;
                }
                if (fileInfo == null || fileInfo.ExifTags == null || fileInfo.ExifTags.Items.Count == 0)
                {
                    GetMetadata(item);
                    fileInfo = item.FileInfo;
                    fileInfo.IsLoading = true;
                }
                if (!File.Exists(item.SmallThumb))
                {
                    fileInfo.IsLoading = false;
                    return;
                }

                using (MagickImage image = new MagickImage(item.SmallThumb))
                {
                    var Blue = new int[256];
                    var Green = new int[256];
                    var Red = new int[256];
                    var Luminance = new int[256];
                    Dictionary<MagickColor, int> h = image.Histogram();
                    foreach (var i in h)
                    {
                        byte R = i.Key.R;
                        byte G = i.Key.G;
                        byte B = i.Key.B;
                        Blue[B] += i.Value;
                        Green[G] += i.Value;
                        Red[R] += i.Value;
                        int lum = (R + R + R + B + G + G + G + G) >> 3;
                        Luminance[lum] += i.Value;
                    }
                    fileInfo.HistogramBlue = Blue;
                    fileInfo.HistogramGreen = Green;
                    fileInfo.HistogramRed = Red;
                    fileInfo.HistogramLuminance = Luminance;
                    fileInfo.IsLoading = false;
                    item.FileInfo = fileInfo;
                }
                item.SaveInfo();
                if (ServiceProvider.Settings.SelectedBitmap.FileItem == item)
                {
                    SetData(ServiceProvider.Settings.SelectedBitmap,
                                 ServiceProvider.Settings.SelectedBitmap.FileItem);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Unable to load histogram", ex);
            }

            //item.FileInfo.HistogramBlue = SmoothHistogram(item.FileInfo.HistogramBlue);
            //item.FileInfo.HistogramGreen = SmoothHistogram(item.FileInfo.HistogramGreen);
            //item.FileInfo.HistogramRed = SmoothHistogram(item.FileInfo.HistogramRed);
            //item.FileInfo.HistogramLuminance = SmoothHistogram(item.FileInfo.HistogramLuminance);
        }