Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Removed duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
lsolesen committed Mar 21, 2016
1 parent 013e946 commit 328ca1c
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/PelJpeg.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,23 @@ public function __construct($data = false)
}
}

/**
* JPEG sections start with 0xFF. The first byte that is not
* 0xFF is a marker (hopefully).
*
* @param PelDataWindow $d
*
* @return integer
*/
protected static function getJpgSectionStart($d) {
for ($i = 0; $i < 7; $i ++) {
if ($d->getByte($i) != 0xFF) {
break;
}
}
return $i;
}

/**
* Load data into a JPEG object.
*
Expand Down Expand Up @@ -179,19 +196,11 @@ public function load(PelDataWindow $d)
* no data left in the window.
*/
while ($d->getSize() > 0) {
/*
* JPEG sections start with 0xFF. The first byte that is not
* 0xFF is a marker (hopefully).
*/
for ($i = 0; $i < 7; $i ++) {
if ($d->getByte($i) != 0xFF) {
break;
}
}
$i = $this->getJpgSectionStart($d);

$marker = $d->getByte($i);

if (! PelJpegMarker::isValid($marker)) {
if (!PelJpegMarker::isValid($marker)) {
throw new \lsolesen\pel\PelJpegInvalidMarkerException($marker, $i);
}

Expand Down Expand Up @@ -655,11 +664,7 @@ public 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;
}
}
$i = self::getJpgSectionStart($d);

return $d->getByte($i) == PelJpegMarker::SOI;
}
Expand Down

0 comments on commit 328ca1c

Please sign in to comment.