12 #include <tdetempfile.h>
16 #include <webp/decode.h>
23 TDE_EXPORT
void kimgio_webp_read( TQImageIO* io )
35 if( ( qf =
dynamic_cast<TQFile*
>( io->ioDevice() ) ) ) {
37 in = fopen( TQFile::encodeName( qf->name() ),
"rb" );
40 tempf =
new KTempFile();
41 if( tempf->status() != 0 ) {
45 tempf->setAutoDelete(
true );
46 TQFile* out = tempf->file();
48 TQByteArray b( 4096 );
51 while( ( size = io->ioDevice()->readBlock( b.data(), 4096 ) ) > 0 ) {
53 if( ( out->writeBlock( b.data(), size ) ) == -1 )
break;
58 in = fopen( TQFile::encodeName( tempf->name() ),
"rb" );
70 fseek(in, 0L, SEEK_END);
71 long size = ftell(in);
72 fseek(in, 0L, SEEK_SET);
75 if ( size > SIZE_MAX ) {
83 uint8_t* compressed_image = (uint8_t*)malloc(size);
84 if( ! compressed_image ) {
92 size_t bytes_read = fread( compressed_image,
sizeof(uint8_t), size, in );
98 if ( bytes_read < size ) {
100 free( compressed_image );
107 if ( ! WebPGetInfo( compressed_image, size, &width, &height ) ) {
109 free( compressed_image );
115 if( ! image.create( width, height, 32 ) ) {
117 free( compressed_image );
122 image.setAlphaBuffer(
true);
125 uint32_t* data = (uint32_t*)image.bits();
128 #ifdef WORDS_BIGENDIAN
129 if ( ! WebPDecodeARGBInto( compressed_image, size, (uint8_t*)data, width*height*4, width*4) ) {
131 if ( ! WebPDecodeBGRAInto( compressed_image, size, (uint8_t*)data, width*height*4, width*4) ) {
134 free( compressed_image );
139 free( compressed_image );
142 io->setImage( image );