/// <summary> /// Constructor /// </summary> /// <param name="data">The exiftool data which is needed to build this object</param> internal ImageInfo(ExifToolPictureData data) { _ExifToolPictureData = data; // Create the face list with all XMP faces _XmpFaces = new FaceList(); if (data.RegionInfoMp != null && data.RegionInfoMp.Regions != null) { foreach (RegionMp region in data.RegionInfoMp.Regions) { string[] rect = region.Rectangle.Split(new char[] { ',' }); float x, y, w, h; x = (float)Math.Round(Convert.ToSingle(rect[0]), Precision); y = (float)Math.Round(Convert.ToSingle(rect[1]), Precision); w = (float)Math.Round(Convert.ToSingle(rect[2]), Precision); h = (float)Math.Round(Convert.ToSingle(rect[3]), Precision); Face f = new Face(region.PersonConvertedName, new RectangleF(x, y, w, h)); _XmpFaces.Add(f); } } // Create the face list with all Picasa faces _PicasaFaces = new FaceList(); if (data.RegionInfo.RegionList != null) { foreach (ExifTool.Region region in data.RegionInfo.RegionList) { float x, y, w, h; x = (float)Math.Round(region.Area.X - (region.Area.W / 2), Precision); y = (float)Math.Round(region.Area.Y - (region.Area.H / 2), Precision); w = (float)Math.Round(region.Area.W, Precision); h = (float)Math.Round(region.Area.H, Precision); Face f = new Face(region.PersonConvertedName, new RectangleF(x, y, w, h)); _PicasaFaces.Add(f); } } }
/// <summary> /// Check the Pictures, if delta is found, set it to DeltaList /// </summary> /// <returns>true, DeltaList is built</returns> public bool CheckPics() { _DeltaList = new FaceList(); _OnlyInPicasa = new FaceList(); _OnlyInExif = new FaceList(); _RegionMismatch = new FaceList(); _WriteData = new FaceList(); #if oldcode // 1) if there are faces in Picasa and none in exif: copy all // 2) if there are none in Picasa and some in exif: do nothing // 3) compare, list difference // 1) if (ExifInfoMissing && !PicasaInfoMissing) { foreach (KeyValuePair <string, Face> kp in PicasaInfo.Faces) { _DeltaList.Add(kp.Key, kp.Value); _OnlyInPicasa.Add(kp.Key, kp.Value); _WriteData.Add(kp.Key, kp.Value); Debug.WriteLine("No XMP Info read with exiftool", this.FileName); } return(true); } // 2) if (PicasaInfoMissing && !ExifInfoMissing) { foreach (KeyValuePair <string, Face> kp in ExifInfo.Faces) { _OnlyInExif.Add(kp.Key, kp.Value); _WriteData.Add(kp.Key, kp.Value); Debug.WriteLine("XMP Info available but none from Picasa", this.FileName); } return(false); } // 3) Compare: not only the name, also the region foreach (KeyValuePair <string, Face> kp in PicasaInfo.Faces) { if (!ExifInfo.Faces.ContainsKey(kp.Key)) { // name was found in Picasa but not in exif. But what if it was // renamed in picasa? we add it here, but we have to check it // when reading exiftool data later on _DeltaList.Add(kp.Key, kp.Value); _OnlyInPicasa.Add(kp.Key, kp.Value); Debug.WriteLine("Found in Picasa but not in XMP", this.FileName); _WriteData.Add(kp.Key, kp.Value); } else { // how about the region? if (!CompareRectangle(kp.Value.Rect, ExifInfo.Faces[kp.Key].Rect)) { if (_RegionMismatch.ContainsKey(kp.Key)) { _RegionMismatch.Add(kp.Key, kp.Value); } else { Debug.WriteLine("Rectangle mismatch", this.FileName); _WriteData.Add(kp.Key, kp.Value); _DeltaList.Add(kp.Key, kp.Value); } } else { // is the same, so add to "write data" (otherwise we loose this info) Debug.WriteLine("Same in Picasa and XMP", this.FileName); _WriteData.Add(kp.Key, kp.Value); } } } foreach (KeyValuePair <string, Face> kp in ExifInfo.Faces) { if (!PicasaInfo.Faces.ContainsKey(kp.Key)) { // Name in Exif but not in Picasa. As picasa has the higher priority, // we have to check whether the region is already used or not bool found = false; foreach (KeyValuePair <string, Face> alreadyHere in _WriteData) { if (CompareRectangle(alreadyHere.Value.Rect, kp.Value.Rect, 10)) { // yes, it is here! Ignore this one found = true; break; } } if (!found) { _OnlyInExif.Add(kp.Key, kp.Value); _WriteData.Add(kp.Key, kp.Value); Debug.WriteLine("Found in XMP but not in Picasa", this.FileName); } else { _DeltaList.Add(kp.Key, kp.Value); } } else { // region? if (!CompareRectangle(kp.Value.Rect, PicasaInfo.Faces[kp.Key].Rect)) { if (_RegionMismatch.ContainsKey(kp.Key)) { _RegionMismatch.Add(kp.Key, kp.Value); } else { if (!_WriteData.ContainsKey(kp.Key)) { _WriteData.Add(kp.Key, kp.Value); } } } else { // is the same, so add to "write data" (otherwise we loose this info) if (!_WriteData.ContainsKey(kp.Key)) { Debug.WriteLine("Same in Picasa and XMP", this.FileName); _WriteData.Add(kp.Key, kp.Value); } } } } #endif return(_WriteData.Count > 0); }