r72371 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72370‎ | r72371 | r72372 >
Date:12:48, 4 September 2010
Author:daniel
Status:ok (Comments)
Tags:
Comment:
replacement for r72279: ignore extra IFDs reported by tiffinfo
Modified paths:
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php (modified) (history)
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler.php
@@ -126,6 +126,8 @@
127127 define('TIFF_METADATA_VERSION', '1.1');
128128 # 1.0: initial
129129 # 1.1: fixed bugs in imageinfo parser
 130+# 1.2: photoshop quirks (reverted)
 131+# 1.3: handing extra IDFs reported by tiffinfo
130132
131133 //$wgHooks['PagedTiffHandlerRenderCommand'][] = 'PagedTiffHandler::renderCommand';
132134 //$wgHooks['PagedTiffHandlerTiffData'][] = 'PagedTiffImage::tiffData';
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php
@@ -196,15 +196,17 @@
197197 }
198198 }
199199
200 - $prevPage = max($prevPage, $entry['page']);
 200+ if ( isset( $entry['width'] ) && isset( $entry['height'] ) ) {
 201+ $prevPage = max($prevPage, $entry['page']);
201202
202 - if ( !isset( $entry['alpha'] ) ) {
203 - $entry['alpha'] = 'false';
 203+ if ( !isset( $entry['alpha'] ) ) {
 204+ $entry['alpha'] = 'false';
 205+ }
 206+
 207+ $entry['pixels'] = $entry['height'] * $entry['width'];
 208+ $metadata['page_data'][$entry['page']] = $entry;
204209 }
205210
206 - $entry['pixels'] = $entry['height'] * $entry['width'];
207 - $metadata['page_data'][$entry['page']] = $entry;
208 -
209211 $entry = array();
210212 return true;
211213 }
@@ -222,8 +224,10 @@
223225 $data = array();
224226 $data['page_data'] = array();
225227
 228+ $ignoreIFDs = array();
226229 $entry = array();
227230
 231+ $ignore = false;
228232 $prevPage = 0;
229233
230234 foreach ( $rows as $row ) {
@@ -245,14 +249,19 @@
246250
247251 if ( $error ) continue;
248252
249 - if ( preg_match('/^TIFF Directory at/', $row) ) {
250 - if ( $entry ) {
 253+ if ( preg_match('/^TIFF Directory at offset 0x[a-f0-9]+ \((\d+)\)/', $row, $m) ) {
 254+ if ( $ignore ) {
 255+ $entry = array();
 256+ } else if ( $entry ) {
251257 $ok = $this->addPageEntry($entry, $data, $prevPage);
252258 if ( !$ok ) {
253259 $error = true;
254260 continue;
255261 }
256262 }
 263+
 264+ $ofs = (int)$m[1];
 265+ $ignore = !empty( $ignoreIFDs[ $ofs ] );
257266 } else if ( preg_match('#^(TIFF.*?Directory): (.*?/.*?): (.*)#i', $row, $m) ) {
258267 $bypass = false;
259268 $msg = $m[3];
@@ -282,6 +291,11 @@
283292 $entry['width'] = (int)$value;
284293 } else if ( $key == 'Image Length' || $key == 'PixelYDimension' ) {
285294 $entry['height'] = (int)$value;
 295+ } else if ( preg_match('/.*IFDOffset/', $key) ) {
 296+ # ignore extra IFDs, see <http://www.awaresystems.be/imaging/tiff/tifftags/exififd.html>
 297+ # Note: we assume that we will always see the reference before the actual IFD, so we know which IFDs to ignore
 298+ $ofs = (int)$value;
 299+ $ignoreIFDs[$ofs] = true;
286300 }
287301 } else {
288302 // strange line
@@ -289,7 +303,7 @@
290304
291305 }
292306
293 - if ( $entry ) {
 307+ if ( $entry && !$ignore ) {
294308 $ok = $this->addPageEntry($entry, $data, $prevPage);
295309 }
296310

Follow-up revisions

RevisionCommit summaryAuthorDate
r72380addendum to r72371: bump TIFF_METADATA_VERSIONdaniel14:56, 4 September 2010
r72523Fix for r72371: use English in variable names.tstarling09:40, 7 September 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r72279photoshop quirks: ignore extra tiff directory causing the same data to show a...daniel12:06, 3 September 2010

Comments

#Comment by Duesentrieb (talk | contribs)   12:54, 4 September 2010

This change fixes a problem with non-image IFDs in TIFF files, as reported by tiffinfo (imagemagick's identify is not affected):

Without this patch, they are counted as pages, causing the same image data to be shown as multiple pages, which in fact the tiff file just contains multiple IFDs for the same page. This is most commonly the case with EXIF data, and can also occur for GPS- and Interoperability IFDs.

See <http://www.awaresystems.be/imaging/tiff/tifftags/exififd.html> and linked pages. Thanks to TheDJ for the pointer.

#Comment by Nikerabbit (talk | contribs)   13:37, 4 September 2010

Is there no need to increase TIFF_METADATA_VERSION? Why have two level version number if every change is major change (=metadata needs to be updated or regeneraged) anyway?

#Comment by Duesentrieb (talk | contribs)   14:55, 4 September 2010

TIFF_METADATA_VERSION must be increased, I added the comment but forgot the actual bump. i'm such a slob. will fix in a sec.

#Comment by Duesentrieb (talk | contribs)   14:56, 4 September 2010

fixed in r72380

#Comment by Duesentrieb (talk | contribs)   13:45, 6 September 2010

to clarify the first part of the diff (changes in addPageEntry()): page entries that don't specify width and height are now ignored. this is an additional safeguard against IFDs that do not actually describe a page/frame/image in the file, but contain extra custom data. Such IFDs should not create a page entry in the meta data.

#Comment by Duesentrieb (talk | contribs)   09:11, 13 September 2010

this should be considered together with r72706

Status & tagging log