#include #include #include #include "./include/tiffio.h" #pragma comment (lib, "lib/libtiff.lib") typedef struct{ TIFF *info; void *data; uint32 tiffsize; int width; int height; uint16 samplesperpixel; uint16 bitspersample; uint16 photometric; uint16 fillorder; uint16 compression; uint16 orientation; uint16 resunit; uint16 planarconfig; } TIFF_DATA; bool tiffRead24(TIFF_DATA *tiffData, char *fname){ int i, j; uint8 *buf, *line; TIFF *tiff; FILE *fp; tiff = TIFFOpen(fname, "r"); if(tiff == NULL){ printf("ファイルを開けません\n"); return false; } // Tagを読み込む TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &tiffData->width); TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &tiffData->height); TIFFGetField(tiff, TIFFTAG_BITSPERSAMPLE, &tiffData->bitspersample); TIFFGetField(tiff, TIFFTAG_SAMPLESPERPIXEL, &tiffData->samplesperpixel); TIFFGetField(tiff, TIFFTAG_COMPRESSION, &tiffData->compression); TIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &tiffData->photometric); TIFFGetField(tiff, TIFFTAG_FILLORDER, &tiffData->fillorder); TIFFGetField(tiff, TIFFTAG_PLANARCONFIG, &tiffData->planarconfig); TIFFGetField(tiff, TIFFTAG_ORIENTATION, &tiffData->orientation); TIFFGetField(tiff, TIFFTAG_RESOLUTIONUNIT, &tiffData->resunit); // 画像の領域確保 tiffData->tiffsize = tiffData->width * tiffData->height * sizeof( uint8 ) * 3; tiffData->data = ( uint8 * )malloc( tiffData->tiffsize ); buf = (uint8 *)tiffData->data; // 画像1ライン分の領域確保 line = ( uint8 * )_TIFFmalloc( TIFFScanlineSize( tiff ) ); // 画像情報を読み込む for (i = 0; i < tiffData->height; ++i){ // 1ラインずつ読み込む if ( TIFFReadScanline( tiff, line, i, 0 ) < 0 ){ printf("読み込めません。\n"); // 解放処理 _TIFFfree( line ); TIFFClose( tiff ); free(buf); return false; } for (j = 0; j < tiffData->width; ++j){ buf[i * tiffData->width * 3 + j * 3] = line[j * 3]; buf[i * tiffData->width * 3 + j * 3 + 1] = line[j * 3 + 1]; buf[i * tiffData->width * 3 + j * 3 + 2] = line[j * 3 + 2]; } } // 解放処理 _TIFFfree( line ); TIFFClose( tiff ); return true; } int main(){ TIFF_DATA tiffData; tiffRead24(&tiffData, "ファイル名"); // 確認 printf("width: %d \n", tiffData.width); printf("height: %d \n", tiffData.height); printf("bitspersample: %d \n", tiffData.bitspersample); printf("samplesperpixel: %d \n", tiffData.samplesperpixel); printf("compression: %d \n", tiffData.compression); printf("photometric: %d \n", tiffData.photometric); printf("fillorder: %d \n", tiffData.fillorder); printf("planarconfig: %d \n", tiffData.planarconfig); printf("resunit: %d \n", tiffData.resunit); return 0; }