public static void Run(HelpSections sections)
 {
     if (_helpData == null)
     {
         Init();
     }
     PhotoUtils.Run(_helpData[sections], "");
 }
Beispiel #2
0
 public void LoadInfo()
 {
     try
     {
         if (File.Exists(InfoFile))
         {
             PhotoUtils.WaitForFile(InfoFile);
             XmlSerializer mySerializer =
                 new XmlSerializer(typeof(FileInfo));
             FileStream myFileStream = new FileStream(InfoFile, FileMode.Open);
             FileInfo = (FileInfo)mySerializer.Deserialize(myFileStream);
             myFileStream.Close();
         }
     }
     catch (Exception e)
     {
         Log.Error(e);
     }
 }
Beispiel #3
0
 public void SaveInfo()
 {
     if (FileInfo == null)
     {
         return;
     }
     try
     {
         PhotoUtils.CreateFolder(InfoFile);
         FileInfo.ValidateValues();
         XmlSerializer serializer = new XmlSerializer(typeof(FileInfo));
         // Create a FileStream to write with.
         System.Text.Encoding code   = Encoding.GetEncoding("UTF-8");
         StreamWriter         writer = new StreamWriter(InfoFile, false, code);
         // Serialize the object, and close the TextWriter
         serializer.Serialize(writer, FileInfo);
         writer.Close();
     }
     catch (Exception)
     {
         Log.Error("Unable to save session branding file");
     }
 }
Beispiel #4
0
 public void Start()
 {
     //_hookID = SetHook(_proc);
     try
     {
         KeyboardHook.KeyDownEvent += KeyDown;
         KeyboardHook.KeyUpEvent   += KeyUp;
         if (ServiceProvider.Settings.UseWebserver)
         {
             WebServer.Start(ServiceProvider.Settings.WebserverPort);
             string file = Path.Combine(Settings.ApplicationFolder, "ngrok.exe");
             _ngrok_process = PhotoUtils.Run(file, "http " + ServiceProvider.Settings.WebserverPort,
                                             ProcessWindowStyle.Hidden);
             if (_ngrok_process == null)
             {
                 return;
             }
             Thread.Sleep(2000);
             using (var client = new WebClient())
             {
                 string  data = client.DownloadString("http://127.0.0.1:4040/api/tunnels");
                 dynamic json = Newtonsoft.Json.JsonConvert.DeserializeObject(data);
                 string  url  = json.tunnels[0].public_url;
                 if (!string.IsNullOrEmpty(url))
                 {
                     client.DownloadString(
                         string.Format("http://digicamcontrol.com/remote/submit.php?id={0}&url={1}",
                                       ServiceProvider.Settings.ClientId, url));
                 }
             }
         }
     }
     catch (Exception)
     {
         Log.Error("Unable to start webserver");
     }
 }
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres, bool showfocuspoints)
        {
            if (fileItem == null)
            {
                return(null);
            }
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
            {
                return(null);
            }
            if (File.Exists(fileItem.InfoFile))
            {
                fileItem.LoadInfo();
            }
            if (fileItem.FileInfo == null)
            {
                fileItem.FileInfo = new FileInfo();
            }

            try
            {
                BitmapDecoder bmpDec = null;
                if (fullres && 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))
                            {
                                bmpDec = BitmapDecoder.Create(new Uri(thumb), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                                File.Delete(thumb);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }

                PhotoUtils.WaitForFile(fullres ? fileItem.FileName : fileItem.LargeThumb);
                if (bmpDec == null)
                {
                    bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                                                  BitmapCreateOptions.None,
                                                  BitmapCacheOption.OnLoad);
                }
                // if no future processing required
                if (!showfocuspoints && ServiceProvider.Settings.RotateIndex == 0 && !ServiceProvider.Settings.FlipPreview)
                {
                    fileItem.Loading = false;
                    var b = new WriteableBitmap(bmpDec.Frames[0]);
                    b.Freeze();
                    return(b);
                }

                var bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);

                if (showfocuspoints && !fileItem.Transformed)
                {
                    DrawFocusPoints(fileItem, bitmap);
                }


                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                    case 1:
                        bitmap = bitmap.Rotate(90);
                        break;

                    case 2:
                        bitmap = bitmap.Rotate(180);
                        break;

                    case 3:
                        bitmap = bitmap.Rotate(270);
                        break;
                    }
                }

                if (ServiceProvider.Settings.FlipPreview)
                {
                    bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                }

                bitmap.Freeze();
                return(bitmap);
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
                if (exception.GetType() == typeof(OutOfMemoryException) && fullres)
                {
                    return(LoadImage(fileItem, false));
                }
            }
            return(null);
        }
        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;
        }
Beispiel #7
0
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres, bool showfocuspoints)
        {
            int rotation = 0;

            if (fileItem == null)
            {
                return(null);
            }
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
            {
                return(null);
            }

            if (File.Exists(fileItem.InfoFile))
            {
                fileItem.LoadInfo();
            }
            else
            {
                fileItem.FileInfo = new FileInfo();
            }

            try
            {
                BitmapDecoder bmpDec = null;
                if (fullres && 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))
                            {
                                bmpDec = BitmapDecoder.Create(new Uri(thumb), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                                File.Delete(thumb);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }

                if (ServiceProvider.Settings.Autorotate && fileItem.FileInfo != null && 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")
                    //    bitmap = bitmap.Rotate(180);

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

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

                if (bmpDec == null)
                {
                    bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                                                  BitmapCreateOptions.None,
                                                  BitmapCacheOption.OnLoad);
                }
                // if no future processing required
                if (rotation == 0 && !showfocuspoints && ServiceProvider.Settings.RotateIndex == 0 && ServiceProvider.Settings.FlipPreview)
                {
                    return(new WriteableBitmap(bmpDec.Frames[0]));
                }


                var bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);


                if (showfocuspoints)
                {
                    DrawFocusPoints(fileItem, bitmap);
                }

                if (rotation != 0)
                {
                    bitmap = bitmap.Rotate(rotation);
                }

                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                    case 1:
                        bitmap = bitmap.Rotate(90);
                        break;

                    case 2:
                        bitmap = bitmap.Rotate(180);
                        break;

                    case 3:
                        bitmap = bitmap.Rotate(270);
                        break;
                    }
                }

                if (ServiceProvider.Settings.FlipPreview)
                {
                    bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                }

                bitmap.Freeze();
                return(bitmap);
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
            }
            return(null);
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
        public void Load(FileItem fileItem)
        {
            var startInfo =
                new ProcessStartInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                                                  "Tools", "exiv2.exe"))
            {
                Arguments = "\"" + fileItem.FileName + "\"" + " -p a",
                RedirectStandardOutput = true,
                UseShellExecute        = false,
                CreateNoWindow         = true,
                WindowStyle            = ProcessWindowStyle.Minimized
            };

            var process = Process.Start(startInfo);

            process.OutputDataReceived += process_OutputDataReceived;
            process.BeginOutputReadLine();

            process.WaitForExit();
            if (Tags.ContainsKey("Exif.Photo.PixelXDimension"))
            {
                int.TryParse(Tags["Exif.Photo.PixelXDimension"].Value, out Width);
                int.TryParse(Tags["Exif.Photo.PixelYDimension"].Value, out Height);
            }
            else
            {
                if (Tags.ContainsKey("Exif.SubImage2.ImageWidth"))
                {
                    int.TryParse(Tags["Exif.SubImage2.ImageWidth"].Value, out Width);
                }
                if (Tags.ContainsKey("Exif.SubImage2.ImageLength"))
                {
                    int.TryParse(Tags["Exif.SubImage2.ImageLength"].Value, out Height);
                }
            }
            int relWidth  = Width;
            int relHeight = Height;

            Focuspoints = new List <Rect>();
            if (Tags.ContainsKey("Exif.NikonAf2.ContrastDetectAF"))
            {
                if (Tags["Exif.NikonAf2.ContrastDetectAF"].Value == "On")
                {
                    int x = (int)(ToSize(Tags["Exif.NikonAf2.AFAreaXPosition"].Value));
                    int y = (int)(ToSize(Tags["Exif.NikonAf2.AFAreaYPosition"].Value));
                    int w = (int)(ToSize(Tags["Exif.NikonAf2.AFAreaWidth"].Value));
                    int h = (int)(ToSize(Tags["Exif.NikonAf2.AFAreaHeight"].Value));
                    if (x - (w / 2) > 0 && y - (h / 2) > 0 && x > 0 && y > 0 && w > 0 && h > 0)
                    {
                        Focuspoints.Add(new Rect(x - (w / 2), y - (h / 2), w, h));
                    }
                }
            }
            if (Tags.ContainsKey("Exif.NikonAf2.PhaseDetectAF") &&
                Tags["Exif.NikonAf2.PhaseDetectAF"].Value == "On (11-point)")
            {
                if (Tags["Exif.NikonAf2.AFPointsUsed"].Value.Contains(" "))
                {
                    string[] strbytes = Tags["Exif.NikonAf2.AFPointsUsed"].Value.Split(' ');
                    byte[]   bytes    = new byte[8];
                    for (int i = 0; i < strbytes.Length; i++)
                    {
                        byte.TryParse(strbytes[i], out bytes[i]);
                    }
                    Int64 focuspoints = BitConverter.ToInt64(bytes, 0);
                    for (var i = 1; i < 12; i++)
                    {
                        if (StaticHelper.GetBit(focuspoints, i - 1))
                        {
                            Focuspoints.Add(ToRect(relWidth, relHeight, FocusPoints11[i.ToString()], 1, 1));
                        }
                    }
                }
            }
            if (Tags.ContainsKey("Exif.NikonAf2.PhaseDetectAF") &&
                Tags["Exif.NikonAf2.PhaseDetectAF"].Value == "On (51-point)")
            {
                if (Tags["Exif.NikonAf2.AFPointsUsed"].Value.Contains(" "))
                {
                    string[] strbytes = Tags["Exif.NikonAf2.AFPointsUsed"].Value.Split(' ');
                    byte[]   bytes    = new byte[8];
                    for (int i = 0; i < strbytes.Length; i++)
                    {
                        byte.TryParse(strbytes[i], out bytes[i]);
                    }
                    BitArray bitArray = new BitArray(bytes);
                    for (var i = 1; i < 52; i++)
                    {
                        if (bitArray.Get(i - 1))
                        {
                            Focuspoints.Add(ToRect(relWidth, relHeight, FocusPoints51[i.ToString()], 1, 1));
                        }
                    }
                }
            }

            if (Tags.ContainsKey("Exif.Canon.AFInfo"))
            {
                if (Tags["Exif.Canon.AFInfo"].Value.Contains(" "))
                {
                    string[] vals   = Tags["Exif.Canon.AFInfo"].Value.Split(' ');
                    int      poinst = PhotoUtils.GetInt(vals[2]);
                    int[]    poitw  = new int[poinst];
                    int[]    poith  = new int[poinst];
                    int[]    poitx  = new int[poinst];
                    int[]    poity  = new int[poinst];
                    if (vals.Length > poinst * 4 + 9)
                    {
                        long activepoint = Convert.ToInt64(vals[9 + (poinst * 4)]);
                        for (int i = 0; i < poinst; i++)
                        {
                            poitw[i] = PhotoUtils.GetInt(vals[8 + i]);
                            poith[i] = PhotoUtils.GetInt(vals[8 + (poinst) + i]);
                            poitx[i] = PhotoUtils.GetInt(vals[8 + (poinst * 2) + i]);
                            poity[i] = PhotoUtils.GetInt(vals[8 + (poinst * 3) + i]);
                        }
                        for (int i = 0; i < poinst; i++)
                        {
                            int x = Convert.ToInt16(poitx[i].ToString("X"), 16);
                            int y = Convert.ToInt16(poity[i].ToString("X"), 16);
                            if (StaticHelper.GetBit(activepoint, i))
                            {
                                x = (Width / 2) + x;
                                y = (Height / 2) - y;
                                Focuspoints.Add(new Rect(x - (poitw[i] / 2), y - (poith[i] / 2), poitw[i], poith[i]));
                            }
                        }
                    }
                }
            }

            if (Tags.ContainsKey("Exif.NikonAf.AFPointsInFocus"))
            {
                if (FocusPoints7.ContainsKey(Tags["Exif.NikonAf.AFPointsInFocus"].Value))
                {
                    Focuspoints.Add(ToRect(relWidth, relHeight, FocusPoints7[Tags["Exif.NikonAf.AFPointsInFocus"].Value],
                                           1, 1));
                }
            }

            if (fileItem.FileInfo == null)
            {
                fileItem.FileInfo = new FileInfo();
            }

            fileItem.FileInfo.ExifTags.Items.Clear();

            foreach (KeyValuePair <string, Exiv2Data> data in Tags)
            {
                fileItem.FileInfo.ExifTags.Items.Add(new ValuePair()
                {
                    Name = data.Key, Value = data.Value.Value
                });
            }
            fileItem.FileInfo.FocusPoints.Clear();
            foreach (Rect focuspoint in Focuspoints)
            {
                fileItem.FileInfo.FocusPoints.Add(focuspoint);
            }
            return;
        }
        public WriteableBitmap LoadImage(FileItem fileItem, bool fullres, bool showfocuspoints)
        {
            if (ServiceProvider.Settings.LowMemoryUsage)
            {
                fullres = false;
            }

            if (fileItem == null)
            {
                return(null);
            }
            if (!File.Exists(fileItem.LargeThumb) && !fullres)
            {
                return(null);
            }

            if (File.Exists(fileItem.InfoFile))
            {
                fileItem.LoadInfo();
            }
            else
            {
                fileItem.FileInfo = new FileInfo();
            }

            try
            {
                BitmapDecoder bmpDec = null;
                if (fullres && 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))
                            {
                                bmpDec = BitmapDecoder.Create(new Uri(thumb), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                                File.Delete(thumb);
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Log.Error("Error get dcraw thumb", exception);
                    }
                }

                if (bmpDec == null)
                {
                    bmpDec = BitmapDecoder.Create(new Uri(fullres ? fileItem.FileName : fileItem.LargeThumb),
                                                  BitmapCreateOptions.None,
                                                  BitmapCacheOption.OnLoad);
                }

                double          dw = (double)MaxThumbSize / bmpDec.Frames[0].PixelWidth;
                WriteableBitmap bitmap;

                /*
                 * if (fullres)
                 *  bitmap =
                 *      BitmapFactory.ConvertToPbgra32Format(GetBitmapFrame(bmpDec.Frames[0],
                 *                                                          (int) (bmpDec.Frames[0].PixelWidth*dw),
                 *                                                          (int) (bmpDec.Frames[0].PixelHeight*dw),
                 *                                                          BitmapScalingMode.NearestNeighbor));
                 * else
                 *  bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);
                 */
                bitmap = BitmapFactory.ConvertToPbgra32Format(bmpDec.Frames[0]);

                if (showfocuspoints)
                {
                    DrawFocusPoints(fileItem, bitmap);
                }

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

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

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

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

                if (ServiceProvider.Settings.RotateIndex != 0)
                {
                    switch (ServiceProvider.Settings.RotateIndex)
                    {
                    case 1:
                        bitmap = bitmap.Rotate(90);
                        break;

                    case 2:
                        bitmap = bitmap.Rotate(180);
                        break;

                    case 3:
                        bitmap = bitmap.Rotate(270);
                        break;
                    }
                }

                if (ServiceProvider.Settings.FlipPreview)
                {
                    bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                }

                bitmap.Freeze();
                return(bitmap);
            }
            catch (Exception exception)
            {
                Log.Error("Error loading image", exception);
            }
            return(null);
        }