diff --git a/generators/tiff/CMakeLists.txt b/generators/tiff/CMakeLists.txt index 8c2e82fe0..599ac84ab 100644 --- a/generators/tiff/CMakeLists.txt +++ b/generators/tiff/CMakeLists.txt @@ -14,7 +14,7 @@ kde4_automoc(${okularGenerator_tiff_SRCS}) kde4_add_plugin(okularGenerator_tiff WITH_PREFIX ${okularGenerator_tiff_SRCS}) -target_link_libraries(okularGenerator_tiff okularcore ${TIFF_LIBRARIES} ${KDE4_KDEUI_LIBS} ) +target_link_libraries(okularGenerator_tiff okularcore ${TIFF_LIBRARIES} ${KDE4_KDEUI_LIBS} ${KDE4_KDEPRINT_LIBS} ) install(TARGETS okularGenerator_tiff DESTINATION ${PLUGIN_INSTALL_DIR}) diff --git a/generators/tiff/generator_tiff.cpp b/generators/tiff/generator_tiff.cpp index b0ae246ad..3eefebbd9 100644 --- a/generators/tiff/generator_tiff.cpp +++ b/generators/tiff/generator_tiff.cpp @@ -11,9 +11,11 @@ #include #include #include +#include #include #include #include +#include #include "core/page.h" #include "generator_tiff.h" @@ -330,5 +332,48 @@ void TIFFGenerator::loadPages( QVector & pagesVector, int rotatio } } +bool TIFFGenerator::print( KPrinter& printer ) +{ + uint32 width = 0; + uint32 height = 0; + + tdir_t dirs = TIFFNumberOfDirectories( d->tiff ); + + QPainter p( &printer ); + + for ( tdir_t i = 0; i < dirs; ++i ) + { + if ( !TIFFSetDirectory( d->tiff, i ) ) + continue; + + if ( TIFFGetField( d->tiff, TIFFTAG_IMAGEWIDTH, &width ) != 1 || + TIFFGetField( d->tiff, TIFFTAG_IMAGELENGTH, &height ) != 1 ) + continue; + + QImage image( width, height, QImage::Format_RGB32 ); + uint32 * data = (uint32 *)image.bits(); + + // read data + if ( TIFFReadRGBAImageOriented( d->tiff, width, height, data, ORIENTATION_TOPLEFT ) != 0 ) + { + // an image read by ReadRGBAImage is ABGR, we need ARGB, so swap red and blue + uint32 size = width * height; + for ( uint32 i = 0; i < size; ++i ) + { + uint32 red = ( data[i] & 0x00FF0000 ) >> 16; + uint32 blue = ( data[i] & 0x000000FF ) << 16; + data[i] = ( data[i] & 0xFF00FF00 ) + red + blue; + } + } + + if ( i != 0 ) + printer.newPage(); + + p.drawImage( 0, 0, image ); + } + + return true; +} + #include "generator_tiff.moc" diff --git a/generators/tiff/generator_tiff.h b/generators/tiff/generator_tiff.h index 8529be774..24b5b757d 100644 --- a/generators/tiff/generator_tiff.h +++ b/generators/tiff/generator_tiff.h @@ -31,6 +31,8 @@ class TIFFGenerator : public Okular::Generator bool supportsRotation() const { return true; }; + bool print( KPrinter& printer ); + private slots: void slotThreadFinished();