12 #include <tdelibs_export.h>
16 #if (TIFFLIB_VERSION >= 20210416)
18 #define uint16 uint16_t
20 #define uint32 uint32_t
25 static tsize_t tiff_read( thandle_t handle, tdata_t buf, tsize_t size )
27 TQIODevice *dev =
reinterpret_cast<TQIODevice *
>( handle );
28 return dev->readBlock(
reinterpret_cast<char *
>( buf ), size );
31 static tsize_t tiff_write( thandle_t, tdata_t, tsize_t )
36 static toff_t tiff_seek( thandle_t handle, toff_t off,
int whence )
38 TQIODevice *dev =
reinterpret_cast<TQIODevice *
>( handle );
40 if ( whence == SEEK_CUR )
42 else if ( whence == SEEK_END )
45 if ( !dev->at( off ) )
51 static toff_t tiff_size( thandle_t handle )
53 TQIODevice *dev =
reinterpret_cast<TQIODevice *
>( handle );
57 static int tiff_close( thandle_t )
62 static int tiff_map( thandle_t, tdata_t *, toff_t * )
67 static void tiff_unmap( thandle_t, tdata_t, toff_t )
71 TDE_EXPORT
void kimgio_tiff_read( TQImageIO *io )
77 uint16 extra_samples_count;
78 uint16 *extra_samples;
83 tiff = TIFFClientOpen( TQFile::encodeName( io->fileName() ),
"r",
84 ( thandle_t )io->ioDevice(),
85 tiff_read, tiff_write, tiff_seek, tiff_close,
86 tiff_size, tiff_map, tiff_unmap );
93 if ((TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &width) != 1) ||
94 (TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height) != 1))
100 TQImage image( width, height, 32 );
101 if( image.isNull()) {
105 data = (uint32 *)image.bits();
112 bool stat =TIFFReadRGBAImage( tiff, width, height, data );
120 for(
unsigned i = 0; i < width * height; ++i )
122 uint32 red = ( 0x00FF0000 & data[i] ) >> 16;
123 uint32 blue = ( 0x000000FF & data[i] ) << 16;
124 data[i] &= 0xFF00FF00;
125 data[i] += red + blue;
129 for(
unsigned ctr = 0; ctr < (height>>1); ) {
130 unsigned *line1 = (
unsigned *)image.scanLine( ctr );
131 unsigned *line2 = (
unsigned *)image.scanLine( height
134 for(
unsigned x = 0; x < width; x++ ) {
146 if (TIFFGetField(tiff, TIFFTAG_EXTRASAMPLES, &extra_samples_count, &extra_samples) == 1)
148 kdDebug(399) <<
"TIFF image has " << extra_samples_count <<
" extra sample(s)." << endl;
149 for (uint16 i = 0; i < extra_samples_count; i++)
151 if ((extra_samples[i] == EXTRASAMPLE_ASSOCALPHA) ||
152 (extra_samples[i] == EXTRASAMPLE_UNASSALPHA))
154 image.setAlphaBuffer(
true);
171 io->setImage( image );
175 TDE_EXPORT
void kimgio_tiff_write( TQImageIO * )