/// <summary>Creates an <code>XMPDateTime</code>-instance from a calendar.</summary>
        /// <param name="calendar">a <code>Calendar</code></param>
        public XMPDateTimeImpl(Sharpen.Calendar calendar)
        {
            // EMPTY
            // extract the date and timezone from the calendar provided
            DateTime     date = calendar.GetTime();
            TimeZoneInfo zone = calendar.GetTimeZone();

            // put that date into a calendar the pretty much represents ISO8601
            // I use US because it is close to the "locale" for the ISO8601 spec
            Sharpen.GregorianCalendar intCalendar = (Sharpen.GregorianCalendar)Sharpen.Calendar.GetInstance(CultureInfo.InvariantCulture);
            intCalendar.SetGregorianChange(Sharpen.Extensions.CreateDate(long.MinValue));
            intCalendar.SetTimeZone(zone);
            intCalendar.SetTime(date);
            this.year  = intCalendar.Get(Sharpen.CalendarEnum.Year);
            this.month = intCalendar.Get(Sharpen.CalendarEnum.Month) + 1;
            // cal is from 0..12
            this.day         = intCalendar.Get(Sharpen.CalendarEnum.DayOfMonth);
            this.hour        = intCalendar.Get(Sharpen.CalendarEnum.HourOfDay);
            this.minute      = intCalendar.Get(Sharpen.CalendarEnum.Minute);
            this.second      = intCalendar.Get(Sharpen.CalendarEnum.Second);
            this.nanoSeconds = intCalendar.Get(Sharpen.CalendarEnum.Millisecond) * 1000000;
            this.timeZone    = intCalendar.GetTimeZone();
            // object contains all date components
            hasDate = hasTime = hasTimeZone = true;
        }
Esempio n. 2
0
 /// <exception cref="Com.Adobe.Xmp.XMPException"/>
 private void ProcessXmpDateTag(XMPMeta meta, XmpDirectory directory, string schemaNS, string propName, int tagType)
 {
     Sharpen.Calendar cal = meta.GetPropertyCalendar(schemaNS, propName);
     if (cal != null)
     {
         directory.SetDate(tagType, cal.GetTime());
     }
 }
Esempio n. 3
0
        /// <exception cref="Com.Adobe.Xmp.XMPException"/>
        private static void ProcessXmpDateTag([NotNull] XMPMeta meta, [NotNull] XmpDirectory directory, int tagType)
        {
            string schemaNS = XmpDirectory._tagSchemaMap.Get(tagType);
            string propName = XmpDirectory._tagPropNameMap.Get(tagType);

            Sharpen.Calendar cal = meta.GetPropertyCalendar(schemaNS, propName);
            if (cal != null)
            {
                directory.SetDate(tagType, cal.GetTime());
            }
        }
Esempio n. 4
0
        /// <exception cref="System.IO.IOException"/>
        private void SetDate(IccDirectory directory, int tagType, RandomAccessReader reader)
        {
            int y = reader.GetUInt16(tagType);
            int m = reader.GetUInt16(tagType + 2);
            int d = reader.GetUInt16(tagType + 4);
            int h = reader.GetUInt16(tagType + 6);
            int M = reader.GetUInt16(tagType + 8);
            int s = reader.GetUInt16(tagType + 10);

            //        final Date value = new Date(Date.UTC(y - 1900, m - 1, d, h, M, s));
            Sharpen.Calendar calendar = Sharpen.Calendar.GetInstance(Sharpen.Extensions.GetTimeZone("UTC"));
            calendar.Set(y, m, d, h, M, s);
            DateTime value = calendar.GetTime();

            directory.SetDate(tagType, value);
        }
Esempio n. 5
0
 /// <summary>Creates an <c>XMPDateTime</c>-instance from a calendar.</summary>
 /// <param name="calendar">a <c>Calendar</c></param>
 public XmpDateTime(Calendar calendar)
 {
     // extract the date and timezone from the calendar provided
     var date = calendar.GetTime();
     var zone = calendar.GetTimeZone();
     // put that date into a calendar the pretty much represents ISO8601
     // I use US because it is close to the "locale" for the ISO8601 spec
     var intCalendar = (GregorianCalendar)Calendar.GetInstance(CultureInfo.InvariantCulture);
     intCalendar.SetGregorianChange(UnixTimeToDateTime(long.MinValue));
     intCalendar.SetTimeZone(zone);
     intCalendar.SetTime(date);
     _year = intCalendar.Get(CalendarEnum.Year);
     _month = intCalendar.Get(CalendarEnum.Month) + 1;
     // cal is from 0..12
     _day = intCalendar.Get(CalendarEnum.DayOfMonth);
     _hour = intCalendar.Get(CalendarEnum.HourOfDay);
     _minute = intCalendar.Get(CalendarEnum.Minute);
     _second = intCalendar.Get(CalendarEnum.Second);
     _nanoseconds = intCalendar.Get(CalendarEnum.Millisecond) * 1000000;
     _timeZone = intCalendar.GetTimeZone();
     // object contains all date components
     HasDate = HasTime = HasTimeZone = true;
 }
Esempio n. 6
0
 /// <exception cref="XmpException"/>
 public void SetPropertyCalendar(string schemaNs, string propName, Calendar propValue)
 {
     SetProperty(schemaNs, propName, propValue, null);
 }
Esempio n. 7
0
 /// <exception cref="XmpException"/>
 public void SetPropertyCalendar(string schemaNs, string propName, Calendar propValue, PropertyOptions options)
 {
     SetProperty(schemaNs, propName, propValue, options);
 }
Esempio n. 8
0
 // EMPTY
 /// <summary>Creates an <code>XMPDateTime</code> from a <code>Calendar</code>-object.</summary>
 /// <param name="calendar">a <code>Calendar</code>-object.</param>
 /// <returns>An <code>XMPDateTime</code>-object.</returns>
 public static XMPDateTime CreateFromCalendar(Sharpen.Calendar calendar)
 {
     return(new XMPDateTimeImpl(calendar));
 }
Esempio n. 9
0
 /// <summary>
 /// Sets the local time zone without touching any other Any existing time zone value is replaced,
 /// the other date/time fields are not adjusted in any way.
 /// </summary>
 /// <param name="dateTime">the <code>XMPDateTime</code> variable containing the value to be modified.</param>
 /// <returns>Returns an updated <code>XMPDateTime</code>-object.</returns>
 public static XMPDateTime SetLocalTimeZone(XMPDateTime dateTime)
 {
     Sharpen.Calendar cal = dateTime.GetCalendar();
     cal.SetTimeZone(System.TimeZoneInfo.Local);
     return(new XMPDateTimeImpl(cal));
 }
        /// <exception cref="Com.Drew.Imaging.Png.PngProcessingException"/>
        /// <exception cref="System.IO.IOException"/>
        private static void ProcessChunk([NotNull] Com.Drew.Metadata.Metadata metadata, [NotNull] PngChunk chunk)
        {
            PngChunkType chunkType = chunk.GetChunkType();

            sbyte[] bytes = chunk.GetBytes();
            if (chunkType.Equals(PngChunkType.Ihdr))
            {
                PngHeader    header    = new PngHeader(bytes);
                PngDirectory directory = new PngDirectory(PngChunkType.Ihdr);
                directory.SetInt(PngDirectory.TagImageWidth, header.GetImageWidth());
                directory.SetInt(PngDirectory.TagImageHeight, header.GetImageHeight());
                directory.SetInt(PngDirectory.TagBitsPerSample, header.GetBitsPerSample());
                directory.SetInt(PngDirectory.TagColorType, header.GetColorType().GetNumericValue());
                directory.SetInt(PngDirectory.TagCompressionType, header.GetCompressionType());
                directory.SetInt(PngDirectory.TagFilterMethod, header.GetFilterMethod());
                directory.SetInt(PngDirectory.TagInterlaceMethod, header.GetInterlaceMethod());
                metadata.AddDirectory(directory);
            }
            else
            {
                if (chunkType.Equals(PngChunkType.Plte))
                {
                    PngDirectory directory = new PngDirectory(PngChunkType.Plte);
                    directory.SetInt(PngDirectory.TagPaletteSize, bytes.Length / 3);
                    metadata.AddDirectory(directory);
                }
                else
                {
                    if (chunkType.Equals(PngChunkType.tRNS))
                    {
                        PngDirectory directory = new PngDirectory(PngChunkType.tRNS);
                        directory.SetInt(PngDirectory.TagPaletteHasTransparency, 1);
                        metadata.AddDirectory(directory);
                    }
                    else
                    {
                        if (chunkType.Equals(PngChunkType.sRGB))
                        {
                            int          srgbRenderingIntent = new SequentialByteArrayReader(bytes).GetInt8();
                            PngDirectory directory           = new PngDirectory(PngChunkType.sRGB);
                            directory.SetInt(PngDirectory.TagSrgbRenderingIntent, srgbRenderingIntent);
                            metadata.AddDirectory(directory);
                        }
                        else
                        {
                            if (chunkType.Equals(PngChunkType.cHRM))
                            {
                                PngChromaticities          chromaticities = new PngChromaticities(bytes);
                                PngChromaticitiesDirectory directory      = new PngChromaticitiesDirectory();
                                directory.SetInt(PngChromaticitiesDirectory.TagWhitePointX, chromaticities.GetWhitePointX());
                                directory.SetInt(PngChromaticitiesDirectory.TagWhitePointX, chromaticities.GetWhitePointX());
                                directory.SetInt(PngChromaticitiesDirectory.TagRedX, chromaticities.GetRedX());
                                directory.SetInt(PngChromaticitiesDirectory.TagRedY, chromaticities.GetRedY());
                                directory.SetInt(PngChromaticitiesDirectory.TagGreenX, chromaticities.GetGreenX());
                                directory.SetInt(PngChromaticitiesDirectory.TagGreenY, chromaticities.GetGreenY());
                                directory.SetInt(PngChromaticitiesDirectory.TagBlueX, chromaticities.GetBlueX());
                                directory.SetInt(PngChromaticitiesDirectory.TagBlueY, chromaticities.GetBlueY());
                                metadata.AddDirectory(directory);
                            }
                            else
                            {
                                if (chunkType.Equals(PngChunkType.gAMA))
                                {
                                    int          gammaInt  = new SequentialByteArrayReader(bytes).GetInt32();
                                    PngDirectory directory = new PngDirectory(PngChunkType.gAMA);
                                    directory.SetDouble(PngDirectory.TagGamma, gammaInt / 100000.0);
                                    metadata.AddDirectory(directory);
                                }
                                else
                                {
                                    if (chunkType.Equals(PngChunkType.iCCP))
                                    {
                                        SequentialReader reader      = new SequentialByteArrayReader(bytes);
                                        string           profileName = reader.GetNullTerminatedString(79);
                                        PngDirectory     directory   = new PngDirectory(PngChunkType.iCCP);
                                        directory.SetString(PngDirectory.TagIccProfileName, profileName);
                                        sbyte compressionMethod = reader.GetInt8();
                                        if (compressionMethod == 0)
                                        {
                                            // Only compression method allowed by the spec is zero: deflate
                                            // This assumes 1-byte-per-char, which it is by spec.
                                            int                 bytesLeft         = bytes.Length - profileName.Length - 2;
                                            sbyte[]             compressedProfile = reader.GetBytes(bytesLeft);
                                            InflaterInputStream inflateStream     = new InflaterInputStream(new ByteArrayInputStream(compressedProfile));
                                            new IccReader().Extract(new RandomAccessStreamReader(inflateStream), metadata);
                                            inflateStream.Close();
                                        }
                                        metadata.AddDirectory(directory);
                                    }
                                    else
                                    {
                                        if (chunkType.Equals(PngChunkType.bKGD))
                                        {
                                            PngDirectory directory = new PngDirectory(PngChunkType.bKGD);
                                            directory.SetByteArray(PngDirectory.TagBackgroundColor, bytes);
                                            metadata.AddDirectory(directory);
                                        }
                                        else
                                        {
                                            if (chunkType.Equals(PngChunkType.tEXt))
                                            {
                                                SequentialReader reader        = new SequentialByteArrayReader(bytes);
                                                string           keyword       = reader.GetNullTerminatedString(79);
                                                int    bytesLeft               = bytes.Length - keyword.Length - 1;
                                                string value                   = reader.GetNullTerminatedString(bytesLeft);
                                                IList <KeyValuePair> textPairs = new AList <KeyValuePair>();
                                                textPairs.Add(new KeyValuePair(keyword, value));
                                                PngDirectory directory = new PngDirectory(PngChunkType.iTXt);
                                                directory.SetObject(PngDirectory.TagTextualData, textPairs);
                                                metadata.AddDirectory(directory);
                                            }
                                            else
                                            {
                                                if (chunkType.Equals(PngChunkType.iTXt))
                                                {
                                                    SequentialReader reader            = new SequentialByteArrayReader(bytes);
                                                    string           keyword           = reader.GetNullTerminatedString(79);
                                                    sbyte            compressionFlag   = reader.GetInt8();
                                                    sbyte            compressionMethod = reader.GetInt8();
                                                    string           languageTag       = reader.GetNullTerminatedString(bytes.Length);
                                                    string           translatedKeyword = reader.GetNullTerminatedString(bytes.Length);
                                                    int    bytesLeft = bytes.Length - keyword.Length - 1 - 1 - 1 - languageTag.Length - 1 - translatedKeyword.Length - 1;
                                                    string text      = null;
                                                    if (compressionFlag == 0)
                                                    {
                                                        text = reader.GetNullTerminatedString(bytesLeft);
                                                    }
                                                    else
                                                    {
                                                        if (compressionFlag == 1)
                                                        {
                                                            if (compressionMethod == 0)
                                                            {
                                                                text = StringUtil.FromStream(new InflaterInputStream(new ByteArrayInputStream(bytes, bytes.Length - bytesLeft, bytesLeft)));
                                                            }
                                                            else
                                                            {
                                                                PngDirectory directory = new PngDirectory(PngChunkType.iTXt);
                                                                directory.AddError("Invalid compression method value");
                                                                metadata.AddDirectory(directory);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            PngDirectory directory = new PngDirectory(PngChunkType.iTXt);
                                                            directory.AddError("Invalid compression flag value");
                                                            metadata.AddDirectory(directory);
                                                        }
                                                    }
                                                    if (text != null)
                                                    {
                                                        if (keyword.Equals("XML:com.adobe.xmp"))
                                                        {
                                                            // NOTE in testing images, the XMP has parsed successfully, but we are not extracting tags from it as necessary
                                                            new XmpReader().Extract(text, metadata);
                                                        }
                                                        else
                                                        {
                                                            IList <KeyValuePair> textPairs = new AList <KeyValuePair>();
                                                            textPairs.Add(new KeyValuePair(keyword, text));
                                                            PngDirectory directory = new PngDirectory(PngChunkType.iTXt);
                                                            directory.SetObject(PngDirectory.TagTextualData, textPairs);
                                                            metadata.AddDirectory(directory);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (chunkType.Equals(PngChunkType.tIME))
                                                    {
                                                        SequentialByteArrayReader reader = new SequentialByteArrayReader(bytes);
                                                        int year   = reader.GetUInt16();
                                                        int month  = reader.GetUInt8() - 1;
                                                        int day    = reader.GetUInt8();
                                                        int hour   = reader.GetUInt8();
                                                        int minute = reader.GetUInt8();
                                                        int second = reader.GetUInt8();
                                                        Sharpen.Calendar calendar = Sharpen.Calendar.GetInstance(Sharpen.Extensions.GetTimeZone("UTC"));
                                                        //noinspection MagicConstant
                                                        calendar.Set(year, month, day, hour, minute, second);
                                                        PngDirectory directory = new PngDirectory(PngChunkType.tIME);
                                                        directory.SetDate(PngDirectory.TagLastModificationTime, calendar.GetTime());
                                                        metadata.AddDirectory(directory);
                                                    }
                                                    else
                                                    {
                                                        if (chunkType.Equals(PngChunkType.pHYs))
                                                        {
                                                            SequentialByteArrayReader reader = new SequentialByteArrayReader(bytes);
                                                            int          pixelsPerUnitX      = reader.GetInt32();
                                                            int          pixelsPerUnitY      = reader.GetInt32();
                                                            sbyte        unitSpecifier       = reader.GetInt8();
                                                            PngDirectory directory           = new PngDirectory(PngChunkType.pHYs);
                                                            directory.SetInt(PngDirectory.TagPixelsPerUnitX, pixelsPerUnitX);
                                                            directory.SetInt(PngDirectory.TagPixelsPerUnitY, pixelsPerUnitY);
                                                            directory.SetInt(PngDirectory.TagUnitSpecifier, unitSpecifier);
                                                            metadata.AddDirectory(directory);
                                                        }
                                                        else
                                                        {
                                                            if (chunkType.Equals(PngChunkType.sBIT))
                                                            {
                                                                PngDirectory directory = new PngDirectory(PngChunkType.sBIT);
                                                                directory.SetByteArray(PngDirectory.TagSignificantBits, bytes);
                                                                metadata.AddDirectory(directory);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 /// <summary>Creates an <c>XMPDateTime</c> from a <c>Calendar</c>-object.</summary>
 /// <param name="calendar">a <c>Calendar</c>-object.</param>
 /// <returns>An <c>XMPDateTime</c>-object.</returns>
 public static IXmpDateTime CreateFromCalendar(Calendar calendar)
 {
     return new XmpDateTime(calendar);
 }