/** * Test data to see if it could be a valid JPEG image. * * The function will only look at the first few bytes of the data, * and try to determine if it could be a valid JPEG image based on * those bytes. This means that the check is more like a heuristic * than a rigorous check. * * @param PelDataWindow the bytes that will be checked. * * @return boolean true if the bytes look like the beginning of a * JPEG image, false otherwise. * * @see PelTiff::isValid() */ static function isValid(PelDataWindow $d) { /* JPEG data is stored in big-endian format. */ $d->setByteOrder(PelConvert::BIG_ENDIAN); for ($i = 0; $i < 7; $i++) { if ($d->getByte($i) != 0xff) { break; } } return $d->getByte($i) == PelJpegMarker::SOI; }
/** * 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; }
function testReadBigIntegers() { $window = new PelDataWindow("‰«Íï", PelConvert::BIG_ENDIAN); $this->assertEqual($window->getSize(), 4); $this->assertEqual($window->getBytes(), "‰«Íï"); $this->assertEqual($window->getByte(0), 0x89); $this->assertEqual($window->getByte(1), 0xab); $this->assertEqual($window->getByte(2), 0xcd); $this->assertEqual($window->getByte(3), 0xef); $this->assertEqual($window->getShort(0), 0x89ab); $this->assertEqual($window->getShort(1), 0xabcd); $this->assertEqual($window->getShort(2), 0xcdef); $this->assertEqual($window->getLong(0), 0x89abcdef); $window->setByteOrder(PelConvert::LITTLE_ENDIAN); $this->assertEqual($window->getSize(), 4); $this->assertEqual($window->getBytes(), "‰«Íï"); $this->assertEqual($window->getByte(0), 0x89); $this->assertEqual($window->getByte(1), 0xab); $this->assertEqual($window->getByte(2), 0xcd); $this->assertEqual($window->getByte(3), 0xef); $this->assertEqual($window->getShort(0), 0xab89); $this->assertEqual($window->getShort(1), 0xcdab); $this->assertEqual($window->getShort(2), 0xefcd); $this->assertEqual($window->getLong(0), 0xefcdab89); }