Opened 15 years ago

Closed 15 years ago

#2959 closed defect (fixed)

Some 11/16 bit JPEG2000 encoded NITF files fail to read imagery

Reported by: warmerdam Owned by: warmerdam
Priority: normal Milestone: 1.7.0
Component: GDAL_Raster Version: unspecified
Severity: normal Keywords: NITF
Cc: ysiddiqui

Description

gdal_translate 08OCT28162657-M1BS-052112935010_01_P004.NTF -srcwin 0 0 1000 1000 out.tif --debug off
Warning 1: Image with 11 bits per sample will not be interpreted properly.
Input file contains subdatasets. Please, select one of them for reading.

This occurs with an image that is JPEG2000 encoded with 11bits of dynamic range but encoded as a 16bit JPEG2000 data stream.

Change History (3)

comment:1 by warmerdam, 15 years ago

Status: newassigned

The problem appears to be related to this part of nitfimage.c which sets the BitsPerPixel to match the ABPP (Apparent Bits Per Pixel) from the header:

/* -------------------------------------------------------------------- */
/*      Some files (ie NSIF datasets) have truncated image              */
/*      headers.  This has been observed with jpeg compressed           */
/*      files.  In this case guess reasonable values for these          */
/*      fields.                                                         */
/* -------------------------------------------------------------------- */
    if( nOffset + 40 > psSegInfo->nSegmentHeaderSize )
    {
        psImage->chIMODE = 'B';
        psImage->nBlocksPerRow = 1;
        psImage->nBlocksPerColumn = 1;
        psImage->nBlockWidth = psImage->nCols;
        psImage->nBlockHeight = psImage->nRows;
        psImage->nBitsPerSample = psImage->nABPP;
        psImage->nIDLVL = 0;
        psImage->nIALVL = 0;
        psImage->nILOCRow = 0;
        psImage->nILOCColumn = 0;
        psImage->szIMAG[0] = '\0';

        nOffset += 40;
    }

A work around would be to just reset the BitsPerPixel based on the underlying JPEG2000 datastream in nitfdataset.cpp when jpeg2000 (or jpeg?) images are used. But first I will investigate if the header is really missing the fields in question.

comment:2 by warmerdam, 15 years ago

I stand corrected, things were not falling into the above code at all. Both the ABPP and NBPP fields are set to 11 in this file. This is (arguably) accurate so we just need to adjust the error handling in the JPEG2000 case in nitfdataset.cpp.

comment:3 by warmerdam, 15 years ago

Milestone: 1.7.0
Resolution: fixed
Status: assignedclosed

Garr,

I was quite confused ... it turns out the warning was not related to the failure of gdal_translate which was due to subdatasets as mentioned in the second line of output from the command. That can be avoided by referencing a specific subdataset.

The warning was only advisory and not interfering with actual processing. I have applied a fix in trunk (r16832) to avoid this warning for jpeg and jpeg2000 encoded images. Since the issue is not very serious, I'll skip propagating to 1.6 branch.

Note: See TracTickets for help on using tickets.