Example #1
0
 /**
  * Check if data is valid TIFF data.
  *
  * This will read just enough data from the data window to determine
  * if the data could be a valid TIFF data. This means that the
  * check is more like a heuristic than a rigorous check.
  *
  * @param PelDataWindow $d
  *            the bytes that will be examined.
  *
  * @return boolean true if the data looks like valid TIFF data,
  *         false otherwise.
  *
  * @see PelJpeg::isValid()
  */
 public static function isValid(PelDataWindow $d)
 {
     /* First check that we have enough data. */
     if ($d->getSize() < 8) {
         return false;
     }
     /* Byte order */
     if ($d->strcmp(0, 'II')) {
         $d->setByteOrder(PelConvert::LITTLE_ENDIAN);
     } elseif ($d->strcmp(0, 'MM')) {
         Pel::debug('Found Motorola byte order');
         $d->setByteOrder(PelConvert::BIG_ENDIAN);
     } else {
         return false;
     }
     /* Verify the TIFF header */
     return $d->getShort(2) == self::TIFF_HEADER;
 }
Example #2
0
 /**
  * Load and parse Exif data.
  *
  * This will populate the object with Exif data, contained as a
  * {@link PelTiff} object. This TIFF object can be accessed with
  * the {@link getTiff()} method.
  *
  * @param PelDataWindow $d
  */
 public function load(PelDataWindow $d)
 {
     Pel::debug('Parsing %d bytes of Exif data...', $d->getSize());
     /* There must be at least 6 bytes for the Exif header. */
     if ($d->getSize() < 6) {
         throw new PelInvalidDataException('Expected at least 6 bytes of Exif ' . 'data, found just %d bytes.', $d->getSize());
     }
     /* Verify the Exif header */
     if ($d->strcmp(0, self::EXIF_HEADER)) {
         $d->setWindowStart(strlen(self::EXIF_HEADER));
     } else {
         throw new PelInvalidDataException('Exif header not found.');
     }
     /* The rest of the data is TIFF data. */
     $this->tiff = new PelTiff();
     $this->tiff->load($d);
 }