/** * 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(); }
/** * 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); } }