using System; using System.Text; using System.Collections; using System.IO; using com.drew.metadata; using com.utils; using System.Globalization; /// /// This class was first written by Drew Noakes in Java. /// /// This is public domain software - that is, you can do whatever you want /// with it, and include it software that is licensed under the GNU or the /// BSD license, or whatever other licence you choose, including proprietary /// closed source licenses. I do ask that you leave this header in tact. /// /// If you make modifications to this code that you think would benefit the /// wider community, please send me a copy and I'll post it on my site. /// /// If you make use of this code, Drew Noakes will appreciate hearing /// about it: drew@drewnoakes.com /// /// Latest Java version of this software kept at /// http://drewnoakes.com/ /// /// The C# class was made by Ferret Renaud: /// renaud91@free.fr /// If you find a bug in the C# code, feel free to mail me. /// namespace com.drew.metadata.jpeg { /// /// The Jpeg Directory class /// public class JpegDirectory : Directory { /// /// This is in bits/sample, usually 8 (12 and 16 not supported by most software). /// public const int TAG_JPEG_DATA_PRECISION = 0; /// /// The image's height. Necessary for decoding the image, so it should always be there. /// public const int TAG_JPEG_IMAGE_HEIGHT = 1; /// /// The image's width. Necessary for decoding the image, so it should always be there. /// public const int TAG_JPEG_IMAGE_WIDTH = 3; /// /// Usually 1 = grey scaled, 3 = color YcbCr or YIQ, 4 = color CMYK Each component TAG_COMPONENT_DATA_[1-4], /// has the following meaning: component Id(1byte)(1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q), /// sampling factors (1byte) (bit 0-3 vertical., 4-7 horizontal.), /// quantization table number (1 byte). /// This info is from http://www.funducode.com/freec/Fileformats/format3/format3b.htm /// public const int TAG_JPEG_NUMBER_OF_COMPONENTS = 5; // NOTE! Component tag type int values must increment in steps of 1 /// /// the first of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS. /// public const int TAG_JPEG_COMPONENT_DATA_1 = 6; /// /// the second of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS. /// public const int TAG_JPEG_COMPONENT_DATA_2 = 7; /// /// the third of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS. /// public const int TAG_JPEG_COMPONENT_DATA_3 = 8; /// /// the fourth of a possible 4 color components. Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS. /// public const int TAG_JPEG_COMPONENT_DATA_4 = 9; protected static readonly ResourceBundle BUNDLE = new ResourceBundle("JpegMarkernote"); protected static readonly IDictionary tagNameMap = JpegDirectory.InitTagMap(); /// /// Initialize the tag map. /// /// the tag map private static IDictionary InitTagMap() { // Create a Hashtable using a case-insensitive code provider and a case-insensitive comparer, // based on the Spanish culture (es-AR), where "I" is not the uppercase version of "i". CultureInfo myCul = new CultureInfo( "es-AR" ); IDictionary resu = new Hashtable( new CaseInsensitiveHashCodeProvider( myCul ), new CaseInsensitiveComparer( myCul )); //IDictionary resu = new Hashtable(); resu.Add(TAG_JPEG_DATA_PRECISION, BUNDLE["TAG_JPEG_DATA_PRECISION"]); resu.Add(TAG_JPEG_IMAGE_WIDTH, BUNDLE["TAG_JPEG_IMAGE_WIDTH"]); resu.Add(TAG_JPEG_IMAGE_HEIGHT, BUNDLE["TAG_JPEG_IMAGE_HEIGHT"]); resu.Add(TAG_JPEG_NUMBER_OF_COMPONENTS, BUNDLE["TAG_JPEG_NUMBER_OF_COMPONENTS"]); resu.Add(TAG_JPEG_COMPONENT_DATA_1, BUNDLE["TAG_JPEG_COMPONENT_DATA_1"]); resu.Add(TAG_JPEG_COMPONENT_DATA_2, BUNDLE["TAG_JPEG_COMPONENT_DATA_2"]); resu.Add(TAG_JPEG_COMPONENT_DATA_3, BUNDLE["TAG_JPEG_COMPONENT_DATA_3"]); resu.Add(TAG_JPEG_COMPONENT_DATA_4, BUNDLE["TAG_JPEG_COMPONENT_DATA_4"]); return resu; } /// /// Constructor of the object. /// public JpegDirectory() : base() { this.SetDescriptor(new JpegDescriptor(this)); } /// /// Provides the name of the directory, for display purposes. E.g. Exif /// /// the name of the directory public override string GetName() { return BUNDLE["MARKER_NOTE_NAME"]; } /// /// Provides the map of tag names, hashed by tag type identifier. /// /// the map of tag names protected override IDictionary GetTagNameMap() { return tagNameMap; } /** * * @param componentNumber * @return */ /// /// Gets the component /// /// The zero-based index of the component. This number is normally between 0 and 3. Use GetNumberOfComponents for bounds-checking. /// the JpegComponent public JpegComponent GetComponent(int componentNumber) { int tagType = JpegDirectory.TAG_JPEG_COMPONENT_DATA_1 + componentNumber; JpegComponent component = (JpegComponent) GetObject(tagType); return component; } /// /// Gets image width /// /// image width public int GetImageWidth() { return GetInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH); } /// /// Gets image height /// /// image height public int GetImageHeight() { return GetInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT); } /// /// Gets the Number Of Components /// /// the Number Of Components public int GetNumberOfComponents() { return GetInt(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS); } } }