[trunk] WIP: solve problem with writing of tga image from an image with signd=1 ...
authorMickael Savinaud <savmickael@users.noreply.github.com>
Wed, 19 Oct 2011 13:18:06 +0000 (13:18 +0000)
committerMickael Savinaud <savmickael@users.noreply.github.com>
Wed, 19 Oct 2011 13:18:06 +0000 (13:18 +0000)
CHANGES
applications/codec/convert.c

diff --git a/CHANGES b/CHANGES
index e64b5a9895f6d945f237857c691a87e7c1ba2030..b049cfa5b27da0272f2995834a8215d9555b9d8d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,7 @@ What's New for OpenJPEG
 + : added
 
 October 19, 2011
+* [mickael] WIP: solve problem with writing of tga image from an image with signd=1 (credit to Winfried)
 * [mickael] WIP: resolve some memory leak in compare functions
 
 October 12, 2011
index d9510b14d00c061c0d33238a14efd186a8ff93e6..d9ea374e4f4f250201dca4269d5a161674f9ef63 100644 (file)
@@ -389,7 +389,7 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
 int imagetotga(opj_image_t * image, const char *outfile) {
        int width, height, bpp, x, y;
        opj_bool write_alpha;
-       int i;
+       int i, adjustR, adjustG, adjustB;
        unsigned int alpha_channel;
        float r,g,b,a;
        unsigned char value;
@@ -426,15 +426,19 @@ int imagetotga(opj_image_t * image, const char *outfile) {
 
        scale = 255.0f / (float)((1<<image->comps[0].prec)-1);
 
+       adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
+       adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
+       adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
+
        for (y=0; y < height; y++) {
                unsigned int index=y*width;
 
                for (x=0; x < width; x++, index++)      {
-                       r = (float)(image->comps[0].data[index]);
+                       r = (float)(image->comps[0].data[index] + adjustR);
 
                        if (image->numcomps>2) {
-                               g = (float)(image->comps[1].data[index]);
-                               b = (float)(image->comps[2].data[index]);
+                               g = (float)(image->comps[1].data[index] + adjustG);
+                               b = (float)(image->comps[2].data[index] + adjustB);
                        }
                        else  {// Greyscale ...
                                g = r;