public virtual void Extract(sbyte[] segmentBytes, Com.Drew.Metadata.Metadata metadata, JpegSegmentType segmentType)
		{
			// skip the first 14 bytes
			sbyte[] iccProfileBytes = new sbyte[segmentBytes.Length - 14];
			System.Array.Copy(segmentBytes, 14, iccProfileBytes, 0, segmentBytes.Length - 14);
			Extract(new ByteArrayReader(iccProfileBytes), metadata);
		}
示例#2
0
 public virtual void Extract(sbyte[] segmentBytes, Com.Drew.Metadata.Metadata metadata, JpegSegmentType segmentType)
 {
     JpegDirectory directory = new JpegDirectory();
     metadata.AddDirectory(directory);
     // The value of TAG_COMPRESSION_TYPE is determined by the segment type found
     directory.SetInt(JpegDirectory.TagCompressionType, segmentType.byteValue - JpegSegmentType.Sof0.byteValue);
     SequentialReader reader = new SequentialByteArrayReader(segmentBytes);
     try
     {
         directory.SetInt(JpegDirectory.TagDataPrecision, reader.GetUInt8());
         directory.SetInt(JpegDirectory.TagImageHeight, reader.GetUInt16());
         directory.SetInt(JpegDirectory.TagImageWidth, reader.GetUInt16());
         short componentCount = reader.GetUInt8();
         directory.SetInt(JpegDirectory.TagNumberOfComponents, componentCount);
         // for each component, there are three bytes of data:
         // 1 - Component ID: 1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q
         // 2 - Sampling factors: bit 0-3 vertical, 4-7 horizontal
         // 3 - Quantization table number
         for (int i = 0; i < (int)componentCount; i++)
         {
             int componentId = reader.GetUInt8();
             int samplingFactorByte = reader.GetUInt8();
             int quantizationTableNumber = reader.GetUInt8();
             JpegComponent component = new JpegComponent(componentId, samplingFactorByte, quantizationTableNumber);
             directory.SetObject(JpegDirectory.TagComponentData1 + i, component);
         }
     }
     catch (IOException ex)
     {
         directory.AddError(ex.Message);
     }
 }
        /// <summary>Gets the set of JPEG segment type identifiers.</summary>
        public virtual Iterable <JpegSegmentType> GetSegmentTypes()
        {
            ICollection <JpegSegmentType> segmentTypes = new HashSet <JpegSegmentType>();

            foreach (sbyte segmentTypeByte in _segmentDataMap.Keys)
            {
                JpegSegmentType segmentType = JpegSegmentType.FromByte(segmentTypeByte);
                if (segmentType == null)
                {
                    throw new InvalidOperationException("Should not have a segmentTypeByte that is not in the enum: " + Sharpen.Extensions.ToHexString(segmentTypeByte));
                }
                segmentTypes.Add(segmentType);
            }
            return(segmentTypes.AsIterable());
        }
 public virtual Iterable <sbyte[]> GetSegments([NotNull] JpegSegmentType segmentType)
 {
     return(GetSegments(segmentType.byteValue));
 }
 public virtual sbyte[] GetSegment([NotNull] JpegSegmentType segmentType, int occurrence)
 {
     return(GetSegment(segmentType.byteValue, occurrence));
 }
		public virtual Iterable<sbyte[]> GetSegments(JpegSegmentType segmentType)
		{
			return GetSegments(segmentType.byteValue);
		}
		public virtual bool CanProcess(sbyte[] segmentBytes, JpegSegmentType segmentType)
		{
			return segmentBytes.Length > 12 && "Photoshop 3.0".Equals(Sharpen.Runtime.GetStringForBytes(segmentBytes, 0, 13));
		}
		/// <summary>Removes a specified instance of a segment's data from the collection.</summary>
		/// <remarks>
		/// Removes a specified instance of a segment's data from the collection.  Use this method when more than one
		/// occurrence of segment data exists for a given type exists.
		/// </remarks>
		/// <param name="segmentType">identifies the required segment</param>
		/// <param name="occurrence">the zero-based index of the segment occurrence to remove.</param>
		public virtual void RemoveSegmentOccurrence(JpegSegmentType segmentType, int occurrence)
		{
			RemoveSegmentOccurrence(segmentType.byteValue, occurrence);
		}
 /// <summary>Removes all segments from the collection having the specified type.</summary>
 /// <param name="segmentType">identifies the required segment</param>
 public virtual void RemoveSegment([NotNull] JpegSegmentType segmentType)
 {
     RemoveSegment(segmentType.byteValue);
 }
		public virtual bool CanProcess(sbyte[] segmentBytes, JpegSegmentType segmentType)
		{
			return segmentBytes.Length == 12 && Sharpen.Runtime.EqualsIgnoreCase("Adobe", Sharpen.Runtime.GetStringForBytes(segmentBytes, 0, 5));
		}
示例#11
0
		public virtual bool CanProcess(sbyte[] segmentBytes, JpegSegmentType segmentType)
		{
			// Check whether the first byte resembles
			return segmentBytes.Length != 0 && segmentBytes[0] == unchecked((int)(0x1c));
		}
示例#12
0
		public virtual bool CanProcess(sbyte[] segmentBytes, JpegSegmentType segmentType)
		{
			return segmentBytes.Length > 27 && Sharpen.Runtime.EqualsIgnoreCase("http://ns.adobe.com/xap/1.0/", Sharpen.Runtime.GetStringForBytes(segmentBytes, 0, 28));
		}
示例#13
0
		/// <summary>Version specifically for dealing with XMP found in JPEG segments.</summary>
		/// <remarks>
		/// Version specifically for dealing with XMP found in JPEG segments. This form of XMP has a peculiar preamble, which
		/// must be removed before parsing the XML.
		/// </remarks>
		/// <param name="segmentBytes">The byte array from which the metadata should be extracted.</param>
		/// <param name="metadata">
		/// The
		/// <see cref="Com.Drew.Metadata.Metadata"/>
		/// object into which extracted values should be merged.
		/// </param>
		/// <param name="segmentType">
		/// The
		/// <see cref="Com.Drew.Imaging.Jpeg.JpegSegmentType"/>
		/// being read.
		/// </param>
		public virtual void Extract(sbyte[] segmentBytes, Com.Drew.Metadata.Metadata metadata, JpegSegmentType segmentType)
		{
			XmpDirectory directory = metadata.GetOrCreateDirectory<XmpDirectory>();
			// XMP in a JPEG file has a 29 byte preamble which is not valid XML.
			int preambleLength = 29;
			// check for the header length
			if (segmentBytes.Length <= preambleLength + 1)
			{
				directory.AddError(Sharpen.Extensions.StringFormat("Xmp data segment must contain at least %d bytes", preambleLength + 1));
				return;
			}
			ByteArrayReader reader = new ByteArrayReader(segmentBytes);
			string preamble = Sharpen.Runtime.GetStringForBytes(segmentBytes, 0, preambleLength);
			if (!"http://ns.adobe.com/xap/1.0/\x0".Equals(preamble))
			{
				directory.AddError("XMP data segment doesn't begin with 'http://ns.adobe.com/xap/1.0/'");
				return;
			}
			sbyte[] xmlBytes = new sbyte[segmentBytes.Length - preambleLength];
			System.Array.Copy(segmentBytes, 29, xmlBytes, 0, xmlBytes.Length);
			Extract(xmlBytes, metadata);
		}
		public virtual sbyte[] GetSegment(JpegSegmentType segmentType)
		{
			return GetSegment(segmentType.byteValue, 0);
		}
		/// <summary>Determines whether data is present for a given segment type.</summary>
		/// <param name="segmentType">identifies the required segment</param>
		/// <returns>true if data exists, otherwise false</returns>
		public virtual bool ContainsSegment(JpegSegmentType segmentType)
		{
			return ContainsSegment(segmentType.byteValue);
		}
		/// <summary>Removes all segments from the collection having the specified type.</summary>
		/// <param name="segmentType">identifies the required segment</param>
		public virtual void RemoveSegment(JpegSegmentType segmentType)
		{
			RemoveSegment(segmentType.byteValue);
		}
 /// <summary>Returns the count of segment data byte arrays stored for a given segment type.</summary>
 /// <param name="segmentType">identifies the required segment</param>
 /// <returns>the segment count (zero if no segments exist).</returns>
 public virtual int GetSegmentCount([NotNull] JpegSegmentType segmentType)
 {
     return(GetSegmentCount(segmentType.byteValue));
 }
示例#18
0
		public virtual bool CanProcess(sbyte[] segmentBytes, JpegSegmentType segmentType)
		{
			return segmentBytes.Length > 10 && Sharpen.Runtime.EqualsIgnoreCase("ICC_PROFILE", Sharpen.Runtime.GetStringForBytes(segmentBytes, 0, 11));
		}
 /// <summary>Removes a specified instance of a segment's data from the collection.</summary>
 /// <remarks>
 /// Removes a specified instance of a segment's data from the collection.  Use this method when more than one
 /// occurrence of segment data exists for a given type exists.
 /// </remarks>
 /// <param name="segmentType">identifies the required segment</param>
 /// <param name="occurrence">the zero-based index of the segment occurrence to remove.</param>
 public virtual void RemoveSegmentOccurrence([NotNull] JpegSegmentType segmentType, int occurrence)
 {
     RemoveSegmentOccurrence(segmentType.byteValue, occurrence);
 }
示例#20
0
		//            JpegSegmentType.SOF4,
		//            JpegSegmentType.SOF12,
		public virtual bool CanProcess(sbyte[] segmentBytes, JpegSegmentType segmentType)
		{
			return true;
		}
 /// <summary>Determines whether data is present for a given segment type.</summary>
 /// <param name="segmentType">identifies the required segment</param>
 /// <returns>true if data exists, otherwise false</returns>
 public virtual bool ContainsSegment([NotNull] JpegSegmentType segmentType)
 {
     return(ContainsSegment(segmentType.byteValue));
 }
示例#22
0
		public virtual bool CanProcess(sbyte[] segmentBytes, JpegSegmentType segmentType)
		{
			return segmentBytes.Length >= JpegExifSegmentPreamble.Length && Sharpen.Runtime.EqualsIgnoreCase(Sharpen.Runtime.GetStringForBytes(segmentBytes, 0, JpegExifSegmentPreamble.Length), JpegExifSegmentPreamble);
		}
 public virtual sbyte[] GetSegment([NotNull] JpegSegmentType segmentType)
 {
     return(GetSegment(segmentType.byteValue, 0));
 }
		/// <summary>Returns the count of segment data byte arrays stored for a given segment type.</summary>
		/// <param name="segmentType">identifies the required segment</param>
		/// <returns>the segment count (zero if no segments exist).</returns>
		public virtual int GetSegmentCount(JpegSegmentType segmentType)
		{
			return GetSegmentCount(segmentType.byteValue);
		}
示例#25
0
		public virtual bool CanProcess(sbyte[] segmentBytes, JpegSegmentType segmentType)
		{
			return segmentBytes.Length > 3 && "JFIF".Equals(Sharpen.Runtime.GetStringForBytes(segmentBytes, 0, 4));
		}
		public virtual bool CanProcess(sbyte[] segmentBytes, JpegSegmentType segmentType)
		{
			// The entire contents of the byte[] is the comment. There's nothing here to discriminate upon.
			return true;
		}
示例#27
0
		public virtual void Extract(sbyte[] segmentBytes, Com.Drew.Metadata.Metadata metadata, JpegSegmentType segmentType)
		{
			if (segmentBytes == null)
			{
				throw new ArgumentNullException("segmentBytes cannot be null");
			}
			if (metadata == null)
			{
				throw new ArgumentNullException("metadata cannot be null");
			}
			if (segmentType == null)
			{
				throw new ArgumentNullException("segmentType cannot be null");
			}
			try
			{
				ByteArrayReader reader = new ByteArrayReader(segmentBytes);
				//
				// Check for the header preamble
				//
				try
				{
					if (!reader.GetString(0, JpegExifSegmentPreamble.Length).Equals(JpegExifSegmentPreamble))
					{
						// TODO what do to with this error state?
						System.Console.Error.Println("Invalid JPEG Exif segment preamble");
						return;
					}
				}
				catch (IOException e)
				{
					// TODO what do to with this error state?
					Sharpen.Runtime.PrintStackTrace(e, System.Console.Error);
					return;
				}
				//
				// Read the TIFF-formatted Exif data
				//
				new TiffReader().ProcessTiff(reader, new ExifTiffHandler(metadata, _storeThumbnailBytes), JpegExifSegmentPreamble.Length);
			}
			catch (TiffProcessingException e)
			{
				// TODO what do to with this error state?
				Sharpen.Runtime.PrintStackTrace(e, System.Console.Error);
			}
			catch (IOException e)
			{
				// TODO what do to with this error state?
				Sharpen.Runtime.PrintStackTrace(e, System.Console.Error);
			}
		}
		public virtual void Extract(sbyte[] segmentBytes, Com.Drew.Metadata.Metadata metadata, JpegSegmentType segmentType)
		{
			JpegCommentDirectory directory = metadata.GetOrCreateDirectory<JpegCommentDirectory>();
			// The entire contents of the directory are the comment
			directory.SetString(JpegCommentDirectory.TagComment, Sharpen.Runtime.GetStringForBytes(segmentBytes));
		}
		public virtual void Extract(sbyte[] segmentBytes, Com.Drew.Metadata.Metadata metadata, JpegSegmentType segmentType)
		{
			Extract(new ByteArrayReader(segmentBytes), metadata);
		}
		public virtual sbyte[] GetSegment(JpegSegmentType segmentType, int occurrence)
		{
			return GetSegment(segmentType.byteValue, occurrence);
		}