Index: frmts/nitf/nitfimage.c
===================================================================
--- frmts/nitf/nitfimage.c	(révision 11867)
+++ frmts/nitf/nitfimage.c	(copie de travail)
@@ -44,6 +44,8 @@
 #endif
 
 static void NITFLoadLocationTable( NITFImage *psImage );
+static void NITFLoadColormapSubSection( NITFImage *psImage );
+static void NITFLoadSubframeMaskTable( NITFImage *psImage );
 static int NITFLoadVQTables( NITFImage *psImage );
 
 void NITFGetGCP ( const char* pachCoord, GDAL_GCP *psIGEOLOGCPs, int iCoord );
@@ -524,6 +526,10 @@
 /*      Is there a location table to load?                              */
 /* -------------------------------------------------------------------- */
     NITFLoadLocationTable( psImage );
+    
+    /* Fix bug #1744 */
+    if (psImage->nBands == 1)
+        NITFLoadColormapSubSection ( psImage );
 
 /* -------------------------------------------------------------------- */
 /*      Setup some image access values.  Some of these may not apply    */
@@ -596,6 +602,9 @@
 
         for( i=0; i < psImage->nBlocksPerRow * psImage->nBlocksPerColumn; i++ )
             psImage->panBlockStart[i] = nLocBase + 6144 * i;
+        
+        /* Fix bug #913 */
+        NITFLoadSubframeMaskTable ( psImage );
     }
 
 /* -------------------------------------------------------------------- */
@@ -2088,8 +2097,224 @@
     return TRUE;
 }
 
+/************************************************************************/
+/*                       NITFLoadColormapSubSection()                   */
+/************************************************************************/
 
+/* This function is directly inspired by function parse_clut coming from ogdi/driver/rpf/utils.c
+   and placed under the following copyright */
+
+/*
+ ******************************************************************************
+ * Copyright (C) 1995 Logiciels et Applications Scientifiques (L.A.S.) Inc
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies, that
+ * both the copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of L.A.S. Inc not be used 
+ * in advertising or publicity pertaining to distribution of the software 
+ * without specific, written prior permission. L.A.S. Inc. makes no
+ * representations about the suitability of this software for any purpose.
+ * It is provided "as is" without express or implied warranty.
+ ******************************************************************************
+ */
+
+
+static void NITFLoadColormapSubSection( NITFImage *psImage )
+{
+    int nLocBaseColorGrayscaleSection = 0;
+    int nLocBaseColormapSubSection = 0;
+    int colorGrayscaleSectionSize = 0;
+    int colormapSubSectionSize = 0;
+    NITFFile *psFile = psImage->psFile;
+    int i, j;
+    unsigned char nOffsetRecs;
+    NITFColormapRecord* colormapRecords;
+    unsigned int colormapOffsetTableOffset;
+    unsigned short offsetRecLen;
+    
+    NITFBandInfo *psBandInfo = psImage->pasBandInfo;
+  
+    for( i = 0; i < psImage->nLocCount; i++ )
+    {
+        if( psImage->pasLocations[i].nLocId == LID_ColorGrayscaleSectionSubheader )
+        {
+            nLocBaseColorGrayscaleSection = psImage->pasLocations[i].nLocOffset;
+            colorGrayscaleSectionSize = psImage->pasLocations[i].nLocSize;
+        }
+        else if( psImage->pasLocations[i].nLocId == LID_ColormapSubsection )
+        {
+            nLocBaseColormapSubSection = psImage->pasLocations[i].nLocOffset;
+            colormapSubSectionSize = psImage->pasLocations[i].nLocSize;
+        }
+    }
+    if (nLocBaseColorGrayscaleSection == 0)
+    {
+        //fprintf(stderr, "nLocBaseColorGrayscaleSection == 0\n");
+        return;
+    }
+    if (nLocBaseColormapSubSection == 0)
+    {
+        //fprintf(stderr, "nLocBaseColormapSubSection == 0\n");
+        return;
+    }
+    
+    if( VSIFSeekL( psFile->fp, nLocBaseColorGrayscaleSection, 
+                  SEEK_SET ) != 0 )
+    {
+        CPLError( CE_Failure, CPLE_FileIO, 
+                  "Failed to seek to %d.",
+                  nLocBaseColorGrayscaleSection );
+        return;
+    }
+    
+    
+    VSIFReadL( &nOffsetRecs, 1, 1, psFile->fp );
+    
+    if( VSIFSeekL( psFile->fp, nLocBaseColormapSubSection, 
+                  SEEK_SET ) != 0  )
+    {
+        CPLError( CE_Failure, CPLE_FileIO, 
+                  "Failed to seek to %d.",
+                  nLocBaseColormapSubSection );
+        return;
+    }
+    
+    colormapRecords = (NITFColormapRecord*)CPLMalloc(nOffsetRecs * sizeof(NITFColormapRecord));
+
+     /* colormap offset table offset length */
+    VSIFReadL( &colormapOffsetTableOffset, 1, sizeof(colormapOffsetTableOffset),  psFile->fp );
+    CPL_MSBPTR32( &colormapOffsetTableOffset );
+
+     /* offset record length */
+    VSIFReadL( &offsetRecLen, 1, sizeof(offsetRecLen),  psFile->fp );
+    CPL_MSBPTR16( &offsetRecLen );
+    
+    for (i = 0; i < nOffsetRecs; i++)
+    {
+        VSIFReadL( &colormapRecords[i].tableId, 1, sizeof(colormapRecords[i].tableId),  psFile->fp );
+        CPL_MSBPTR16( &colormapRecords[i].tableId );
+        
+        VSIFReadL( &colormapRecords[i].nRecords, 1, sizeof(colormapRecords[i].nRecords),  psFile->fp );
+        CPL_MSBPTR32( &colormapRecords[i].nRecords );
+        
+        VSIFReadL( &colormapRecords[i].elementLength, 1, sizeof(colormapRecords[i].elementLength),  psFile->fp );
+    
+        VSIFReadL( &colormapRecords[i].histogramRecordLength, 1, sizeof(colormapRecords[i].histogramRecordLength),  psFile->fp );
+        CPL_MSBPTR16( &colormapRecords[i].histogramRecordLength );
+    
+        VSIFReadL( &colormapRecords[i].colorTableOffset, 1, sizeof(colormapRecords[i].colorTableOffset),  psFile->fp );
+        CPL_MSBPTR32( &colormapRecords[i].colorTableOffset );
+    
+        VSIFReadL( &colormapRecords[i].histogramTableOffset, 1, sizeof(colormapRecords[i].histogramTableOffset),  psFile->fp );
+        CPL_MSBPTR32( &colormapRecords[i].histogramTableOffset );
+    }
+    
+    for (i=0; i<nOffsetRecs; i++)
+    {
+        if( VSIFSeekL( psFile->fp, nLocBaseColormapSubSection + colormapRecords[i].colorTableOffset, 
+                    SEEK_SET ) != 0  )
+        {
+            CPLError( CE_Failure, CPLE_FileIO, 
+                    "Failed to seek to %d.",
+                    nLocBaseColormapSubSection + colormapRecords[i].colorTableOffset );
+            return;
+        }
+        
+        /* This test is very CADRG specific. See MIL-C-89038, paragraph 3.12.5.a */
+        if (i == 0 &&
+            colormapRecords[i].tableId == 2 &&
+            colormapRecords[i].elementLength == 4 &&
+            colormapRecords[i].nRecords == 216)   /* read, use colortable */
+        {
+            for (j = 0; j < colormapRecords[i].nRecords; j++)
+            {
+                unsigned char r, g, b, m;
+                VSIFReadL(&r, 1, 1, psFile->fp);
+                VSIFReadL(&g, 1, 1, psFile->fp);
+                VSIFReadL(&b, 1, 1, psFile->fp);
+                VSIFReadL(&m, 1, 1, psFile->fp);
+                psBandInfo->pabyLUT[j] = r;
+                psBandInfo->pabyLUT[j+256] = g;
+                psBandInfo->pabyLUT[j+512] = b;
+            }
+        }
+    } 
+
+    CPLFree(colormapRecords);
+}
+
+
 /************************************************************************/
+/*                       NITFLoadSubframeMaskTable()                        */
+/************************************************************************/
+
+static void NITFLoadSubframeMaskTable( NITFImage *psImage )
+{
+    int i;
+    NITFFile *psFile = psImage->psFile;
+    NITFSegmentInfo *psSegInfo = psFile->pasSegmentInfo + psImage->iSegment;
+    GUInt32  nLocBaseSpatialDataSubsection = psSegInfo->nSegmentStart;
+    GUInt32  nLocBaseMaskSubsection = 0;
+    GUInt16 subframeSequenceRecordLength, transparencySequenceRecordLength, transparencyOutputPixelCodeLength;
+
+    for( i = 0; i < psImage->nLocCount; i++ )
+    {
+        if( psImage->pasLocations[i].nLocId == LID_SpatialDataSubsection )
+        {
+            nLocBaseSpatialDataSubsection = psImage->pasLocations[i].nLocOffset;
+        }
+        else if( psImage->pasLocations[i].nLocId == LID_MaskSubsection )
+        {
+            nLocBaseMaskSubsection = psImage->pasLocations[i].nLocOffset;
+        }
+    }
+    if (nLocBaseMaskSubsection == 0)
+    {
+        //fprintf(stderr, "nLocBase(LID_MaskSubsection) == 0\n");
+        return;
+    }
+    
+    //fprintf(stderr, "nLocBaseMaskSubsection = %d\n", nLocBaseMaskSubsection);
+    if( VSIFSeekL( psFile->fp, nLocBaseMaskSubsection, 
+                    SEEK_SET ) != 0  )
+    {
+        CPLError( CE_Failure, CPLE_FileIO, 
+                "Failed to seek to %d.",
+                nLocBaseMaskSubsection );
+        return;
+    }
+    
+    VSIFReadL( &subframeSequenceRecordLength, 1, sizeof(subframeSequenceRecordLength),  psFile->fp );
+    CPL_MSBPTR16( &subframeSequenceRecordLength );
+    
+    VSIFReadL( &transparencySequenceRecordLength, 1, sizeof(transparencySequenceRecordLength),  psFile->fp );
+    CPL_MSBPTR16( &transparencySequenceRecordLength );
+    
+    /* in bits */
+    VSIFReadL( &transparencyOutputPixelCodeLength, 1, sizeof(transparencyOutputPixelCodeLength),  psFile->fp );
+    CPL_MSBPTR16( &transparencyOutputPixelCodeLength );
+    
+    for (i=0; i < transparencyOutputPixelCodeLength / 8; i++)
+    {
+        unsigned char ignored;
+        VSIFReadL( &ignored, 1, sizeof(ignored),  psFile->fp );
+    }
+
+    for( i=0; i < psImage->nBlocksPerRow * psImage->nBlocksPerColumn; i++ )
+    {
+        unsigned int offset;
+        VSIFReadL( &offset, 1, sizeof(offset),  psFile->fp );
+        CPL_MSBPTR32( &offset );
+        //fprintf(stderr, "%d : %d\n", i, offset);
+        if (offset == 0xffffffff)
+            psImage->panBlockStart[i] = 0xffffffff;
+        else
+            psImage->panBlockStart[i] = nLocBaseSpatialDataSubsection + offset;
+    }
+}
+
+/************************************************************************/
 /*                       NITFLoadLocationTable()                        */
 /************************************************************************/
 
Index: frmts/nitf/nitflib.h
===================================================================
--- frmts/nitf/nitflib.h	(révision 11867)
+++ frmts/nitf/nitflib.h	(copie de travail)
@@ -99,6 +99,17 @@
     int nLocSize;
 } NITFLocation;
 
+typedef struct
+{
+  unsigned short   tableId;
+  unsigned int     nRecords;
+  unsigned char    elementLength;
+  unsigned short   histogramRecordLength;
+  unsigned int     colorTableOffset;
+  unsigned int     histogramTableOffset;
+} NITFColormapRecord;
+
+
 typedef struct {
     NITFFile  *psFile;
     int        iSegment;

