GNOME Bugzilla – Bug 138495
Allow to open multi-page images as either Layers or Images (TIFF, PS, PDF, ...)
Last modified: 2007-04-24 19:49:08 UTC
Load a multi-page tiff file. GIMP shown a multi-layer image instead. From the status bar, pressing page-up/down, the status does change accordingly. But only the topmost layer is displayed. When printing, only the "merged" image is printed.
This sounds like several enhancement requests instead of a bug: 1) switching (visibilty) of layers with hotkeys 2) printing layers one by one 2) might already be covered by the gimp-print plug-in, but I've never used it yet. Or is the tiff plug-in already supposed to have these functions?
Gimp does not have the concept of multiple pages in an image. Instead of throwing away all image data except for the first page (which was the earlier behaviour of the tiff-plugin) the pages get load into multiple layers. The print plugin of course prints the image the way it is currently visible. I don't know what to do about this, but it is definitely an enhancement request and not a blocker.
The postscript plugin however does load multi-page documents as multiple images. In this TIFF case, The GIMP would not be able to save the TIFF back, if it would be loaded into multiple images, but changing the plug-in to make it optional to load multiple pages as layers or separate images should not be hard.
Actually, each plug-in which can load multi-page documents should have an option to load the pages either as layers or as images. Changing summary accordingly. Please file a separate report for the unrelated issue of printing the opened image(s).
This is now addressed by the new GimpPageSelector widget. The new PDF export plug-in will provide this functionality. What remains to be done is to change the TIFF and Postscript plug-ins to use the new widget.
PDF export?
Import, I meant to write PDF import. Sorry for the confusion. Adding the gnome-love keyword since this is an overseeable job that doesn't require much knowledge about GIMP. It's just a matter of porting two plug-ins to a new widget, based on example code from a third plug-in. A nice way to get into hacking the GIMP...
Created attachment 49109 [details] [review] first try in patching the postscript plugin This is a first try of mine to change the postscript plugin to use the PageSelector. I kept the old behavoir for PDF files, because I'm unable to get the number of pages in such a file. The PageSelector widget is hidden if the file only has one page. Support for layering postscript pages is included as well (not sure if it's done correctly)
Created attachment 49161 [details] [review] corrected patch I uploaded the wrong patch yesterday. PDF loading did not work. Thats fixed in this one.
Is countPSPages() really the only way to get to the number of pages in a postscript file? The use of g_utf8_strup() is wrong here, btw. The filename isn't necessarily in UTF-8 encoding. g_ascii_toupper() is probably a better choice since it won't barf on other charsets. Also, if the patch would adhere to the GIMP coding style, that would make it easier to get it into CVS.
Counting the pages of a postscript file will be very hard, except you interpret it and count the invocations of the "showpage" operator. Since this can be quite disguised in a postscript file it does not help to just count the occurances of "showpage". The patch seems to rely on the Adobe DSC's (Document Structuring Comments) which were invented to tackle exactly this problem. Note that Comments are just postscript comments and not every postscript file is DSC-conformant.
Created attachment 49508 [details] [review] cleaned-up postscript patch I hope I got the formatting right this time. I changed g_utf8_strup to its ascii pendant, too. count_ps_pages() now counts the occurance of the "showpage" operator when it passes by, since it walks the whole file until it finds a "%%Pages" comment anyway.
If I'm not mistaken, there are still some formatting issues (the indentation of some ifs). I didn't investigate the code into full depth, but something makes me suspicious: when pages should be added as layers, these are taken from the images that are created by the existing code. Shouldn't these images be deleted afterwards, or is this done automatically? And finally, opening pages as layers should be made the default.
This is even totally wrong. You can't take layers of one image and add them to a second image. The layers need to be created for the destination image in the first place.
Um, sorry, I was commention on the previous patch. The current one will work for "open as layers", however it will waste tons of memory and is not committable as-is. Some comments: - the layers should be added to the final image in the first place. - the final image's undo should be disabled. - the g_file_test() in count_ps_pages() is redundant. - the error message if opening fails in count_ps_pages() should use the standard translatable message "opening foo failed". - i have now idea how correct count_ps_pages(). - GIMP should still be able to open all pages of all postscript documents, no matter if whey were countable before or not.
Gah, I should have a coffee before commenting in bugzilla: s/commention/commenting/ and - i have no idea how correct count_ps_pages() is. :-)
Created attachment 50679 [details] [review] newly updated postscript patch This should change the following: - the last indentation faults are hopefully eliminated - images are deleted after layering pages - final images undo stack is disabled while putting layers together - removed g_file_test and fixed error message in count_ps_pages() - if the pages cannot be counted the dialog falls back to the old behaviour with an GtkEntry for page selection plus an additional GtkComboBox for selecting the page mode But there is one thing I'm not sure with. What do you mean by "the layers should be added to the final image in the first place"? I'm adding the layer to the image before adding the alpha channel now, but I'm not sure if it's what you meant.
Created attachment 50680 [details] [review] correct patch Doh! Last one was the wrong one.
I meant that it would be nicer (less temp memory used) if it didn't create a new image for each page and then duplicated each image's single layer in order to construct the final image. Anyway, the patch looks fine now and should go into CVS, it can always be improved after that.
Hacked the patch a bit and appliged it to CVS HEAD: 2005-08-15 Michael Natterer <mitch@gimp.org> * plug-ins/common/postscript.c: applied patch from Felix Riemann that adds page counting and a page selector widget to the load dialog. Fixed some minor issues in the patch and added code that names layers and images after the document's pages. Disable undo on all created images and set them clean before returning them. Addresses bug #138495.
Oops, didn't mean to set to NEEDINFO.
Done for poppler: 2005-08-23 Michael Natterer <mitch@gimp.org> * plug-ins/common/poppler.c: added loading of pages as images. Addresses bug #138495.
What needs to be done to close this report? As far as I can see, the TIFF plug-in should be using the page selector UI in case that the TIFF file being opened contains an image directory. Would that make sense? Are there other file plug-ins that need similar changes?
It seemed that this is solved well enough for 2.4, and I will bump the target for the remaining parts to Future.
IMO we should still try to get this into the TIFF plug-in for 2.4. With the availability of the GimpPageSelector widget, this should be a small change.
Removing from Postscript tracker bug as the requested changes to the Postscript plug-in are done.
Added this functionality for TIFF in Subversion changeset 22314: 2007-04-24 Mukund Sivaraman <muks@mukund.org> * plug-ins/common/tiff.c: added support to load multi-page TIFF images as single layered image or multiple individual per-page images, after prompting the user for choice using a GimpPageSelector widget. Fixes the rest of bug #138495.
Closing as it's all done now.