Opening TGA files reports Could not open file file.tga

Bug #987641 reported by grofaty
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Pinta
Fix Released
High
Cameron White

Bug Description

Pinta latest development on Ubuntu 11.10:
1. Open Pinta.
2. Draw something e.g. with Paintbrush tool.
3. File | Save As.
4. In Name filed type in: test
5. From file type drop-down box select: "TGA image" and click Save button.
6. File | Close.
7. File | Open.
8. "Open Image File" dialog opens, selecting a test.tga file and click on Open error is displayed:
Could not open file: /home/[myuser_name]/Pictures/test.tga.

I have tested this on Pinta 1.2 on Windows and TGA files can be normally saved and opened. I have also copied TGA file witch was created by above procedure on Ubuntu and can be normally opened on Pinta 1.2 on Windows. So it looks like Ubuntu specific problem or some regression in development version.

Revision history for this message
Cameron White (cameronwhite91) wrote :

Confirmed on Ubuntu 11.10, both with Pinta 1.2 and latest development version.

Changed in pinta:
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Cameron White (cameronwhite91) wrote :

I did a bit of investigation, here's the exception's stack trace:

GLib.GException: Icon has zero width
  at Gdk.PixbufLoader.Write (System.Byte[] buf, UInt64 count) [0x00000] in <filename unknown>:0
  at Gdk.PixbufLoader.Write (System.Byte[] bytes, UInt32 count) [0x00000] in <filename unknown>:0
  at Gdk.PixbufLoader.LoadFromStream (System.IO.Stream input) [0x00000] in <filename unknown>:0
  at Gdk.PixbufLoader.InitFromStream (System.IO.Stream stream) [0x00000] in <filename unknown>:0
  at Gdk.PixbufLoader..ctor (System.IO.Stream stream) [0x00000] in <filename unknown>:0
  at Gdk.Pixbuf..ctor (System.IO.Stream stream) [0x00000] in <filename unknown>:0
  at Pinta.Core.GdkPixbufFormat.Import (System.String fileName) [0x00009] in /home/cameron/code/Pinta/Pinta.Core/ImageFormats/GdkPixbufFormat.cs:49
  at Pinta.Core.WorkspaceManager.OpenFile (System.String file) [0x00013] in /home/cameron/code/Pinta/Pinta.Core/Managers/WorkspaceManager.cs:181

Revision history for this message
Robert Nordan (rpvn) wrote :

Extremely strange, I went digging in the gdk-pixbuf source code again and only found that error in the loader for ICO files. ( http://git.gnome.org/browse/gdk-pixbuf/tree/gdk-pixbuf/io-ico.c#n354 ) I couldn't find it in the loader for TGA files.

So, for some reason we're trying to load tga files as icos on Ubuntu, but correctly loading as tga files on Windows? I notice that Pinta has it's own TGA exporter ported from Paint.Net, but relies on GDKPixBuf for importing. (GdkPixBuf only has TGA import, not export it seems.)

This is a possible theory: I think I found the GDK code that identifies the kind of file being loaded: http://git.gnome.org/browse/gdk-pixbuf/tree/gdk-pixbuf/gdk-pixbuf-io.c#n891

It has some ifdefs in the code, so if the Windows and Linux versions are compiled with different flags (One is compiled with GDK_PIXBUF_USE_GIO_MIME and the other isn't) that might account for that one detects our file as tga and the other as ico. But I'm not sure yet if GDK_PIXBUF_USE_GIO_MIME gives the right answer for us or not.

Either way, I think that this is either a bug in GDK, the flags used to compile GDK on major Linux distros, or possibly our TGA exporter if it sets some header that is only understood in a Windows context. (It s after all ported from a Windows product.)

Revision history for this message
Robert Nordan (rpvn) wrote :

Ok, according to to the manual for the GIO library that GDK uses to decide on file type when GDK_PIXBUF_USE_GIO_MIME is enabled (http://developer.gnome.org/gio/2.26/gio-GContentType.html#gio-GContentType.synopsis), has a platform-dependent way of doing it. So it could vary depending on platforms even with the same flags.

But wait, there's more! I did the obvious thing and checked if Eye Of Gnome could open the file, and it could. Since it should be using the same GDK, that's curious. It could possibly be a bug in gdk-sharp, the GDK binding we use.

If I open a terminal and run "file --mime-type test1.tga" it returns application/octet-stream instead of the expected (in GDK) image/x-tga, while pngs and jpegs get image/png and image/jpeg. There could be something there as well.

Lots of possible reasons so far! :P

Revision history for this message
grofaty (grofaty) wrote :

Maybe you should look for solution upstream, maybe report bug or something.

Revision history for this message
Cameron White (cameronwhite91) wrote :

I did a bit more digging into this issue: when GDK tries to identify the mime type (http://git.gnome.org/browse/gdk-pixbuf/tree/gdk-pixbuf/gdk-pixbuf-io.c#n891), it somehow decides that TGA files created by Pinta have the mime type image/x-win-bitmap.

I tried other TGA files (such as from http://www.fileformat.info/format/tga/sample/index.htm) and Pinta was able to open them without any issue, and they are correctly identified as image/x-tga.

I think the issue happens because GDK looks at the file contents before the file extension, and the file contents generated by Pinta happen to look a lot like an ICO file. In particular, the first few bytes of Pinta's TGA files are the same as the expected first few bytes of an ICO file (see http://en.wikipedia.org/wiki/ICO_(file_format)).

A possible fix is to have a non-empty image ID field (http://en.wikipedia.org/wiki/Truevision_TGA#Header), with contents such as "Created by Pinta", since that would make the first byte non-zero. It's a bit of a hack, but I verified that it causes the file to be properly opened by Pinta. Thoughts?

Revision history for this message
Cameron White (cameronwhite91) wrote :

Here's a patch for the above comment

Revision history for this message
Robert Nordan (rpvn) wrote : Re: [Bug 987641] Re: Opening TGA files reports Could not open file file.tga

Well, since it seems to be allowed by the TGA spec I'd say go for it! ;-)
On Sep 8, 2012 8:20 AM, "Cameron White" <email address hidden> wrote:

> Here's a patch for the above comment
>
> ** Patch added: "tga.patch"
>
> https://bugs.launchpad.net/pinta/+bug/987641/+attachment/3300239/+files/tga.patch
>
> --
> You received this bug notification because you are a member of Pinta
> Maintainers, which is subscribed to Pinta.
> https://bugs.launchpad.net/bugs/987641
>
> Title:
> Opening TGA files reports Could not open file file.tga
>
> Status in Pinta:
> Confirmed
>
> Bug description:
> Pinta latest development on Ubuntu 11.10:
> 1. Open Pinta.
> 2. Draw something e.g. with Paintbrush tool.
> 3. File | Save As.
> 4. In Name filed type in: test
> 5. From file type drop-down box select: "TGA image" and click Save
> button.
> 6. File | Close.
> 7. File | Open.
> 8. "Open Image File" dialog opens, selecting a test.tga file and click
> on Open error is displayed:
> Could not open file: /home/[myuser_name]/Pictures/test.tga.
>
> I have tested this on Pinta 1.2 on Windows and TGA files can be
> normally saved and opened. I have also copied TGA file witch was
> created by above procedure on Ubuntu and can be normally opened on
> Pinta 1.2 on Windows. So it looks like Ubuntu specific problem or some
> regression in development version.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/pinta/+bug/987641/+subscriptions
>

Revision history for this message
grofaty (grofaty) wrote :

If I understand correctly THE problem is that Pinta saves tga file type in such a way that Pinta (on Ubuntu) can't recognize file type when opening the file it saves by itself.

I am for the hack if this generated file can be opened with other editing/viewing applications like e.g. Gimp. It probably should because this is allowed by tga file.

So this would fix the MAIN problem, opening file that was generated by Pinta application. On the other hand there may be some other program that generated the tga file in the same way as currently Pinta does, in this situation (don't know if such an application even exists) we will have a problem opening such a file again - so hack will not work.

In my humble opinion it is currently dramatically more important that Pinta can open tga file that has generated by itself then any other hypothetical application that would generated the same structured file type - so I vote for a hack.

Revision history for this message
Cameron White (cameronwhite91) wrote :
Changed in pinta:
assignee: nobody → Cameron White (cameronwhite91)
milestone: none → 1.4
status: Confirmed → Fix Committed
Revision history for this message
grofaty (grofaty) wrote :

Tested latest development on Ubuntu 12.04 and I can confirm this bug is fixed. Thanks.

grofaty (grofaty)
Changed in pinta:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.