/* * tiffload.c - loading TIFF bitmaps */ #include "../base/mdjvucfg.h" #ifdef HAVE_LIBTIFF #include #define MDJVU_USE_TIFFIO #endif #include #include #include #ifdef HAVE_LIBTIFF static mdjvu_bitmap_t load_tiff(const char *path, int32 *presolution, mdjvu_error_t *perr, uint32 idx) { uint16 photometric; uint32 w, h; uint16 bits_per_sample = 0, samples_per_pixel = 0; float dpi; mdjvu_bitmap_t result; tsize_t scanline_size; unsigned char *scanline; uint32 i; TIFF *tiff = TIFFOpen(path, "r"); for ( i=0; tiff != NULL && i> (w & 7)); memcpy(mdjvu_bitmap_access_packed_row(result, i), scanline, mdjvu_bitmap_get_packed_row_size(result)); } free(scanline); TIFFClose(tiff); return result; } MDJVU_IMPLEMENT uint32 mdjvu_get_tiff_page_count(const char *path) { int dircount = 0; TIFF* tif = TIFFOpen(path, "r"); /* a "directory" is a page in a multipage tiff */ if ( tif ) { do { dircount++; } while ( TIFFReadDirectory(tif) ); TIFFClose(tif); } return dircount; } #endif /* HAVE_LIBTIFF */ MDJVU_IMPLEMENT mdjvu_bitmap_t mdjvu_load_tiff(const char *path, int32 *presolution, mdjvu_error_t *perr, uint32 idx) { #ifdef HAVE_LIBTIFF return load_tiff(path, presolution, perr, idx); #else *perr = mdjvu_get_error(mdjvu_error_tiff_support_disabled); return NULL; #endif }