Example #1
0
 /**
  * Process the raw data from a binary stream
  * 
  * @return  void
  */
 public function processData(Woops_Tiff_Binary_Stream $stream)
 {
     // Gets the TIFF byte order
     $byteOrder = $stream->read(2);
     // Checks the TIFF byte order
     if ($byteOrder === 'II') {
         // Byte order is little endian
         $this->_isBigEndian = false;
     } elseif ($byteOrder === 'MM') {
         // Byte order is big endian
         $this->_isBigEndian = true;
     } else {
         // Error - Invalid byte order
         throw new Woops_Tiff_Header_Exception('Invalid TIFF file signature (' . $byteOrder . ')', Woops_Tiff_Header_Exception::EXCEPTION_BAD_SIGNATURE);
     }
     // Gets the TIFF signature
     $signature = $this->_isBigEndian ? $stream->bigEndianUnsignedShort() : $stream->littleEndianUnsignedShort();
     // Checks the TIFF signature
     if ($signature !== 0x2a) {
         // Error - Invalid TIFF signature
         throw new Woops_Tiff_Header_Exception('Invalid TIFF file signature (' . $signature . ')', Woops_Tiff_Header_Exception::EXCEPTION_BAD_SIGNATURE);
     }
     // Gets the IFD offset
     $this->_offset = $this->_isBigEndian ? $stream->bigEndianUnsignedLong() : $stream->littleEndianUnsignedLong();
 }
Example #2
0
 /**
  * Class constructor
  * 
  * @param   resource    The file handle for which to create a binary stream
  * @param   boolean     Whether to close the file handle or not
  * @return  void
  * @see     Woops_Tiff_Binary_Stream::__construct
  */
 public function __construct($handle, $closeHandle = true)
 {
     // Checks if the file exists
     if (!is_resource($handle)) {
         // Error - The file does not exist
         throw new Woops_Tiff_Binary_File_Resource_Stream_Exception('Passed argument must be a valid file handle', Woops_Tiff_Binary_File_Resource_Stream_Exception::EXCEPTION_NO_RESOURCE);
     }
     // Storage
     $data = '';
     // Reads until the end of the file handle
     while (!feof($handle)) {
         // Reads from the file handle
         $data .= fread($handle, 8192);
     }
     // Checks if we must close the file handle
     if ($closeHandle) {
         // Closes the file handle
         fclose($handle);
     }
     // Calls the parent constructor
     parent::__construct($data);
 }
Example #3
0
 /**
  * Process the raw data from a binary stream
  * 
  * @param   Woops_Tiff_Binary_Stream    The binary stream
  * @return  void
  * @throws  Woops_Tiff_Tag_Exception    If the value type is invalid
  */
 public function processData(Woops_Tiff_Binary_Stream $stream)
 {
     // Resets the value array
     $this->_values = array();
     // Gets the value type
     $this->_valueType = $this->_header->isBigEndian() ? $stream->bigEndianUnsignedShort() : $stream->littleEndianUnsignedShort();
     // Checks the value type
     if (!isset(self::$_types[$this->_valueType])) {
         // Error - Invalid value type
         throw new Woops_Tiff_Tag_Exception('Invalid value type (' . $this->_valueType . ')', Woops_Tiff_Tag_Exception::EXCEPTION_INVALID_VALUE_TYPE);
     }
     // Gets the number of values
     $valueCount = $this->_header->isBigEndian() ? $stream->bigEndianUnsignedLong() : $stream->littleEndianUnsignedLong();
     // Number of bytes to read for the value
     $readBytes = $valueCount * self::$_types[$this->_valueType];
     // Gets the current offset, so we can rewind the stream
     $offset = $stream->getOffset();
     // Checks if the value can be contained in the tag
     if ($readBytes > 4) {
         // Gets the value offset
         $valueOffset = $this->_header->isBigEndian() ? $stream->bigEndianUnsignedLong() : $stream->littleEndianUnsignedLong();
         // Moves to the value offset
         $stream->seek($valueOffset, Woops_Tiff_Binary_Stream::SEEK_SET);
         // Reads the value(s)
         $this->_readValuesFromStream($stream, $valueCount);
         // Moves the stream to the end of the value offset
         $stream->seek($offset + 4, Woops_Tiff_Binary_Stream::SEEK_SET);
     } else {
         // Reads the value(s)
         $this->_readValuesFromStream($stream, $valueCount);
         // Moves the stream to the end of the value
         $stream->seek($offset + 4, Woops_Tiff_Binary_Stream::SEEK_SET);
     }
 }
Example #4
0
 /**
  * Process the raw data from a binary stream
  * 
  * @return  void
  */
 public function processData(Woops_Tiff_Binary_Stream $stream)
 {
     // Resets the tag array
     $this->_tags = array();
     // Gets the number of directory entries
     $entries = $this->_header->isBigEndian() ? $stream->bigEndianUnsignedShort() : $stream->littleEndianUnsignedShort();
     // Process each directory entry
     for ($i = 0; $i < $entries; $i++) {
         // Gets the tag type
         $type = $this->_header->isBigEndian() ? $stream->bigEndianUnsignedShort() : $stream->littleEndianUnsignedShort();
         // Prevents unknown TIFF tags to create an exceprion
         try {
             // Creates a new tag
             $tag = $this->newTag($type);
         } catch (Woops_Tiff_Ifd_Exception $e) {
             // Checks if the exception was made for an unknown TIFF tag
             if ($e->getCode() !== Woops_Tiff_Ifd_Exception::EXCEPTION_INVALID_TAG_TYPE) {
                 // No - Throws the exception again
                 throw $e;
             }
             // Creates an unknown tag object, and adds it
             $tag = new Woops_Tiff_UnknownTag($this->_file, $type);
             $this->addTag($tag);
         }
         // Process the tag data
         $tag->processData($stream);
         // Support for the EXIF IFD pointer tags
         if ($type === self::TAG_EXIF_IFD_POINTER || $type === self::TAG_EXIF_GPS_IFD_POINTER || $type === self::TAG_EXIF_INTEROPERABILITY_IFD_POINTER) {
             // Stores the current offset
             $offset = $stream->getOffset();
             // Gets the IFD offset
             $ifdOffset = $tag->getValue();
             // Moves to the IFD offset
             $stream->seek($ifdOffset, Woops_Tiff_Binary_Stream::SEEK_SET);
             // Exif IFD classname
             $classname = $type === self::TAG_EXIF_IFD_POINTER ? 'Woops_Exif_Tiff_Ifd' : ($type === self::TAG_EXIF_GPS_IFD_POINTER ? 'Woops_Exif_Tiff_Gps_Ifd' : 'Woops_Exif_Tiff_Interoperability_Ifd');
             // Creates the EXIF IFD
             $ifd = $this->_file->newIfd($classname);
             // Process the IFD data
             $ifd->processData($stream);
             // Rewinds the stream
             $stream->seek($offset, Woops_Tiff_Binary_Stream::SEEK_SET);
         }
     }
     // Gets the offset of the next IFD
     $this->_offset = $this->_header->isBigEndian() ? $stream->bigEndianUnsignedLong() : $stream->littleEndianUnsignedLong();
 }
Example #5
0
 /**
  * Process the raw data from a binary stream
  * 
  * @return  void
  */
 public function processData(Woops_Tiff_Binary_Stream $stream)
 {
     // Resets the tag array
     $this->_tags = array();
     // Gets the number of directory entries
     $entries = $this->_header->isBigEndian() ? $stream->bigEndianUnsignedShort() : $stream->littleEndianUnsignedShort();
     // Process each directory entry
     for ($i = 0; $i < $entries; $i++) {
         // Gets the tag type
         $type = $this->_header->isBigEndian() ? $stream->bigEndianUnsignedShort() : $stream->littleEndianUnsignedShort();
         // Prevents unknown TIFF tags to create an exceprion
         try {
             // Creates a new tag
             $tag = $this->newTag($type);
         } catch (Woops_Exif_Tiff_Interoperability_Ifd_Exception $e) {
             // Checks if the exception was made for an unknown TIFF tag
             if ($e->getCode() !== Woops_Exif_Tiff_Interoperability_Ifd_Exception::EXCEPTION_INVALID_TAG_TYPE) {
                 // No - Throws the exception again
                 throw $e;
             }
             // Creates an unknown tag object, and adds it
             $tag = new Woops_Exif_Tiff_Interoperability_UnknownTag($this->_file, $type);
             $this->addTag($tag);
         }
         // Process the tag data
         $tag->processData($stream);
     }
     // Gets the offset of the next IFD
     $this->_offset = $this->_header->isBigEndian() ? $stream->bigEndianUnsignedLong() : $stream->littleEndianUnsignedLong();
 }