Skip to content

Commit

Permalink
Merge up (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondrake authored Jan 20, 2024
1 parent 111b4ed commit 8afb74f
Show file tree
Hide file tree
Showing 38 changed files with 329 additions and 321 deletions.
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@
"homepage": "https://github.com/FileEye/MediaProbe",
"license": "GPL-3.0",
"require": {
"php": ">=7.4",
"php": ">=8.1",
"ext-gd": "*",
"ext-mbstring": "*",
"composer-runtime-api": "^2.0.0",
"psr/log": "*",
"monolog/monolog": "^3",
"shanethehat/pretty-xml": "*",
"sibche/plist": "*",
"symfony/stopwatch": "^6"
"symfony/stopwatch": "^6 | ^7"
},
"require-dev" : {
"ext-exif": "*",
"phpunit/phpunit": "^9",
"phpunit/phpunit": "^10",
"squizlabs/php_codesniffer": "*",
"symfony/console": "^6",
"symfony/finder": "^6",
"symfony/filesystem": "^6",
"symfony/process": "^6",
"symfony/var-dumper": "^6",
"symfony/yaml": "^6",
"symfony/console": "^6 | ^7",
"symfony/finder": "^6 | ^7",
"symfony/filesystem": "^6 | ^7",
"symfony/process": "^6 | ^7",
"symfony/var-dumper": "^6 | ^7",
"symfony/yaml": "^6 | ^7",
"bramus/monolog-colored-line-formatter": "^3"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion specs/ExifMakerNotes/Canon/FilterInfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ collection: ExifMakerNotes\Canon\FilterInfo
name: CanonFilterInfo
title: 'Canon FilterInfo'
class: FileEye\MediaProbe\Block\Exif\Vendor\Canon\FilterInfoIndex
DOMNode: index
DOMNode: filterInfo
defaultItemCollection: Tag
compiler:
exiftool:
Expand Down
1 change: 1 addition & 0 deletions src/Block/Exif/Exif.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Exif extends BlockBase
*/
protected function doParseData(DataElement $data): void
{
assert($this->debugInfo(['dataElement' => $data]));
if (Tiff::getTiffSegmentByteOrder($data, strlen(self::EXIF_HEADER)) !== null) {
$tiff = new ItemDefinition(CollectionFactory::get('Tiff\Tiff'));
$this->addBlock($tiff)->parseData($data, strlen(self::EXIF_HEADER), $data->getSize() - strlen(self::EXIF_HEADER));
Expand Down
12 changes: 9 additions & 3 deletions src/Block/Exif/Ifd.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public function parseData(DataElement $data_element, int $start = 0, ?int $size
$this->executePostParseCallbacks($data_element);
}

/**
* @todo remove, replace by parser
*/
protected function doParseData(DataElement $data): void
{
}

/**
* Gets the number of items in the IFD, from the data.
*
Expand Down Expand Up @@ -445,11 +452,10 @@ public function collectInfo(array $context = []): array
$info['seq'] = $parent_name . '.' . $info['seq'];
}

$item = $this->getAttribute('id');
if ($item ==! null) {
if (isset($parentInfo['item'])) {
$msg .= ' ({item})';
$info['item'] = is_numeric($parentInfo['item']) ? $parentInfo['item'] . '/0x' . strtoupper(dechex($parentInfo['item'])) : $parentInfo['item'];
}
$info['item'] = is_numeric($item) ? $item . '/0x' . strtoupper(dechex($item)) : $item;

if (isset($context['dataElement']) && $context['dataElement'] instanceof DataWindow) {
$info['offset'] = $context['dataElement']->getAbsoluteOffset($this->getDefinition()->getDataOffset()) . '/0x' . strtoupper(dechex($context['dataElement']->getAbsoluteOffset($this->getDefinition()->getDataOffset())));
Expand Down
2 changes: 2 additions & 0 deletions src/Block/Exif/Vendor/Apple/RunTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class RunTime extends ListBase
*/
protected function doParseData(DataElement $data): void
{
assert($this->debugInfo(['dataElement' => $data]));

$plist = new CFPropertyList();
$plist->parse($data->getBytes(0, $this->getDefinition()->getValuesCount()));

Expand Down
10 changes: 5 additions & 5 deletions src/Block/Exif/Vendor/Canon/AFInfoIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ protected function doParseData(DataElement $data): void
// property is true, the first entry is a special case that is handled
// by opening a 'rawData' node instead of a 'tag'.
$offset = 0;
$index_components = $this->getDefinition()->getValuesCount();
assert($this->debugInfo(['dataElement' => $data, 'itemsCount' => $index_components]));
$this->components = $this->getDefinition()->getValuesCount();
assert($this->debugInfo(['dataElement' => $data]));

for ($i = 0; $i < $index_components; $i++) {
for ($i = 0; $i < $this->components; $i++) {
$item_definition = $this->getItemDefinitionFromData($i, $i, $data, $offset);

// Check if this tag should be skipped.
Expand All @@ -40,10 +40,10 @@ protected function doParseData(DataElement $data): void

if (in_array($item_definition->getCollection()->getPropertyValue('name'), ['AFAreaWidths', 'AFAreaHeights', 'AFAreaXPositions', 'AFAreaYPositions'])) {
$value_components = $this->getElement("tag[@name='NumAFPoints']")->getElement("entry")->getValue();
$index_components -= ($value_components - 1);
$this->components -= ($value_components - 1);
} elseif (in_array($item_definition->getCollection()->getPropertyValue('name'), ['AFPointsInFocus', 'AFPointsSelected'])) {
$value_components = (int) (($this->getElement("tag[@name='NumAFPoints']")->getElement("entry")->getValue() + 15) / 16);
$index_components -= ($value_components - 1);
$this->components -= ($value_components - 1);
} else {
$value_components = 1;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Block/Exif/Vendor/Canon/CustomFunctions2.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class CustomFunctions2 extends ListBase
*/
protected function doParseData(DataElement $data): void
{
assert($this->debugInfo(['dataElement' => $data]));

$rec_pos = 0;
for ($n = 0; $n < $this->getDefinition()->getValuesCount(); $n++) {
$id = $data->getLong($rec_pos);
Expand Down
2 changes: 2 additions & 0 deletions src/Block/Exif/Vendor/Canon/CustomFunctions2Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class CustomFunctions2Header extends ListBase
*/
protected function doParseData(DataElement $data): void
{
assert($this->debugInfo(['dataElement' => $data]));

$offset = 0;
$size = $this->getDefinition()->getSize();

Expand Down
43 changes: 31 additions & 12 deletions src/Block/Exif/Vendor/Canon/Filter.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
<?php declare(strict_types=1);

namespace FileEye\MediaProbe\Block\Exif\Vendor\Canon;

use FileEye\MediaProbe\Block\ListBase;
use FileEye\MediaProbe\Block\Index;
use FileEye\MediaProbe\Block\ListBase;
use FileEye\MediaProbe\Block\Map;
use FileEye\MediaProbe\Block\RawData;
use FileEye\MediaProbe\Block\Tag;
use FileEye\MediaProbe\Data\DataElement;
use FileEye\MediaProbe\Data\DataFormat;
use FileEye\MediaProbe\Data\DataWindow;
use FileEye\MediaProbe\ItemDefinition;
use FileEye\MediaProbe\Data\DataFormat;
use FileEye\MediaProbe\MediaProbe;
use FileEye\MediaProbe\MediaProbeException;
use FileEye\MediaProbe\Model\BlockInterface;
use FileEye\MediaProbe\Utility\ConvertBytes;

/**
Expand All @@ -30,6 +31,12 @@ class Filter extends ListBase
*/
protected int $paramsCount;

public function __construct(ItemDefinition $definition, BlockInterface $parent = null, BlockInterface $reference = null)
{
parent::__construct($definition, $parent, $reference);
$this->setAttribute('name', $this->getParentElement()->getAttribute('name') . '.' . $definition->getSequence());
}

/**
* {@inheritdoc}
*/
Expand All @@ -38,22 +45,35 @@ protected function doParseData(DataElement $data): void
$offset = 0;

// The id of the filter is at offset 0.
$this->setAttribute('id', $data->getLong($offset));
$this->setAttribute('id', (string) $data->getLong($offset));

// The count of filter parameters is at offset 8.
$this->paramsCount = $data->getLong($offset + 8);
$offset += 12;

assert($this->debugInfo(['dataElement' => $data]));

// Loop and parse through the parameters.
for ($p = 0; $p < $this->paramsCount; $p++) {
$id = $data->getLong($offset);
$id = (string) $data->getLong($offset);
$val_count = $data->getLong($offset + 4);
$offset += 8;

// The items are defined in the collection of the parent element.
$this
->addBlock(new ItemDefinition($this->getParentElement()->getCollection()->getItemCollection($id), DataFormat::SIGNED_LONG, $val_count))
->parseData(new DataWindow($data, $offset, $val_count * DataFormat::getSize(DataFormat::SIGNED_LONG)));
->addBlock(new ItemDefinition(
$this->getParentElement()->getCollection()->getItemCollection($id),
DataFormat::SIGNED_LONG,
$val_count,
0,
$offset,
$p,
))
->parseData(new DataWindow(
$data,
$offset,
$val_count * DataFormat::getSize(DataFormat::SIGNED_LONG)
));

$offset += 4 * $val_count;
}
Expand All @@ -67,13 +87,13 @@ public function toBytes(int $byte_order = ConvertBytes::LITTLE_ENDIAN, int $offs
$bytes = '';

// The id of the filter.
$bytes .= ConvertBytes::fromLong($this->getAttribute('id'), $byte_order);
$bytes .= ConvertBytes::fromLong((int) $this->getAttribute('id'), $byte_order);

// Build the parameters.
$params = $this->getMultipleElements('*');
$data_area_bytes = '';
foreach ($params as $param) {
$data_area_bytes .= ConvertBytes::fromLong($param->getAttribute('id'), $byte_order);
$data_area_bytes .= ConvertBytes::fromLong((int) $param->getAttribute('id'), $byte_order);
$data_area_bytes .= ConvertBytes::fromLong($param->getComponents(), $byte_order);
$data_area_bytes .= $param->toBytes($byte_order);
}
Expand All @@ -93,10 +113,9 @@ public function toBytes(int $byte_order = ConvertBytes::LITTLE_ENDIAN, int $offs
public function collectInfo(array $context = []): array
{
return array_merge(parent::collectInfo($context), [
'_msg' =>'filter#{seq} @{offset}, {parms} parameter(s), size {size} bytes',
'_msg' =>'#{seq}.{name} @{offset}, {parmetersCount} parameter(s), size {size} bytes',
'seq' => $this->getDefinition()->getSequence() + 1,
'parms' => $this->paramsCount ?? 'n/a',
'size' => $this->getDefinition()->getSize(),
'parmetersCount' => $this->paramsCount,
]);
}

Expand Down
33 changes: 23 additions & 10 deletions src/Block/Exif/Vendor/Canon/FilterInfoIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,29 @@ protected function doParseData(DataElement $data): void
{
$offset = 0;

// The count of filters is at offset 4.
$this->components = $data->getLong($offset + 4);

assert($this->debugInfo(['dataElement' => $data]));

// The first 4 bytes is a marker (?), store as RawData.
$this
->addBlock(new ItemDefinition(CollectionFactory::get('RawData', ['name' => 'filterHeader']), DataFormat::BYTE, 4))
->parseData(new DataWindow($data, $offset, 4));
$offset += 4;

// The next 4 bytes define the count of filters.
$index_components = $data->getLong($offset);
$this->debug("{filters} filters", [
'filters' => $index_components,
]);
$offset += 4;
$offset += 8;

// Loop and parse through the filters.
for ($i = 0; $i < $index_components; $i++) {
for ($i = 0; $i < $this->components; $i++) {
$filter_size = $data->getLong($offset + 4);
$this
->addBlock(new ItemDefinition(CollectionFactory::get('ExifMakerNotes\Canon\Filter'), DataFormat::BYTE, $filter_size, $offset, 0, $i))
->addBlock(
new ItemDefinition(CollectionFactory::get('ExifMakerNotes\Canon\Filter'),
DataFormat::BYTE,
$filter_size,
$offset,
0,
$i
))
->parseData(new DataWindow($data, $offset, $filter_size + 4));
$offset += 4 + $filter_size;
}
Expand Down Expand Up @@ -98,4 +103,12 @@ public function toBytes(int $byte_order = ConvertBytes::LITTLE_ENDIAN, int $offs

return $bytes;
}

public function collectInfo(array $context = []): array
{
$info = [];
$parentInfo = parent::collectInfo($context);
$info['tags'] = $this->components;
return array_merge($parentInfo, $info);
}
}
13 changes: 6 additions & 7 deletions src/Block/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ protected function doParseData(DataElement $data): void
// property is true, the first entry is a special case that is handled
// by opening a 'rawData' node instead of a 'tag'.
$offset = 0;
$index_components = $this->getDefinition()->getValuesCount();
assert($this->debugInfo(['dataElement' => $data, 'itemsCount' => $index_components]));
$this->components = $this->getDefinition()->getValuesCount();
assert($this->debugInfo(['dataElement' => $data]));

for ($i = 0; $i < $index_components; $i++) {
for ($i = 0; $i < $this->components; $i++) {
$item_definition = $this->getItemDefinitionFromData($i, $i, $data, $offset);

// Check if this tag should be skipped.
Expand All @@ -67,7 +67,7 @@ protected function doParseData(DataElement $data): void
continue;
};

$index_components -= ($item_definition->getValuesCount() - 1);
$this->components -= ($item_definition->getValuesCount() - 1);

// Adds the 'tag'.
$this->addBlock($item_definition)->parseData($data, $item_definition->getDataOffset(), $item_definition->getSize());
Expand Down Expand Up @@ -219,11 +219,10 @@ public function collectInfo(array $context = []): array
$info['seq'] = $parent_name . '.' . $info['seq'];
}

$item = $this->getAttribute('id');
if ($item ==! null) {
if (isset($parentInfo['item'])) {
$msg .= ' ({item})';
$info['item'] = is_numeric($parentInfo['item']) ?$parentInfo['item'] . '/0x' . strtoupper(dechex($parentInfo['item'])) : $parentInfo['item'];
}
$info['item'] = is_numeric($item) ? $item . '/0x' . strtoupper(dechex($item)) : $item;

if (isset($parentInfo['size'])) {
$msg .= isset($parentInfo['offset']) ? ' @{offset}, {tags} entries, f {format}, s {size}' : ' {tags} entries, format ?xxx, size {size}';
Expand Down
2 changes: 2 additions & 0 deletions src/Block/Jpeg.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class Jpeg extends BlockBase
*/
protected function doParseData(DataElement $data): void
{
assert($this->debugInfo(['dataElement' => $data]));

// JPEG data is stored in big-endian format.
$data->setByteOrder(ConvertBytes::BIG_ENDIAN);

Expand Down
1 change: 1 addition & 0 deletions src/Block/JpegSegment.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class JpegSegment extends JpegSegmentBase
*/
protected function doParseData(DataElement $data): void
{
assert($this->debugInfo(['dataElement' => $data]));
// Adds the segment data as an Undefined entry.
new Undefined($this, $data);
}
Expand Down
1 change: 1 addition & 0 deletions src/Block/JpegSegmentApp1.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class JpegSegmentApp1 extends JpegSegmentBase
*/
protected function doParseData(DataElement $data): void
{
assert($this->debugInfo(['dataElement' => $data]));
// If we have an Exif table, parse it.
if (Exif::isExifSegment($data, 4)) {
$exif = new ItemDefinition(CollectionFactory::get('Exif\Exif'));
Expand Down
1 change: 1 addition & 0 deletions src/Block/JpegSegmentCom.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class JpegSegmentCom extends JpegSegmentBase
*/
protected function doParseData(DataElement $data): void
{
assert($this->debugInfo(['dataElement' => $data]));
// Adds the segment data as a Char string.
new Char($this, new DataWindow($data, 4));
}
Expand Down
1 change: 1 addition & 0 deletions src/Block/JpegSegmentSos.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class JpegSegmentSos extends JpegSegmentBase
*/
protected function doParseData(DataElement $data): void
{
assert($this->debugInfo(['dataElement' => $data]));
// This segment is last before End Of Image, and its length needs to be
// determined by finding the EOI marker backwards from the end of data.
// Some images have some trailing (garbage?) following the EOI marker,
Expand Down
5 changes: 5 additions & 0 deletions src/Block/ListBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
abstract class ListBase extends BlockBase
{
/**
* The amount of components in the list.
*/
protected int $components;

/**
* {@inheritdoc}
*/
Expand Down
Loading

0 comments on commit 8afb74f

Please sign in to comment.