After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 578876 - Allow customization of TIFF parameters when saving a pixbuf
Allow customization of TIFF parameters when saving a pixbuf
Status: RESOLVED FIXED
Product: gdk-pixbuf
Classification: Platform
Component: general
git master
Other All
: Normal enhancement
: ---
Assigned To: gdk-pixbuf-maint
gdk-pixbuf-maint
Depends on:
Blocks:
 
 
Reported: 2009-04-13 20:50 UTC by Marcelo Fernández
Modified: 2014-10-23 04:06 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Bug #578876 - Allow saving 1-bit mono TIFFs used in faxes (10.06 KB, patch)
2012-02-01 19:51 UTC, Mukund Sivaraman
reviewed Details | Review
Updated patch to address review comments (15.61 KB, patch)
2012-02-03 23:58 UTC, Mukund Sivaraman
needs-work Details | Review
Allow saving 1-bit mono TIFFs used in faxes (14.76 KB, patch)
2014-10-22 19:54 UTC, Robert Ancell
accepted-commit_now Details | Review

Description Marcelo Fernández 2009-04-13 20:50:43 UTC
When saving a TIFF file, there are some hard-coded values I'd like to be allowed to be customized in the resulting TIFF file, like the bits per sample and/or the fill order, which are important when developing Fax management software. For example, b/w images (2 Bits per sample) are common in this kind of applications; instead of getting a small ~80KB per fax (1728x2872 pixels, black/white), I'm getting a fat 16MB file (RGB).

Despite the Gdk-Pixbuf allows to pass custom options to the save callback function (the **keys and **values pointers), these doesn't get used within the TIFF backend. I can see this in the io-tiff.c source file (gdk_pixbuf__tiff_image_save_to_callback() function):

688: TIFFSetField (tiff, TIFFTAG_BITSPERSAMPLE, 8);
[...]
696: TIFFSetField (tiff, TIFFTAG_FILLORDER, FILLORDER_MSB2LSB);

This is the source file:
http://svn.gnome.org/viewvc/gtk%2B/trunk/gdk-pixbuf/io-tiff.c?view=markup

So this bug report is to ask for support saving tiff pixbufs with custom bits per sample and fill order, using the standard parameter options.

Thanks you!
Marcelo
Comment 1 Mukund Sivaraman 2012-02-01 19:51:58 UTC
Created attachment 206590 [details] [review]
Bug #578876 - Allow saving 1-bit mono TIFFs used in faxes

While working on a GTK+ 3 port of Hildon, I'm upstreaming some patches
from Maemo's repositories. This one is repurposed from:
http://maemo.gitorious.org/hildon/gtk/commit/005de8d5

  From: Christian Dywan <christian@lanedo.com>
  Date: Wed, 20 Jan 2010 11:22:29 +0100
  Subject: [PATCH] Fixes: NB#116221 - Sharing TIF image with Size Option
   Large makes the image much larger than the original one when shared
   to OVI or Flickr.

This patch combined other bits which were removed, and the code was
modified a little.
Comment 2 Marcelo Fernández 2012-02-01 20:34:09 UTC
Hi Mukund,

This patch (seems to me) that improves the situation :-)

I'm reading TIFFs with 1 or 8 bpp are allowed through the "bits-per-sample" options, and if it is 1bpp, it selects CCIT Fax Group4 compression, right? Nice!


Regards
Comment 3 Mukund Sivaraman 2012-02-02 06:30:51 UTC
Cool :) Yes, if 1-bit is selected, it uses CCITTFAX4. I tested it with some sample images here. A fax app may have used this on the N900 (this patch is adapted from the Maemo gtk repository). I forgot to add a Nokia copyright to the code as it's a decent sized chunk. Will do that when it gets committed.

I wonder why I didn't get a bugzilla mail... didn't get a notice that you updated the bug.
Comment 4 Matthias Clasen 2012-02-03 21:02:54 UTC
Review of attachment 206590 [details] [review]:

You should update the docs of gdk_pixbuf_save where we already mention the "compression" parameter, and add the new one.

::: gdk-pixbuf/io-tiff.c
@@ +721,1 @@
+        /* We recognize "compression" and "bits-per-sample" */

The comment should probably mention icc-profile as well

@@ +757,3 @@
+        /* We support 1 bit or 8 bit saving */
+        if (bits_per_sample &&
+            (atol (bits_per_sample) == 1)) {

bits_per_sample can be coming in via the api here, right ?
So we probably need to do some minimal error handling to catch the case where bits_per_sample is not "1" or "8"

@@ +799,3 @@
         TIFFSetField (tiff, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
 
+        if (G_UNLIKELY (mono_row)) {

Don't think the UNLIKELY is adding much here. I'd just leave that out
Comment 5 Mukund Sivaraman 2012-02-03 23:58:25 UTC
Created attachment 206745 [details] [review]
Updated patch to address review comments

This patch also adds Floyd-Steinberg dithering. The results are as follows:

https://malgudi.org/~muks/tmp/tiff-before.png <- prior Nokia work
https://malgudi.org/~muks/tmp/tiff-after.png <- modified patch
Comment 6 Bastien Nocera 2014-10-21 18:24:14 UTC
Review of attachment 206745 [details] [review]:

Marking as needs-work, as the patch doesn't apply cleanly against the current git master.

The rest looks good to commit.

::: gdk-pixbuf/io-tiff.c
@@ +792,3 @@
+        /* libtiff supports a number of 'codecs' such as:
+           1 None, 2 Huffman, 5 LZW, 7 JPEG, 8 Deflate, see tiff.h */
+        guint16 codec = strtol (compression, NULL, 0);

declaration needs to be at the top of the function.
Comment 7 Robert Ancell 2014-10-22 19:54:51 UTC
Created attachment 289170 [details] [review]
Allow saving 1-bit mono TIFFs used in faxes

Updated to master. Passes tests and I've visually checked it but not tested in depth.

Bastien - you owe me some beers :)
Comment 8 Bastien Nocera 2014-10-22 21:40:04 UTC
Review of attachment 289170 [details] [review]:

Looks great, please push to master.