34    unsigned long int size;
 
   38    if (ptr_ifd==NULL) 
return NULL;
 
   41    unsigned char* buf = 
read_file(fname, &size);
 
   42    if (size<=0 || buf==NULL) {
 
   51        if (ptr_ifd[num]==NULL) 
break;
 
   59    for (i=0; i<num; i++) {
 
 
   88    if (buf[0]==
'I' && buf[1]==
'I') {
 
   91    else if (buf[0]==
'M' && buf[1]==
'M') {
 
   98    unsigned char* ptr = buf + 2;
 
   99    short version = *((
short*)ptr);
 
  106    unsigned int offset = *((
unsigned int*)ptr);
 
  111    while (k!=num && offset!=0) {
 
  114        short nn = *((
short*)ptr);
 
  123            memset(ifd, 0, 
sizeof(
TIFF_ifd)*(nn+1));
 
  125            memset(&ifd[0], 0, 12);
 
  129            for (i=1; i<=nn; i++) {
 
  131                    memcpy(&ifd[i], ptr, 12);
 
  144            for (i=0; i<nn; i++) ptr += 12;
 
  147        offset = *((
unsigned int*)ptr);
 
  151    if (ifd!=NULL) ifd[0].
value = offset;
 
 
  159    int cnt = ptr->
count;
 
  160    int width=0, height=0, depth=1, bdepth=1, comp=1, color=0;
 
  161    int tilew=0, tileh=0;
 
  167    memset(&vp, 0, 
sizeof(MSGraph));
 
  170    for (i=1; i<=cnt; i++) {
 
  175            ifd->
ex_value = (
void*)malloc(offsize);
 
  192            else if (ifd->
count>=2) {
 
  193                for (j=0, depth=0; j<(int)ifd->
count; j++) {
 
  197            bdepth = (depth+7)/8;
 
  219            vp = make_MSGraph(width, height, 1, depth);
 
  222                    memcpy(vp.gp, buf+ifd->
value, width*height*bdepth);
 
  235                unsigned char* img = (
unsigned char*)vp.gp;
 
  236                for (j=0; j<(int)ifd->
count; j++) {
 
  239                    memcpy(img, buf+img_ptr, size);
 
  255            if (tilew>0 && tileh>0) {
 
  256                int xnum = (width +tilew-1)/tilew;
 
  257                int ynum = (height+tileh-1)/tileh;
 
  258                if (vp.gp!=NULL) free_MSGraph(&vp);
 
  260                vp = make_MSGraph(tilew*xnum, tileh*ynum, 1, depth);
 
  262                    MSGraph mp = make_MSGraph(tilew, tileh, 1, depth);
 
  263                    int size = tilew*tileh*bdepth;
 
  265                    for (j=0; j<(int)ifd->
count; j++) {             
 
  267                        memcpy(mp.gp, buf+img_ptr, size);
 
  272                        for (k=0; k<tileh; k++) {
 
  274                            int yy = (jj*tileh + k)*vp.xs;
 
  275                            for (l=0; l<tilew; l++) {
 
  276                                int ll = (kk + l)*bdepth;
 
  277                                int xx = (yy + ii*tilew + l)*bdepth;
 
  278                                for (m=0; m<bdepth; m++) {
 
  279                                    vp.gp[xx+m] = mp.gp[ll+m];
 
  294                int block = tilew*tileh*bdepth;
 
  295                for (j=0; j<(int)ifd->
count; j++) {
 
  298                        PRINT_MESG(
"PROC_TIFF_IFD: Not match Tile Size %d != %d\n", block, size);
 
  314            ptr->
ex_value = (
void*)malloc(
sizeof(MSGraph));
 
  315            memcpy(ptr->
ex_value, &vp, 
sizeof(MSGraph));
 
 
  325    if (max_values<0) max_values = 0;
 
  328        int num = ifd->
count;
 
  330        for (i=1; i<=num; i++) {
 
 
  345    if (max_values<0) max_values = 0;
 
  347    fprintf(fp, 
"%5d %2d %d -> ", ifd->
tag, ifd->
type, ifd->
count);
 
  350        int count = 
Min((
int)ifd->
count, max_values);
 
  367        else if (count>0) fprintf(fp, 
" PRINT_TIFF_IFD_INDIV: not supported IFD type => %d", ifd->
type);
 
  371    else fprintf(fp, 
" %d", ifd->
value);
 
 
  380    if (ifd==NULL) 
return;
 
 
  388    if (ptr_ifd==NULL) 
return;
 
  391    while ((*ptr)!=NULL) {
 
  392        if ((*ptr)->tag==0) {
 
  393            if ((*ptr)->ex_value!=NULL) {
 
  394                free_MSGraph((MSGraph*)(*ptr)->ex_value);
 
 
  408    if (ifd==NULL) 
return NULL;
 
  410    if (offset<0) offset = 0;
 
  413    unsigned char* ptr = NULL;
 
  416    else ptr = (
unsigned char*)&(ifd->
value);
 
  418    return (
char*)(ptr + offset);
 
 
  424    if (ifd==NULL) 
return 0;
 
  428    if (offset<0) offset = 0;
 
  430    unsigned int ret = 0;
 
  432    unsigned char* ptr = NULL;
 
  435    else ptr = (
unsigned char*)&(ifd->
value);
 
  441        else                ret = *(
unsigned short*)(ptr + offset*2);
 
  445        else                ret = *(
unsigned int*)(ptr + offset*4);
 
 
  454    if (ifd==NULL) 
return 0.0;
 
  456    if (offset<0) offset = 0;
 
  460    unsigned char* ptr = NULL;
 
  463    else ptr = (
unsigned char*)&(ifd->
value);
 
  466        ret = *(
float*)(ptr + offset*4);
 
  469        ret = *(
double*)(ptr + offset*8);
 
 
  478    int  byte_num[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
 
  480    if (type>0 && type<13) 
return byte_num[type];
 
 
  487    if (ifd==NULL && tag<=0) 
return NULL;
 
  490    int count = ifd->
count;
 
  493        if (ifd->
tag==tag) 
return ifd;
 
  498    for (i=0; i<count; i++) {
 
  499        if (ifd->
tag==tag) 
return ifd;