AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
August 2007

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2007.08.07 14:41 "Indexed Images", by Christian Henning
2007.08.07 14:48 "Re: Indexed Images", by Toby Thain
2007.08.07 15:23 "Re: Indexed Images", by Frank Warmerdam
2007.08.07 15:41 "Re: Indexed Images", by Toby Thain
2007.08.07 14:57 "Re: Indexed Images", by Christian Henning

2007.08.07 15:41 "Re: Indexed Images", by Toby Thain

On 7-Aug-07, at 12:23 PM, Frank Warmerdam wrote:

> Christian Henning wrote:
>> Hi there, I'm trying to write a 4-bit indexed image using libtiff
>> 3.8.2 on a Windows machine. For some reasons writing the color map
>> always crashes and I have no idea why. Here is my code, it's very
>> straight forward:
>> int main()
>> {
>>    tsize_t width  = 100;
>>    tsize_t height = 100;
>>    tsize_t bits_per_sample = 4;
>>    tsize_t samples_per_pixel = 1;
>>    tsize_t image_size_in_bytes = ( width * height ) / 2;
>>    tsize_t palette_size = 16 * 3;
>>    TIFF* file = TIFFOpen( "palette.tif", "w" );
>>    TIFFSetField( file, TIFFTAG_IMAGEWIDTH     ,  
>> width               );
>>    TIFFSetField( file, TIFFTAG_IMAGELENGTH    ,  
>> height              );
>>    TIFFSetField( file, TIFFTAG_BITSPERSAMPLE  ,  
>> bits_per_sample     );
>>    TIFFSetField( file, TIFFTAG_SAMPLESPERPIXEL,  
>> samples_per_pixel   );
>>    TIFFSetField( file, TIFFTAG_ROWSPERSTRIP   ,  
>> height              );
>>    std::vector< short > palette( palette_size );
>>    std::fill( palette.begin(), palette.end(), 0 );
>>    TIFFSetField( file, TIFFTAG_COLORMAP, &palette.front() );
>>    std::vector< unsigned char > image( image_size_in_bytes );
>>    std::fill( image.begin(), image.end(), 0 );
>>    TIFFWriteEncodedStrip( file
>>                         , 0
>>                         , &image.front()
>>                         , image_size_in_bytes );
>>    TIFFClose( file );
>> }
>> Can anyone tell me why the line
>> TIFFSetField( file, TIFFTAG_COLORMAP, &palette.front() );
>> always crashes?
>
> Christian,
>
> Because TIFFSetField() expects three short arrays as an argument for
> key TIFFTAG_COLORMAP. (red, green and blue portions of the palette).
>
> Contrary to what Toby says, I'm fairly confident that taking the  
> address
> of the reference returned by palette.front() should work.

Disclaimer: I'm much more familiar with C than C++, but why would  
taking the address of the vector.front() element have the meaning as  
taking &array[0]? Or should I just RTFM? :-)

--Toby

>   Oddly, I
> setup some similar code just last night using std::vector<> for TIFF
> palettes.  A simple example of passing three short arrays looks like
> this:
>
>         TIFFSetField( hTIFF, TIFFTAG_COLORMAP, anTRed, anTGreen,  
> anTBlue );
>
> Best regards,
> -- 
> --------------------------------------- 
> +--------------------------------------
> I set the clouds in motion - turn up   | Frank Warmerdam,  
> warmerdam@pobox.com
> light and sound - activate the windows | http://pobox.com/~warmerdam
> and watch the world go round - Rush    | President OSGeo, http:// 
> osgeo.org
>
> _______________________________________________
> Tiff mailing list: Tiff@lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/tiff
> http://www.remotesensing.org/libtiff/