GraphLib/TiffTool.h File Reference

TIFF TOOL Header. More...

#include "xtools.h"
#include "gdata.h"
#include "Gdata.h"
Include dependency graph for TiffTool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TIFF_ifd
struct  TIFFImage

Defines

#define MAX_IFD_DEM_NUM   20
#define TIFF_TYPE_BYTE   1
#define TIFF_TYPE_ASCII   2
#define TIFF_TYPE_SOHRT   3
#define TIFF_TYPE_LONG   4
#define TIFF_TYPE_RATIONAL   5
#define TIFF_TYPE_SBYTE   6
#define TIFF_TYPE_UNDEFINED   7
#define TIFF_TYPE_SSHORT   8
#define TIFF_TYPE_SLONG   9
#define TIFF_TYPE_SRATIONAL   10
#define TIFF_TYPE_FLOAT   11
#define TIFF_TYPE_DOUBLE   12
#define TIFF_TAG_WIDTH   0x0100
#define TIFF_TAG_HEIGHT   0x0101
#define TIFF_TAG_DEPTH   0x0102
#define TIFF_TAG_COMP   0x0103
#define TIFF_TAG_COLOR   0x0106
#define TIFF_TAG_STRIP   0x0111
#define TIFF_TAG_STRIP_RAW   0x0116
#define TIFF_TAG_STRIP_CNT   0x0117
#define TIFF_TAG_XRES   0x011a
#define TIFF_TAG_YRES   0x011b
#define TIFF_TAG_RES_UNIT   0x0128
#define TIFF_TAG_COLORMAP   0x0140
#define TIFF_TAG_PIXEL   0x0115
#define TIFF_TAG_PLANAR   0x011c
#define TIFF_TAG_SOFTWARE   0x0131
#define TIFF_TAG_TILE_WIDTH   0x0142
#define TIFF_TAG_TILE_HEIGHT   0x0143
#define TIFF_TAG_TILE_OFFSET   0x0144
#define TIFF_TAG_TILE_BYTE   0x0145
#define TIFF_TAG_SMPL_FORMAT   0x0153
#define TIFF_TAG_COPYRIGHT   0x8298
#define TIFF_TAG_GEO_PXL_SCALE   0x830e
#define TIFF_TAG_GEO_TIEPOINT   0x8482
#define TIFF_TAG_GEO_TRANS   0x85d8
#define TIFF_TAG_GEO_DIR   0x87af
#define TIFF_TAG_GEO_DOUBLE_PM   0x87b0
#define TIFF_TAG_GEO_ASCII_PM   0x87b1

Functions

TIFF_ifd ** read_tiff_file (const char *fname)
TIFF_ifdget_tiff_ifd (unsigned char *buf, int num)
TIFF_ifdfind_tiff_ifd (TIFF_ifd *ifd, unsigned short tag)
void proc_tiff_ifd (TIFF_ifd *ifd, unsigned char *buf)
void free_TIFF_ifd (TIFF_ifd *ifd)
void free_TIFF_ifd_dem (TIFF_ifd **ptr_ifd)
void print_tiff_ifd (FILE *fp, TIFF_ifd *ifd, int max_values)
void print_tiff_ifd_indiv (FILE *fp, TIFF_ifd *ifd, int max_values)
char * get_tiff_ascii_field (TIFF_ifd *ifd, int offset)
unsigned int get_tiff_uint_field (TIFF_ifd *ifd, int offset)
double get_tiff_double_field (TIFF_ifd *ifd, int offset)
int get_tiff_type_length (short type)

Variables

int TIFF_Swap_Flag

Detailed Description

Version:
0.9
Date:
2010/11/9
Author:
Fumi.Iseki (C)
Attention:
C から C++へ.まだ書き換え中!!

Definition in file TiffTool.h.


Define Documentation

#define MAX_IFD_DEM_NUM   20

Definition at line 45 of file TiffTool.h.

Referenced by read_tiff_file().

#define TIFF_TAG_COLOR   0x0106

Definition at line 64 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_COLORMAP   0x0140

Definition at line 71 of file TiffTool.h.

#define TIFF_TAG_COMP   0x0103

Definition at line 63 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_COPYRIGHT   0x8298

Definition at line 83 of file TiffTool.h.

#define TIFF_TAG_DEPTH   0x0102

Definition at line 62 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_GEO_ASCII_PM   0x87b1

Definition at line 91 of file TiffTool.h.

#define TIFF_TAG_GEO_DIR   0x87af

Definition at line 89 of file TiffTool.h.

#define TIFF_TAG_GEO_DOUBLE_PM   0x87b0

Definition at line 90 of file TiffTool.h.

#define TIFF_TAG_GEO_PXL_SCALE   0x830e

Definition at line 86 of file TiffTool.h.

#define TIFF_TAG_GEO_TIEPOINT   0x8482

Definition at line 87 of file TiffTool.h.

#define TIFF_TAG_GEO_TRANS   0x85d8

Definition at line 88 of file TiffTool.h.

#define TIFF_TAG_HEIGHT   0x0101

Definition at line 61 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_PIXEL   0x0115

Definition at line 73 of file TiffTool.h.

#define TIFF_TAG_PLANAR   0x011c

Definition at line 74 of file TiffTool.h.

#define TIFF_TAG_RES_UNIT   0x0128

Definition at line 70 of file TiffTool.h.

#define TIFF_TAG_SMPL_FORMAT   0x0153

Definition at line 81 of file TiffTool.h.

#define TIFF_TAG_SOFTWARE   0x0131

Definition at line 75 of file TiffTool.h.

#define TIFF_TAG_STRIP   0x0111

Definition at line 65 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_STRIP_CNT   0x0117

Definition at line 67 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_STRIP_RAW   0x0116

Definition at line 66 of file TiffTool.h.

#define TIFF_TAG_TILE_BYTE   0x0145

Definition at line 80 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_TILE_HEIGHT   0x0143

Definition at line 78 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_TILE_OFFSET   0x0144

Definition at line 79 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_TILE_WIDTH   0x0142

Definition at line 77 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_WIDTH   0x0100

Definition at line 60 of file TiffTool.h.

Referenced by proc_tiff_ifd().

#define TIFF_TAG_XRES   0x011a

Definition at line 68 of file TiffTool.h.

#define TIFF_TAG_YRES   0x011b

Definition at line 69 of file TiffTool.h.

#define TIFF_TYPE_ASCII   2

Definition at line 48 of file TiffTool.h.

Referenced by get_tiff_ascii_field(), and print_tiff_ifd_indiv().

#define TIFF_TYPE_BYTE   1

Definition at line 47 of file TiffTool.h.

#define TIFF_TYPE_DOUBLE   12

Definition at line 58 of file TiffTool.h.

Referenced by get_tiff_double_field(), and print_tiff_ifd_indiv().

#define TIFF_TYPE_FLOAT   11

Definition at line 57 of file TiffTool.h.

Referenced by get_tiff_double_field(), and print_tiff_ifd_indiv().

#define TIFF_TYPE_LONG   4

Definition at line 50 of file TiffTool.h.

Referenced by get_tiff_uint_field(), and print_tiff_ifd_indiv().

#define TIFF_TYPE_RATIONAL   5

Definition at line 51 of file TiffTool.h.

Referenced by get_tiff_uint_field(), and print_tiff_ifd_indiv().

#define TIFF_TYPE_SBYTE   6

Definition at line 52 of file TiffTool.h.

#define TIFF_TYPE_SLONG   9

Definition at line 55 of file TiffTool.h.

Referenced by get_tiff_uint_field(), and print_tiff_ifd_indiv().

#define TIFF_TYPE_SOHRT   3

Definition at line 49 of file TiffTool.h.

Referenced by get_tiff_uint_field(), and print_tiff_ifd_indiv().

#define TIFF_TYPE_SRATIONAL   10

Definition at line 56 of file TiffTool.h.

Referenced by get_tiff_uint_field(), and print_tiff_ifd_indiv().

#define TIFF_TYPE_SSHORT   8

Definition at line 54 of file TiffTool.h.

Referenced by get_tiff_uint_field(), and print_tiff_ifd_indiv().

#define TIFF_TYPE_UNDEFINED   7

Definition at line 53 of file TiffTool.h.


Function Documentation

TIFF_ifd* find_tiff_ifd ( TIFF_ifd ifd,
unsigned short  tag 
)

Definition at line 485 of file TiffTool.cpp.

References TIFF_ifd::count, and TIFF_ifd::tag.

00486 {
00487     if (ifd==NULL && tag<=0) return NULL;
00488 
00489     int i;
00490     int count = ifd->count;
00491 
00492     if (ifd->tag!=0) {
00493         if (ifd->tag==tag) return ifd;
00494         else return NULL;
00495     }
00496 
00497     ifd++;
00498     for (i=0; i<count; i++) {
00499         if (ifd->tag==tag) return ifd;
00500         ifd++;
00501     }
00502     return NULL;    
00503 }

void free_TIFF_ifd ( TIFF_ifd ifd  ) 

Definition at line 378 of file TiffTool.cpp.

References TIFF_ifd::ex_value, and freeNull.

Referenced by free_TIFF_ifd_dem().

00379 {
00380     if (ifd==NULL) return;
00381     freeNull(ifd->ex_value);
00382     free(ifd);
00383 }

Here is the caller graph for this function:

void free_TIFF_ifd_dem ( TIFF_ifd **  ptr_ifd  ) 

Definition at line 386 of file TiffTool.cpp.

References free_TIFF_ifd().

00387 {
00388     if (ptr_ifd==NULL) return;
00389 
00390     TIFF_ifd** ptr = ptr_ifd;
00391     while ((*ptr)!=NULL) {
00392         if ((*ptr)->tag==0) {
00393             if ((*ptr)->ex_value!=NULL) {
00394                 free_MSGraph((MSGraph*)(*ptr)->ex_value);
00395             }
00396         }
00397 
00398         free_TIFF_ifd(*ptr);
00399         ptr++;
00400     }
00401 
00402     free(ptr_ifd);
00403 }

Here is the call graph for this function:

char* get_tiff_ascii_field ( TIFF_ifd ifd,
int  offset 
)

Definition at line 406 of file TiffTool.cpp.

References TIFF_ifd::count, TIFF_ifd::ex_value, get_tiff_type_length(), TIFF_TYPE_ASCII, TIFF_ifd::type, and TIFF_ifd::value.

Referenced by print_tiff_ifd_indiv().

00407 {
00408     if (ifd==NULL) return NULL;
00409     if (ifd->type!=TIFF_TYPE_ASCII) return NULL;
00410     if (offset<0) offset = 0;
00411 
00412     int len = get_tiff_type_length(ifd->type);
00413     unsigned char* ptr = NULL;
00414 
00415     if (len*ifd->count>4 && ifd->ex_value!=NULL) ptr = (unsigned char*)(ifd->ex_value);
00416     else ptr = (unsigned char*)&(ifd->value);
00417 
00418     return (char*)(ptr + offset);
00419 }

Here is the call graph for this function:

Here is the caller graph for this function:

double get_tiff_double_field ( TIFF_ifd ifd,
int  offset 
)

Definition at line 452 of file TiffTool.cpp.

References TIFF_ifd::count, TIFF_ifd::ex_value, get_tiff_type_length(), TIFF_TYPE_DOUBLE, TIFF_TYPE_FLOAT, TIFF_ifd::type, and TIFF_ifd::value.

Referenced by print_tiff_ifd_indiv().

00453 {
00454     if (ifd==NULL) return 0.0;
00455     if (ifd->type!=TIFF_TYPE_FLOAT && ifd->type!=TIFF_TYPE_DOUBLE) return 0.0;
00456     if (offset<0) offset = 0;
00457 
00458     double ret = 0.0;
00459     int    len = get_tiff_type_length(ifd->type);
00460     unsigned char* ptr = NULL;
00461 
00462     if (len*ifd->count>4 && ifd->ex_value!=NULL) ptr = (unsigned char*)(ifd->ex_value);
00463     else ptr = (unsigned char*)&(ifd->value);
00464 
00465     if (len==4) {
00466         ret = *(float*)(ptr + offset*4);
00467     }
00468     else if (len==8) {
00469         ret = *(double*)(ptr + offset*8);
00470     }
00471 
00472     return ret;
00473 }

Here is the call graph for this function:

Here is the caller graph for this function:

TIFF_ifd* get_tiff_ifd ( unsigned char *  buf,
int  num 
)

TIFF_ifd* get_tiff_ifd(unsigned char* buf, int num)

TIFF形式のデータから num番目の IFDデータを取り出す.

Parameters:
buf TIFFデータの格納された Buffer型変数
num 何番目の IFDデータを取り出すか?
Returns:
IFDデータ (ifd)
Return values:
ifd->tga==0 is header
ifd->type is seq number of this image (num)
ifd->count is number of IFDs in this image
ifd->value is next image IFD offset. if this is 0, next image does not exist

Definition at line 83 of file TiffTool.cpp.

References TIFF_ifd::count, TIFF_ifd::ex_value, is_big_endian(), is_little_endian(), swapl(), swaps(), TIFF_ifd::tag, TIFF_Swap_Flag, TRUE, TIFF_ifd::type, and TIFF_ifd::value.

Referenced by read_tiff_file().

00084 {
00085     TIFF_ifd* ifd = NULL;
00086     int  i, k;
00087 
00088     // Endian
00089     if (buf[0]=='I' && buf[1]=='I') {
00090         if (is_big_endian()) TIFF_Swap_Flag = TRUE;
00091     }
00092     else if (buf[0]=='M' && buf[1]=='M') {
00093         if (is_little_endian()) TIFF_Swap_Flag = TRUE;
00094     }
00095     else {
00096         return NULL;
00097     }
00098 
00099     unsigned char* ptr = buf + 2;
00100     short version = *((short*)ptr);
00101     if (TIFF_Swap_Flag) version = swaps(version);
00102     if (version!=42) {
00103         return NULL;
00104     }
00105 
00106     ptr += 2;
00107     unsigned int offset = *((unsigned int*)ptr);
00108     if (TIFF_Swap_Flag) offset = swapl(offset);
00109 
00110     if (num<0) num = 1;
00111     k = 0;
00112     while (k!=num && offset!=0) {
00113         k++;
00114         ptr = buf + offset;
00115         short nn = *((short*)ptr);
00116         if (TIFF_Swap_Flag) nn = swaps(nn);
00117         ptr += 2;
00118 
00119         if (k==num) {
00120             ifd = (TIFF_ifd*)malloc(sizeof(TIFF_ifd)*(nn+1));
00121             if (ifd==NULL) {
00122                 return NULL;
00123             }
00124 
00125             memset(&ifd[0], 0, 12);
00126             ifd[0].type  = num;
00127             ifd[0].count = nn;
00128 
00129             for (i=1; i<=nn; i++) {
00130                 if (k==num) {
00131                     memcpy(&ifd[i], ptr, 12);
00132                     if (TIFF_Swap_Flag) {
00133                         ifd[i].tag   = swaps(ifd[i].tag);
00134                         ifd[i].type  = swaps(ifd[i].type);
00135                         ifd[i].count = swapl(ifd[i].count);
00136                         ifd[i].value = swapl(ifd[i].value);
00137                     }
00138                     ifd[i].ex_value = NULL;
00139                 }
00140                 ptr += 12;
00141             }
00142         }
00143         else {
00144             for (i=0; i<nn; i++) ptr += 12;
00145         }
00146 
00147         offset = *((unsigned int*)ptr);
00148         if (TIFF_Swap_Flag) offset = swapl(offset);
00149     }
00150 
00151     if (ifd!=NULL) ifd[0].value = offset;
00152     return ifd;
00153 }

Here is the call graph for this function:

Here is the caller graph for this function:

int get_tiff_type_length ( short  type  ) 

Definition at line 476 of file TiffTool.cpp.

Referenced by get_tiff_ascii_field(), get_tiff_double_field(), get_tiff_uint_field(), and proc_tiff_ifd().

00477 {
00478     int  byte_num[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
00479 
00480     if (type>0 && type<13) return byte_num[type];
00481     return 0;
00482 }

Here is the caller graph for this function:

unsigned int get_tiff_uint_field ( TIFF_ifd ifd,
int  offset 
)

Definition at line 422 of file TiffTool.cpp.

References TIFF_ifd::count, TIFF_ifd::ex_value, get_tiff_type_length(), swapl(), swaps(), TIFF_Swap_Flag, TIFF_TYPE_LONG, TIFF_TYPE_RATIONAL, TIFF_TYPE_SLONG, TIFF_TYPE_SOHRT, TIFF_TYPE_SRATIONAL, TIFF_TYPE_SSHORT, TIFF_ifd::type, and TIFF_ifd::value.

Referenced by print_tiff_ifd_indiv(), and proc_tiff_ifd().

00423 {
00424     if (ifd==NULL) return 0;
00425     if (ifd->type!=TIFF_TYPE_SOHRT    && ifd->type!=TIFF_TYPE_SSHORT &&
00426         ifd->type!=TIFF_TYPE_LONG     && ifd->type!=TIFF_TYPE_SLONG  &&
00427         ifd->type!=TIFF_TYPE_RATIONAL && ifd->type!=TIFF_TYPE_SRATIONAL) return 0;
00428     if (offset<0) offset = 0;
00429 
00430     unsigned int ret = 0;
00431     int len = get_tiff_type_length(ifd->type);
00432     unsigned char* ptr = NULL;
00433 
00434     if (len*ifd->count>4 && ifd->ex_value!=NULL) ptr = (unsigned char*)(ifd->ex_value);
00435     else ptr = (unsigned char*)&(ifd->value);
00436 
00437     if (ifd->type==TIFF_TYPE_RATIONAL || ifd->type==TIFF_TYPE_SRATIONAL) len /= 2;
00438 
00439     if (len==2) {
00440         if (TIFF_Swap_Flag) ret = swaps(*(unsigned short*)(ptr + offset*2));
00441         else                ret = *(unsigned short*)(ptr + offset*2);
00442     }
00443     else if (len==4) {
00444         if (TIFF_Swap_Flag) ret = swapl(*(unsigned int*)(ptr + offset*4));
00445         else                ret = *(unsigned int*)(ptr + offset*4);
00446     }
00447 
00448     return ret;
00449 }

Here is the call graph for this function:

Here is the caller graph for this function:

void print_tiff_ifd ( FILE *  fp,
TIFF_ifd ifd,
int  max_values 
)

Definition at line 322 of file TiffTool.cpp.

References TIFF_ifd::count, print_tiff_ifd_indiv(), and TIFF_ifd::tag.

00323 {
00324     int  i;
00325     if (max_values<0) max_values = 0;
00326 
00327     if (ifd->tag==0) {
00328         int num = ifd->count;
00329         ifd++;
00330         for (i=1; i<=num; i++) {
00331             print_tiff_ifd_indiv(fp, ifd, max_values);
00332             ifd++;
00333         }
00334     }
00335     else {
00336         print_tiff_ifd_indiv(fp, ifd, max_values);
00337     }
00338 
00339 }

Here is the call graph for this function:

void print_tiff_ifd_indiv ( FILE *  fp,
TIFF_ifd ifd,
int  max_values 
)

Definition at line 342 of file TiffTool.cpp.

References TIFF_ifd::count, TIFF_ifd::ex_value, get_tiff_ascii_field(), get_tiff_double_field(), get_tiff_uint_field(), Min, TIFF_ifd::tag, TIFF_TYPE_ASCII, TIFF_TYPE_DOUBLE, TIFF_TYPE_FLOAT, TIFF_TYPE_LONG, TIFF_TYPE_RATIONAL, TIFF_TYPE_SLONG, TIFF_TYPE_SOHRT, TIFF_TYPE_SRATIONAL, TIFF_TYPE_SSHORT, TIFF_ifd::type, and TIFF_ifd::value.

Referenced by print_tiff_ifd().

00343 {
00344     int  i;
00345     if (max_values<0) max_values = 0;
00346 
00347     fprintf(fp, "%5d %2d %d -> ", ifd->tag, ifd->type, ifd->count);
00348 
00349     if (ifd->ex_value!=NULL) {
00350         int count = Min((int)ifd->count, max_values);
00351 
00352         if (ifd->type==TIFF_TYPE_ASCII) {
00353             fprintf(fp, " %s", get_tiff_ascii_field(ifd, 0));
00354         }
00355         else if (ifd->type==TIFF_TYPE_SOHRT || ifd->type==TIFF_TYPE_SSHORT) {
00356             for (i=0; i<count; i++) fprintf(fp, " %d", get_tiff_uint_field(ifd, i));
00357         }
00358         else if (ifd->type==TIFF_TYPE_LONG || ifd->type==TIFF_TYPE_SLONG) {
00359             for (i=0; i<count; i++) fprintf(fp, " %d", get_tiff_uint_field(ifd, i));
00360         }
00361         else if (ifd->type==TIFF_TYPE_RATIONAL || ifd->type==TIFF_TYPE_SRATIONAL) {
00362             for (i=0; i<count; i++) fprintf(fp, " %d/%d", get_tiff_uint_field(ifd, 2*i), get_tiff_uint_field(ifd, 2*i+1));
00363         }
00364         else if (ifd->type==TIFF_TYPE_FLOAT || ifd->type==TIFF_TYPE_DOUBLE) {
00365             for (i=0; i<count; i++) fprintf(fp, " %f", get_tiff_double_field(ifd, i));
00366         }
00367         else if (count>0) fprintf(fp, " PRINT_TIFF_IFD_INDIV: not supported IFD type => %d", ifd->type);
00368 
00369         if (ifd->type!=TIFF_TYPE_ASCII && count<(int)ifd->count && count!=0) fprintf(fp, " .......");
00370     }
00371     else fprintf(fp, " %d", ifd->value);
00372 
00373     fprintf(fp, "\n");
00374     fflush(fp);
00375 }

Here is the call graph for this function:

Here is the caller graph for this function:

void proc_tiff_ifd ( TIFF_ifd ifd,
unsigned char *  buf 
)

Definition at line 156 of file TiffTool.cpp.

References TIFF_ifd::count, TIFF_ifd::ex_value, get_tiff_type_length(), get_tiff_uint_field(), PRINT_MESG, TIFF_ifd::tag, TIFF_TAG_COLOR, TIFF_TAG_COMP, TIFF_TAG_DEPTH, TIFF_TAG_HEIGHT, TIFF_TAG_STRIP, TIFF_TAG_STRIP_CNT, TIFF_TAG_TILE_BYTE, TIFF_TAG_TILE_HEIGHT, TIFF_TAG_TILE_OFFSET, TIFF_TAG_TILE_WIDTH, TIFF_TAG_WIDTH, TIFF_ifd::type, and TIFF_ifd::value.

Referenced by read_tiff_file().

00157 {
00158     int i, j;
00159     int cnt = ptr->count;
00160     int width=0, height=0, depth=1, bdepth=1, comp=1, color=0;
00161     int tilew=0, tileh=0;
00162 
00163     MSGraph vp;
00164     TIFF_ifd* ifd = ptr + 1;
00165     TIFF_ifd* strip_ifd = NULL;
00166 
00167     memset(&vp, 0, sizeof(MSGraph));
00168 
00169     //
00170     for (i=1; i<=cnt; i++) {
00171 
00172         int offsize = get_tiff_type_length(ifd->type)*ifd->count;
00173         if (offsize>4) {
00174             //PRINT_MESG("Malloc Ex_Value. Tag = %d, Length = %d\n", ifd->tag, offsize);
00175             ifd->ex_value = (void*)malloc(offsize);
00176             memcpy(ifd->ex_value, buf + ifd->value, offsize);
00177         }
00178 
00179         // Tag
00180         switch(ifd->tag) {
00181 
00182           case TIFF_TAG_WIDTH:
00183             width  = get_tiff_uint_field(ifd, 0);
00184             break;
00185 
00186           case TIFF_TAG_HEIGHT:
00187             height = get_tiff_uint_field(ifd, 0);
00188             break;
00189 
00190           case TIFF_TAG_DEPTH:
00191             if (ifd->count==1) depth = ifd->value;
00192             else if (ifd->count>=2) {
00193                 for (j=0, depth=0; j<(int)ifd->count; j++) {
00194                     depth += get_tiff_uint_field(ifd, j);
00195                 }
00196             }
00197             bdepth = (depth+7)/8;
00198             break;
00199 
00200           case TIFF_TAG_COMP:
00201             comp = get_tiff_uint_field(ifd, 0);
00202             if (comp!=1) {
00203                 //PRINT_MESG("PROC_TIFF_IFD: In this version, I can not processes compressed TIFF imgae!!\n");
00204                 ptr->type = -1;
00205             }
00206             break;
00207 
00208           case TIFF_TAG_COLOR:
00209             color = get_tiff_uint_field(ifd, 0);
00210             if (color==3) {
00211                 //PRINT_MESG("PROC_TIFF_IFD: In this version, I can not processes Color Map!!\n");
00212                 ptr->type = -1;
00213             }
00214             break;
00215 
00216 
00217           // STRIP
00218           case TIFF_TAG_STRIP:
00219             vp = make_MSGraph(width, height, 1, depth);
00220             if (vp.gp!=NULL) {
00221                 if (ifd->count==1) {
00222                     memcpy(vp.gp, buf+ifd->value, width*height*bdepth);
00223                 }
00224                 else {
00225                     strip_ifd = ifd;
00226                 }
00227             }
00228             else {
00229                 ptr->type = -2;
00230             }
00231             break;
00232 
00233           case TIFF_TAG_STRIP_CNT:
00234             if (ifd->count>1) {
00235                 unsigned char* img = (unsigned char*)vp.gp;
00236                 for (j=0; j<(int)ifd->count; j++) {
00237                     int size    = get_tiff_uint_field(ifd, j);
00238                     int img_ptr = get_tiff_uint_field(strip_ifd, j);
00239                     memcpy(img, buf+img_ptr, size);
00240                     img += size;
00241                 }
00242             }
00243             break;
00244 
00245           // TILE
00246           case TIFF_TAG_TILE_WIDTH:
00247             tilew = get_tiff_uint_field(ifd, 0);
00248             break;
00249 
00250           case TIFF_TAG_TILE_HEIGHT:
00251             tileh = get_tiff_uint_field(ifd, 0);
00252             break;
00253 
00254           case TIFF_TAG_TILE_OFFSET:
00255             if (tilew>0 && tileh>0) {
00256                 int xnum = (width +tilew-1)/tilew;
00257                 int ynum = (height+tileh-1)/tileh;
00258                 if (vp.gp!=NULL) free_MSGraph(&vp);
00259 
00260                 vp = make_MSGraph(tilew*xnum, tileh*ynum, 1, depth);
00261                 if (vp.gp!=NULL) {
00262                     MSGraph mp = make_MSGraph(tilew, tileh, 1, depth);
00263                     int size = tilew*tileh*bdepth;
00264 
00265                     for (j=0; j<(int)ifd->count; j++) {             // Block
00266                         int img_ptr = get_tiff_uint_field(ifd, j);
00267                         memcpy(mp.gp, buf+img_ptr, size);
00268 
00269                         int k, l, m;
00270                         int ii = j%xnum;
00271                         int jj = j/xnum;
00272                         for (k=0; k<tileh; k++) {
00273                             int kk = k*tilew;
00274                             int yy = (jj*tileh + k)*vp.xs;
00275                             for (l=0; l<tilew; l++) {
00276                                 int ll = (kk + l)*bdepth;
00277                                 int xx = (yy + ii*tilew + l)*bdepth;
00278                                 for (m=0; m<bdepth; m++) {
00279                                     vp.gp[xx+m] = mp.gp[ll+m];
00280                                 }
00281                             }
00282                         }
00283                     }
00284                     free_MSGraph(&mp);
00285                 }
00286                 else {
00287                     ptr->type = -2;
00288                 }
00289             }
00290             break;
00291 
00292           case TIFF_TAG_TILE_BYTE:
00293             {
00294                 int block = tilew*tileh*bdepth;
00295                 for (j=0; j<(int)ifd->count; j++) {
00296                     int size = get_tiff_uint_field(ifd, j);
00297                     if (block!=size) {
00298                         PRINT_MESG("PROC_TIFF_IFD: Not match Tile Size %d != %d\n", block, size);
00299                         ptr->type = -1;
00300                     }
00301                 }
00302             }
00303             break;
00304         }
00305 
00306         ifd++;
00307     }
00308 
00309     if (ptr->type<0) {
00310         free_MSGraph(&vp);
00311     }
00312     else {
00313         if (vp.gp!=NULL) {
00314             ptr->ex_value = (void*)malloc(sizeof(MSGraph));
00315             memcpy(ptr->ex_value, &vp, sizeof(MSGraph));
00316         }
00317     }
00318     return;
00319 }

Here is the call graph for this function:

Here is the caller graph for this function:

TIFF_ifd** read_tiff_file ( const char *  fname  ) 

TIFF_ifd** read_tiff_file(const char* fname)

TIFF形式の画像データを読みこむ.

Parameters:
fname 読み込むファイル名
Returns:
TIFFImage データ

Definition at line 32 of file TiffTool.cpp.

References freeNull, get_tiff_ifd(), MAX_IFD_DEM_NUM, proc_tiff_ifd(), and read_file().

00033 {
00034     TIFF_ifd** ptr_ifd = NULL;
00035     unsigned long int size;
00036     int  i;
00037 
00038     ptr_ifd = (TIFF_ifd**)malloc((MAX_IFD_DEM_NUM+1)*sizeof(TIFF_ifd*));
00039     if (ptr_ifd==NULL) return NULL;
00040     for (i=0; i<MAX_IFD_DEM_NUM+1; i++) ptr_ifd[i] = NULL;
00041         
00042     unsigned char* buf = read_file(fname, &size);
00043     if (size<=0 || buf==NULL) {
00044         free(ptr_ifd);
00045         freeNull(buf);
00046         return NULL;
00047     }
00048 
00049     int num = 0;
00050     do {
00051         ptr_ifd[num] = get_tiff_ifd(buf, num+1);
00052         if (ptr_ifd[num]==NULL) break;
00053         num++;
00054     } while(num<MAX_IFD_DEM_NUM && ptr_ifd[num-1]->value!=0);
00055 
00056     //if (num==MAX_IFD_DEM_NUM && ptr_ifd[num-1]->value!=0) {
00057     //  PRINT_MESG("READ_TIFF_FILE: included image file number is over %d!!\n", MAX_IFD_DEM_NUM);
00058     //}
00059 
00060     for (i=0; i<num; i++) {
00061         proc_tiff_ifd(ptr_ifd[i], buf);
00062     }
00063 
00064     freeNull(buf);
00065     return ptr_ifd;
00066 }

Here is the call graph for this function:


Variable Documentation

Definition at line 21 of file TiffTool.cpp.

Referenced by get_tiff_ifd(), and get_tiff_uint_field().


Generated on 15 Nov 2023 for JunkBox_Lib++ (for Windows) by  doxygen 1.6.1