Changeset 11849

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

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

Files:

Legend:

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

    r11821 r11849  
    19561956/*      Do we have a palette?  If so, create a TIFF compatible version. */ 
    19571957/* -------------------------------------------------------------------- */ 
    1958     unsigned short     anTRed[65536], anTGreen[65536], anTBlue[65536]
     1958    std::vector<unsigned short> anTRed, anTGreen, anTBlue
    19591959    unsigned short      *panRed=NULL, *panGreen=NULL, *panBlue=NULL; 
    19601960 
     
    19671967        else 
    19681968            nColors = 65536; 
     1969         
     1970        anTRed.resize(nColors,0); 
     1971        anTGreen.resize(nColors,0); 
     1972        anTBlue.resize(nColors,0); 
    19691973         
    19701974        for( int iColor = 0; iColor < nColors; iColor++ ) 
     
    19861990        } 
    19871991 
    1988         panRed = anTRed
    1989         panGreen = anTGreen
    1990         panBlue = anTBlue
     1992        panRed = &(anTRed[0])
     1993        panGreen = &(anTGreen[0])
     1994        panBlue = &(anTBlue[0])
    19911995    } 
    19921996         
     
    38763880             && eType == GDT_UInt16 ) 
    38773881    { 
    3878         unsigned short  anTRed[65536], anTGreen[65536], anTBlue[65536]
     3882        unsigned short  *panTRed, *panTGreen, *panTBlue
    38793883        GDALColorTable *poCT; 
     3884 
     3885        panTRed   = (unsigned short *) CPLMalloc(65536*sizeof(unsigned short)); 
     3886        panTGreen = (unsigned short *) CPLMalloc(65536*sizeof(unsigned short)); 
     3887        panTBlue  = (unsigned short *) CPLMalloc(65536*sizeof(unsigned short)); 
    38803888 
    38813889        poCT = poSrcDS->GetRasterBand(1)->GetColorTable(); 
     
    38893897                poCT->GetColorEntryAsRGB( iColor, &sRGB ); 
    38903898 
    3891                 anTRed[iColor] = (unsigned short) (256 * sRGB.c1); 
    3892                 anTGreen[iColor] = (unsigned short) (256 * sRGB.c2); 
    3893                 anTBlue[iColor] = (unsigned short) (256 * sRGB.c3); 
     3899                panTRed[iColor] = (unsigned short) (256 * sRGB.c1); 
     3900                panTGreen[iColor] = (unsigned short) (256 * sRGB.c2); 
     3901                panTBlue[iColor] = (unsigned short) (256 * sRGB.c3); 
    38943902            } 
    38953903            else 
    38963904            { 
    3897                 anTRed[iColor] = anTGreen[iColor] = anTBlue[iColor] = 0; 
     3905                panTRed[iColor] = panTGreen[iColor] = panTBlue[iColor] = 0; 
    38983906            } 
    38993907        } 
     
    39013909        if( !bForcePhotometric ) 
    39023910            TIFFSetField( hTIFF, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_PALETTE ); 
    3903         TIFFSetField( hTIFF, TIFFTAG_COLORMAP, anTRed, anTGreen, anTBlue ); 
     3911        TIFFSetField( hTIFF, TIFFTAG_COLORMAP, panTRed, panTGreen, panTBlue ); 
     3912 
     3913        CPLFree( panTRed ); 
     3914        CPLFree( panTGreen ); 
     3915        CPLFree( panTBlue ); 
    39043916    } 
    39053917    else if( poSrcDS->GetRasterBand(1)->GetColorTable() != NULL )