Initial commit

This commit is contained in:
Thastertyn committed 2024-06-07 00:47:07 +02:00
commit 262601edb8
2025 files changed
+218754

No files matched your search

+145
View File
@@ -0,0 +1,145 @@
//
// Codec.cs:
//
// Author:
// Ruben Vermeersch (ruben@savanne.be)
// Mike Gemuende (mike@gemuende.de)
//
// Copyright (C) 2009 Ruben Vermeersch
// Copyright (C) 2009 Mike Gemuende
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
using System;
namespace TagLib.Image
{
/// <summary>
/// A photo codec. Contains basic photo details.
/// </summary>
public abstract class Codec : IPhotoCodec
{
#region Properties
/// <summary>
/// Gets the duration of the media represented by the current
/// instance.
/// </summary>
/// <value>
/// A <see cref="TimeSpan" /> containing the duration of the
/// media represented by the current instance.
/// </value>
public TimeSpan Duration { get { return TimeSpan.Zero; } }
/// <summary>
/// Gets the types of media represented by the current
/// instance.
/// </summary>
/// <value>
/// A bitwise combined <see cref="MediaTypes" /> containing
/// the types of media represented by the current instance.
/// </value>
public MediaTypes MediaTypes { get { return MediaTypes.Photo; } }
/// <summary>
/// Gets a text description of the media represented by the
/// current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing a description
/// of the media represented by the current instance.
/// </value>
public abstract string Description { get; }
/// <summary>
/// Gets the width of the photo represented by the current
/// instance.
/// </summary>
/// <value>
/// A <see cref="int" /> value containing the width of the
/// photo represented by the current instance.
/// </value>
public int PhotoWidth { get; protected set; }
/// <summary>
/// Gets the height of the photo represented by the current
/// instance.
/// </summary>
/// <value>
/// A <see cref="int" /> value containing the height of the
/// photo represented by the current instance.
/// </value>
public int PhotoHeight { get; protected set; }
/// <summary>
/// Gets the (format specific) quality indicator of the photo
/// represented by the current instance.
/// </summary>
/// <value>
/// A <see cref="int" /> value indicating the quality. A value
/// 0 means that there was no quality indicator for the format
/// or the file.
/// </value>
public int PhotoQuality { get; protected set; }
#endregion
#region Constructors
/// <summary>
/// Constructs a new <see cref="Codec" /> with the given width
/// and height.
/// </summary>
/// <param name="width">
/// The width of the photo.
/// </param>
/// <param name="height">
/// The height of the photo.
/// </param>
/// <returns>
/// A new <see cref="Codec" /> instance.
/// </returns>
public Codec (int width, int height)
: this (width, height, 0)
{
}
/// <summary>
/// Constructs a new <see cref="Codec" /> with the given width
/// and height.
/// </summary>
/// <param name="width">
/// The width of the photo.
/// </param>
/// <param name="height">
/// The height of the photo.
/// </param>
/// <param name="quality">
/// The quality indicator for the photo, if the format supports it.
/// </param>
/// <returns>
/// A new <see cref="Codec" /> instance.
/// </returns>
public Codec (int width, int height, int quality)
{
PhotoWidth = width;
PhotoHeight = height;
PhotoQuality = quality;
}
#endregion
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 53e27162094a4524997407685f897a19
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,666 @@
//
// CombinedImageTag.cs: The class provides an abstraction to combine
// ImageTags.
//
// Author:
// Mike Gemuende (mike@gemuende.de)
// Paul Lange (palango@gmx.de)
//
// Copyright (C) 2009 Mike Gemuende
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
using System;
using System.Collections.Generic;
using TagLib.IFD;
using TagLib.Xmp;
namespace TagLib.Image
{
/// <summary>
/// Combines some <see cref="ImageTag"/> instance to behave as one.
/// </summary>
public class CombinedImageTag : ImageTag
{
#region Private Fields
/// <summary>
/// Direct access to the Exif (IFD) tag (if any)
/// </summary>
public IFDTag Exif { get; private set; }
/// <summary>
/// Direct access to the Xmp tag (if any)
/// </summary>
public XmpTag Xmp { get; private set; }
/// <summary>
/// Other image tags available in this tag.
/// </summary>
public List<ImageTag> OtherTags { get; private set; }
/// <summary>
/// Stores the types of the tags, which are allowed for
/// the current instance.
/// </summary>
internal TagTypes AllowedTypes { get; private set; }
/// <summary>
/// Returns all image tags in this tag, with XMP
/// and Exif first.
/// </summary>
public List<ImageTag> AllTags {
get {
if (all_tags == null) {
all_tags = new List<ImageTag> ();
if (Xmp != null)
all_tags.Add (Xmp);
if (Exif != null)
all_tags.Add (Exif);
all_tags.AddRange (OtherTags);
}
return all_tags;
}
}
List<ImageTag> all_tags;
#endregion
#region Constructors
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="CombinedImageTag" /> with a restriction on the
/// allowed tag types contained in this combined tag.
/// </summary>
/// <param name="allowedTypes">
/// A <see cref="TagTypes" /> value, which restricts the
/// types of metadata that can be contained in this
/// combined tag.
/// </param>
public CombinedImageTag (TagTypes allowedTypes)
{
AllowedTypes = allowedTypes;
OtherTags = new List<ImageTag> ();
}
#endregion
#region Protected Methods
internal void AddTag (ImageTag tag)
{
if ((tag.TagTypes & AllowedTypes) != tag.TagTypes)
throw new Exception ($"Attempted to add {tag.TagTypes} to an image, but the only allowed types are {AllowedTypes}");
if (tag is IFDTag)
Exif = tag as IFDTag;
else if (tag is XmpTag) {
// we treat a IPTC-IIM tag as a XMP tag. However, we prefer the real XMP tag.
// See comments in Jpeg/File.cs for what we should do to deal with this properly.
if (Xmp != null && (tag is IIM.IIMTag || Xmp is IIM.IIMTag)) {
if (!(tag is IIM.IIMTag iimTag)) {
iimTag = Xmp as IIM.IIMTag;
Xmp = tag as XmpTag;
}
if (string.IsNullOrEmpty (Xmp.Title))
Xmp.Title = iimTag.Title;
if (string.IsNullOrEmpty (Xmp.Creator))
Xmp.Creator = iimTag.Creator;
if (string.IsNullOrEmpty (Xmp.Copyright))
Xmp.Copyright = iimTag.Copyright;
if (string.IsNullOrEmpty (Xmp.Comment))
Xmp.Comment = iimTag.Comment;
if (Xmp.Keywords == null)
Xmp.Keywords = iimTag.Keywords;
} else {
Xmp = tag as XmpTag;
}
} else
OtherTags.Add (tag);
all_tags = null;
}
internal void RemoveTag (ImageTag tag)
{
if (tag is IFDTag)
Exif = null;
else if (tag is XmpTag)
Xmp = null;
else
OtherTags.Remove (tag);
all_tags = null;
}
#endregion
#region Public Methods (Tag)
/// <summary>
/// Gets the tag types contained in the current instance.
/// </summary>
/// <value>
/// A bitwise combined <see cref="TagLib.TagTypes" />
/// containing the tag types contained in the current
/// instance.
/// </value>
public override TagTypes TagTypes {
get {
TagTypes types = TagTypes.None;
foreach (ImageTag tag in AllTags)
types |= tag.TagTypes;
return types;
}
}
/// <summary>
/// Clears all of the child tags.
/// </summary>
public override void Clear ()
{
foreach (ImageTag tag in AllTags)
tag.Clear ();
}
#endregion
#region Public Properties (ImageTag)
/// <summary>
/// Gets or sets the keywords for the image described
/// by the current instance.
/// </summary>
/// <value>
/// A <see cref="T:string[]" /> containing the keywords of the
/// current instace.
/// </value>
public override string[] Keywords {
get {
foreach (ImageTag tag in AllTags) {
string[] value = tag.Keywords;
if (value != null && value.Length > 0)
return value;
}
return new string[] { };
}
set {
foreach (ImageTag tag in AllTags)
tag.Keywords = value;
}
}
/// <summary>
/// Gets or sets the rating for the image described
/// by the current instance.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> containing the rating of the
/// current instace.
/// </value>
public override uint? Rating {
get {
foreach (ImageTag tag in AllTags) {
uint? value = tag.Rating;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Rating = value;
}
}
/// <summary>
/// Gets or sets the time when the image, the current instance
/// belongs to, was taken.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the time the image was taken.
/// </value>
public override DateTime? DateTime {
get {
foreach (ImageTag tag in AllTags) {
DateTime? value = tag.DateTime;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.DateTime = value;
}
}
/// <summary>
/// Gets or sets the orientation of the image described
/// by the current instance.
/// </summary>
/// <value>
/// A <see cref="TagLib.Image.ImageOrientation" /> containing the orienatation of the
/// image
/// </value>
public override ImageOrientation Orientation {
get {
foreach (ImageTag tag in AllTags) {
ImageOrientation value = tag.Orientation;
if ((uint)value >= 1U && (uint)value <= 8U)
return value;
}
return ImageOrientation.None;
}
set {
foreach (ImageTag tag in AllTags)
tag.Orientation = value;
}
}
/// <summary>
/// Gets or sets the software the image, the current instance
/// belongs to, was created with.
/// </summary>
/// <value>
/// A <see cref="string" /> containing the name of the
/// software the current instace was created with.
/// </value>
public override string Software {
get {
foreach (ImageTag tag in AllTags) {
string value = tag.Software;
if (!string.IsNullOrEmpty (value))
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Software = value;
}
}
/// <summary>
/// Gets or sets the latitude of the GPS coordinate the current
/// image was taken.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the latitude ranging from -90.0
/// to +90.0 degrees.
/// </value>
public override double? Latitude {
get {
foreach (ImageTag tag in AllTags) {
double? value = tag.Latitude;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Latitude = value;
}
}
/// <summary>
/// Gets or sets the longitude of the GPS coordinate the current
/// image was taken.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the longitude ranging from -180.0
/// to +180.0 degrees.
/// </value>
public override double? Longitude {
get {
foreach (ImageTag tag in AllTags) {
double? value = tag.Longitude;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Longitude = value;
}
}
/// <summary>
/// Gets or sets the altitude of the GPS coordinate the current
/// image was taken. The unit is meter.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the altitude. A positive value
/// is above sea level, a negative one below sea level. The unit is meter.
/// </value>
public override double? Altitude {
get {
foreach (ImageTag tag in AllTags) {
double? value = tag.Altitude;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Altitude = value;
}
}
/// <summary>
/// Gets the exposure time the image, the current instance belongs
/// to, was taken with.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the exposure time in seconds.
/// </value>
public override double? ExposureTime {
get {
foreach (ImageTag tag in AllTags) {
double? value = tag.ExposureTime;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.ExposureTime = value;
}
}
/// <summary>
/// Gets the FNumber the image, the current instance belongs
/// to, was taken with.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the FNumber.
/// </value>
public override double? FNumber {
get {
foreach (ImageTag tag in AllTags) {
double? value = tag.FNumber;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.FNumber = value;
}
}
/// <summary>
/// Gets the ISO speed the image, the current instance belongs
/// to, was taken with.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the ISO speed as defined in ISO 12232.
/// </value>
public override uint? ISOSpeedRatings {
get {
foreach (ImageTag tag in AllTags) {
uint? value = tag.ISOSpeedRatings;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.ISOSpeedRatings = value;
}
}
/// <summary>
/// Gets the focal length the image, the current instance belongs
/// to, was taken with.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the focal length in millimeters.
/// </value>
public override double? FocalLength {
get {
foreach (ImageTag tag in AllTags) {
double? value = tag.FocalLength;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.FocalLength = value;
}
}
/// <summary>
/// Gets the focal length the image, the current instance belongs
/// to, was taken with, assuming a 35mm film camera.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the focal length in 35mm equivalent in millimeters.
/// </value>
public override uint? FocalLengthIn35mmFilm {
get {
foreach (ImageTag tag in AllTags) {
uint? value = tag.FocalLengthIn35mmFilm;
if (value != null)
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.FocalLengthIn35mmFilm = value;
}
}
/// <summary>
/// Gets the manufacture of the recording equipment the image, the
/// current instance belongs to, was taken with.
/// </summary>
/// <value>
/// A <see cref="string" /> with the manufacture name.
/// </value>
public override string Make {
get {
foreach (ImageTag tag in AllTags) {
string value = tag.Make;
if (!string.IsNullOrEmpty (value))
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Make = value;
}
}
/// <summary>
/// Gets the model name of the recording equipment the image, the
/// current instance belongs to, was taken with.
/// </summary>
/// <value>
/// A <see cref="string" /> with the model name.
/// </value>
public override string Model {
get {
foreach (ImageTag tag in AllTags) {
string value = tag.Model;
if (!string.IsNullOrEmpty (value))
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Model = value;
}
}
/// <summary>
/// Gets or sets the creator of the image.
/// </summary>
/// <value>
/// A <see cref="string" /> with the name of the creator.
/// </value>
public override string Creator {
get {
foreach (ImageTag tag in AllTags) {
string value = tag.Creator;
if (!string.IsNullOrEmpty (value))
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Creator = value;
}
}
#endregion
#region Public Properties (Tag)
/// <summary>
/// Gets and sets the title for the media described by the
/// current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing the title for
/// the media described by the current instance or <see
/// langword="null" /> if no value is present.
/// </value>
public override string Title {
get {
foreach (ImageTag tag in AllTags) {
string value = tag.Title;
if (!string.IsNullOrEmpty (value))
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Title = value;
}
}
/// <summary>
/// Gets and sets a user comment on the media represented by
/// the current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing user comments
/// on the media represented by the current instance or <see
/// langword="null" /> if no value is present.
/// </value>
public override string Comment {
get {
foreach (ImageTag tag in AllTags) {
string value = tag.Comment;
if (!string.IsNullOrEmpty (value))
return value;
}
return string.Empty;
}
set {
foreach (ImageTag tag in AllTags)
tag.Comment = value;
}
}
/// <summary>
/// Gets and sets the copyright information for the media
/// represented by the current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing the copyright
/// information for the media represented by the current
/// instance or <see langword="null" /> if no value present.
/// </value>
public override string Copyright {
get {
foreach (ImageTag tag in AllTags) {
string value = tag.Copyright;
if (!string.IsNullOrEmpty (value))
return value;
}
return null;
}
set {
foreach (ImageTag tag in AllTags)
tag.Copyright = value;
}
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 27a6e5e0d0f39c9e2a7e78de79aaa404
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+224
View File
@@ -0,0 +1,224 @@
//
// File.cs: Base class for Image types.
//
// Author:
// Ruben Vermeersch (ruben@savanne.be)
//
// Copyright (C) 2009 Ruben Vermeersch
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
using System;
using System.Collections.Generic;
using TagLib.Gif;
using TagLib.IFD;
using TagLib.Jpeg;
using TagLib.Png;
using TagLib.Xmp;
namespace TagLib.Image
{
/// <summary>
/// This class extends <see cref="TagLib.File" /> to provide basic
/// functionality common to all image types.
/// </summary>
public abstract class File : TagLib.File
{
#region Constructors
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="File" /> for a specified path in the local file
/// system.
/// </summary>
/// <param name="path">
/// A <see cref="string" /> object containing the path of the
/// file to use in the new instance.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="path" /> is <see langword="null" />.
/// </exception>
protected File (string path)
: base (path)
{
}
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="File" /> for a specified file abstraction.
/// </summary>
/// <param name="abstraction">
/// A <see cref="TagLib.File.IFileAbstraction" /> object to use when
/// reading from and writing to the file.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="abstraction" /> is <see langword="null"
/// />.
/// </exception>
protected File (IFileAbstraction abstraction)
: base (abstraction)
{
}
#endregion
#region Public Properties
/// <summary>
/// Gets a abstract representation of all tags stored in the
/// current instance.
/// </summary>
/// <value>
/// A <see cref="TagLib.Tag" /> object representing all tags
/// stored in the current instance.
/// </value>
public override Tag Tag { get { return ImageTag; } }
/// <summary>
/// Gets a abstract representation of all tags stored in the
/// current instance.
/// </summary>
/// <value>
/// A <see cref="TagLib.Image.CombinedImageTag" /> object
/// representing all image tags stored in the current instance.
/// </value>
public CombinedImageTag ImageTag { get; protected set; }
#endregion
#region Public Methods
/// <summary>
/// The method creates all tags which are allowed for the current
/// instance of the image file. This method can be used to ensure,
/// that all tags are in place and properties can be safely used
/// to set values.
/// </summary>
public void EnsureAvailableTags ()
{
foreach (TagTypes type in Enum.GetValues (typeof (TagTypes))) {
if ((type & ImageTag.AllowedTypes) != 0x00 && type != TagTypes.AllTags)
GetTag (type, true);
}
}
/// <summary>
/// Removes a set of tag types from the current instance.
/// </summary>
/// <param name="types">
/// A bitwise combined <see cref="TagLib.TagTypes" /> value
/// containing tag types to be removed from the file.
/// </param>
/// <remarks>
/// In order to remove all tags from a file, pass <see
/// cref="TagTypes.AllTags" /> as <paramref name="types" />.
/// </remarks>
public override void RemoveTags (TagTypes types)
{
List<ImageTag> to_delete = new List<ImageTag> ();
foreach (ImageTag tag in ImageTag.AllTags) {
if ((tag.TagTypes & types) == tag.TagTypes)
to_delete.Add (tag);
}
foreach (ImageTag tag in to_delete)
ImageTag.RemoveTag (tag);
}
/// <summary>
/// Gets a tag of a specified type from the current instance,
/// optionally creating a new tag if possible.
/// </summary>
/// <param name="type">
/// A <see cref="TagLib.TagTypes" /> value indicating the
/// type of tag to read.
/// </param>
/// <param name="create">
/// A <see cref="bool" /> value specifying whether or not to
/// try and create the tag if one is not found.
/// </param>
/// <returns>
/// A <see cref="Tag" /> object containing the tag that was
/// found in or added to the current instance. If no
/// matching tag was found and none was created, <see
/// langword="null" /> is returned.
/// </returns>
public override Tag GetTag (TagTypes type,
bool create)
{
foreach (Tag tag in ImageTag.AllTags) {
if ((tag.TagTypes & type) == type)
return tag;
}
if (!create || (type & ImageTag.AllowedTypes) == 0)
return null;
ImageTag new_tag = null;
switch (type) {
case TagTypes.JpegComment:
new_tag = new JpegCommentTag ();
break;
case TagTypes.GifComment:
new_tag = new GifCommentTag ();
break;
case TagTypes.Png:
new_tag = new PngTag ();
break;
case TagTypes.TiffIFD:
new_tag = new IFDTag ();
break;
case TagTypes.XMP:
new_tag = new XmpTag ();
break;
}
if (new_tag != null) {
ImageTag.AddTag (new_tag);
return new_tag;
}
throw new NotImplementedException ($"Adding tag of type {type} not supported!");
}
/// <summary>
/// Copies metadata from the given file..
/// </summary>
/// <param name='file'>
/// File to copy metadata from.
/// </param>
public void CopyFrom (File file)
{
EnsureAvailableTags ();
var from_tag = file.ImageTag;
var to_tag = ImageTag;
foreach (var prop in typeof (ImageTag).GetProperties ()) {
if (!prop.CanWrite || prop.Name == "TagTypes")
continue;
var value = prop.GetValue (from_tag, null);
prop.SetValue (to_tag, value, null);
}
}
#endregion
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6155abdbbf42b2d1b88614fc62d7a4ad
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+319
View File
@@ -0,0 +1,319 @@
//
// ImageBlockFile.cs: Base class for Images files which are organized
// which are organized as blocks.
//
// Author:
// Mike Gemuende (mike@gemuende.de)
//
// Copyright (C) 2010 Mike Gemuende
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
using System;
using System.Collections.Generic;
namespace TagLib.Image
{
/// <summary>
/// Some image file formats are organized as a sequence of mostly
/// independent data blocks whose order can be changed. Metadata is
/// stored in some of those blocks and when metadata is saved, often the
/// same task remains: Delete some blocks which contain metadata and
/// overwrite some blocks with other metadata.
/// This class extends <see cref="TagLib.Image.File" /> to provide this
/// functionality. Blocks can be marked as metadata and when metadata is
/// saved their space is used or they are deleted.
/// </summary>
public abstract class ImageBlockFile : File
{
/// <summary>
/// This class represents a metadata block to overwrite.
/// </summary>
class MetadataBlock
{
/// <summary>
/// The start index
/// </summary>
public long Start { get; set; }
/// <summary>
/// The length of the block
/// </summary>
public long Length { get; set; }
/// <summary>
/// Constructor
/// </summary>
/// <param name="start">
/// A <see cref="System.Int64"/> with the start of the block
/// </param>
/// <param name="length">
/// A <see cref="System.Int64"/> with the length of the block
/// </param>
public MetadataBlock (long start, long length)
{
if (start < 0)
throw new ArgumentOutOfRangeException (nameof (start));
if (length < 0)
throw new ArgumentOutOfRangeException (nameof (length));
Start = start;
Length = length;
}
/// <summary>
/// Constructor. Creates a new instance with an empty block
/// </summary>
public MetadataBlock () : this (0, 0) { }
/// <summary>
/// Checks if the given block overlaps with this instance.
/// </summary>
/// <param name="block">
/// A <see cref="MetadataBlock"/> with the block to check
/// overlapping.
/// </param>
/// <returns>
/// A <see cref="System.Boolean"/> which is true, if the given
/// block overlapps with the current instance.
/// </returns>
/// <remarks>
/// Overlapping means here also that blocks directly follow.
/// </remarks>
public bool OverlapsWith (MetadataBlock block)
{
if (block.Start >= Start && block.Start <= Start + Length)
return true;
if (Start >= block.Start && Start <= block.Start + block.Length)
return true;
return false;
}
/// <summary>
/// Adds the given block to the current instance, if this is possible.
/// </summary>
/// <param name="block">
/// A <see cref="MetadataBlock"/> with the block to add.
/// </param>
public void Add (MetadataBlock block)
{
if (block.Start >= Start && block.Start <= Start + Length) {
Length = Math.Max (Length, block.Start + block.Length - Start);
return;
}
if (Start >= block.Start && Start <= block.Start + block.Length) {
Length = Math.Max (block.Length, Start + Length - block.Start);
Start = block.Start;
return;
}
throw new ArgumentException ($"blocks do not overlap: {this} and {block}");
}
/// <summary>
/// Checks, if the one block is before the other. That means,
/// if the current instance ends before the given block starts.
/// </summary>
/// <param name="block">
/// A <see cref="MetadataBlock"/> to compare with.
/// </param>
/// <returns>
/// A <see cref="System.Boolean"/> which is true if the current
/// instance is before the given block.
/// </returns>
public bool Before (MetadataBlock block)
{
return (Start + Length < block.Start);
}
/// <summary>
/// Provides a readable <see cref="System.String"/> for
/// the current instance.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> representing the current
/// instance.
/// </returns>
public override string ToString ()
{
return $"[MetadataBlock: Start={Start}, Length={Length}]";
}
}
/// <summary>
/// An odered list of the metadata blocks. The blocks do not overlap.
/// </summary>
readonly List<MetadataBlock> metadata_blocks = new List<MetadataBlock> ();
/// <summary>
/// Adds a range to be treated as metadata.
/// </summary>
/// <param name="start">
/// A <see cref="System.Int64"/> with the start index of the metadata block
/// </param>
/// <param name="length">
/// A <see cref="System.Int64"/> with the length of the metadata block
/// </param>
protected void AddMetadataBlock (long start, long length)
{
MetadataBlock new_block = new MetadataBlock (start, length);
// We keep the list sorted and unique. Therefore, we add the new block to
// the list and join overlapping blocks if necessary.
// iterate through all existing blocks.
for (int i = 0; i < metadata_blocks.Count; i++) {
var block = metadata_blocks[i];
// if one block overlaps with the new one, join them.
if (new_block.OverlapsWith (block)) {
block.Add (new_block);
// Since we joined two blocks, they may overlap with
// other blocks which follows in the list. Therfore,
// we iterate through the tail of the list and join
// blocks which are now contained.
i++;
while (i < metadata_blocks.Count) {
var next_block = metadata_blocks[i];
if (block.OverlapsWith (next_block)) {
block.Add (next_block);
metadata_blocks.Remove (next_block);
} else {
return;
}
}
return;
// if the new block is 'smaller' than the one in the list,
// just add it to the list.
} else if (new_block.Before (block)) {
metadata_blocks.Insert (i, new_block);
return;
}
}
// if the new block is 'bigger' than all other blocks, at it to the end.
metadata_blocks.Add (new_block);
}
/// <summary>
/// Saves the given data at the given position. All metadata blocks are
/// either deleted or overwritten.
/// </summary>
/// <param name="data">
/// A <see cref="ByteVector"/> with the metadata to write.
/// </param>
/// <param name="start">
/// A <see cref="System.Int64"/> with the index to save the metadata at.
/// </param>
protected void SaveMetadata (ByteVector data, long start)
{
long new_start = 0;
// this ensures that the block with the start index is contained.
AddMetadataBlock (start, 0);
// start iterating through the metadata block from the end,
// because deleting such blocks do not affect the smaller indices.
for (int i = metadata_blocks.Count - 1; i >= 0; i--) {
var block = metadata_blocks[i];
// this is the block to save the metadata in
if (block.Start <= start && block.Start + block.Length >= start) {
// the metadata is saved starting at the beginning of the block,
// because the bytes will be removed.
Insert (data, block.Start, block.Length);
new_start = block.Start;
} else {
// remove block
Insert ("", block.Start, block.Length);
// update start of the metadata block, if metadata was written
// before, i.e. we have removed a block which is before the saved
// metadata
if (block.Start < start)
new_start -= block.Length;
}
}
// and reset the metadata blocks
// (there is now just one block contained)
metadata_blocks.Clear ();
AddMetadataBlock (new_start, data.Count);
}
#region Constructors
/// <summary>
/// Constructs and initializes a new instance for a specified
/// path in the local file system.
/// </summary>
/// <param name="path">
/// A <see cref="string" /> object containing the path of the
/// file to use in the new instance.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="path" /> is <see langword="null" />.
/// </exception>
protected ImageBlockFile (string path)
: base (path)
{
}
/// <summary>
/// Constructs and initializes a new instance for a specified
/// file abstraction.
/// </summary>
/// <param name="abstraction">
/// A <see cref="TagLib.File.IFileAbstraction" /> object to use when
/// reading from and writing to the file.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="abstraction" /> is <see langword="null"
/// />.
/// </exception>
protected ImageBlockFile (IFileAbstraction abstraction)
: base (abstraction)
{
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c919735bd377f71f9aa58b535b2b29cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,90 @@
//
// ImageOrientation.cs: Enum for the orientation of an image
//
// Author:
// Paul Lange (palango@gmx.de)
//
// Copyright (C) 2009 Paul Lange
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
namespace TagLib.Image
{
/**
1 2 3 4 5 6 7 8
888888 888888 88 88 8888888888 88 88 8888888888
88 88 88 88 88 88 88 88 88 88 88 88
8888 8888 8888 8888 88 8888888888 8888888888 88
88 88 88 88
88 88 888888 888888
t-l t-r b-r b-l l-t r-t r-b l-b
**/
/// <summary>
/// Describes the orientation of an image.
/// Values are viewed in terms of rows and columns.
/// </summary>
public enum ImageOrientation : uint
{
/// <summary>
/// No value is known.
/// </summary>
None = 0,
/// <summary>
/// No need to do any transformations.
/// </summary>
TopLeft = 1,
/// <summary>
/// Mirror image vertically.
/// </summary>
TopRight = 2,
/// <summary>
/// Rotate image 180 degrees.
/// </summary>
BottomRight = 3,
/// <summary>
/// Mirror image horizontally
/// </summary>
BottomLeft = 4,
/// <summary>
/// Mirror image horizontally and rotate 90 degrees clockwise.
/// </summary>
LeftTop = 5,
/// <summary>
/// Rotate image 90 degrees clockwise.
/// </summary>
RightTop = 6,
/// <summary>
/// Mirror image vertically and rotate 90 degrees clockwise.
/// </summary>
RightBottom = 7,
/// <summary>
/// Rotate image 270 degrees clockwise.
/// </summary>
LeftBottom = 8
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: acf6025bcc02cefba8e40784bea5e516
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+241
View File
@@ -0,0 +1,241 @@
//
// ImageTag.cs: This abstract class extends the Tag class by basic Image
// properties.
//
// Author:
// Mike Gemuende (mike@gemuende.de)
// Paul Lange (palango@gmx.de)
//
// Copyright (C) 2009 Mike Gemuende
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
using System;
namespace TagLib.Image
{
/// <summary>
/// A class to abstract the image tags. It extends the <see cref="Tag"/>
/// class and adds some image specific propties.
/// </summary>
public abstract class ImageTag : Tag
{
#region Public Properties
/// <summary>
/// Gets or sets the keywords for the image described
/// by the current instance.
/// </summary>
/// <value>
/// A <see cref="T:string[]" /> containing the keywords of the
/// current instace.
/// </value>
public virtual string[] Keywords {
get { return new string[] { }; }
set { }
}
/// <summary>
/// Gets or sets the rating for the image described
/// by the current instance.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> containing the rating of the
/// current instace.
/// </value>
public virtual uint? Rating {
get { return null; }
set { }
}
/// <summary>
/// Gets or sets the time when the image, the current instance
/// belongs to, was taken.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the time the image was taken.
/// </value>
public virtual DateTime? DateTime {
get { return null; }
set { }
}
/// <summary>
/// Gets or sets the orientation of the image described
/// by the current instance.
/// </summary>
/// <value>
/// A <see cref="TagLib.Image.ImageOrientation" /> containing the orientation of the
/// image
/// </value>
public virtual ImageOrientation Orientation {
get { return ImageOrientation.None; }
set { }
}
/// <summary>
/// Gets or sets the software the image, the current instance
/// belongs to, was created with.
/// </summary>
/// <value>
/// A <see cref="string" /> containing the name of the
/// software the current instace was created with.
/// </value>
public virtual string Software {
get { return null; }
set { }
}
/// <summary>
/// Gets or sets the latitude of the GPS coordinate the current
/// image was taken.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the latitude ranging from -90.0
/// to +90.0 degrees.
/// </value>
public virtual double? Latitude {
get { return null; }
set { }
}
/// <summary>
/// Gets or sets the longitude of the GPS coordinate the current
/// image was taken.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the longitude ranging from -180.0
/// to +180.0 degrees.
/// </value>
public virtual double? Longitude {
get { return null; }
set { }
}
/// <summary>
/// Gets or sets the altitude of the GPS coordinate the current
/// image was taken. The unit is meter.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the altitude. A positive value
/// is above sea level, a negative one below sea level. The unit is meter.
/// </value>
public virtual double? Altitude {
get { return null; }
set { }
}
/// <summary>
/// Gets the exposure time the image, the current instance belongs
/// to, was taken with.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the exposure time in seconds.
/// </value>
public virtual double? ExposureTime {
get { return null; }
set { }
}
/// <summary>
/// Gets the FNumber the image, the current instance belongs
/// to, was taken with.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the FNumber.
/// </value>
public virtual double? FNumber {
get { return null; }
set { }
}
/// <summary>
/// Gets the ISO speed the image, the current instance belongs
/// to, was taken with.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the ISO speed as defined in ISO 12232.
/// </value>
public virtual uint? ISOSpeedRatings {
get { return null; }
set { }
}
/// <summary>
/// Gets the focal length the image, the current instance belongs
/// to, was taken with.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the focal length in millimeters.
/// </value>
public virtual double? FocalLength {
get { return null; }
set { }
}
/// <summary>
/// Gets the focal length the image, the current instance belongs
/// to, was taken with, assuming a 35mm film camera.
/// </summary>
/// <value>
/// A <see cref="System.Nullable"/> with the focal length in 35mm equivalent in millimeters.
/// </value>
public virtual uint? FocalLengthIn35mmFilm {
get { return null; }
set { }
}
/// <summary>
/// Gets the manufacture of the recording equipment the image, the
/// current instance belongs to, was taken with.
/// </summary>
/// <value>
/// A <see cref="string" /> with the manufacture name.
/// </value>
public virtual string Make {
get { return null; }
set { }
}
/// <summary>
/// Gets the model name of the recording equipment the image, the
/// current instance belongs to, was taken with.
/// </summary>
/// <value>
/// A <see cref="string" /> with the model name.
/// </value>
public virtual string Model {
get { return null; }
set { }
}
/// <summary>
/// Gets or sets the creator of the image.
/// </summary>
/// <value>
/// A <see cref="string" /> with the name of the creator.
/// </value>
public virtual string Creator {
get { return null; }
set { }
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 53736b7df4782890baa9a43cba900505
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b0399363c72dc9b26ae809cbe85dd5c6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,185 @@
//
// File.cs: Provides an empty wrapper for files that don't support metadata.
//
// Author:
// Ruben Vermeersch (ruben@savanne.be)
//
// Copyright (C) 2010 Ruben Vermeersch
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
using System;
namespace TagLib.Image.NoMetadata
{
/// <summary>
/// This class extends <see cref="TagLib.Image.File" /> to provide tagging
/// some sort of support for files that don't support metadata. You
/// obviously can't write to them, but you can populate an XMP tag, for
/// sidecar purposes.
/// </summary>
[SupportedMimeType ("taglib/bmp", "bmp")]
[SupportedMimeType ("image/x-MS-bmp")]
[SupportedMimeType ("image/x-bmp")]
[SupportedMimeType ("taglib/ppm", "ppm")]
[SupportedMimeType ("taglib/pgm", "pgm")]
[SupportedMimeType ("taglib/pbm", "pbm")]
[SupportedMimeType ("taglib/pnm", "pnm")]
[SupportedMimeType ("image/x-portable-pixmap")]
[SupportedMimeType ("image/x-portable-graymap")]
[SupportedMimeType ("image/x-portable-bitmap")]
[SupportedMimeType ("image/x-portable-anymap")]
[SupportedMimeType ("taglib/pcx", "pcx")]
[SupportedMimeType ("image/x-pcx")]
[SupportedMimeType ("taglib/svg", "svg")]
[SupportedMimeType ("taglib/svgz", "svgz")]
[SupportedMimeType ("image/svg+xml")]
[SupportedMimeType ("taglib/kdc", "kdc")] // FIXME: Not supported yet!
[SupportedMimeType ("taglib/orf", "orf")] // FIXME: Not supported yet!
[SupportedMimeType ("taglib/srf", "srf")] // FIXME: Not supported yet!
[SupportedMimeType ("taglib/crw", "crw")] // FIXME: Not supported yet!
[SupportedMimeType ("taglib/mrw", "mrw")] // FIXME: Not supported yet!
[SupportedMimeType ("taglib/raf", "raf")] // FIXME: Not supported yet!
[SupportedMimeType ("taglib/x3f", "x3f")] // FIXME: Not supported yet!
public class File : TagLib.Image.File
{
#region public Properties
/// <summary>
/// Gets the media properties of the file represented by the
/// current instance.
/// </summary>
/// <value>
/// A <see cref="TagLib.Properties" /> object containing the
/// media properties of the file represented by the current
/// instance.
/// </value>
public override Properties Properties {
get { return null; }
}
/// <summary>
/// Indicates if tags can be written back to the current file or not
/// </summary>
/// <value>
/// A <see cref="bool" /> which is true if tags can be written to the
/// current file, otherwise false.
/// </value>
public override bool Writeable {
get { return false; }
}
#endregion
#region Constructors
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="File" /> for a specified path in the local file
/// system and specified read style.
/// </summary>
/// <param name="path">
/// A <see cref="string" /> object containing the path of the
/// file to use in the new instance.
/// </param>
/// <param name="propertiesStyle">
/// A <see cref="ReadStyle" /> value specifying at what level
/// of accuracy to read the media properties, or <see
/// cref="ReadStyle.None" /> to ignore the properties.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="path" /> is <see langword="null" />.
/// </exception>
public File (string path, ReadStyle propertiesStyle)
: this (new LocalFileAbstraction (path), propertiesStyle)
{
}
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="File" /> for a specified path in the local file
/// system.
/// </summary>
/// <param name="path">
/// A <see cref="string" /> object containing the path of the
/// file to use in the new instance.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="path" /> is <see langword="null" />.
/// </exception>
public File (string path)
: this (path, ReadStyle.Average)
{
}
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="File" /> for a specified file abstraction and
/// specified read style.
/// </summary>
/// <param name="abstraction">
/// A <see cref="TagLib.File.IFileAbstraction" /> object to use when
/// reading from and writing to the file.
/// </param>
/// <param name="propertiesStyle">
/// A <see cref="ReadStyle" /> value specifying at what level
/// of accuracy to read the media properties, or <see
/// cref="ReadStyle.None" /> to ignore the properties.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="abstraction" /> is <see langword="null"
/// />.
/// </exception>
public File (IFileAbstraction abstraction, ReadStyle propertiesStyle)
: base (abstraction)
{
ImageTag = new CombinedImageTag (TagTypes.XMP);
}
/// <summary>
/// Constructs and initializes a new instance of <see
/// cref="File" /> for a specified file abstraction.
/// </summary>
/// <param name="abstraction">
/// A <see cref="TagLib.File.IFileAbstraction" /> object to use when
/// reading from and writing to the file.
/// </param>
/// <exception cref="ArgumentNullException">
/// <paramref name="abstraction" /> is <see langword="null"
/// />.
/// </exception>
protected File (IFileAbstraction abstraction)
: this (abstraction, ReadStyle.Average)
{
}
#endregion
#region Public Methods
/// <summary>
/// Saves the changes made in the current instance to the
/// file it represents.
/// </summary>
public override void Save ()
{
throw new NotSupportedException ();
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5c2b6069b4d94cb5bafcb1363279861e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: