1 | <?php |
---|
2 | /* |
---|
3 | * --:: JPEG MetaDatas ::------------------------------------------------------- |
---|
4 | * |
---|
5 | * Author : Grum |
---|
6 | * email : grum at piwigo.org |
---|
7 | * website : http://photos.grum.fr |
---|
8 | * |
---|
9 | * << May the Little SpaceFrog be with you ! >> |
---|
10 | * |
---|
11 | * ----------------------------------------------------------------------------- |
---|
12 | * |
---|
13 | * |
---|
14 | * ----------------------------------------------------------------------------- |
---|
15 | * |
---|
16 | * ----------------------------------------------------------------------------- |
---|
17 | */ |
---|
18 | |
---|
19 | require_once(JPEG_METADATA_DIR."Common/ConvertData.class.php"); |
---|
20 | require_once(JPEG_METADATA_DIR."Common/Data.class.php"); |
---|
21 | require_once(JPEG_METADATA_DIR."Readers/SegmentReader.class.php"); |
---|
22 | require_once(JPEG_METADATA_DIR."Readers/IfdReader.class.php"); |
---|
23 | |
---|
24 | class TiffReader extends SegmentReader |
---|
25 | { |
---|
26 | private $IFDs = Array(); |
---|
27 | private $offsetData = 0; |
---|
28 | private $byteOrder = BYTE_ORDER_LITTLE_ENDIAN; |
---|
29 | private $firstIFDOffset = 0; |
---|
30 | |
---|
31 | function __construct(Data $data, $offsetData=0) |
---|
32 | { |
---|
33 | parent::__construct($data); |
---|
34 | |
---|
35 | $this->offsetData = $offsetData; |
---|
36 | $header=$this->data->readASCII(2); |
---|
37 | |
---|
38 | /* |
---|
39 | * TIFF Header begins wih "II" or "MM" (indicate the byte order) |
---|
40 | * next value is an USHORT, must equals 0x2a |
---|
41 | * |
---|
42 | * all data have to be read with the byte order defined in header |
---|
43 | */ |
---|
44 | if($header=="II" or $header="MM") |
---|
45 | { |
---|
46 | $this->byteOrder=$header; |
---|
47 | $this->data->setByteOrder($this->byteOrder); |
---|
48 | |
---|
49 | $header=$this->data->readUShort(); |
---|
50 | if($header==0x2a) |
---|
51 | { |
---|
52 | $this->isValid=true; |
---|
53 | $this->firstIFDOffset=$this->data->readULong(); |
---|
54 | $this->readData(); |
---|
55 | } |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | function __destruct() |
---|
60 | { |
---|
61 | unset($this->IFDs); |
---|
62 | } |
---|
63 | |
---|
64 | private function readData() |
---|
65 | { |
---|
66 | $nextIFD = $this->firstIFDOffset; |
---|
67 | while($nextIFD!=0) |
---|
68 | { |
---|
69 | $this->data->seek($nextIFD); |
---|
70 | $IFD = new IfdReader($this->data->readASCII(), $nextIFD, $this->byteOrder); |
---|
71 | $this->IFDs[]=$IFD; |
---|
72 | $nextIFD = $IFD->getNextIFDOffset(); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | public function getNbIFDs() |
---|
77 | { |
---|
78 | return(count($this->IFDs)); |
---|
79 | } |
---|
80 | |
---|
81 | public function getIFDs() |
---|
82 | { |
---|
83 | return($this->IFDs); |
---|
84 | } |
---|
85 | |
---|
86 | public function getIFD($num) |
---|
87 | { |
---|
88 | if($num>=0 and $num<count($this->IFDs)) |
---|
89 | return($this->IFDs[$num]); |
---|
90 | else |
---|
91 | return(null); |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | public function toString() |
---|
96 | { |
---|
97 | $returned="TIFF block offset: ".sprintf("%08x", $this->offsetData). |
---|
98 | " ; byteOrder: ".$this->byteOrder. |
---|
99 | " ; isValid: ".($this->isValid?"Y":"N"). |
---|
100 | " ; isLoaded: ".($this->isValid?"Y":"N"). |
---|
101 | " ; IFDs: ".count($this->IFDs). |
---|
102 | " ; first IFD Offset: ".sprintf("0x%04x", $this->firstIFDOffset); |
---|
103 | return($returned); |
---|
104 | } |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | ?> |
---|