Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#6905 closed defect (fixed)

Northwood GRC driver returns incorrect alpha value in color table

Reported by: Daniel Morissette Owned by: Daniel Morissette
Priority: normal Milestone: 1.11.6
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords:
Cc: Even Rouault

Description

I was tracking down an issue with MapServer which was not rendering Northwood GRC files properly, and eventually found that the problem is that the GDAL driver returns a collor table with invalid alpha values.

The code in grcdataset.cpp assumes that alpha 0=opaque and 255=transparent instead of 0=transparent and 255=opaque as it should, so all colors in the returned color table are 100% transparent. In the end the issue is not that MapServer does not render the GRC file, it is that it renders it using transparent ink.

I am surprised that anyone has ever been able to use files read by this driver since this code has not changed in 7 years, so this issue has always been there.

Even, can you please confirm that the following patch makes sense and that I am not missing something obvious about alpha values?

Index: grcdataset.cpp
===================================================================
--- grcdataset.cpp	(revision 38717)
+++ grcdataset.cpp	(working copy)
@@ -117,9 +117,9 @@
     // load the color table and might as well to the ClassNames
     poGDS->poColorTable = new GDALColorTable();
 
-    GDALColorEntry oEntry = { 255, 255, 255, 255 };
+    GDALColorEntry oEntry = { 255, 255, 255, 0 };
     // null value = 0 is transparent
-    // alpha 255 = transparent
+    // alpha 0 = transparent
 
     poGDS->poColorTable->SetColorEntry( 0, &oEntry );
 
@@ -130,7 +130,7 @@
         oEntry.c1 = poGDS->pGrd->stClassDict->stClassifedItem[i]->r;
         oEntry.c2 = poGDS->pGrd->stClassDict->stClassifedItem[i]->g;
         oEntry.c3 = poGDS->pGrd->stClassDict->stClassifedItem[i]->b;
-        oEntry.c4 = 0;            // alpha 0 = solid
+        oEntry.c4 = 255;            // alpha 255 = solid
 
         poGDS->poColorTable->SetColorEntry( poGDS->pGrd->
                                           stClassDict->stClassifedItem[i]->

Change History (9)

comment:1 by Even Rouault, 7 years ago

Daniel, this looks good to me. (I presume most people don't use the c4 value from color tables, and/or this driver is not heavily used.)

comment:2 by Daniel Morissette, 7 years ago

Thank you for confirming this Even. I will commit the fix to trunk and also backport to the 1.11 and 2.x stable branches.

comment:3 by Daniel Morissette, 7 years ago

Cc: Even Rouault added
Owner: changed from Even Rouault to Daniel Morissette
Status: assignednew

comment:4 by Daniel Morissette, 7 years ago

Resolution: fixed
Status: newclosed

In 38721:

Fix handling of alpha values in GRC color table (fixes #6905)

comment:5 by Daniel Morissette, 7 years ago

In 38726:

Fix handling of alpha values in GRC color table (fixes #6905)

comment:6 by Daniel Morissette, 7 years ago

In 38727:

Fix handling of alpha values in GRC color table (backport, fixes #6905)

comment:7 by Daniel Morissette, 7 years ago

In 38728:

Fix handling of alpha values in GRC color table (backport, fixes #6905)

comment:8 by Daniel Morissette, 7 years ago

In 38729:

Fix handling of alpha values in GRC color table (backport, fixes #6905)

comment:9 by Daniel Morissette, 7 years ago

Fix will be part of the following GDAL releases if/when they happen: 2.3.0 (current trunk), 2.2.1, 2.1.4, 2.0.4 and 1.11.6

Note: See TracTickets for help on using tickets.