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 521751 - add more image type support to g-screenshot
add more image type support to g-screenshot
Status: RESOLVED FIXED
Product: gnome-screenshot
Classification: Core
Component: general
git master
Other All
: Normal enhancement
: ---
Assigned To: gnome-screenshot-maint
gnome-screenshot-maint
: 325187 346336 552148 637651 699358 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-03-11 11:17 UTC by Riccardo Setti
Modified: 2013-09-06 14:32 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
add more image type support (23.54 KB, patch)
2008-03-11 11:18 UTC, Riccardo Setti
reviewed Details | Review
To determine image format by filename extension. (2.39 KB, patch)
2012-06-29 04:17 UTC, Shih-Yuan Lee (FourDollars)
needs-work Details | Review
Revised Patch (2.94 KB, patch)
2012-07-11 16:17 UTC, Shih-Yuan Lee (FourDollars)
needs-work Details | Review
Determine image format by extension instead of a fixed PNG format. (4.82 KB, patch)
2012-08-30 15:20 UTC, Shih-Yuan Lee (FourDollars)
needs-work Details | Review
Determine image format by extension instead of a fixed PNG format. (6.14 KB, patch)
2012-09-04 15:18 UTC, Shih-Yuan Lee (FourDollars)
none Details | Review
Determine image format by extension instead of a fixed PNG format. (6.19 KB, patch)
2012-09-04 15:30 UTC, Shih-Yuan Lee (FourDollars)
reviewed Details | Review
Determine image format by extension instead of a fixed PNG format. (6.10 KB, patch)
2012-09-05 01:18 UTC, Shih-Yuan Lee (FourDollars)
committed Details | Review

Description Riccardo Setti 2008-03-11 11:17:43 UTC
Attached you can find an initial patch (mostly UI changes) that show how many image file format can be used before saving screenshots.

At the moment "png" is the default (hardcoded) file format. 

Via GdkPixbuf g-s can determinate how many file formats are avaiable and then write the image in these formats.

the patch is not yet finished as i'm having trouble how to removed the hardcoded fileformats, i wanted to something like:
screenshot_dialog_get_uri()

comments/suggestions are welcome (as usual)
Comment 1 Riccardo Setti 2008-03-11 11:18:46 UTC
Created attachment 107050 [details] [review]
add more image type support
Comment 2 Dennis Cranston 2008-03-25 04:31:35 UTC
reassigning bug to the correct module
Comment 3 Emmanuele Bassi (:ebassi) 2008-04-07 14:36:24 UTC
this patch should go in after we switched from the current custom dialog to a GtkFileChooserDialog, so we can use the extra widget field of that dialog.

the patch logic looks fine.
Comment 4 Vincent Untz 2008-07-27 14:49:23 UTC
*** Bug 325187 has been marked as a duplicate of this bug. ***
Comment 5 Cosimo Cecchi 2008-09-20 17:16:57 UTC
*** Bug 552148 has been marked as a duplicate of this bug. ***
Comment 6 Cosimo Cecchi 2008-09-20 17:18:18 UTC
Last duplicate bug 552148 contains an UI mockup for this feature.
Comment 7 Cosimo Cecchi 2011-06-13 19:25:40 UTC
*** Bug 637651 has been marked as a duplicate of this bug. ***
Comment 8 Cosimo Cecchi 2011-09-17 03:29:31 UTC
*** Bug 346336 has been marked as a duplicate of this bug. ***
Comment 9 Shih-Yuan Lee (FourDollars) 2012-06-29 04:17:16 UTC
Created attachment 217573 [details] [review]
To determine image format by filename extension.

I made this patch to determine image format by filename extension.
Comment 10 Emmanuele Bassi (:ebassi) 2012-06-29 06:43:42 UTC
Review of attachment 217573 [details] [review]:

thanks for your patch.

could you please attach the next iteration as a patch generated by `git format-patch`? see: https://live.gnome.org/Git/Developers#Contributing_patches - this would allow us to credit you properly.

rather than have format detection using the extension, I'd probably add a combo box with all the supported formats that can be used for writing to a file, though.

again, thanks for the patch!

::: gnome-screenshot-3.4.1.orig/src/screenshot-application.c
@@ +222,3 @@
+    extension++;
+
+  GSList *result = gdk_pixbuf_get_formats();

you should not be using C99 style declarations after statements.

@@ +223,3 @@
+
+  GSList *result = gdk_pixbuf_get_formats();
+  void foreach_print (gpointer data, gpointer user_data) {

internal functions are a GCC extensions; you should move it out and make it a regular function.

@@ +233,3 @@
+      }
+  }
+  g_slist_foreach (result, foreach_print, NULL);

the list returned by gdk_pixbuf_get_formats() should be freed using g_slist_free().
Comment 11 Shih-Yuan Lee (FourDollars) 2012-07-11 16:17:00 UTC
Created attachment 218569 [details] [review]
Revised Patch

Thanks for your review.
I made a revised patch.
Any feedback is welcome.
Comment 12 Hubert Figuiere (:hub) 2012-08-27 20:10:55 UTC
I think  removing '"tEXt::Software", "gnome-screenshot"' when creating the pixbuf is not a good idea. It should be kept as is for PNG. And eventually adapted for JPEG, TIFF.
Comment 13 Cosimo Cecchi 2012-08-27 23:17:39 UTC
Review of attachment 218569 [details] [review]:

Thanks for the updated patch. I have some comments below:

::: src/screenshot-application.c
@@ +213,3 @@
+  while (*ptr != NULL) {
+    if (g_strcmp0 (*ptr, *format) == 0) {
+  gchar **format  = (gchar **) user_data;

This function duplicates the string, so we'll leak it when the g_strcmp0() succeeds (we never call g_free() on extension in the following function).

@@ +237,3 @@
+    extension++;
+
+  if (extension == NULL)

Coding style: we usually declare variables at the top of a block...

@@ +238,3 @@
+
+  GSList *formats = gdk_pixbuf_get_formats();
+    extension = "png";

...but I don't really like this.

First of all, in case the extension is NULL or "png", we don't need to go through the whole format list, as the case is basically equivalent to the old code.
Also, I would remove the separate foreach() function and just use a for loop here, breaking the loop as soon as we find a format name that matches the extension.
Finally, I think we also need an error dialog in case the specified extension is not supported.

Another option would be to move the extension validation code to the save dialog, and make the "Save" action insensitive as long as the typed-in extension is not supported (possibly adding an inline message saying so to the dialog). This would avoid the need of a separate dialog in case of error, and is probably a better user experience too. If we do this, we should also treat the case where the user types in no extension at all by automatically saving to PNG.

@@ -239,2 @@
                                      save_pixbuf_ready_cb, self,
-                                     "tEXt::Software", "gnome-screenshot",

As already mentioned, we don't want to lose this information; it should still be saved in case the image is PNG. What happens if you pass this to GdkPixbuf when saving e.g. a JPEG image? If saving works and the option is just ignored by the backend, we might want to set it in all cases.
Comment 14 Cosimo Cecchi 2012-08-27 23:19:11 UTC
Review of attachment 218569 [details] [review]:

::: src/screenshot-application.c
@@ +209,3 @@
+{
+  gchar **format  = (gchar **) user_data;
+  gchar **extensions = gdk_pixbuf_format_get_extensions ((GdkPixbufFormat*) data);

Oh, another thing I think we should do is checking gdk_pixbuf_format_is_writable() before using it for the later checks.
Comment 15 Shih-Yuan Lee (FourDollars) 2012-08-29 02:42:39 UTC
"tEXt::Software" will make some formats failed to save, so I remove it from my previous patch.
Comment 16 Cosimo Cecchi 2012-08-29 14:08:38 UTC
(In reply to comment #15)
> "tEXt::Software" will make some formats failed to save, so I remove it from my
> previous patch.

Okay, then we should only still set it when the format is PNG.
Comment 17 Shih-Yuan Lee (FourDollars) 2012-08-30 15:17:39 UTC
I don't know why g_strcmp0() will leak it. http://developer.gnome.org/glib/2.32/glib-String-Utility-Functions.html#g-strcmp0
Comment 18 Shih-Yuan Lee (FourDollars) 2012-08-30 15:20:49 UTC
Created attachment 222948 [details] [review]
Determine image format by extension instead of a fixed PNG format.

I have revised my patch.
Please help to review it.
Any feedback is welcome, thanks.
Comment 19 Cosimo Cecchi 2012-08-30 15:22:14 UTC
(In reply to comment #17)
> I don't know why g_strcmp0() will leak it.
> http://developer.gnome.org/glib/2.32/glib-String-Utility-Functions.html#g-strcmp0

It's not g_strcmp0() that's leaking the string directly...you are doing

+    if (g_strcmp0 (*ptr, *format) == 0) {
+      *format = gdk_pixbuf_format_get_name ((GdkPixbufFormat*) data);
+      break;
+    }

That assigns a duplicated string to the memory location pointed to by gchar **format, which is the same pointer you pass here

+  g_slist_foreach (formats, find_format_from_extension, (gpointer) &extension);

But then you never call g_free() on extension.
Comment 20 Cosimo Cecchi 2012-08-30 19:07:21 UTC
Review of attachment 222948 [details] [review]:

::: src/screenshot-application.c
@@ +219,3 @@
+        {
+          *name = gdk_pixbuf_format_get_name (format);
+  gchar          **ptr        = extensions;

Still has the leak I pointed out in the previous comment

@@ +242,3 @@
+    extension = "png";
+  else
+    extension++;

You didn't address most of the comments I had about this part of the code in my review in comment #13.

@@ +265,3 @@
   if (self->priv->icc_profile_base64 != NULL)
+    {
+      if (g_strcmp0 (extension, "png") == 0)

I don't like the fact that we end up calling this function in 4 different blocks, but since we don't have any API In GdkPixbuf for non-varargs saving to stream I don't see any way around this unfortunately; also, the color profile is only supported by the PNG and TIFF backends in GdkPixbuf.

It would still be simpler (and more robust) to reverse the checks and do something like (pseudo-code)

if (is_png)
  {
    if (has_profile)
      save_with_description_and_profile()
    else
      save_with_description()
  }
else
  {
    save_with_no_profile_or_description()
  }
Comment 21 Shih-Yuan Lee (FourDollars) 2012-09-04 15:18:27 UTC
Created attachment 223435 [details] [review]
Determine image format by extension instead of a fixed PNG format.

I have revised my patch.
Please help to review it.
Any feedback is welcome, thanks.
Comment 22 Shih-Yuan Lee (FourDollars) 2012-09-04 15:30:04 UTC
Created attachment 223437 [details] [review]
Determine image format by extension instead of a fixed PNG format.

Sorry, I do a little modification.
Please help to review this patch.
Any feedback is welcome, thanks.
Comment 23 Cosimo Cecchi 2012-09-04 18:00:44 UTC
Review of attachment 223437 [details] [review]:

Thanks for the updated patch, looks better. I opened (with patches) bug 683063 for the non-varargs version of save_to_stream that would make this patch easier.
I have additional comments below:

::: src/screenshot-application.c
@@ +353,3 @@
+    {
+      if (has_profile (self))
+        save_with_profile (self, os, format);

As I explained in a previous comment, setting icc-profile won't work generically for all formats (even if gdk-pixbuf gained support for this in JPEG just yesterday).
We would also probably need API in GdkPixbuf to find out whether a specific format supports a given option.

In the meantime, my suggestion is to do one of these:
- change find_out_writable_format_by_extension() to also return a should_save_profile gboolean (which also takes into account whether self->priv->icc_profile_base64 is not NULL) - you'll need to move the list iteration inside the function for this
- such a boolean flag should be TRUE for the "tiff", "jpeg" and "png" formats
- in order for that to work on JPEGs we need to bump the required gdk-pixbuf version to git master (2.26.4)

or

- just call save_with_no_profile_or_description() if the image is not PNG for now, and leave everything else unchanged (probably the easiest)
Comment 24 Shih-Yuan Lee (FourDollars) 2012-09-05 01:18:55 UTC
Created attachment 223489 [details] [review]
Determine image format by extension instead of a fixed PNG format.

I suggest to choose the easier one, and polish it later.
Comment 25 Shih-Yuan Lee (FourDollars) 2012-09-05 10:50:24 UTC
Please help to review the patch in Comment 24.
Any feedback is welcome, thanks.
Comment 26 Cosimo Cecchi 2012-09-05 12:47:03 UTC
Review of attachment 223489 [details] [review]:

Thanks! This looks good to commit once we exit the feature freeze and branch for 3.6.
Comment 27 Shih-Yuan Lee (FourDollars) 2012-09-05 14:43:45 UTC
Thanks a lot. :)
Comment 28 Shih-Yuan Lee (FourDollars) 2012-11-07 16:16:32 UTC
Hi, when will exit the feature freeze and branch for 3.6?
Comment 29 André Klapper 2012-11-07 20:21:53 UTC
In general: https://live.gnome.org/ThreePointSeven/ . We are out of hardcode freeze now, but branching is up to each maintainer.
Comment 30 Cosimo Cecchi 2012-11-07 22:15:30 UTC
Comment on attachment 223489 [details] [review]
Determine image format by extension instead of a fixed PNG format.

gnome-screenshot has branched already, this can be pushed to master now.
Comment 31 Shih-Yuan Lee (FourDollars) 2012-11-13 04:43:00 UTC
What should I do to push this commit to master?
Comment 32 André Klapper 2012-11-13 10:27:00 UTC
(In reply to comment #31)
> What should I do to push this commit to master?

Have GNOME Git commit access. If you don't have please mention, so somebody else can commit for you.
Comment 33 Cosimo Cecchi 2013-04-30 22:47:48 UTC
*** Bug 699358 has been marked as a duplicate of this bug. ***
Comment 34 Matthias Clasen 2013-04-30 23:02:32 UTC
Attachment 223489 [details] pushed as 4e03093 - Determine image format by extension instead of a fixed PNG format.
Comment 35 jdsampayo 2013-09-06 14:18:04 UTC
Hello,

I have version 3.6.1 installed and still doesn't have this feature.
Comment 36 Hubert Figuiere (:hub) 2013-09-06 14:32:23 UTC
That's because it is supposed to be in a version newer than 3.6.