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

+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0764cf5c24a6b4e5f9ef1cfb24cb605b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+162
View File
@@ -0,0 +1,162 @@
//
// File.cs: Provides tagging for Sony ARW files
//
// 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.Tiff.Arw
{
/// <summary>
/// This class extends <see cref="TagLib.Tiff.File" /> to provide tagging
/// for ARW image files.
/// </summary>
[SupportedMimeType ("taglib/arw", "arw")]
[SupportedMimeType ("image/arw")]
[SupportedMimeType ("image/x-sony-arw")]
public class File : TagLib.Tiff.File
{
#region public Properties
/// <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, propertiesStyle)
{
}
/// <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
/// <summary>
/// Create a codec that describes the photo properties.
/// </summary>
/// <returns>
/// A <see cref="Codec" /> object.
/// </returns>
protected override Codec CreateCodec (int width, int height)
{
return new Codec (width, height, "Sony Raw File");
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 453aee29132d2f79693f777265fb317a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+245
View File
@@ -0,0 +1,245 @@
//
// BaseTiffFile.cs:
//
// 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 TagLib.IFD;
namespace TagLib.Tiff
{
/// <summary>
/// This class extends <see cref="TagLib.Image.File" /> to provide some basic behavior
/// for Tiff based file formats.
/// </summary>
public abstract class BaseTiffFile : TagLib.Image.File
{
#region Public Properties
/// <summary>
/// Indicates if the current file is in big endian or little endian format.
/// </summary>
/// <remarks>
/// The method <see cref="ReadHeader()"/> must be called from a subclass to
/// properly initialize this property.
/// </remarks>
public bool IsBigEndian { get; private set; }
#endregion
#region Protected Properties
/// <summary>
/// The identifier used to recognize the file. This is 42 for most TIFF files.
/// </summary>
protected ushort Magic { get; set; }
#endregion
#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 BaseTiffFile (string path)
: base (path)
{
Magic = 42;
}
/// <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 BaseTiffFile (IFileAbstraction abstraction)
: base (abstraction)
{
Magic = 42;
}
#endregion
#region Protected Methods
/// <summary>
/// Reads and validates the TIFF header at the current position.
/// </summary>
/// <returns>
/// A <see cref="System.UInt32"/> with the offset value to the first
/// IFD contained in the file.
/// </returns>
/// <remarks>
/// This method should only be called, when the current read position is
/// the beginning of the file.
/// </remarks>
protected uint ReadHeader ()
{
// TIFF header:
//
// 2 bytes Indicating the endianess (II or MM)
// 2 bytes Tiff Magic word (usually 42)
// 4 bytes Offset to first IFD
ByteVector header = ReadBlock (8);
if (header.Count != 8)
throw new CorruptFileException ("Unexpected end of header");
string order = header.Mid (0, 2).ToString ();
if (order == "II") {
IsBigEndian = false;
} else if (order == "MM") {
IsBigEndian = true;
} else {
throw new CorruptFileException ("Unknown Byte Order");
}
if (header.Mid (2, 2).ToUShort (IsBigEndian) != Magic)
throw new CorruptFileException ($"TIFF Magic ({Magic}) expected");
uint first_ifd_offset = header.Mid (4, 4).ToUInt (IsBigEndian);
return first_ifd_offset;
}
/// <summary>
/// Reads IFDs starting from the given offset.
/// </summary>
/// <param name="offset">
/// A <see cref="System.UInt32"/> with the IFD offset to start
/// reading from.
/// </param>
protected void ReadIFD (uint offset)
{
ReadIFD (offset, -1);
}
/// <summary>
/// Reads a certain number of IFDs starting from the given offset.
/// </summary>
/// <param name="offset">
/// A <see cref="System.UInt32"/> with the IFD offset to start
/// reading from.
/// </param>
/// <param name="ifd_count">
/// A <see cref="System.Int32"/> with the number of IFDs to read.
/// </param>
protected void ReadIFD (uint offset, int ifd_count)
{
long length;
try {
length = Length;
} catch (Exception) {
// Use a safety-value of 4 gigabyte.
length = 1073741824L * 4;
}
var ifd_tag = GetTag (TagTypes.TiffIFD, true) as IFDTag;
var reader = CreateIFDReader (this, IsBigEndian, ifd_tag.Structure, 0, offset, (uint)length);
reader.Read (ifd_count);
}
/// <summary>
/// Creates an IFD reader to parse the file.
/// </summary>
/// <param name="file">
/// A <see cref="File"/> to read from.
/// </param>
/// <param name="is_bigendian">
/// A <see cref="System.Boolean"/>, it must be true, if the data of the IFD should be
/// read as bigendian, otherwise false.
/// </param>
/// <param name="structure">
/// A <see cref="IFDStructure"/> that will be populated.
/// </param>
/// <param name="base_offset">
/// A <see cref="System.Int64"/> value describing the base were the IFD offsets
/// refer to. E.g. in Jpegs the IFD are located in an Segment and the offsets
/// inside the IFD refer from the beginning of this segment. So <paramref
/// name="base_offset"/> must contain the beginning of the segment.
/// </param>
/// <param name="ifd_offset">
/// A <see cref="System.UInt32"/> value with the beginning of the IFD relative to
/// <paramref name="base_offset"/>.
/// </param>
/// <param name="max_offset">
/// A <see cref="System.UInt32"/> value with maximal possible offset. This is to limit
/// the size of the possible data;
/// </param>
protected virtual IFDReader CreateIFDReader (BaseTiffFile file, bool is_bigendian, IFDStructure structure, long base_offset, uint ifd_offset, uint max_offset)
{
return new IFDReader (file, is_bigendian, structure, base_offset, ifd_offset, max_offset);
}
/// <summary>
/// Renders a TIFF header with the given offset to the first IFD.
/// The returned data has length 8.
/// </summary>
/// <param name="first_ifd_offset">
/// A <see cref="System.UInt32"/> with the offset to the first IFD
/// to be included in the header.
/// </param>
/// <returns>
/// A <see cref="ByteVector"/> with the rendered header of length 8.
/// </returns>
protected ByteVector RenderHeader (uint first_ifd_offset)
{
var data = new ByteVector ();
if (IsBigEndian)
data.Add ("MM");
else
data.Add ("II");
data.Add (ByteVector.FromUShort (Magic, IsBigEndian));
data.Add (ByteVector.FromUInt (first_ifd_offset, IsBigEndian));
return data;
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3ec5000488d626141bbc719dac634c3e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+82
View File
@@ -0,0 +1,82 @@
//
// Codec.cs:
//
// 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
//
namespace TagLib.Tiff
{
/// <summary>
/// A TIFF photo codec. Contains basic photo details.
/// </summary>
public class Codec : Image.Codec
{
readonly string description = "TIFF File";
/// <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 override string Description { get { return description; } }
/// <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)
: base (width, height) { }
/// <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="description">
/// The description of the photo type.
/// </param>
/// <returns>
/// A new <see cref="Codec" /> instance.
/// </returns>
public Codec (int width, int height, string description)
: base (width, height)
{
this.description = description;
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5198161ac9ebd33f989a014972fa0a65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7cda42bf16523f5e7b08ab4f010d037a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+283
View File
@@ -0,0 +1,283 @@
//
// File.cs: Provides tagging for Canon CR2 files
//
// Author:
// Mike Gemuende (mike@gemuende.be)
//
// 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 TagLib.IFD;
using TagLib.IFD.Tags;
using TagLib.Image;
namespace TagLib.Tiff.Cr2
{
/// <summary>
/// This class extends <see cref="TagLib.Tiff.BaseTiffFile" /> to provide tagging
/// for CR2 image files.
/// </summary>
[SupportedMimeType ("taglib/cr2", "cr2")]
[SupportedMimeType ("image/cr2")]
[SupportedMimeType ("image/x-canon-cr2")]
public class File : BaseTiffFile
{
#region private fields
/// <summary>
/// The Properties of the image
/// </summary>
Properties properties;
#endregion
#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 properties; }
}
/// <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)
{
Read (propertiesStyle);
}
/// <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
#region private methods
/// <summary>
/// Reads the information from file with a specified read style.
/// </summary>
/// <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>
void Read (ReadStyle propertiesStyle)
{
Mode = AccessMode.Read;
try {
ImageTag = new CombinedImageTag (TagTypes.TiffIFD);
ReadFile ();
TagTypesOnDisk = TagTypes;
if ((propertiesStyle & ReadStyle.Average) != 0)
properties = ExtractProperties ();
} finally {
Mode = AccessMode.Closed;
}
}
/// <summary>
/// Parses the CR2 file
/// </summary>
void ReadFile ()
{
// A CR2 file starts with a Tiff header followed by a CR2 header
uint first_ifd_offset = ReadHeader ();
uint raw_ifd_offset = ReadAdditionalCR2Header ();
ReadIFD (first_ifd_offset, 3);
ReadIFD (raw_ifd_offset, 1);
}
/// <summary>
/// Reads and validates the CR2 header started at the current position.
/// </summary>
/// <returns>
/// A <see cref="System.UInt32"/> with the offset to the IFD with the RAW data.
/// </returns>
uint ReadAdditionalCR2Header ()
{
// CR2 Header
//
// CR2 Information:
//
// 2 bytes CR2 Magic word (CR)
// 1 byte CR2 major version (2)
// 1 byte CR2 minor version (0)
// 4 bytes Offset to RAW IFD
//
ByteVector header = ReadBlock (8);
if (header.Count != 8)
throw new CorruptFileException ("Unexpected end of CR2 header");
if (header.Mid (0, 2).ToString () != "CR")
throw new CorruptFileException ("CR2 Magic (CR) expected");
byte major_version = header[2];
byte minor_version = header[3];
if (major_version != 2 || minor_version != 0)
throw new UnsupportedFormatException ("Only major version 2 and minor version 0 are supported");
uint raw_ifd_offset = header.Mid (4, 4).ToUInt (IsBigEndian);
return raw_ifd_offset;
}
/// <summary>
/// Attempts to extract the media properties of the main
/// photo.
/// </summary>
/// <returns>
/// A <see cref="Properties" /> object with a best effort guess
/// at the right values. When no guess at all can be made,
/// <see langword="null" /> is returned.
/// </returns>
Properties ExtractProperties ()
{
int width = 0, height = 0;
IFDTag tag = GetTag (TagTypes.TiffIFD) as IFDTag;
width = (int)(tag.ExifIFD.GetLongValue (0, (ushort)ExifEntryTag.PixelXDimension) ?? 0);
height = (int)(tag.ExifIFD.GetLongValue (0, (ushort)ExifEntryTag.PixelYDimension) ?? 0);
if (width > 0 && height > 0) {
return new Properties (TimeSpan.Zero, new Codec (width, height, "Canon RAW File"));
}
return null;
}
#endregion
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ab14a97cd1e00503b26b9520868a040
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e94ca2d56e0c62f5b89b051a7a51e31f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+203
View File
@@ -0,0 +1,203 @@
//
// File.cs: Provides tagging for DNG files
//
// 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;
using TagLib.IFD;
using TagLib.IFD.Entries;
using TagLib.IFD.Tags;
namespace TagLib.Tiff.Dng
{
/// <summary>
/// This class extends <see cref="TagLib.Tiff.File" /> to provide tagging
/// for DNG image files.
/// </summary>
[SupportedMimeType ("taglib/dng", "dng")]
[SupportedMimeType ("image/dng")]
[SupportedMimeType ("image/x-adobe-dng")]
public class File : TagLib.Tiff.File
{
#region public Properties
/// <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, propertiesStyle)
{
}
/// <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
/// <summary>
/// Attempts to extract the media properties of the main
/// photo.
/// </summary>
/// <returns>
/// A <see cref="Properties" /> object with a best effort guess
/// at the right values. When no guess at all can be made,
/// <see langword="null" /> is returned.
/// </returns>
protected override Properties ExtractProperties ()
{
int width = 0, height = 0;
var tag = GetTag (TagTypes.TiffIFD) as IFDTag;
IFDStructure structure = tag.Structure;
// DNG uses SubIFDs for images, the one with SubfileType = 0 is the RAW data.
if (!(structure.GetEntry (0, (ushort)IFDEntryTag.SubIFDs) is SubIFDArrayEntry sub_ifds)) {
return base.ExtractProperties ();
}
foreach (var entry in sub_ifds.Entries) {
var type = entry.GetLongValue (0, (ushort)IFDEntryTag.NewSubfileType);
if (type == 0) {
width = (int)(entry.GetLongValue (0, (ushort)IFDEntryTag.ImageWidth) ?? 0);
height = (int)(entry.GetLongValue (0, (ushort)IFDEntryTag.ImageLength) ?? 0);
break; // No need to iterate the other SubIFDs
}
}
if (width > 0 && height > 0) {
return new Properties (TimeSpan.Zero, CreateCodec (width, height));
}
// Fall back to normal detection.
return base.ExtractProperties ();
}
/// <summary>
/// Create a codec that describes the photo properties.
/// </summary>
/// <returns>
/// A <see cref="Codec" /> object.
/// </returns>
protected override Codec CreateCodec (int width, int height)
{
return new Codec (width, height, "Adobe Digital Negative File");
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a213b3afb7ff3739fb09bc7bc083956b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+292
View File
@@ -0,0 +1,292 @@
//
// File.cs:
//
// 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 TagLib.IFD;
using TagLib.IFD.Entries;
using TagLib.IFD.Tags;
using TagLib.Image;
using TagLib.Xmp;
namespace TagLib.Tiff
{
/// <summary>
/// This class extends <see cref="TagLib.Tiff.BaseTiffFile" /> to provide tagging
/// and properties support for Tiff files.
/// </summary>
[SupportedMimeType ("taglib/tiff", "tiff")]
[SupportedMimeType ("taglib/tif", "tif")]
[SupportedMimeType ("image/tiff")]
public class File : BaseTiffFile
{
#region Private Fields
/// <summary>
/// Contains the media properties.
/// </summary>
Properties properties;
#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) : base (path)
{
}
/// <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.TiffIFD | TagTypes.XMP);
Mode = AccessMode.Read;
try {
Read (propertiesStyle);
TagTypesOnDisk = TagTypes;
} finally {
Mode = AccessMode.Closed;
}
}
/// <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 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 properties; }
}
#endregion
#region Public Methods
/// <summary>
/// Saves the changes made in the current instance to the
/// file it represents.
/// </summary>
public override void Save ()
{
// Boilerplate
PreSave ();
Mode = AccessMode.Write;
try {
WriteFile ();
TagTypesOnDisk = TagTypes;
} finally {
Mode = AccessMode.Closed;
}
}
#endregion
#region Private Methods
/// <summary>
/// Render the whole file and write it back.
/// </summary>
void WriteFile ()
{
// Check, if IFD0 is contained
IFDTag exif = ImageTag.Exif;
if (exif == null)
throw new Exception ("Tiff file without tags");
UpdateTags (exif);
// first IFD starts at 8
uint first_ifd_offset = 8;
ByteVector data = RenderHeader (first_ifd_offset);
var renderer = new IFDRenderer (IsBigEndian, exif.Structure, first_ifd_offset);
data.Add (renderer.Render ());
Insert (data, 0, Length);
}
/// <summary>
/// Update the XMP stored in the Tiff IFD
/// </summary>
/// <param name="exif">
/// A <see cref="IFDTag"/> The Tiff IFD to update the entries
/// </param>
void UpdateTags (IFDTag exif)
{
// update the XMP entry
exif.Structure.RemoveTag (0, (ushort)IFDEntryTag.XMP);
XmpTag xmp = ImageTag.Xmp;
if (xmp != null)
exif.Structure.AddEntry (0, new ByteVectorIFDEntry ((ushort)IFDEntryTag.XMP, xmp.Render ()));
}
/// <summary>
/// Reads the file with a specified read style.
/// </summary>
/// <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>
protected void Read (ReadStyle propertiesStyle)
{
Mode = AccessMode.Read;
try {
uint first_ifd_offset = ReadHeader ();
ReadIFD (first_ifd_offset);
// Find XMP data
if (ImageTag.Exif.Structure.GetEntry (0, (ushort)IFDEntryTag.XMP) is ByteVectorIFDEntry xmp_entry) {
ImageTag.AddTag (new XmpTag (xmp_entry.Data.ToString (), this));
}
if ((propertiesStyle & ReadStyle.Average) == 0)
return;
properties = ExtractProperties ();
} finally {
Mode = AccessMode.Closed;
}
}
/// <summary>
/// Attempts to extract the media properties of the main
/// photo.
/// </summary>
/// <returns>
/// A <see cref="Properties" /> object with a best effort guess
/// at the right values. When no guess at all can be made,
/// <see langword="null" /> is returned.
/// </returns>
protected virtual Properties ExtractProperties ()
{
int width = 0, height = 0;
IFDTag tag = GetTag (TagTypes.TiffIFD) as IFDTag;
IFDStructure structure = tag.Structure;
width = (int)(structure.GetLongValue (0, (ushort)IFDEntryTag.ImageWidth) ?? 0);
height = (int)(structure.GetLongValue (0, (ushort)IFDEntryTag.ImageLength) ?? 0);
if (width > 0 && height > 0) {
return new Properties (TimeSpan.Zero, CreateCodec (width, height));
}
return null;
}
/// <summary>
/// Create a codec that describes the photo properties.
/// </summary>
/// <returns>
/// A <see cref="Codec" /> object.
/// </returns>
protected virtual Codec CreateCodec (int width, int height)
{
return new Codec (width, height);
}
#endregion
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8df8c599604c4997937fe27e5cb90d0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee40fffd0785b4425a2e73d21d04c9d6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+161
View File
@@ -0,0 +1,161 @@
//
// File.cs: Provides tagging for Nikon NEF files
//
// 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.Tiff.Nef
{
/// <summary>
/// This class extends <see cref="TagLib.Tiff.File" /> to provide tagging
/// for NEF image files.
/// </summary>
[SupportedMimeType ("taglib/nef", "nef")]
[SupportedMimeType ("image/nef")]
[SupportedMimeType ("image/x-nikon-nef")]
public class File : TagLib.Tiff.File
{
#region public Properties
/// <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, propertiesStyle)
{
}
/// <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
/// <summary>
/// Create a codec that describes the photo properties.
/// </summary>
/// <returns>
/// A <see cref="Codec" /> object.
/// </returns>
protected override Codec CreateCodec (int width, int height)
{
return new Codec (width, height, "Nikon Raw File");
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8f1e36a4c18b59431a05326acf616392
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 30e5f0c76cc53c5e78abdd95636c5c0c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+163
View File
@@ -0,0 +1,163 @@
//
// File.cs: Provides tagging for Pentax CR2 files
//
// 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.Tiff.Pef
{
/// <summary>
/// This class extends <see cref="TagLib.Tiff.BaseTiffFile" /> to provide tagging
/// for PEF image files.
/// </summary>
[SupportedMimeType ("taglib/pef", "pef")]
[SupportedMimeType ("image/pef")]
[SupportedMimeType ("image/x-pentax-pef")]
public class File : TagLib.Tiff.File
{
#region public Properties
/// <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, propertiesStyle)
{
}
/// <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
/// <summary>
/// Create a codec that describes the photo properties.
/// </summary>
/// <returns>
/// A <see cref="Codec" /> object.
/// </returns>
protected override Codec CreateCodec (int width, int height)
{
return new Codec (width, height, "Pentax Raw File");
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b676c36c60636e93fbebf5d845d25436
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 869176644a1493e4a94a3ee3f9106847
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+349
View File
@@ -0,0 +1,349 @@
//
// File.cs: Provides tagging for Panasonic Rw2 files
//
// 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;
using TagLib.IFD;
using TagLib.Image;
namespace TagLib.Tiff.Rw2
{
/// <summary>
/// This class extends <see cref="TagLib.Tiff.BaseTiffFile" /> to provide tagging
/// for RW2 image files.
/// </summary>
[SupportedMimeType ("taglib/rw2", "rw2")]
[SupportedMimeType ("image/rw2")]
[SupportedMimeType ("taglib/raw", "raw")]
[SupportedMimeType ("image/raw")]
[SupportedMimeType ("image/x-raw")]
[SupportedMimeType ("image/x-panasonic-raw")]
public class File : BaseTiffFile
{
#region private fields
/// <summary>
/// The Properties of the image
/// </summary>
Properties properties;
#endregion
#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 properties; }
}
/// <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; }
}
/// <summary>
/// The JPEG file that's embedded in the RAW file.
/// </summary>
public Jpeg.File JpgFromRaw {
get;
internal set;
}
#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)
{
Magic = 85; // Panasonic uses 0x55
Read (propertiesStyle);
}
/// <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 ();
}
/// <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)
{
Tag tag = base.GetTag (type, false);
if (tag != null) {
return tag;
}
if (!create || (type & ImageTag.AllowedTypes) == 0)
return null;
if (type != TagTypes.TiffIFD)
return base.GetTag (type, create);
ImageTag new_tag = new IFDTag (this);
ImageTag.AddTag (new_tag);
return new_tag;
}
#endregion
#region private methods
/// <summary>
/// Reads the information from file with a specified read style.
/// </summary>
/// <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>
void Read (ReadStyle propertiesStyle)
{
Mode = AccessMode.Read;
try {
ImageTag = new CombinedImageTag (TagTypes.TiffIFD);
ReadFile ();
TagTypesOnDisk = TagTypes;
if ((propertiesStyle & ReadStyle.Average) != 0)
properties = ExtractProperties ();
} finally {
Mode = AccessMode.Closed;
}
}
/// <summary>
/// Parses the RW2 file
/// </summary>
void ReadFile ()
{
// A RW2 file starts with a Tiff header followed by a RW2 header
uint first_ifd_offset = ReadHeader ();
uint raw_ifd_offset = ReadAdditionalRW2Header ();
ReadIFD (first_ifd_offset, 3);
ReadIFD (raw_ifd_offset, 1);
}
/// <summary>
/// Reads and validates the RW2 header started at the current position.
/// </summary>
/// <returns>
/// A <see cref="System.UInt32"/> with the offset to the IFD with the RAW data.
/// </returns>
uint ReadAdditionalRW2Header ()
{
// RW2 Header
//
// Seems to be 16 bytes, no idea on the meaning of these.
ByteVector header = ReadBlock (16);
if (header.Count != 16)
throw new CorruptFileException ("Unexpected end of RW2 header");
return (uint)Tell;
}
/// <summary>
/// Attempts to extract the media properties of the main
/// photo.
/// </summary>
/// <returns>
/// A <see cref="Properties" /> object with a best effort guess
/// at the right values. When no guess at all can be made,
/// <see langword="null" /> is returned.
/// </returns>
Properties ExtractProperties ()
{
int width = 0, height = 0;
IFDTag tag = GetTag (TagTypes.TiffIFD) as IFDTag;
IFDStructure structure = tag.Structure;
width = (int)(structure.GetLongValue (0, 0x07) ?? 0);
height = (int)(structure.GetLongValue (0, 0x06) ?? 0);
var vendor = ImageTag.Make;
if (vendor == "LEICA")
vendor = "Leica";
var desc = $"{vendor} RAW File";
if (width > 0 && height > 0) {
return new Properties (TimeSpan.Zero, new Codec (width, height, desc));
}
return null;
}
/// <summary>
/// Creates an IFD reader to parse the file.
/// </summary>
/// <param name="file">
/// A <see cref="File"/> to read from.
/// </param>
/// <param name="is_bigendian">
/// A <see cref="System.Boolean"/>, it must be true, if the data of the IFD should be
/// read as bigendian, otherwise false.
/// </param>
/// <param name="structure">
/// A <see cref="IFDStructure"/> that will be populated.
/// </param>
/// <param name="base_offset">
/// A <see cref="System.Int64"/> value describing the base were the IFD offsets
/// refer to. E.g. in Jpegs the IFD are located in an Segment and the offsets
/// inside the IFD refer from the beginning of this segment. So <paramref
/// name="base_offset"/> must contain the beginning of the segment.
/// </param>
/// <param name="ifd_offset">
/// A <see cref="System.UInt32"/> value with the beginning of the IFD relative to
/// <paramref name="base_offset"/>.
/// </param>
/// <param name="max_offset">
/// A <see cref="System.UInt32"/> value with maximal possible offset. This is to limit
/// the size of the possible data;
/// </param>
protected override IFD.IFDReader CreateIFDReader (BaseTiffFile file, bool is_bigendian, IFDStructure structure, long base_offset, uint ifd_offset, uint max_offset)
{
return new IFDReader (file, is_bigendian, structure, base_offset, ifd_offset, max_offset);
}
#endregion
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3af45a01bea4ee838c000da54a6ec9e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+137
View File
@@ -0,0 +1,137 @@
//
// IFDReader.cs: Panasonic Rw2-specific IFD reader
//
// 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.IO;
using TagLib.IFD;
namespace TagLib.Tiff.Rw2
{
/// <summary>
/// Panasonic Rw2-specific IFD reader
/// </summary>
public class IFDReader : TagLib.IFD.IFDReader
{
#region Constructors
/// <summary>
/// Constructor. Reads an IFD from given file, using the given endianness.
/// </summary>
/// <param name="file">
/// A <see cref="File"/> to read from.
/// </param>
/// <param name="is_bigendian">
/// A <see cref="System.Boolean"/>, it must be true, if the data of the IFD should be
/// read as bigendian, otherwise false.
/// </param>
/// <param name="structure">
/// A <see cref="IFDStructure"/> that will be populated.
/// </param>
/// <param name="base_offset">
/// A <see cref="System.Int64"/> value describing the base were the IFD offsets
/// refer to. E.g. in Jpegs the IFD are located in an Segment and the offsets
/// inside the IFD refer from the beginning of this segment. So <paramref
/// name="base_offset"/> must contain the beginning of the segment.
/// </param>
/// <param name="ifd_offset">
/// A <see cref="System.UInt32"/> value with the beginning of the IFD relative to
/// <paramref name="base_offset"/>.
/// </param>
/// <param name="max_offset">
/// A <see cref="System.UInt32"/> value with maximal possible offset. This is to limit
/// the size of the possible data;
/// </param>
public IFDReader (BaseTiffFile file, bool is_bigendian, IFDStructure structure, long base_offset, uint ifd_offset, uint max_offset) :
base (file, is_bigendian, structure, base_offset, ifd_offset, max_offset)
{
}
#endregion
/// <summary>
/// Try to parse the given IFD entry, used to discover format-specific entries.
/// </summary>
/// <param name="tag">
/// A <see cref="System.UInt16"/> with the tag of the entry.
/// </param>
/// <param name="type">
/// A <see cref="System.UInt16"/> with the type of the entry.
/// </param>
/// <param name="count">
/// A <see cref="System.UInt32"/> with the data count of the entry.
/// </param>
/// <param name="base_offset">
/// A <see cref="System.Int64"/> with the base offset which every offsets in the
/// IFD are relative to.
/// </param>
/// <param name="offset">
/// A <see cref="System.UInt32"/> with the offset of the entry.
/// </param>
/// <returns>
/// A <see cref="IFDEntry"/> with the given parameters, or null if none was parsed, after
/// which the normal TIFF parsing is used.
/// </returns>
protected override IFDEntry ParseIFDEntry (ushort tag, ushort type, uint count, long base_offset, uint offset)
{
if (tag == 0x002e && !seen_jpgfromraw) {
// FIXME: JpgFromRaw
file.Seek (base_offset + offset, SeekOrigin.Begin);
var data = file.ReadBlock ((int)count);
var mem_stream = new MemoryStream (data.Data);
var res = new StreamJPGAbstraction (mem_stream);
(file as File).JpgFromRaw = new Jpeg.File (res, ReadStyle.Average);
seen_jpgfromraw = true;
return null;
}
return base.ParseIFDEntry (tag, type, count, base_offset, offset);
}
bool seen_jpgfromraw;
}
class StreamJPGAbstraction : TagLib.File.IFileAbstraction
{
public StreamJPGAbstraction (Stream stream)
{
ReadStream = stream;
}
public string Name {
get { return "JpgFromRaw.jpg"; }
}
public void CloseStream (Stream stream)
{
stream.Close ();
}
public Stream ReadStream { get; private set; }
public Stream WriteStream {
get { return ReadStream; }
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 848f6e443474cdfefaa25124a6cf318d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+86
View File
@@ -0,0 +1,86 @@
//
// IFDTag.cs: Handles Panasonics weird metadata structure.
//
// 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 TagLib.IFD.Tags;
namespace TagLib.Tiff.Rw2
{
/// <summary>
/// Handles the weird structure of Panasonic metadata.
/// </summary>
public class IFDTag : TagLib.IFD.IFDTag
{
readonly File file;
internal IFDTag (File file)
{
this.file = file;
}
/// <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>
/// <remarks>
/// <para>Panasonic stores these in a somewhat unstandard location.</para>
/// </remarks>
public override uint? ISOSpeedRatings {
// TODO: The value in JPGFromRAW should probably be used as well.
get {
return Structure.GetLongValue (0, (ushort)PanasonicMakerNoteEntryTag.ISO);
}
set {
Structure.SetLongValue (0, (ushort)PanasonicMakerNoteEntryTag.ISO, value ?? 0);
}
}
/// <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>
/// <remarks>
/// <para>Panasonic stores these in a somewhat unstandard location.</para>
/// </remarks>
public override uint? FocalLengthIn35mmFilm {
get {
var jpg = file.JpgFromRaw;
if (jpg == null)
return base.FocalLengthIn35mmFilm;
if (!(jpg.GetTag (TagTypes.TiffIFD, true) is Image.ImageTag tag))
return base.FocalLengthIn35mmFilm;
return tag.FocalLengthIn35mmFilm ?? base.FocalLengthIn35mmFilm;
}
set {
(file.JpgFromRaw.GetTag (TagTypes.TiffIFD, true) as Image.ImageTag).FocalLengthIn35mmFilm = value;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 89b744bace7dfa6a485d00d422087ba0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: