Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
  • Loading branch information
mondrake committed Jan 25, 2024
1 parent 18f9850 commit 14d45da
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 28 deletions.
4 changes: 2 additions & 2 deletions specs/Tiff/Ifd0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ alias:
- '0'
- Main
postParse:
- 'FileEye\MediaProbe\Block\Tiff\Ifd::thumbnailToBlock'
- 'FileEye\MediaProbe\Block\Tiff\Ifd::makerNoteToBlock'
- 'FileEye\MediaProbe\Parser\Tiff\Ifd::thumbnailToBlock'
- 'FileEye\MediaProbe\Parser\Tiff\Ifd::makerNoteToBlock'
compiler:
exiftool:
g1: IFD0
Expand Down
2 changes: 1 addition & 1 deletion specs/Tiff/Ifd1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ alias:
- '1'
- Thumbnail
postParse:
- 'FileEye\MediaProbe\Block\Tiff\Ifd::thumbnailToBlock'
- 'FileEye\MediaProbe\Parser\Tiff\Ifd::thumbnailToBlock'
compiler:
exiftool:
g1: IFD1
Expand Down
2 changes: 2 additions & 0 deletions src/Collection/Jpeg/Exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Exif extends CollectionBase {
protected static $map = array (
'title' => 'JPEG Exif data',
'class' => 'FileEye\\MediaProbe\\Block\\Jpeg\\Exif',
'parser' => 'FileEye\\MediaProbe\\Parser\\Jpeg\\Exif',
'writer' => 'FileEye\\MediaProbe\\Writer\\Jpeg\\Exif',
'DOMNode' => 'exif',
'id' => 'Jpeg\\Exif',
'items' =>
Expand Down
2 changes: 2 additions & 0 deletions src/Collection/Jpeg/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Segment extends CollectionBase {
protected static $map = array (
'title' => 'Generic JPEG data segment',
'class' => 'FileEye\\MediaProbe\\Block\\Jpeg\\Segment',
'parser' => 'FileEye\\MediaProbe\\Parser\\Jpeg\\Segment',
'writer' => 'FileEye\\MediaProbe\\Writer\\Jpeg\\Segment',
'DOMNode' => 'jpegSegment',
'id' => 'Jpeg\\Segment',
);
Expand Down
2 changes: 2 additions & 0 deletions src/Collection/Jpeg/SegmentApp1.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class SegmentApp1 extends CollectionBase {
'title' => 'JPEG Application segment 1',
'payload' => 'variable',
'class' => 'FileEye\\MediaProbe\\Block\\Jpeg\\SegmentApp1',
'parser' => 'FileEye\\MediaProbe\\Parser\\Jpeg\\SegmentApp1',
'writer' => 'FileEye\\MediaProbe\\Writer\\Jpeg\\SegmentApp1',
'DOMNode' => 'jpegSegment',
'id' => 'Jpeg\\SegmentApp1',
'items' =>
Expand Down
2 changes: 2 additions & 0 deletions src/Collection/Jpeg/SegmentCom.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class SegmentCom extends CollectionBase {
'title' => 'JPEG Comment',
'payload' => 'variable',
'class' => 'FileEye\\MediaProbe\\Block\\Jpeg\\SegmentCom',
'parser' => 'FileEye\\MediaProbe\\Parser\\Jpeg\\SegmentCom',
'writer' => 'FileEye\\MediaProbe\\Writer\\Jpeg\\SegmentCom',
'DOMNode' => 'jpegSegment',
'id' => 'Jpeg\\SegmentCom',
);
Expand Down
6 changes: 4 additions & 2 deletions src/Collection/Tiff/Ifd0.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Ifd0 extends CollectionBase {
'name' => 'IFD0',
'title' => 'IFD0',
'class' => 'FileEye\\MediaProbe\\Block\\Tiff\\Ifd',
'parser' => 'FileEye\\MediaProbe\\Parser\\Tiff\\Ifd',
'writer' => 'FileEye\\MediaProbe\\Writer\\Tiff\\Ifd',
'DOMNode' => 'ifd',
'defaultItemCollection' => 'Tiff\\Tag',
'alias' =>
Expand All @@ -25,8 +27,8 @@ class Ifd0 extends CollectionBase {
),
'postParse' =>
array (
0 => 'FileEye\\MediaProbe\\Block\\Tiff\\Ifd::thumbnailToBlock',
1 => 'FileEye\\MediaProbe\\Block\\Tiff\\Ifd::makerNoteToBlock',
0 => 'FileEye\\MediaProbe\\Parser\\Tiff\\Ifd::thumbnailToBlock',
1 => 'FileEye\\MediaProbe\\Parser\\Tiff\\Ifd::makerNoteToBlock',
),
'id' => 'Tiff\\Ifd0',
'itemsByName' =>
Expand Down
4 changes: 3 additions & 1 deletion src/Collection/Tiff/Ifd1.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class Ifd1 extends CollectionBase {
'name' => 'IFD1',
'title' => 'IFD1',
'class' => 'FileEye\\MediaProbe\\Block\\Tiff\\Ifd',
'parser' => 'FileEye\\MediaProbe\\Parser\\Tiff\\Ifd',
'writer' => 'FileEye\\MediaProbe\\Writer\\Tiff\\Ifd',
'DOMNode' => 'ifd',
'defaultItemCollection' => 'Tiff\\Tag',
'alias' =>
Expand All @@ -25,7 +27,7 @@ class Ifd1 extends CollectionBase {
),
'postParse' =>
array (
0 => 'FileEye\\MediaProbe\\Block\\Tiff\\Ifd::thumbnailToBlock',
0 => 'FileEye\\MediaProbe\\Parser\\Tiff\\Ifd::thumbnailToBlock',
),
'id' => 'Tiff\\Ifd1',
'itemsByName' =>
Expand Down
2 changes: 2 additions & 0 deletions src/Collection/Tiff/IfdAny.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class IfdAny extends CollectionBase {
protected static $map = array (
'title' => 'A catchall generic IFD definition, used as a fallback to describe tags that are not expected in a specific IFD.',
'class' => 'FileEye\\MediaProbe\\Block\\Tiff\\Ifd',
'parser' => 'FileEye\\MediaProbe\\Parser\\Tiff\\Ifd',
'writer' => 'FileEye\\MediaProbe\\Writer\\Tiff\\Ifd',
'defaultItemCollection' => 'Tiff\\Tag',
'id' => 'Tiff\\IfdAny',
'itemsByName' =>
Expand Down
2 changes: 2 additions & 0 deletions src/Collection/Tiff/IfdExif.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class IfdExif extends CollectionBase {
'name' => 'ExifIFD',
'title' => 'Exif IFD',
'class' => 'FileEye\\MediaProbe\\Block\\Tiff\\Ifd',
'parser' => 'FileEye\\MediaProbe\\Parser\\Tiff\\Ifd',
'writer' => 'FileEye\\MediaProbe\\Writer\\Tiff\\Ifd',
'DOMNode' => 'ifd',
'defaultItemCollection' => 'Tiff\\Tag',
'id' => 'Tiff\\IfdExif',
Expand Down
2 changes: 2 additions & 0 deletions src/Collection/Tiff/IfdGps.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class IfdGps extends CollectionBase {
'name' => 'GPS',
'title' => 'GPS IFD',
'class' => 'FileEye\\MediaProbe\\Block\\Tiff\\Ifd',
'parser' => 'FileEye\\MediaProbe\\Parser\\Tiff\\Ifd',
'writer' => 'FileEye\\MediaProbe\\Writer\\Tiff\\Ifd',
'DOMNode' => 'ifd',
'defaultItemCollection' => 'Tiff\\Tag',
'id' => 'Tiff\\IfdGps',
Expand Down
2 changes: 2 additions & 0 deletions src/Collection/Tiff/IfdInteroperability.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class IfdInteroperability extends CollectionBase {
'name' => 'InteropIFD',
'title' => 'Interoperability IFD',
'class' => 'FileEye\\MediaProbe\\Block\\Tiff\\Ifd',
'parser' => 'FileEye\\MediaProbe\\Parser\\Tiff\\Ifd',
'writer' => 'FileEye\\MediaProbe\\Writer\\Tiff\\Ifd',
'DOMNode' => 'ifd',
'alias' =>
array (
Expand Down
5 changes: 1 addition & 4 deletions src/Model/BlockBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ public function parseData(DataElement $dataElement, int $start = 0, ?int $size =
}

/**
* Invoke post-parse callbacks.
*
* @param \FileEye\MediaProbe\Data\DataElement $dataElement
* @todo
* @deprecated
*/
protected function executePostParseCallbacks(DataElement $dataElement): static
{
Expand Down
5 changes: 5 additions & 0 deletions src/Model/ElementBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ public function isValid(): bool
return $this->valid;
}

public function setValid(bool $valid): void
{
$this->valid = $valid;
}

/**
* @todo
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Parser/ParserBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,20 @@ public function __construct(
}

abstract public function parseData(DataElement $data): void;

/**
* Invoke post-parse callbacks.
*
* @param \FileEye\MediaProbe\Data\DataElement $dataElement
* @todo
*/
protected function executePostParseCallbacks(DataElement $dataElement): void
{
$post_load_callbacks = $this->block->getCollection()->getPropertyValue('postParse');
if (!empty($post_load_callbacks)) {
foreach ($post_load_callbacks as $callback) {
call_user_func($callback, $dataElement, $this->block);
}
}
}
}
39 changes: 21 additions & 18 deletions src/Parser/Tiff/Ifd.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace FileEye\MediaProbe\Parser\Tiff;

use FileEye\MediaProbe\Block\Jpeg\Jpeg as JpegBlock;
use FileEye\MediaProbe\Block\Tiff\Ifd as IfdBlock;
use FileEye\MediaProbe\Block\Tiff\Tiff as TiffBlock;
use FileEye\MediaProbe\Collection\CollectionFactory;
use FileEye\MediaProbe\Data\DataElement;
use FileEye\MediaProbe\Data\DataException;
use FileEye\MediaProbe\Data\DataFormat;
use FileEye\MediaProbe\Data\DataWindow;
use FileEye\MediaProbe\ItemDefinition;
use FileEye\MediaProbe\Parser\ParserBase;
use FileEye\MediaProbe\Utility\ConvertBytes;
Expand All @@ -16,13 +19,13 @@
*/
class Ifd extends ParserBase
{
public function parseData(DataElement $data, int $start = 0, ?int $size = null, $xxx = 0): void
public function parseData(DataElement $dataElement, int $start = 0, ?int $size = null, $xxx = 0): void
{
$offset = $this->getDefinition()->getDataOffset();
$offset = $this->block->getDefinition()->getDataOffset();

// Get the number of entries.
$n = $this->getItemsCountFromData($dataElement, $offset);
assert($this->debugInfo(['dataElement' => $dataElement, 'itemsCount' => $n]));
assert($this->block->debugInfo(['dataElement' => $dataElement, 'itemsCount' => $n]));

// Parse the items.
for ($i = 0; $i < $n; $i++) {
Expand All @@ -32,16 +35,16 @@ public function parseData(DataElement $data, int $start = 0, ?int $size = null,

// Check data is accessible, warn otherwise.
if ($item_definition->getDataOffset() >= $dataElement->getSize()) {
$this->warning(
$this->block->warning(
'Could not access value for item {item} in \'{ifd}\', overflow',
[
'item' => MediaProbe::dumpIntHex($item_definition->getCollection()->getPropertyValue('name') ?? 'n/a'),
'ifd' => $this->getAttribute('name'),
'ifd' => $this->block->getAttribute('name'),
]
);
continue;
}
/* $this->debug(
/* $this->debug(
'Item Offset {o} Components {c} Format {f} Formatsize {fs} Size {s} DataElement Size {des}', [
'o' => MediaProbe::dumpIntHex($dataElement->getAbsoluteOffset($item_definition->getDataOffset())),
'c' => $item_definition->getValuesCount(),
Expand All @@ -52,18 +55,18 @@ public function parseData(DataElement $data, int $start = 0, ?int $size = null,
]
);*/
if ($item_definition->getDataOffset() + $item_definition->getSize() > $dataElement->getSize()) {
$this->warning(
$this->block->warning(
'Could not get value for item {item} in \'{ifd}\', not enough data',
[
'item' => MediaProbe::dumpIntHex($item_definition->getCollection()->getPropertyValue('name') ?? 'n/a'),
'ifd' => $this->getAttribute('name'),
'ifd' => $this->block->getAttribute('name'),
]
);
continue;
}

// Adds the item to the DOM.
$item = new $item_class($item_definition, $this);
$item = new $item_class($item_definition, $this->block);
try {
if (is_a($item_class, Ifd::class, true)) {
$item->parseData($dataElement);
Expand All @@ -76,7 +79,7 @@ public function parseData(DataElement $data, int $start = 0, ?int $size = null,
}
} catch (DataException $e) {
$item->error($e->getMessage());
$item->valid = false;
$item->setValid(false);
}
}

Expand Down Expand Up @@ -106,8 +109,8 @@ protected function getItemsCountFromData(DataElement $dataElement, $offset): int
// Check if we have enough data.
if (2 + 12 * $entries_count > $dataElement->getSize()) {
$entries_count = floor(($offset - $dataElement->getSize()) / 12);
$this->warning('Wrong number of IFD entries in ifd {ifdname}, adjusted to {tags}', [
'ifdname' => $this->getAttribute('name'),
$this->block->warning('Wrong number of IFD entries in ifd {ifdname}, adjusted to {tags}', [
'ifdname' => $this->block->getAttribute('name'),
'tags' => $entries_count,
]);
}
Expand Down Expand Up @@ -141,15 +144,15 @@ protected function getItemDefinitionFromData(int $seq, DataElement $dataElement,
// Fall back to the generic IFD collection if the item is missing from
// the appropriate one.
try {
$item_collection = $this->getCollection()->getItemCollection($id);
$item_collection = $this->block->getCollection()->getItemCollection($id);
} catch (MediaProbeException $e) {
if ($fallback_collection_id !== null) {
$item_collection = CollectionFactory::get($fallback_collection_id)->getItemCollection($id, 0, 'Tiff\UnknownTag', [
'item' => $id,
'DOMNode' => 'tag',
]);
} else {
$item_collection = $this->getCollection()->getItemCollection($id, 0, 'Tiff\UnknownTag', [
$item_collection = $this->block->getCollection()->getItemCollection($id, 0, 'Tiff\UnknownTag', [
'item' => $id,
'DOMNode' => 'tag',
]);
Expand Down Expand Up @@ -188,7 +191,7 @@ protected function getItemDefinitionFromData(int $seq, DataElement $dataElement,
* the data from which the thumbnail will be
* extracted.
*/
public static function thumbnailToBlock(DataElement $dataElement, Ifd $ifd): void
public static function thumbnailToBlock(DataElement $dataElement, IfdBlock $ifd): void
{
if (!$ifd->getElement("tag[@name='ThumbnailOffset']") || !$ifd->getElement("tag[@name='ThumbnailLength']")) {
return;
Expand Down Expand Up @@ -220,7 +223,7 @@ public static function thumbnailToBlock(DataElement $dataElement, Ifd $ifd): voi
'offset' => $offset,
'size' => $dataElement->getSize(),
]);
$ifd->valid = false;
$ifd->setValid(false);
return;
}

Expand All @@ -241,7 +244,7 @@ public static function thumbnailToBlock(DataElement $dataElement, Ifd $ifd): voi
$size = $dataxx->getSize();

// Now move backwards until we find the EOI JPEG marker.
while ($dataxx->getByte($size - 2) !== Jpeg::JPEG_DELIMITER || $dataxx->getByte($size - 1) != CollectionFactory::get('Jpeg\Jpeg')->getItemCollectionByName('EOI')->getPropertyValue('item')) {
while ($dataxx->getByte($size - 2) !== JpegBlock::JPEG_DELIMITER || $dataxx->getByte($size - 1) != CollectionFactory::get('Jpeg\Jpeg')->getItemCollectionByName('EOI')->getPropertyValue('item')) {
$size --;
}
if ($size != $dataxx->getSize()) {
Expand All @@ -267,7 +270,7 @@ public static function thumbnailToBlock(DataElement $dataElement, Ifd $ifd): voi
* @param Ifd $ifd
* the root Ifd object.
*/
public static function makerNoteToBlock(DataElement $d, Ifd $ifd): void
public static function makerNoteToBlock(DataElement $d, IfdBlock $ifd): void
{
// Get the Exif subIfd if existing.
if (!$exif_ifd = $ifd->getElement("ifd[@name='ExifIFD']")) {
Expand Down

0 comments on commit 14d45da

Please sign in to comment.