Changeset 11848

Show
Ignore:
Timestamp:
08/07/07 02:29:31 (1 year ago)
Author:
warmerdam
Message:

avoid allocating 64K entry color tables on stack (#1736)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/gtiff/geotiff.cpp

    r11843 r11848  
    20442044/*      Do we have a palette?  If so, create a TIFF compatible version. */ 
    20452045/* -------------------------------------------------------------------- */ 
    2046     unsigned short     anTRed[65536], anTGreen[65536], anTBlue[65536]
     2046    std::vector<unsigned short> anTRed, anTGreen, anTBlue
    20472047    unsigned short      *panRed=NULL, *panGreen=NULL, *panBlue=NULL; 
    20482048 
     
    20552055        else 
    20562056            nColors = 65536; 
     2057         
     2058        anTRed.resize(nColors,0); 
     2059        anTGreen.resize(nColors,0); 
     2060        anTBlue.resize(nColors,0); 
    20572061         
    20582062        for( int iColor = 0; iColor < nColors; iColor++ ) 
     
    20742078        } 
    20752079 
    2076         panRed = anTRed
    2077         panGreen = anTGreen
    2078         panBlue = anTBlue
     2080        panRed = &(anTRed[0])
     2081        panGreen = &(anTGreen[0])
     2082        panBlue = &(anTBlue[0])
    20792083    } 
    20802084         
     
    41044108             && eType == GDT_UInt16 ) 
    41054109    { 
    4106         unsigned short  anTRed[65536], anTGreen[65536], anTBlue[65536]
     4110        unsigned short  *panTRed, *panTGreen, *panTBlue
    41074111        GDALColorTable *poCT; 
     4112 
     4113        panTRed   = (unsigned short *) CPLMalloc(65536*sizeof(unsigned short)); 
     4114        panTGreen = (unsigned short *) CPLMalloc(65536*sizeof(unsigned short)); 
     4115        panTBlue  = (unsigned short *) CPLMalloc(65536*sizeof(unsigned short)); 
    41084116 
    41094117        poCT = poSrcDS->GetRasterBand(1)->GetColorTable(); 
     
    41174125                poCT->GetColorEntryAsRGB( iColor, &sRGB ); 
    41184126 
    4119                 anTRed[iColor] = (unsigned short) (256 * sRGB.c1); 
    4120                 anTGreen[iColor] = (unsigned short) (256 * sRGB.c2); 
    4121                 anTBlue[iColor] = (unsigned short) (256 * sRGB.c3); 
     4127                panTRed[iColor] = (unsigned short) (256 * sRGB.c1); 
     4128                panTGreen[iColor] = (unsigned short) (256 * sRGB.c2); 
     4129                panTBlue[iColor] = (unsigned short) (256 * sRGB.c3); 
    41224130            } 
    41234131            else 
    41244132            { 
    4125                 anTRed[iColor] = anTGreen[iColor] = anTBlue[iColor] = 0; 
     4133                panTRed[iColor] = panTGreen[iColor] = panTBlue[iColor] = 0; 
    41264134            } 
    41274135        } 
     
    41294137        if( !bForcePhotometric ) 
    41304138            TIFFSetField( hTIFF, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE ); 
    4131         TIFFSetField( hTIFF, TIFFTAG_COLORMAP, anTRed, anTGreen, anTBlue ); 
     4139        TIFFSetField( hTIFF, TIFFTAG_COLORMAP, panTRed, panTGreen, panTBlue ); 
     4140 
     4141        CPLFree( panTRed ); 
     4142        CPLFree( panTGreen ); 
     4143        CPLFree( panTBlue ); 
    41324144    } 
    41334145    else if( poSrcDS->GetRasterBand(1)->GetColorTable() != NULL )