Beispiel #1
0
        public virtual void Extract([NotNull] RandomAccessReader reader, [NotNull] Com.Drew.Metadata.Metadata metadata)
        {
            // TODO review whether the 'tagPtr' values below really do require RandomAccessReader or whether SequentialReader may be used instead
            IccDirectory directory = new IccDirectory();

            try
            {
                int profileByteCount = reader.GetInt32(IccDirectory.TagProfileByteCount);
                directory.SetInt(IccDirectory.TagProfileByteCount, profileByteCount);
                // For these tags, the int value of the tag is in fact it's offset within the buffer.
                Set4ByteString(directory, IccDirectory.TagCmmType, reader);
                SetInt32(directory, IccDirectory.TagProfileVersion, reader);
                Set4ByteString(directory, IccDirectory.TagProfileClass, reader);
                Set4ByteString(directory, IccDirectory.TagColorSpace, reader);
                Set4ByteString(directory, IccDirectory.TagProfileConnectionSpace, reader);
                SetDate(directory, IccDirectory.TagProfileDatetime, reader);
                Set4ByteString(directory, IccDirectory.TagSignature, reader);
                Set4ByteString(directory, IccDirectory.TagPlatform, reader);
                SetInt32(directory, IccDirectory.TagCmmFlags, reader);
                Set4ByteString(directory, IccDirectory.TagDeviceMake, reader);
                int temp = reader.GetInt32(IccDirectory.TagDeviceModel);
                if (temp != 0)
                {
                    if (temp <= unchecked ((int)(0x20202020)))
                    {
                        directory.SetInt(IccDirectory.TagDeviceModel, temp);
                    }
                    else
                    {
                        directory.SetString(IccDirectory.TagDeviceModel, GetStringFromInt32(temp));
                    }
                }
                SetInt32(directory, IccDirectory.TagRenderingIntent, reader);
                SetInt64(directory, IccDirectory.TagDeviceAttr, reader);
                float[] xyz = new float[] { reader.GetS15Fixed16(IccDirectory.TagXyzValues), reader.GetS15Fixed16(IccDirectory.TagXyzValues + 4), reader.GetS15Fixed16(IccDirectory.TagXyzValues + 8) };
                directory.SetObject(IccDirectory.TagXyzValues, xyz);
                // Process 'ICC tags'
                int tagCount = reader.GetInt32(IccDirectory.TagTagCount);
                directory.SetInt(IccDirectory.TagTagCount, tagCount);
                for (int i = 0; i < tagCount; i++)
                {
                    int     pos     = IccDirectory.TagTagCount + 4 + i * 12;
                    int     tagType = reader.GetInt32(pos);
                    int     tagPtr  = reader.GetInt32(pos + 4);
                    int     tagLen  = reader.GetInt32(pos + 8);
                    sbyte[] b       = reader.GetBytes(tagPtr, tagLen);
                    directory.SetByteArray(tagType, b);
                }
            }
            catch (IOException ex)
            {
                directory.AddError("Exception reading ICC profile: " + ex.Message);
            }
            metadata.AddDirectory(directory);
        }
Beispiel #2
0
        public virtual void TestExtract()
        {
            sbyte[] app2Bytes = FileUtil.ReadBytes("Tests/Data/iccDataInvalid1.jpg.app2");
            // ICC data starts after a 14-byte preamble
            sbyte[] icc = TestHelper.SkipBytes(app2Bytes, 14);
            Com.Drew.Metadata.Metadata metadata = new Com.Drew.Metadata.Metadata();
            new IccReader().Extract(new ByteArrayReader(icc), metadata);
            IccDirectory directory = metadata.GetFirstDirectoryOfType <IccDirectory>();

            NUnit.Framework.Assert.IsNotNull(directory);
        }
Beispiel #3
0
 public virtual void Extract([NotNull] RandomAccessReader reader, [NotNull] Com.Drew.Metadata.Metadata metadata)
 {
     // TODO review whether the 'tagPtr' values below really do require RandomAccessReader or whether SequentialReader may be used instead
     IccDirectory directory = new IccDirectory();
     try
     {
         int profileByteCount = reader.GetInt32(IccDirectory.TagProfileByteCount);
         directory.SetInt(IccDirectory.TagProfileByteCount, profileByteCount);
         // For these tags, the int value of the tag is in fact it's offset within the buffer.
         Set4ByteString(directory, IccDirectory.TagCmmType, reader);
         SetInt32(directory, IccDirectory.TagProfileVersion, reader);
         Set4ByteString(directory, IccDirectory.TagProfileClass, reader);
         Set4ByteString(directory, IccDirectory.TagColorSpace, reader);
         Set4ByteString(directory, IccDirectory.TagProfileConnectionSpace, reader);
         SetDate(directory, IccDirectory.TagProfileDatetime, reader);
         Set4ByteString(directory, IccDirectory.TagSignature, reader);
         Set4ByteString(directory, IccDirectory.TagPlatform, reader);
         SetInt32(directory, IccDirectory.TagCmmFlags, reader);
         Set4ByteString(directory, IccDirectory.TagDeviceMake, reader);
         int temp = reader.GetInt32(IccDirectory.TagDeviceModel);
         if (temp != 0)
         {
             if (temp <= unchecked((int)(0x20202020)))
             {
                 directory.SetInt(IccDirectory.TagDeviceModel, temp);
             }
             else
             {
                 directory.SetString(IccDirectory.TagDeviceModel, GetStringFromInt32(temp));
             }
         }
         SetInt32(directory, IccDirectory.TagRenderingIntent, reader);
         SetInt64(directory, IccDirectory.TagDeviceAttr, reader);
         float[] xyz = new float[] { reader.GetS15Fixed16(IccDirectory.TagXyzValues), reader.GetS15Fixed16(IccDirectory.TagXyzValues + 4), reader.GetS15Fixed16(IccDirectory.TagXyzValues + 8) };
         directory.SetObject(IccDirectory.TagXyzValues, xyz);
         // Process 'ICC tags'
         int tagCount = reader.GetInt32(IccDirectory.TagTagCount);
         directory.SetInt(IccDirectory.TagTagCount, tagCount);
         for (int i = 0; i < tagCount; i++)
         {
             int pos = IccDirectory.TagTagCount + 4 + i * 12;
             int tagType = reader.GetInt32(pos);
             int tagPtr = reader.GetInt32(pos + 4);
             int tagLen = reader.GetInt32(pos + 8);
             sbyte[] b = reader.GetBytes(tagPtr, tagLen);
             directory.SetByteArray(tagType, b);
         }
     }
     catch (IOException ex)
     {
         directory.AddError("Exception reading ICC profile: " + ex.Message);
     }
     metadata.AddDirectory(directory);
 }
Beispiel #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);
        }
		/// <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);
		}