Last modified: 2013-07-25 07:04:29 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T39692, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 37692 - PagedTiffHandler assumes one-based page numbers; doesn't work with ImageMagick 6.7.7-2 which returns zero-based page numbers
PagedTiffHandler assumes one-based page numbers; doesn't work with ImageMagic...
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
PagedTiffHandler (Other open bugs)
master
All Mac OS X 10.7
: Normal normal (vote)
: ---
Assigned To: Lupo
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-18 15:04 UTC by Lupo
Modified: 2013-07-25 07:04 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
ImageMagick identify output on two test files (824 bytes, text/plain)
2012-06-19 05:49 UTC, Lupo
Details
Patch showing my quick hack mentioned in comment 2 (1.52 KB, patch)
2012-10-31 22:10 UTC, Lupo
Details

Description Lupo 2012-06-18 15:04:03 UTC
Installed the extension on my local test wiki running from master. Got the extension through a git clone of the PagedTiffHandler master.

After I had set it up, I was no longer able to upload tiff files.

Some debugging revealed that PagedTiffHandler.image.php assumed that the page numbers as returned by ImageMagick's identify command started at 1. However, my ImageMagick 6.7.7-2 returns zero-based page numbers (i.e., the first page got "page=0"). As a result, the extension always complained about "inconsistent page numbering in TIFF directory" in PagedTiffInfoParserState::finishPage() on the first page since $this->prevPage is also initialized to zero.

I don't know whether other versions of ImageMagick return one-based page numbers.

I fixed this locally by hacking in mapping zero-based page numbers to one-based numbers in parseIdentifyOutput(), and then the extension worked as advertized.
Comment 1 Markus Glaser 2012-06-18 22:48:09 UTC
Hi Lupo, need to investigate this. In our tests, it worked with page number one. Maybe it is a ImageMagic version issue, but that does not sound right ;) Can you post your workaround here? I would then incorporate this into the code. I think we need to normalize the starting page number according to MediaWiki needs, either to 0 or 1. That should not be a major issue.
Comment 2 Lupo 2012-06-19 05:49:13 UTC
Created attachment 10769 [details]
ImageMagick identify output on two test files

I'd rather not; I really just hacked it in, and I don't really have the time to do this right.

I didn't analyze whether this could be fixed simply by initializing $prevPage to -1 instead of zero.

I don't know if it's some ImageMagick version thing. I got my ImageMagick through MacPorts; maybe their version does something wrong (or at least differently from other distributions).

In any case, I've attached the output of my ImageMagick on two test files from the Commons:

http://commons.wikimedia.org/wiki/File:Lehndorf_(Saara)_-_Zentrum.tif

http://commons.wikimedia.org/wiki/File:Tochon_d%27Annecy.tiff

The first is a single page, the second has two pages.
Comment 3 Lupo 2012-06-19 05:50:37 UTC
BTW, note the that the alpha2 values also do not correspond to what the extension tests for.
Comment 4 Derk-Jan Hartman 2012-06-19 06:38:51 UTC
Lupo, can you add your 'convert -version' info ?
Comment 5 Lupo 2012-06-19 10:52:24 UTC
Sure, though I don't see what convert has got to do with it, as the extension uses identify to get the info it wants. Anyway, it's identical to the version of identify:

$ convert -version
Version: ImageMagick 6.7.7-2 2012-05-28 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features:  OpenCL

$
Comment 6 Derk-Jan Hartman 2012-10-29 16:36:04 UTC
Confirmed, i see the same problem.

The issue is in PagedTiffInfoParserState, which has prevPage, which starts at 0, which only works if the first page starts with 1.
Comment 7 Derk-Jan Hartman 2012-10-29 17:26:41 UTC
Path in https://gerrit.wikimedia.org/r/30621
Comment 8 Lupo 2012-10-31 22:10:35 UTC
Created attachment 11272 [details]
Patch showing my quick hack mentioned in comment 2

Hi DJ,

I've left you some comments on that patch in Gerrit. Since apparently there are quite a few other places that assume 1-based indexing (and no gaps), I have now attached here my quick hack to map 0-based IM output to 1-based internal page numbers. Maybe that's easier than doing it your way, which did look cleaner at first sight, but which might require adapting several other parts.

Maybe you can use it, and maybe not. I'm not sure what would be the best way to handle this page numbering cleanly. And perhaps you see a simple way to fix the problems I mentioned in Gerrit.
Comment 9 Derk-Jan Hartman 2012-11-04 15:00:30 UTC
Interestingly: http://www.awaresystems.be/imaging/tiff/tifftags/pagenumber.html

"The first page is numbered 0 (zero)."
Comment 10 Derk-Jan Hartman 2012-11-04 16:13:43 UTC
I'd like to figure out the exact imagemagick version where this is switched, if anyone has any clues, I'd welcome it.
Comment 11 Lupo 2012-11-04 23:44:38 UTC
I think it was this change:

http://trac.imagemagick.org/changeset/4014/ImageMagick/trunk/magick/property.c

It should have a +1 in line 2815. (Unless the change from 1-based to zero-based indexing was intentional, of course).

That would place the change betweeen IM 6.6.8-8 (1-based) and 6.6.8-10 (zero-based) according to http://www.imagemagick.org/script/changelog.php.
Comment 12 Lupo 2012-12-08 22:48:01 UTC
New patch in Gerrit (basically attachment 11272 [details]): https://gerrit.wikimedia.org/r/#/c/37654/

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links