/// <summary> /// Authors /// </summary> public static List<string> GetAuthors(ImageData data) { if(InitializeReader(data) == false) { return null; } // extract the tags try { XmlNode node = data.XmpDocument.SelectSingleNode("/rdf:RDF/rdf:Description/dc:creator/rdf:Seq", namespaceManager); if(node != null) { List<string> authors = new List<string>(); // copy the tags foreach(XmlNode author in node) { authors.Add(author.InnerText); } return authors; } } catch { } return null; }
protected override bool AllowProperty(bool condition, ImageData data) { // get the author from XMP List<string> authors = XmpReader.GetAuthors(data); if(authors != null && authors.Count > 0) { for(int i = 0; i < authors.Count; i++) { if(_regularExpression) { bool? value = IsRegexMatch(authors[i]); if(value.HasValue && value.Value == true) { return condition; } } else { // normal match if(authors[i].IndexOf(_value, _matchCase ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase) >= 0) { return condition; } } } } else { // get the author from EXIF string text = ExifReader.GetAuthor(data); if(text == null || _value == null) { return !condition; } if(_regularExpression) { bool? value = IsRegexMatch(text); if(value.HasValue && value.Value == true) { return condition; } } else { // normal match if(text.IndexOf(_value, _matchCase ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase) >= 0) { return condition; } } } return !condition; }
/// <summary> /// Title /// </summary> public static string GetTitle(ImageData data) { if(InitializeReader(data) == false) { return null; } // extract the title try { XmlNode node = data.XmpDocument.SelectSingleNode("/rdf:RDF/rdf:Description/dc:title/rdf:Alt", namespaceManager); if(node != null && node.ChildNodes.Count > 0) { return node.ChildNodes[0].InnerText; } } catch { } return null; }
public override bool Allow(string file) { Debug.AssertNotNull(file, "File is null"); bool condition = _condition == FilterCondition.IS ? true : false; ImageData data = null; if(_helperObject != null) { if(_helperObject is ImageData) { _helperObject = (ImageData)_helperObject; } else { _helperObject.Dispose(); } } else { // create a new helper object _helperObject = new ImageData(); data = (ImageData)_helperObject; // load the picture if(IsImage(file) == false || data.LoadImage(file) == false) { // failed return !condition; } } return AllowProperty(condition, data); }
/// <summary> /// Orientation /// </summary> public static ImageOrientation? GetOrientation(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(OrientationId); int value = BitConverter.ToInt16(item.Value, 0); switch(value) { case 1: { return ImageOrientation.Correct; } case 6: { return ImageOrientation.RotateRight; } case 8: { return ImageOrientation.RotateLeft; } default: { return ImageOrientation.Correct; } } } catch(Exception e) { return null; } }
/// <summary> /// ISO /// </summary> public static int? GetIso(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(IsoId); return BitConverter.ToInt16(item.Value, 0); } catch(Exception e) { return null; } }
/// <summary> /// Flash fired /// </summary> public static bool? GetFlashFired(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(FlashFiredId); return BitConverter.ToInt16(item.Value, 0) == 1; } catch(Exception e) { return null; } }
/// <summary> /// Exposure program /// </summary> public static ExposureProgram? GetExposureProgram(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(ExposureProgramId); int value = BitConverter.ToInt16(item.Value, 0); switch(value) { case 0: { return ExposureProgram.NotDefined; } case 1: { return ExposureProgram.Manual; } case 2: { return ExposureProgram.Program; } case 3: { return ExposureProgram.AperaturePriority; } case 4: { return ExposureProgram.ShutterPriority; } case 5: { return ExposureProgram.CreativeProgram; } case 6: { return ExposureProgram.ActionProgram; } case 7: { return ExposureProgram.PortaitMode; } case 8: { return ExposureProgram.LandscapeMode; } default: { return ExposureProgram.NotDefined; } } } catch(Exception e) { return null; } }
/// <summary> /// Taken date /// </summary> public static DateTime? GetDateTaken(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(TakenDateId); return DateTime.Parse(data.Ascii.GetString(item.Value)); } catch(Exception e) { return null; } }
protected override bool AllowProperty(bool condition, ImageData data) { ExifReader.ExposureProgram? program = ExifReader.GetExposureProgram(data); if(program.HasValue) { if(program.Value == _value) { return condition; } } return !condition; }
protected override bool AllowProperty(bool condition, ImageData data) { DateTime? date = ExifReader.GetDateTaken(data); if(date.HasValue) { if(_dateImplication == DateImplication.From) { if(date.Value.Day == _value.Day && date.Value.Month == _value.Month && date.Value.Year == _value.Year) { return condition; } } else if(_dateImplication == DateImplication.OlderOrFrom) { if(date.Value <= _value) { return condition; } } else { if(date.Value >= _value) { return condition; } } } return !condition; }
protected override bool AllowProperty(bool condition, ImageData data) { string text = ExifReader.GetCopyright(data); if(text == null || _value == null) { return !condition; } if(_regularExpression) { bool? value = IsRegexMatch(text); if(value.HasValue && value.Value == true) { return condition; } } else { // normal match if(text.IndexOf(_value, _matchCase ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase) >= 0) { return condition; } } return !condition; }
/// <summary> /// Rating /// </summary> public static int? GetRating(ImageData data) { if(InitializeReader(data) == false) { return null; } // extract the rating try { XmlNode node = data.XmpDocument.SelectSingleNode("/rdf:RDF/rdf:Description/xap:Rating", namespaceManager); if(node != null) { return int.Parse(node.InnerText); } else { // try to get it from Vista Photo Gallery node = data.XmpDocument.SelectSingleNode("/rdf:RDF/rdf:Description", namespaceManager); foreach(XmlAttribute attribute in node.Attributes) { if(attribute.Name == "MicrosoftPhoto:Rating") { // values are ranging from 0 to 100 // convert to 0 - 5 stars double value = double.Parse(attribute.Value) / 100; return (int)Math.Floor(value * 5.0); } } } } catch { } return null; }
private static bool InitializeReader(ImageData data) { if(data.XmpDocument == null) { string xmpData = GetXmpXmlDocFromImage(data.Stream); if(xmpData == null || xmpData.Length == 0) { return false; } data.XmpDocument = GetXmpDocument(xmpData); // generate the namespace manager if(data.XmpDocument != null) { GenerateNamespaceManager(data.XmpDocument); } return data.XmpDocument != null; } else { return true; } }
protected override bool AllowProperty(bool condition, ImageData data) { // get the list of tags List<string> tagList = XmpReader.GetTags(data); if(tagList != null && tagList.Count > 0) { int count = _tags.Count; bool result = true; for(int i = 0; i < count; i++) { // skip disabled tags if(_tags[i].Enabled == false) { continue; } result &= MatchTags(tagList, _tags[i]); if(_tagImplication == TagImplication.All && result == false) { // not all tags match return !condition; } else if(_tagImplication == TagImplication.Some && result == true) { return condition; } } if(result == false) { return !condition; } else { return condition; } } return !condition; }
protected override bool AllowProperty(bool condition, ImageData data) { int? rating = XmpReader.GetRating(data); // presume the rating is 0 if it couldn't be retrieved if(rating.HasValue == false && _value > 0) { return !condition; } else { rating = 0; } // filter if(_sizeImplication == SizeImplication.Equals) { if(rating.Value == _value) { return condition; } } else if(_sizeImplication == SizeImplication.LessThan) { if(rating.Value <= _value) { return condition; } } else { if(rating.Value >= _value) { return condition; } } return !condition; }
protected override bool AllowProperty(bool condition, ImageData data) { ExifReader.Fraction time = ExifReader.GetExposureTime(data); if(time != null) { // invalid values, would throw a DivideByZeroException if(time.Denominator == 0 || _value.Denominator == 0) { return !condition; } double a = (double)time.Numerator / (double)time.Denominator; double b = (double)_value.Numerator / (double)_value.Denominator; if(_sizeImplication == SizeImplication.Equals) { if(Math.Abs(b - a) < Epsilon) { return condition; } } else if(_sizeImplication == SizeImplication.LessThan) { if(b <= a) { return condition; } } else { if(b >= a) { return condition; } } } return !condition; }
/// <summary> /// Exposure bias /// </summary> public static double? GetExposureBias(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(ExposureBiasId); return (double)BitConverter.ToInt16(item.Value, 0) / 2.0; } catch(Exception e) { return null; } }
protected override bool AllowProperty(bool condition, ImageData data) { bool? fired = ExifReader.GetFlashFired(data); if(fired.HasValue) { if(fired.Value == _value) { return condition; } } return !condition; }
/// <summary> /// Exposure time /// </summary> public static Fraction GetExposureTime(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(ExposureTimeId); Fraction value = new Fraction(BitConverter.ToInt16(item.Value, 0), BitConverter.ToInt16(item.Value, 4)); // simplify fraction if(value.Denominator % 10 == 0 && value.Numerator % 10 == 0) { value.Denominator /= 10; value.Numerator /= 10; } return value; } catch(Exception e) { return null; } }
protected override bool AllowProperty(bool condition, ImageData data) { double? number = ExifReader.GetFNumber(data); if(number.HasValue) { if(_sizeImplication == SizeImplication.Equals) { if(Math.Abs(number.Value - _value) < Epsilon) { return condition; } } else if(_sizeImplication == SizeImplication.LessThan) { if(number.Value <= _value) { return condition; } } else { if(number.Value >= _value) { return condition; } } } return !condition; }
/// <summary> /// FNumber /// </summary> public static double? GetFNumber(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(FNumberId); int value = BitConverter.ToInt16(item.Value, 0); if(value < 100) { return Math.Round((double)value / 10, 1); } else { return value; } } catch(Exception e) { return null; } }
protected override bool AllowProperty(bool condition, ImageData data) { int? iso = ExifReader.GetIso(data); if(iso.HasValue) { if(_sizeImplication == SizeImplication.Equals) { if(iso.Value == _value) { return condition; } } else if(_sizeImplication == SizeImplication.LessThan) { if(iso.Value <= _value) { return condition; } } else { if(iso.Value >= _value) { return condition; } } } return !condition; }
/// <summary> /// Metering mode /// </summary> public static MeteringMode? GetMeteringMode(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(ExposureBiasId); int value = BitConverter.ToInt16(item.Value, 0); switch(value) { case 0: { return MeteringMode.Unknown; } case 1: { return MeteringMode.AverageMetering; } case 2: { return MeteringMode.CenterWeightedAverageMetering; } case 3: { return MeteringMode.SpotMetering; } case 4: { return MeteringMode.MultiSpotMetering; } case 5: { return MeteringMode.MatrixMetering; } case 6: { return MeteringMode.PartialMetering; } default: { return MeteringMode.AverageMetering; } } } catch(Exception e) { return null; } }
protected override bool AllowProperty(bool condition, ImageData data) { ExifReader.MeteringMode? mode = ExifReader.GetMeteringMode(data); if(mode.HasValue) { if(mode.Value == _value) { return condition; } } return !condition; }
/// <summary> /// Camera maker /// </summary> public static string GetTitle(ImageData data) { try { PropertyItem item = data.Image.GetPropertyItem(TitleId); return data.Ascii.GetString(item.Value); } catch(Exception e) { return null; } }
protected override bool AllowProperty(bool condition, ImageData data) { ExifReader.ImageOrientation? orientation = ExifReader.GetOrientation(data); if(orientation.HasValue && orientation.Value == _value) { return condition; } return !condition; }
/// <summary> /// Abstract method that needs to be implemented in the derived objects /// </summary> protected abstract bool AllowProperty(bool condition, ImageData data);
/// <summary> /// Tags /// </summary> public static List<string> GetTags(ImageData data) { if(InitializeReader(data) == false) { return null; } // extract the tags try { XmlNode node = data.XmpDocument.SelectSingleNode("/rdf:RDF/rdf:Description/dc:subject/rdf:Bag", namespaceManager); if(node != null) { List<string> tags = new List<string>(); // copy the tags foreach(XmlNode tag in node) { tags.Add(tag.InnerText); } return tags; } } catch { } return null; }