1: <?php
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: class Horde_Image_Exif_Parser_Sanyo extends Horde_Image_Exif_Parser_Base
30: {
31: 32: 33: 34: 35:
36: protected function _lookupTag($tag)
37: {
38: switch($tag) {
39: case '0200': $tag = 'SpecialMode'; break;
40: case '0201': $tag = 'Quality'; break;
41: case '0202': $tag = 'Macro'; break;
42: case '0203': $tag = 'Unknown'; break;
43: case '0204': $tag = 'DigiZoom'; break;
44: case '0f00': $tag = 'DataDump'; break;
45: default: $tag = 'unknown:' . $tag; break;
46: }
47:
48: return $tag;
49: }
50:
51: 52: 53: 54: 55: 56: 57: 58:
59: protected function _formatData($type, $tag, $intel, $data)
60: {
61: switch ($type) {
62: case 'ASCII':
63: case 'UNDEFINED':
64: break;
65:
66: case 'URATIONAL':
67: case 'SRATIONAL':
68: $data = bin2hex($data);
69: if ($intel) {
70: $data = Horde_Image_Exif::intel2Moto($data);
71: }
72: $top = hexdec(substr($data, 8, 8));
73: $bottom = hexdec(substr($data, 0, 8));
74: if ($bottom) {
75: $data = $top / $bottom;
76: } elseif (!$top) {
77: $data = 0;
78: } else {
79: $data = $top . '/' . $bottom;
80: }
81: break;
82:
83: case 'USHORT':
84: case 'SSHORT':
85: case 'ULONG':
86: case 'SLONG':
87: case 'FLOAT':
88: case 'DOUBLE':
89: $data = bin2hex($data);
90: if ($intel) {
91: $data = Horde_Image_Exif::intel2Moto($data);
92: }
93: $data = hexdec($data);
94:
95: switch ($tag) {
96: case '0200':
97:
98: $data = $data == 0 ? Horde_Image_Translation::t("Normal") : Horde_Image_Translation::t("Unknown") . ': ' . $data;
99: break;
100: case '0201':
101:
102: $data = $data == 2 ? Horde_Image_Translation::t("High") : Horde_Image_Translation::t("Unknown") . ': ' . $data;
103: break;
104: case '0202':
105:
106: $data = $data == 0 ? Horde_Image_Translation::t("Normal") : Horde_Image_Translation::t("Unknown") . ': ' . $data;
107: break;
108: }
109: break;
110:
111: default:
112: $data = bin2hex($data);
113: if ($intel) {
114: $data = Horde_Image_Exif::intel2Moto($data);
115: }
116: }
117:
118: return $data;
119: }
120:
121: 122: 123: 124: 125: 126: 127: 128:
129: public function parse($block, &$result, $seek, $globalOffset)
130: {
131: $intel = $result['Endien']=='Intel';
132: $model = $result['IFD0']['Model'];
133:
134: $place = 8;
135: $offset = 8;
136:
137:
138: $num = bin2hex(substr($block, $place, 2));
139: $place += 2;
140: if ($intel) {
141: $num = Horde_Image_Exif::intel2Moto($num);
142: }
143: $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = hexdec($num);
144:
145:
146: for ($i = 0; $i < hexdec($num); $i++) {
147:
148: $tag = bin2hex(substr($block, $place, 2));
149: $place += 2;
150: if ($intel) {
151: $tag = Horde_Image_Exif::intel2Moto($tag);
152: }
153: $tag_name = $this->_lookupTag($tag);
154:
155:
156: $type = bin2hex(substr($block, $place, 2));
157: $place += 2;
158: if ($intel) {
159: $type = Horde_Image_Exif::intel2Moto($type);
160: }
161: $this->_lookupType($type, $size);
162:
163:
164: $count = bin2hex(substr($block, $place, 4));
165: $place += 4;
166: if ($intel) {
167: $count = Horde_Image_Exif::intel2Moto($count);
168: }
169: $bytesofdata = $size * hexdec($count);
170:
171:
172: $value = substr($block, $place, 4);
173: $place += 4;
174:
175: if ($bytesofdata <= 4) {
176: $data = $value;
177: } else {
178: $value = bin2hex($value);
179: if ($intel) {
180: $value = Horde_Image_Exif::intel2Moto($value);
181: }
182:
183:
184: $v = fseek($seek, $globalOffset + hexdec($value));
185: if ($v == 0) {
186: $data = fread($seek, $bytesofdata);
187: } elseif ($v == -1) {
188: $result['Errors'] = $result['Errors']++;
189: }
190: }
191: $formated_data = $this->_formatData($type, $tag, $intel, $data);
192: $result['SubIFD']['MakerNote'][$tag_name] = $formated_data;
193: }
194: }
195: }
196: