comparison libinterp/dldfcn/__tiff__.cc @ 31101:f24d7bcad2d3

Partially fixed formatting of C++ code
author magedrifaat <magedrifaat@gmail.com>
date Wed, 29 Jun 2022 02:27:54 +0200
parents 6fc4bf5e14e1
children d6ecf0e8838b
comparison
equal deleted inserted replaced
31100:4c606686d4ef 31101:f24d7bcad2d3
8 8
9 #include <tiffio.h> 9 #include <tiffio.h>
10 10
11 // TODO(maged): Tidy up the formatting to be consistant with octave 11 // TODO(maged): Tidy up the formatting to be consistant with octave
12 12
13 void validate_tiff_get_field(bool status, void *p_to_free=NULL) 13 // Error if status is not 1 (success status for TIFFGetField)
14 { 14 void
15 if (!status) 15 validate_tiff_get_field (bool status, void *p_to_free=NULL)
16 {
17 if (status != 1)
18 {
19 if (p_to_free != NULL)
20 _TIFFfree (p_to_free);
21 error ("Failed to read tag");
22 }
23 }
24
25 // Convert memory buffer into suitable octave values
26 // depending on tag_datatype
27 octave_value_list
28 interpret_data (void *data, uint32_t count, TIFFDataType tag_datatype)
29 {
30 // TODO(maged): Find the correct way fo returning multivalues
31 octave_value_list ovl_data;
32 dim_vector arr_dims (1, count);
33
34 switch (tag_datatype)
16 { 35 {
17 if (p_to_free != NULL) 36 case TIFF_BYTE:
18 _TIFFfree(p_to_free); 37 case TIFF_UNDEFINED:
19 error("Failed to read tag"); 38 {
20 } 39 uint8NDArray arr (arr_dims);
21 } 40 for (uint32_t i = 0; i < count; i++)
22 41 {
23 octave_value_list interpret_data(void *data, uint32_t count, TIFFDataType tag_datatype)
24 {
25 // TODO(maged): Find the correct way fo returning multivalues (Matrix for numericals?)
26 octave_value_list ovl_data;
27 dim_vector arr_dims(1, count);
28 if (tag_datatype == TIFF_BYTE || tag_datatype == TIFF_UNDEFINED)
29 {
30 uint8NDArray arr(arr_dims);
31 for (uint32_t i = 0; i < count; i++)
32 {
33 arr(i) = ((uint8_t *)data)[i]; 42 arr(i) = ((uint8_t *)data)[i];
34 } 43 }
35 ovl_data(0) = arr; 44 ovl_data(0) = arr;
36 } 45 break;
37 else if(tag_datatype == TIFF_ASCII) 46 }
38 { 47 case TIFF_ASCII:
48 {
39 ovl_data(0) = *(char **)data; 49 ovl_data(0) = *(char **)data;
40 } 50 break;
41 else if (tag_datatype == TIFF_SHORT) 51 }
42 { 52 case TIFF_SHORT:
43 uint16NDArray arr(arr_dims); 53 {
44 for (uint32_t i = 0; i < count; i++) 54 uint16NDArray arr (arr_dims);
45 { 55 for (uint32_t i = 0; i < count; i++)
56 {
46 arr(i) = ((uint16_t *)data)[i]; 57 arr(i) = ((uint16_t *)data)[i];
47 } 58 }
48 ovl_data(0) = arr; 59 ovl_data(0) = arr;
49 } 60 break;
50 else if (tag_datatype == TIFF_LONG) 61 }
51 { 62 case TIFF_LONG:
52 uint32NDArray arr(arr_dims); 63 {
53 for (uint32_t i = 0; i < count; i++) 64 uint32NDArray arr (arr_dims);
54 { 65 for (uint32_t i = 0; i < count; i++)
66 {
55 arr(i) = ((uint32_t *)data)[i]; 67 arr(i) = ((uint32_t *)data)[i];
56 } 68 }
57 ovl_data(0) = arr; 69 ovl_data(0) = arr;
58 } 70 break;
59 else if (tag_datatype == TIFF_LONG8) 71 }
60 { 72 case TIFF_LONG8:
61 uint64NDArray arr(arr_dims); 73 {
62 for (uint32_t i = 0; i < count; i++) 74 uint64NDArray arr (arr_dims);
63 { 75 for (uint32_t i = 0; i < count; i++)
76 {
64 arr(i) = ((uint64_t *)data)[i]; 77 arr(i) = ((uint64_t *)data)[i];
65 } 78 }
66 ovl_data(0) = arr; 79 ovl_data(0) = arr;
67 } 80 break;
68 else if (tag_datatype == TIFF_RATIONAL) 81 }
69 { 82 case TIFF_RATIONAL:
70 NDArray arr(arr_dims); 83 {
84 NDArray arr (arr_dims);
71 for (uint32_t i = 0; i < count; i+=2) 85 for (uint32_t i = 0; i < count; i+=2)
72 { 86 {
73 arr(i / 2) = (float)((uint32_t *)data)[i] / (float)((uint32_t *)data)[i+1]; 87 arr(i / 2) = (float)((uint32_t *)data)[i]
74 } 88 / (float)((uint32_t *)data)[i+1];
75 ovl_data(0) = arr; 89 }
76 } 90 ovl_data(0) = arr;
77 else if (tag_datatype == TIFF_SBYTE) 91 break;
78 { 92 }
79 int8NDArray arr(arr_dims); 93 case TIFF_SBYTE:
80 for (uint32_t i = 0; i < count; i++) 94 {
81 { 95 int8NDArray arr (arr_dims);
96 for (uint32_t i = 0; i < count; i++)
97 {
82 arr(i) = ((int8_t *)data)[i]; 98 arr(i) = ((int8_t *)data)[i];
83 } 99 }
84 ovl_data(0) = arr; 100 ovl_data(0) = arr;
85 } 101 break;
86 else if (tag_datatype == TIFF_SSHORT) 102 }
87 { 103 case TIFF_SSHORT:
88 int16NDArray arr(arr_dims); 104 {
89 for (uint32_t i = 0; i < count; i++) 105 int16NDArray arr (arr_dims);
90 { 106 for (uint32_t i = 0; i < count; i++)
107 {
91 arr(i) = ((int16_t *)data)[i]; 108 arr(i) = ((int16_t *)data)[i];
92 } 109 }
93 ovl_data(0) = arr; 110 ovl_data(0) = arr;
94 } 111 break;
95 else if (tag_datatype == TIFF_SLONG) 112 }
96 { 113 case TIFF_SLONG:
97 int32NDArray arr(arr_dims); 114 {
98 for (uint32_t i = 0; i < count; i++) 115 int32NDArray arr (arr_dims);
99 { 116 for (uint32_t i = 0; i < count; i++)
117 {
100 arr(i) = ((int32_t *)data)[i]; 118 arr(i) = ((int32_t *)data)[i];
101 } 119 }
102 ovl_data(0) = arr; 120 ovl_data(0) = arr;
103 } 121 break;
104 else if (tag_datatype == TIFF_SLONG8) 122 }
105 { 123 case TIFF_SLONG8:
106 int64NDArray arr(arr_dims); 124 {
107 for (uint32_t i = 0; i < count; i++) 125 int64NDArray arr (arr_dims);
108 { 126 for (uint32_t i = 0; i < count; i++)
127 {
109 arr(i) = ((int64_t *)data)[i]; 128 arr(i) = ((int64_t *)data)[i];
110 } 129 }
111 ovl_data(0) = arr; 130 ovl_data(0) = arr;
112 } 131 break;
113 else if (tag_datatype == TIFF_FLOAT) 132 }
114 { 133 case TIFF_FLOAT:
115 NDArray arr(arr_dims); 134 {
116 for (uint32_t i = 0; i < count; i++) 135 NDArray arr (arr_dims);
117 { 136 for (uint32_t i = 0; i < count; i++)
137 {
118 arr(i) = ((float *)data)[i]; 138 arr(i) = ((float *)data)[i];
119 } 139 }
120 ovl_data(0) = arr; 140 ovl_data(0) = arr;
121 } 141 break;
122 else if (tag_datatype == TIFF_DOUBLE) 142 }
123 { 143 case TIFF_DOUBLE:
124 NDArray arr(arr_dims); 144 {
145 NDArray arr (arr_dims);
125 for (uint32_t i = 0; i < count; i++) 146 for (uint32_t i = 0; i < count; i++)
126 { 147 {
127 arr(i) = ((double *)data)[i]; 148 arr(i) = ((double *)data)[i];
128 } 149 }
129 ovl_data(0) = arr; 150 ovl_data(0) = arr;
151 break;
152 }
153 case TIFF_SRATIONAL:
154 {
155 NDArray arr (arr_dims);
156 for (uint32_t i = 0; i < count; i+=2)
157 {
158 arr(i / 2) = (float)((int32_t *)data)[i]
159 / (float)((int32_t *)data)[i+1];
160 }
161 ovl_data(0) = arr;
162 break;
163 }
164 case TIFF_IFD:
165 case TIFF_IFD8:
166 // TODO(maged): implement IFD datatype?
167 error ("Unimplemented IFFD data type");
168 break;
169 default:
170 error ("Unsupported tag data type");
130 } 171 }
131 else if (tag_datatype == TIFF_SRATIONAL) 172
173 return ovl_data;
174 }
175
176 octave_value_list
177 get_scalar_field_data (TIFF *tif, const TIFFField *fip)
178 {
179 octave_value_list tag_data_ovl;
180 uint32_t tag_id = TIFFFieldTag (fip);
181
182 // TIFFFieldReadCount returns VARIABLE for some scalar tags
183 // (e.g. Compression) But TIFFFieldPassCount seems consistent
184 // Since scalar tags are the last to be handled, any tag that
185 // require a count to be passed is an unsupported tag.
186 if (TIFFFieldPassCount (fip))
187 error ("Unsupported tag");
188
189 // TODO(maged): test this function vs actual data type size
190 int type_size = TIFFDataWidth (TIFFFieldDataType (fip));
191 void *data = _TIFFmalloc (type_size);
192 validate_tiff_get_field (TIFFGetField (tif, tag_id, data), data);
193 tag_data_ovl = interpret_data (data, 1, TIFFFieldDataType (fip));
194 _TIFFfree (data);
195
196 return tag_data_ovl;
197 }
198
199 octave_value_list
200 get_array_field_data (TIFF *tif, const TIFFField *fip, uint32_t array_size)
201 {
202 void *data;
203 validate_tiff_get_field (TIFFGetField (tif, TIFFFieldTag (fip), &data));
204
205 return interpret_data (data, array_size, TIFFFieldDataType (fip));
206 }
207
208 octave_value_list
209 get_field_data (TIFF *tif, const TIFFField *fip)
210 {
211 octave_value_list tag_data_ovl;
212 uint32_t tag_id = TIFFFieldTag (fip);
213
214 // TODO(maged): find/create images to test the special tags
215 switch (tag_id)
132 { 216 {
133 NDArray arr(arr_dims); 217 case TIFFTAG_STRIPBYTECOUNTS:
134 for (uint32_t i = 0; i < count; i+=2) 218 case TIFFTAG_STRIPOFFSETS:
135 { 219 tag_data_ovl = get_array_field_data (tif, fip,
136 arr(i / 2) = (float)((int32_t *)data)[i] / (float)((int32_t *)data)[i+1]; 220 TIFFNumberOfStrips (tif));
137 } 221 break;
138 ovl_data(0) = arr; 222 case TIFFTAG_TILEBYTECOUNTS:
139 } 223 case TIFFTAG_TILEOFFSETS:
140 else if (tag_datatype == TIFF_IFD || tag_datatype == TIFF_IFD8) 224 tag_data_ovl = get_array_field_data (tif, fip, TIFFNumberOfTiles (tif));
141 { 225 break;
142 // TODO(maged): implement IFD datatype? 226 case TIFFTAG_YCBCRCOEFFICIENTS:
143 error("Unimplemented IFFD data type"); 227 tag_data_ovl = get_array_field_data (tif, fip, 3);
144 } 228 break;
145 else 229 case TIFFTAG_REFERENCEBLACKWHITE:
146 { 230 tag_data_ovl = get_array_field_data (tif, fip, 6);
147 // TODO(maged): find the correct response in this case 231 break;
148 error("Unsupported tag data type"); 232 case TIFFTAG_COLORMAP:
149 } 233 {
150 234 uint16_t bits_per_sample;
151 return ovl_data; 235 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample))
152 } 236 error ("Failed to obtain the bit depth");
153 237
154 octave_value_list get_scalar_field_data(TIFF *tif, const TIFFField *fip) 238 if (bits_per_sample > 24)
155 { 239 error ("Too high bit depth for a palette image");
156 octave_value_list tag_data_ovl; 240
157 uint32_t tag_ID = TIFFFieldTag(fip); 241 uint32_t count = 1 << bits_per_sample;
158 242 uint16_t *red, *green, *blue;
159 // TIFFFieldReadCount returns VARIABLE for some scalar tags (e.g. Compression) 243 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP,
160 // But TIFFFieldPassCount seems consistent 244 &red, &green, &blue));
161 validate_tiff_get_field(!TIFFFieldPassCount(fip)); 245 tag_data_ovl(0)
162 // TODO(maged): test this function vs actual data type size 246 = octave_value (interpret_data (red, count,
163 int type_size = TIFFDataWidth(TIFFFieldDataType(fip)); 247 TIFFFieldDataType (fip)));
164 void *data = _TIFFmalloc(type_size); 248 tag_data_ovl(1)
165 validate_tiff_get_field(TIFFGetField(tif, tag_ID, data), data); 249 = octave_value (interpret_data (green, count,
166 tag_data_ovl = interpret_data(data, 1, TIFFFieldDataType(fip)); 250 TIFFFieldDataType (fip)));
167 _TIFFfree(data); 251 tag_data_ovl(2)
168 252 = octave_value (interpret_data (blue, count,
169 return tag_data_ovl; 253 TIFFFieldDataType (fip)));
170 } 254
171 255 break;
172 octave_value_list get_array_field_data(TIFF *tif, const TIFFField *fip, uint32_t array_size) 256 }
173 { 257 case TIFFTAG_TRANSFERFUNCTION:
174 octave_value_list tag_data_ovl; 258 {
175 259 uint16_t samples_per_pixel;
176 uint32_t tag_ID = TIFFFieldTag(fip); 260 if (! TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel))
177 TIFFDataType tag_datatype = TIFFFieldDataType(fip); 261 error ("Failed to obtain the number of samples per pixel");
178 void *data; 262
179 validate_tiff_get_field(TIFFGetField(tif, tag_ID, &data)); 263 uint16_t bits_per_sample;
180 264 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample))
181 return interpret_data(data, array_size, tag_datatype); 265 error ("Failed to obtain the number of samples per pixel");
182 } 266
183 267 uint32_t count = 1 << bits_per_sample;
184 octave_value_list get_field_data(TIFF *tif, const TIFFField *fip) 268 uint16_t *ch1, *ch2, *ch3;
185 { 269 if (samples_per_pixel == 1)
186 octave_value_list tag_data_ovl; 270 {
187 uint32_t tag_ID = TIFFFieldTag(fip); 271 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP, &ch1));
188 272 tag_data_ovl(0)
189 // TODO(maged): find/create images to test the special tags 273 = octave_value (interpret_data (ch1, count,
190 switch(tag_ID) 274 TIFFFieldDataType (fip)));
191 { 275 }
192 case TIFFTAG_STRIPBYTECOUNTS: 276 else
193 case TIFFTAG_STRIPOFFSETS: 277 {
194 tag_data_ovl = get_array_field_data(tif, fip, TIFFNumberOfStrips(tif)); 278 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP,
195 break; 279 &ch1, &ch2, &ch3));
196 case TIFFTAG_TILEBYTECOUNTS: 280 tag_data_ovl(0)
197 case TIFFTAG_TILEOFFSETS: 281 = octave_value (interpret_data (ch1, count,
198 tag_data_ovl = get_array_field_data(tif, fip, TIFFNumberOfTiles(tif)); 282 TIFFFieldDataType (fip)));
199 break; 283 tag_data_ovl(1)
200 case TIFFTAG_YCBCRCOEFFICIENTS: 284 = octave_value (interpret_data (ch2, count,
201 tag_data_ovl = get_array_field_data(tif, fip, 3); 285 TIFFFieldDataType (fip)));
202 break; 286 tag_data_ovl(2)
203 case TIFFTAG_REFERENCEBLACKWHITE: 287 = octave_value (interpret_data (ch3, count,
204 tag_data_ovl = get_array_field_data(tif, fip, 6); 288 TIFFFieldDataType (fip)));
205 break; 289 }
206 // colormap is not always 3 channels, but libtiff hardcodes it as 3 290 break;
207 case TIFFTAG_COLORMAP: 291 }
208 { 292 case TIFFTAG_PAGENUMBER:
209 uint16_t bits_per_sample; 293 case TIFFTAG_HALFTONEHINTS:
210 if (!TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) 294 case TIFFTAG_DOTRANGE:
211 { 295 case TIFFTAG_YCBCRSUBSAMPLING:
212 error("Failed to obtain the bit depth"); 296 {
213 } 297 uint16_t tag_part1, tag_part2;
214 298 validate_tiff_get_field (TIFFGetField (tif, tag_id,
215 if (bits_per_sample > 24) 299 &tag_part1, &tag_part2));
216 { 300 tag_data_ovl(0)
217 error("Too high bit depth for a palette image"); 301 = octave_value (interpret_data (&tag_part1, 1,
218 } 302 TIFFFieldDataType (fip)));
219 303 tag_data_ovl(1)
220 uint32_t count = 1<<bits_per_sample; 304 = octave_value (interpret_data (&tag_part2, 1,
221 uint16_t *red, *green, *blue; 305 TIFFFieldDataType (fip)));
222 validate_tiff_get_field(TIFFGetField(tif, TIFFTAG_COLORMAP, &red, &green, &blue)); 306 break;
223 tag_data_ovl(0) = octave_value(interpret_data(red, count, TIFFFieldDataType(fip))); 307 }
224 tag_data_ovl(1) = octave_value(interpret_data(green, count, TIFFFieldDataType(fip))); 308 case TIFFTAG_SUBIFD:
225 tag_data_ovl(2) = octave_value(interpret_data(blue, count, TIFFFieldDataType(fip))); 309 {
226 } 310 uint16_t count;
227 break; 311 uint64_t *offsets;
228 case TIFFTAG_TRANSFERFUNCTION: 312 validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &offsets));
229 { 313 tag_data_ovl = interpret_data (offsets, count, TIFFFieldDataType (fip));
230 uint16_t samples_per_pixel; 314 break;
231 if (!TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel)) 315 }
232 { 316 case TIFFTAG_EXTRASAMPLES:
233 error("Failed to obtain the number of samples per pixel"); 317 {
234 } 318 uint16_t count;
235 319 uint16_t *types;
236 uint16_t bits_per_sample; 320 validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &types));
237 if (!TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) 321 tag_data_ovl = interpret_data (types, count, TIFFFieldDataType (fip));
238 { 322 break;
239 error("Failed to obtain the number of samples per pixel"); 323 }
240 } 324 // TODO(maged): Do I just return bytes? pass it to some parser lib?
241 325 case TIFFTAG_XMLPACKET:
242 uint32_t count = 1<<bits_per_sample; 326 case TIFFTAG_RICHTIFFIPTC:
243 uint16_t *ch1, *ch2, *ch3; 327 case TIFFTAG_PHOTOSHOP:
244 if (samples_per_pixel == 1) 328 case TIFFTAG_ICCPROFILE:
245 { 329 {
246 validate_tiff_get_field(TIFFGetField(tif, TIFFTAG_COLORMAP, &ch1)); 330 uint16_t count;
247 tag_data_ovl(0) = octave_value(interpret_data(ch1, count, TIFFFieldDataType(fip))); 331 void *data;
248 } 332 validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &data));
249 else 333 tag_data_ovl = interpret_data (data, count, TIFF_BYTE);
250 { 334 break;
251 validate_tiff_get_field(TIFFGetField(tif, TIFFTAG_COLORMAP, &ch1, &ch2, &ch3)); 335 }
252 tag_data_ovl(0) = octave_value(interpret_data(ch1, count, TIFFFieldDataType(fip))); 336 default:
253 tag_data_ovl(1) = octave_value(interpret_data(ch2, count, TIFFFieldDataType(fip))); 337 tag_data_ovl = get_scalar_field_data (tif, fip);
254 tag_data_ovl(2) = octave_value(interpret_data(ch3, count, TIFFFieldDataType(fip))); 338 }
255 } 339
256 } 340 return tag_data_ovl;
257 break;
258 case TIFFTAG_PAGENUMBER:
259 case TIFFTAG_HALFTONEHINTS:
260 case TIFFTAG_DOTRANGE:
261 case TIFFTAG_YCBCRSUBSAMPLING:
262 {
263 uint16_t tag_part1, tag_part2;
264 validate_tiff_get_field(TIFFGetField(tif, tag_ID, &tag_part1, &tag_part2));
265 tag_data_ovl(0) = octave_value(interpret_data(&tag_part1, 1, TIFFFieldDataType(fip)));
266 tag_data_ovl(1) = octave_value(interpret_data(&tag_part2, 1, TIFFFieldDataType(fip)));
267 }
268 break;
269 case TIFFTAG_SUBIFD:
270 {
271 uint16_t count;
272 uint64_t *offsets;
273 validate_tiff_get_field(TIFFGetField(tif, tag_ID, &count, &offsets));
274 tag_data_ovl = interpret_data(offsets, count, TIFFFieldDataType(fip));
275 }
276 break;
277 case TIFFTAG_EXTRASAMPLES:
278 {
279 uint16_t count;
280 uint16_t *types;
281 validate_tiff_get_field(TIFFGetField(tif, tag_ID, &count, &types));
282 tag_data_ovl = interpret_data(types, count, TIFFFieldDataType(fip));
283 }
284 break;
285 // TODO(maged): Do I just return bytes? pass it to some parser lib?
286 case TIFFTAG_XMLPACKET:
287 case TIFFTAG_RICHTIFFIPTC:
288 case TIFFTAG_PHOTOSHOP:
289 case TIFFTAG_ICCPROFILE:
290 {
291 uint16_t count;
292 void *data;
293 validate_tiff_get_field(TIFFGetField(tif, tag_ID, &count, &data));
294 tag_data_ovl = interpret_data(data, count, TIFF_BYTE);
295 }
296 break;
297 default:
298 tag_data_ovl = get_scalar_field_data(tif, fip);
299 }
300
301 return tag_data_ovl;
302 } 341 }
303 342
304 DEFUN_DLD (__open_tiff__, args, nargout, 343 DEFUN_DLD (__open_tiff__, args, nargout,
305 "Open a Tiff file and return its handle") 344 "Open a Tiff file and return its handle")
306 { 345 {
307 int nargin = args.length(); 346 int nargin = args.length ();
308 347
309 if (nargin == 0 || nargin > 2) 348 if (nargin == 0 || nargin > 2)
310 { 349 {
311 // TODO(maged): return invalid object instead?? 350 // TODO(maged): return invalid object instead??
312 error("No filename supplied\n"); 351 error ("No filename supplied\n");
313 } 352 }
314 353
315 std::string filename = args(0).string_value(); 354 std::string filename = args (0).string_value ();
316 std::string mode = "r"; 355 std::string mode = "r";
317 356
318 // TODO(maged): check valid mode 357 // TODO(maged): check valid mode
319 if (nargin == 2) 358 if (nargin == 2)
320 mode = args(1).string_value(); 359 mode = args (1).string_value ();
321 360
322 // TODO(maged): Look into unwind action 361 // TODO(maged): Look into unwind action
323 TIFF *tif = TIFFOpen(filename.c_str(), mode.c_str()); 362 TIFF *tif = TIFFOpen (filename.c_str (), mode.c_str ());
324 363
325 if (!tif) 364 if (! tif)
326 error("Failed to open Tiff file\n"); 365 error ("Failed to open Tiff file\n");
327 366
328 // TODO(maged): use inheritance of octave_base_value instead 367 // TODO(maged): use inheritance of octave_base_value instead
329 octave_value tiff_ov = octave_value((uint64_t)tif); 368 octave_value tiff_ov = octave_value ((uint64_t)tif);
330 return octave_value_list (tiff_ov); 369 return octave_value_list (tiff_ov);
331 } 370 }
332 371
333 372
334 DEFUN_DLD (__close_tiff__, args, nargout, 373 DEFUN_DLD (__close_tiff__, args, nargout,
335 "Close a tiff file") 374 "Close a tiff file")
336 { 375 {
337 int nargin = args.length(); 376 int nargin = args.length ();
338 377
339 if (nargin == 0) 378 if (nargin == 0)
340 { 379 error ("No handle provided\n");
341 error("No handle provided\n"); 380
342 } 381 TIFF *tif = (TIFF *)(args (0).uint64_value ());
343 382 TIFFClose (tif);
344 TIFF *tif = (TIFF *)(args(0).uint64_value()); 383
345 TIFFClose(tif); 384 return octave_value_list ();
346
347 return octave_value_list ();
348 } 385 }
349 386
350 387
351 DEFUN_DLD (__tiff_get_tag__, args, nargout, 388 DEFUN_DLD (__tiff_get_tag__, args, nargout,
352 "Get the value of a tag from a tiff image") 389 "Get the value of a tag from a tiff image")
353 { 390 {
354 int nargin = args.length(); 391 int nargin = args.length ();
355 392
356 if (nargin == 0) 393 if (nargin == 0)
357 { 394 error ("No handle provided\n");
358 error("No handle provided\n");
359 }
360 395
361 if (nargin < 2) 396 if (nargin < 2)
362 { 397 error ("No tag name provided\n");
363 error("No tag name provided\n");
364 }
365 398
366 TIFF *tif = (TIFF *)(args(0).uint64_value()); 399 TIFF *tif = (TIFF *)(args (0).uint64_value ());
367 400
368 uint32_t tag_ID; 401 uint32_t tag_id;
369 const TIFFField *fip; 402 const TIFFField *fip;
370 if (args(1).type_name() == "string") 403 if (args (1).type_name () == "string")
371 { 404 {
372 std::string tagName = args(1).string_value(); 405 std::string tagName = args (1).string_value ();
373 fip = TIFFFieldWithName(tif, tagName.c_str()); 406 fip = TIFFFieldWithName (tif, tagName.c_str ());
374 if (!fip) 407 if (! fip)
375 error("Tiff tag not found"); 408 error ("Tiff tag not found");
376 409
377 tag_ID = TIFFFieldTag(fip); 410 tag_id = TIFFFieldTag (fip);
378 } 411 }
379 else 412 else
380 { 413 {
381 tag_ID = args(1).int_value(); 414 tag_id = args (1).int_value ();
382 fip = TIFFFieldWithTag(tif, tag_ID); 415 fip = TIFFFieldWithTag (tif, tag_id);
383 // TODO(maged): Handle other types of errors (e.g. unsupported tags) 416 // TODO(maged): Handle other types of errors (e.g. unsupported tags)
384 if (!fip) 417 if (! fip)
385 error("Tiff tag not found"); 418 error ("Tiff tag not found");
386 } 419 }
387 420
388 421
389 octave_value_list tag_data_ovl = get_field_data(tif, fip); 422 octave_value_list tag_data_ovl = get_field_data (tif, fip);
390 423
391 return tag_data_ovl; 424 return tag_data_ovl;
392 } 425 }