Package: openjpeg-tools
Version: 1:1.5.2-3
Tags: patch

The TGA file writer used by j2k_to_image writes a wrong field to the
header for alpha-less images.

To reproduce:
1. Take any 24-bit j2k image with no alpha.
2. Convert it to TGA with j2k_to_image -i <image>.j2k -o <image>.tga
3. Open <image>.tga with Gimp.

When opened, the image will have a wrong alpha channel, because Gimp
uses a certain field in the header to determine if the image has alpha.
That field is saved wrongly by j2k_to_image for alpha-less images. Per
the TGA specification, Gimp is correct in this case.

The attached patch fixes this issue.
--- openjpeg-1.5.2/applications/codec/convert.c.orig	2014-03-27 11:58:06.000000000 +0100
+++ openjpeg-1.5.2/applications/codec/convert.c	2015-02-11 00:12:10.000000000 +0100
@@ -243,7 +243,10 @@
 
 	if(fwrite(&pixel_depth, 1, 1, fp) != 1) goto fails;
 
-	image_desc = 8; /* 8 bits per component. */
+	tga.image_desc = // bits 0-3 are # of alpha bits per pixel
+		bits_per_pixel == 16 ? 1 :
+		bits_per_pixel == 32 ? 8 :
+		0;
 
 	if (flip_image)
 		image_desc |= 32;

Reply via email to