r72279 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72278‎ | r72279 | r72280 >
Date:12:06, 3 September 2010
Author:daniel
Status:reverted (Comments)
Tags:
Comment:
photoshop quirks: ignore extra tiff directory causing the same data to show as two pages in the tiff
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
@@ -123,9 +123,10 @@
124124 $wgMediaHandlers['image/tiff'] = 'PagedTiffHandler';
125125 $wgHooks['LanguageGetMagic'][] = 'PagedTiffHandler::addTiffLossyMagicWordLang';
126126
127 -define('TIFF_METADATA_VERSION', '1.1');
 127+define('TIFF_METADATA_VERSION', '1.2');
128128 # 1.0: initial
129129 # 1.1: fixed bugs in imageinfo parser
 130+# 1.2: photoshop quirks for imageinfo parser
130131
131132 //$wgHooks['PagedTiffHandlerRenderCommand'][] = 'PagedTiffHandler::renderCommand';
132133 //$wgHooks['PagedTiffHandlerTiffData'][] = 'PagedTiffImage::tiffData';
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php
@@ -225,6 +225,7 @@
226226 $entry = array();
227227
228228 $prevPage = 0;
 229+ $quirks = false;
229230
230231 foreach ( $rows as $row ) {
231232 $row = trim( $row );
@@ -282,17 +283,37 @@
283284 $entry['width'] = (int)$value;
284285 } else if ( $key == 'Image Length' || $key == 'PixelYDimension' ) {
285286 $entry['height'] = (int)$value;
 287+ } else if ( $key == 'Software' && preg_match('/photoshop/i', $value) ) {
 288+ $quirks = "photoshop";
 289+ } else if ( $key == 'Subfile Type' ) {
 290+ $entry['type'] = (int)$value;
286291 }
287292 } else {
288293 // strange line
289294 }
290 -
291295 }
292296
293297 if ( $entry ) {
294298 $ok = $this->addPageEntry($entry, $data, $prevPage);
295299 }
296300
 301+ if ( $quirks === 'photoshop' && count( $data['page_data'] ) > 1 ) {
 302+ # Photoshop may use multiple directories for a single page image
 303+ # Ignore the ones with SubfileType == 0
 304+ foreach ( $data['page_data'] as $i => $entry ) {
 305+ if ( isset($entry['type']) && $entry['type'] === 0 ) {
 306+ unset( $data['page_data'][$i] );
 307+ $data['warnings'][] = "removed spurious frame (photoshop quirk)";
 308+ }
 309+ }
 310+
 311+ $data['page_data'] = array_values( $data['page_data'] ); # re-index
 312+ array_unshift( $data['page_data'], null ); # make 1-indexed
 313+ unset( $data['page_data'][0] ); #remove dummy
 314+ }
 315+
 316+ $data['quirks'] = $quirks;
 317+
297318 if ( !isset( $data['page_amount'] ) ) {
298319 $data['page_amount'] = count( $data['page_data'] );
299320 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r72370revert for r72279: photoshop quirks to be replaced by generic handling of EXI...daniel12:22, 4 September 2010
r72371replacement for r72279: ignore extra IFDs reported by tiffinfodaniel12:48, 4 September 2010

Comments

#Comment by Duesentrieb (talk | contribs)   12:10, 3 September 2010

photoshop generates two tiff directories even for single page images. this patch will identify and remove the spurious page entries.

I'm not 100% confident that this is The Right Thing. In theory, SubfileType should always be set, and should usually be 1. However, it seems to be usually left out, and sometimes is 0 even for a full size single frame (see smallliz.tif from the libtiff test data set).

#Comment by Duesentrieb (talk | contribs)   12:11, 3 September 2010

Note: this change depends on r72278. wihtout that, the affected photoshop generated tiffs won't get shown at all.

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

reverted in favor of a more generic solution to be committed soon.

Status & tagging log