TIFF file reader

Hello,
first of all sorry for my English :)

I have program which reads tiff files, and shows header.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <fstream>

using namespace std;


#define II   1      
#define MM   2       


typedef struct {             
  short unsigned byte_order;  
  short unsigned version;    
  unsigned int ifd_offset;   
} TIFF_HEADER;               


short convert_short(short in);
long convert_long(long in);


int main(int argc, char **argv) {
TIFF_HEADER *header;
short iimm;

if(argc < 2) {  // nie podano parametru (nazwy pliku) 
  cout << "uruchomienie: tiff <nazwa_pliku_tiff>" << endl;
return 1;}


ifstream tiff(argv[1], ios::in | ios::binary);

if (!tiff.is_open()) { 
  cout << "plik nie istnieje..." << endl;
return 2;}

tiff.read(reinterpret_cast<char*>(header) , sizeof(*header));
tiff.close(); 

if (header->byte_order == 0x4d4d)       // Motorola
  {iimm = MM;}
else if (header->byte_order == 0x4949)  // Intel
  {iimm = II;}
else  
  {printf("INVALID TIFF BYTE ORDER: 0x%04x\n", header->byte_order); return 3;}


if (iimm == MM) {  
  header->version = convert_short(header->version);
  header->ifd_offset = convert_long(header->ifd_offset);
  }
if (header->version != 42) { 
  printf("INVALID TIFF VERSION: %d\n", header->version); return 4;}

printf("\nbyte order: 0x%04x (%s)\n",
        header->byte_order, ((iimm == MM)?"Motorola":"Intel"));
printf("version:    0x%04x\n", header->version);
printf("ifd_offset: 0x%08x\n", header->ifd_offset);

return 0;}  

short convert_short(short in) {
short out;
char *p_in = reinterpret_cast<char*>(&in);
char *p_out = reinterpret_cast<char*>(&out);
p_out[0] = p_in[1];
p_out[1] = p_in[0];
return out;}

long convert_long(long in) {
long out;
char *p_in = reinterpret_cast<char*>(&in);
char *p_out = reinterpret_cast<char*>(&out);
p_out[0] = p_in[3];
p_out[1] = p_in[2];
p_out[2] = p_in[1];
p_out[3] = p_in[0];
return out;}


but I have a problem, my program doesn't shows:

ImageWidth
ImageLength
XResolution
YResolution


I must do this, without using another library like libtiff...
Can anyone help me?
I commented out everything but this line below and the program crashed.
tiff.read(reinterpret_cast<char*>(header) , sizeof(*header));

I know that's not much help but I'd start looking there.
Topic archived. No new replies allowed.