Mercurial > octave-libtiff
annotate libinterp/dldfcn/__tiff__.cc @ 31114:9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
* __tiff__.cc (get_field_data): fixed return matrix for colormap and transferfunction
to be consistent with matlab.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Sat, 16 Jul 2022 17:29:14 +0200 |
parents | a74059523d74 |
children | 5b3465a9c340 |
rev | line source |
---|---|
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1 #if defined (HAVE_CONFIG_H) |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
2 # include "config.h" |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
3 #endif |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
4 |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
5 #include <string> |
31094
ab5b33e447b0
Modified getTag to account for different tag data types and multivalued tags, the current implementation is still buggy for most tags and data types
magedrifaat <magedrifaat@gmail.com>
parents:
31093
diff
changeset
|
6 #include <iostream> |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
7 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
8 #include "defun-dld.h" |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
9 #include "ov.h" |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
10 #include "ovl.h" |
31093
e2bed4daae82
Fix typo in module-files
magedrifaat <magedrifaat@gmail.com>
parents:
31092
diff
changeset
|
11 #include "error.h" |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
12 |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
13 #include "errwarn.h" |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
14 |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
15 #if defined (HAVE_TIFF) |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
16 # include <tiffio.h> |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
17 #endif |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
18 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
19 // TODO(maged): Tidy up the formatting to be consistant with octave |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
20 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
21 namespace octve |
31099
6fc4bf5e14e1
Cleaned up the interface
magedrifaat <magedrifaat@gmail.com>
parents:
31098
diff
changeset
|
22 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
23 #if defined (HAVE_TIFF) |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
24 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
25 struct tiff_image_data |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
26 { |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
27 public: |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
28 uint32_t width; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
29 uint32_t height; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
30 uint16_t samples_per_pixel; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
31 uint16_t bits_per_sample; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
32 uint16_t planar_configuration; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
33 uint16_t is_tiled; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
34 }; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
35 |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
36 template <typename T> |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
37 octave_value |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
38 read_stripped_image (TIFF *tif, tiff_image_data *image_data) |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
39 { |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
40 typedef typename T::element_type P; |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
41 |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
42 T img = T (dim_vector (image_data->height, image_data->width, |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
43 image_data->samples_per_pixel)); |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
44 P *img_fvec = img.fortran_vec (); |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
45 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
46 // Obtain the necessary data for handling the strips |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
47 uint32_t strip_count = TIFFNumberOfStrips (tif); |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
48 tdata_t buf = _TIFFmalloc (TIFFStripSize (tif)); |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
49 if (! buf) |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
50 error ("Failed to allocate buffer for strip data"); |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
51 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
52 uint32_t row_index = 0; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
53 uint32_t row_size_in_bits = image_data->width |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
54 * image_data->samples_per_pixel |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
55 * image_data->bits_per_sample; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
56 // According to the Tiff format specification, the row size is |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
57 // padded at least up to the next byte, so we add padding to |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
58 // complete the byte |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
59 row_size_in_bits += (8 - row_size_in_bits % 8) % 8; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
60 for (uint32_t strip = 0; strip < strip_count; strip++) |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
61 { |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
62 uint32_t strip_bytes = TIFFReadEncodedStrip (tif, strip, buf, -1); |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
63 if (strip_bytes == -1) |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
64 error ("Failed to read strip data"); |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
65 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
66 if (image_data->planar_configuration == PLANARCONFIG_CONTIG) |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
67 { |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
68 uint32_t rows_in_strip = strip_bytes * 8 / row_size_in_bits; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
69 for (uint32_t row_subindex = 0; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
70 row_subindex < rows_in_strip; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
71 row_subindex++) |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
72 { |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
73 for (uint32_t column = 0; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
74 column < image_data->width; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
75 column++) |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
76 { |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
77 uint32_t row_offset = row_size_in_bits / 8 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
78 * row_subindex; |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
79 // TODO(maged): support arbitrary BitsPerSample? |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
80 if (image_data->bits_per_sample >= 8 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
81 && image_data->bits_per_sample % 8 == 0) |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
82 { |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
83 // TODO(maged): copy entire strip at once? |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
84 for (uint16_t sample = 0; |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
85 sample < image_data->samples_per_pixel; sample++) |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
86 // The memory organization of fvec is inverted from |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
87 // what would be expected for a normal C-like array. |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
88 // It is treated as samples * columns * rows as |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
89 // opposed to rows * columns * samples. |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
90 img_fvec[sample * image_data->width * image_data->height |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
91 + column * image_data->height |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
92 + row_index + row_subindex] |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
93 = ((P *)buf)[row_subindex * image_data->width * image_data->samples_per_pixel |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
94 + column * image_data->samples_per_pixel + sample]; |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
95 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
96 else if (image_data->bits_per_sample == 4 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
97 && image_data->samples_per_pixel == 1) |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
98 { |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
99 // TODO(maged): Check FillOrder for completeness |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
100 uint8_t nibble |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
101 = ((uint8_t *)buf)[row_offset + column / 2]; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
102 // Extract the needed nibble from the byte |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
103 nibble = (column % 2 == 0? nibble >> 4: nibble) & 0x0F; |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
104 img_fvec[(row_index + row_subindex) |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
105 + column * image_data->height] = nibble; |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
106 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
107 else if (image_data->bits_per_sample == 1 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
108 && image_data->samples_per_pixel == 1) |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
109 { |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
110 uint8_t byte |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
111 = ((uint8_t *)buf)[row_offset + column / 8]; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
112 // Extract the needed bit from the byte |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
113 uint8_t bit = (byte >> (7 - column % 8)) & 0x01; |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
114 img_fvec[(row_index + row_subindex) |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
115 + column * image_data->height] = bit; |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
116 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
117 else |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
118 error ("Unsupported bit depth"); |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
119 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
120 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
121 row_index += rows_in_strip; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
122 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
123 else |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
124 error ("Images with multiple planes are not implemented yet"); |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
125 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
126 _TIFFfree (buf); |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
127 |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
128 return octave_value(img); |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
129 } |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
130 |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
131 template <typename T> |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
132 octave_value |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
133 read_image (TIFF *tif, tiff_image_data *image_data) |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
134 { |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
135 if (image_data->is_tiled) |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
136 // TODO(maged): Implement tiled images |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
137 error ("Tiled images are not implemented yet"); |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
138 else |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
139 return read_stripped_image<T> (tif, image_data); |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
140 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
141 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
142 // Error if status is not 1 (success status for TIFFGetField) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
143 void |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
144 validate_tiff_get_field (bool status, void *p_to_free=NULL) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
145 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
146 if (status != 1) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
147 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
148 if (p_to_free != NULL) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
149 _TIFFfree (p_to_free); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
150 error ("Failed to read tag"); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
151 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
152 } |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
153 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
154 // Convert tag value to double |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
155 octave_value |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
156 interpret_scalar_tag_data (void *data, TIFFDataType tag_datatype) |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
157 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
158 double retval; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
159 |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
160 switch (tag_datatype) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
161 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
162 case TIFF_BYTE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
163 case TIFF_UNDEFINED: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
164 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
165 retval = (double)(*((uint8_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
166 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
167 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
168 case TIFF_SHORT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
169 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
170 retval = (double)(*((uint16_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
171 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
172 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
173 case TIFF_LONG: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
174 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
175 retval = (double)(*((uint32_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
176 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
177 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
178 case TIFF_LONG8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
179 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
180 retval = (double)(*((uint64_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
181 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
182 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
183 case TIFF_RATIONAL: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
184 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
185 error ("TIFF_RATIONAL should have at least 2 elements but got only 1"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
186 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
187 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
188 case TIFF_SBYTE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
189 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
190 retval = (double)(*((int8_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
191 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
192 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
193 case TIFF_SSHORT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
194 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
195 retval = (double)(*((int16_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
196 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
197 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
198 case TIFF_SLONG: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
199 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
200 retval = (double)(*((int32_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
201 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
202 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
203 case TIFF_SLONG8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
204 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
205 retval = (double)(*((int64_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
206 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
207 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
208 case TIFF_FLOAT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
209 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
210 retval = *((float *)data); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
211 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
212 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
213 case TIFF_DOUBLE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
214 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
215 retval = *((double *)data); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
216 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
217 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
218 case TIFF_SRATIONAL: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
219 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
220 error ("TIFF_SRATIONAL should have at least 2 elements but got only 1"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
221 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
222 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
223 case TIFF_IFD: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
224 case TIFF_IFD8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
225 error ("Unimplemented IFFD data type"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
226 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
227 default: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
228 error ("Unsupported tag data type"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
229 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
230 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
231 return octave_value (retval); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
232 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
233 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
234 // Convert memory buffer into a suitable octave value |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
235 // depending on tag_datatype |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
236 octave_value |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
237 interpret_tag_data (void *data, uint32_t count, TIFFDataType tag_datatype) |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
238 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
239 octave_value retval; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
240 // Apparently matlab converts scalar numerical values into double |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
241 // but doesn't do the same for arrays |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
242 if (count == 1 && tag_datatype != TIFF_ASCII) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
243 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
244 retval = interpret_scalar_tag_data (data, tag_datatype); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
245 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
246 else |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
247 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
248 dim_vector arr_dims (1, count); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
249 |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
250 switch (tag_datatype) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
251 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
252 case TIFF_BYTE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
253 case TIFF_UNDEFINED: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
254 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
255 uint8NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
256 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
257 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
258 arr(i) = ((uint8_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
259 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
260 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
261 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
262 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
263 case TIFF_ASCII: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
264 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
265 retval = octave_value (*(char **)data); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
266 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
267 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
268 case TIFF_SHORT: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
269 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
270 uint16NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
271 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
272 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
273 arr(i) = ((uint16_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
274 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
275 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
276 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
277 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
278 case TIFF_LONG: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
279 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
280 uint32NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
281 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
282 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
283 arr(i) = ((uint32_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
284 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
285 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
286 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
287 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
288 case TIFF_LONG8: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
289 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
290 uint64NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
291 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
292 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
293 arr(i) = ((uint64_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
294 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
295 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
296 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
297 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
298 case TIFF_RATIONAL: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
299 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
300 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
301 for (uint32_t i = 0; i < count; i+=2) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
302 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
303 arr(i / 2) = (float)((uint32_t *)data)[i] |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
304 / (float)((uint32_t *)data)[i+1]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
305 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
306 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
307 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
308 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
309 case TIFF_SBYTE: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
310 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
311 int8NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
312 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
313 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
314 arr(i) = ((int8_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
315 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
316 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
317 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
318 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
319 case TIFF_SSHORT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
320 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
321 int16NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
322 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
323 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
324 arr(i) = ((int16_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
325 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
326 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
327 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
328 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
329 case TIFF_SLONG: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
330 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
331 int32NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
332 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
333 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
334 arr(i) = ((int32_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
335 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
336 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
337 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
338 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
339 case TIFF_SLONG8: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
340 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
341 int64NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
342 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
343 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
344 arr(i) = ((int64_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
345 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
346 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
347 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
348 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
349 case TIFF_FLOAT: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
350 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
351 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
352 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
353 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
354 arr(i) = ((float *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
355 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
356 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
357 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
358 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
359 case TIFF_DOUBLE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
360 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
361 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
362 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
363 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
364 arr(i) = ((double *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
365 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
366 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
367 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
368 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
369 case TIFF_SRATIONAL: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
370 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
371 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
372 for (uint32_t i = 0; i < count; i+=2) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
373 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
374 arr(i / 2) = (float)((int32_t *)data)[i] |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
375 / (float)((int32_t *)data)[i+1]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
376 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
377 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
378 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
379 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
380 case TIFF_IFD: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
381 case TIFF_IFD8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
382 // TODO(maged): implement IFD datatype? |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
383 error ("Unimplemented IFFD data type"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
384 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
385 default: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
386 error ("Unsupported tag data type"); |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
387 } |
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
388 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
389 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
390 return retval; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
391 } |
31094
ab5b33e447b0
Modified getTag to account for different tag data types and multivalued tags, the current implementation is still buggy for most tags and data types
magedrifaat <magedrifaat@gmail.com>
parents:
31093
diff
changeset
|
392 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
393 octave_value |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
394 get_scalar_field_data (TIFF *tif, const TIFFField *fip) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
395 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
396 uint32_t tag_id = TIFFFieldTag (fip); |
31097
75ab26f147a5
getTag: Implemented single array tags, only multi-array and special tags are unimplemented
magedrifaat <magedrifaat@gmail.com>
parents:
31096
diff
changeset
|
397 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
398 // TIFFFieldReadCount returns VARIABLE for some scalar tags |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
399 // (e.g. Compression) But TIFFFieldPassCount seems consistent |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
400 // Since scalar tags are the last to be handled, any tag that |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
401 // require a count to be passed is an unsupported tag. |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
402 if (TIFFFieldPassCount (fip)) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
403 error ("Unsupported tag"); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
404 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
405 // TODO(maged): test this function vs actual data type size |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
406 int type_size = TIFFDataWidth (TIFFFieldDataType (fip)); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
407 void *data = _TIFFmalloc (type_size); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
408 validate_tiff_get_field (TIFFGetField (tif, tag_id, data), data); |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
409 octave_value tag_data_ov = interpret_tag_data (data, 1, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
410 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
411 _TIFFfree (data); |
31094
ab5b33e447b0
Modified getTag to account for different tag data types and multivalued tags, the current implementation is still buggy for most tags and data types
magedrifaat <magedrifaat@gmail.com>
parents:
31093
diff
changeset
|
412 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
413 return tag_data_ov; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
414 } |
31094
ab5b33e447b0
Modified getTag to account for different tag data types and multivalued tags, the current implementation is still buggy for most tags and data types
magedrifaat <magedrifaat@gmail.com>
parents:
31093
diff
changeset
|
415 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
416 octave_value |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
417 get_array_field_data (TIFF *tif, const TIFFField *fip, uint32_t array_size) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
418 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
419 void *data; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
420 validate_tiff_get_field (TIFFGetField (tif, TIFFFieldTag (fip), &data)); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
421 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
422 return interpret_tag_data (data, array_size, TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
423 } |
31097
75ab26f147a5
getTag: Implemented single array tags, only multi-array and special tags are unimplemented
magedrifaat <magedrifaat@gmail.com>
parents:
31096
diff
changeset
|
424 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
425 octave_value_list |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
426 get_field_data (TIFF *tif, const TIFFField *fip) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
427 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
428 octave_value_list tag_data_ovl (1); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
429 uint32_t tag_id = TIFFFieldTag (fip); |
31097
75ab26f147a5
getTag: Implemented single array tags, only multi-array and special tags are unimplemented
magedrifaat <magedrifaat@gmail.com>
parents:
31096
diff
changeset
|
430 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
431 // TODO(maged): find/create images to test the special tags |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
432 switch (tag_id) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
433 { |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
434 case TIFFTAG_STRIPBYTECOUNTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
435 case TIFFTAG_STRIPOFFSETS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
436 tag_data_ovl = get_array_field_data (tif, fip, |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
437 TIFFNumberOfStrips (tif)); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
438 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
439 case TIFFTAG_TILEBYTECOUNTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
440 case TIFFTAG_TILEOFFSETS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
441 tag_data_ovl = get_array_field_data (tif, fip, TIFFNumberOfTiles (tif)); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
442 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
443 case TIFFTAG_YCBCRCOEFFICIENTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
444 tag_data_ovl = get_array_field_data (tif, fip, 3); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
445 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
446 case TIFFTAG_REFERENCEBLACKWHITE: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
447 tag_data_ovl = get_array_field_data (tif, fip, 6); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
448 break; |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
449 case TIFFTAG_GRAYRESPONSECURVE: |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
450 { |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
451 uint16_t bits_per_sample; |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
452 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
453 error ("Failed to obtain the bit depth"); |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
454 |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
455 tag_data_ovl = get_array_field_data (tif, fip, 1<<bits_per_sample); |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
456 break; |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
457 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
458 case TIFFTAG_COLORMAP: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
459 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
460 // TODO(maged): Fix output formatting to be consistent with matlab |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
461 // Matlab returns a float colormap? |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
462 uint16_t bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
463 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
464 error ("Failed to obtain the bit depth"); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
465 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
466 if (bits_per_sample > 24) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
467 error ("Too high bit depth for a palette image"); |
31098
3cbd0d82167c
getTag: Implemented all special tags, only unsupported geotiff tags not implemented
magedrifaat <magedrifaat@gmail.com>
parents:
31097
diff
changeset
|
468 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
469 uint32_t count = 1 << bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
470 uint16_t *red, *green, *blue; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
471 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP, |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
472 &red, &green, &blue)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
473 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
474 uint16NDArray mat_out (dim_vector (count, 3)); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
475 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
476 uint16NDArray red_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
477 = interpret_tag_data (red, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
478 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
479 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
480 uint16NDArray green_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
481 = interpret_tag_data (green, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
482 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
483 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
484 uint16NDArray blue_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
485 = interpret_tag_data (blue, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
486 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
487 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
488 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
489 octave_uint16 *out_ptr = mat_out.fortran_vec (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
490 memcpy (out_ptr, red_array.fortran_vec (), sizeof(uint16_t) * count); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
491 out_ptr += count; |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
492 memcpy (out_ptr, green_array.fortran_vec (), sizeof(uint16_t) * count); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
493 out_ptr += count; |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
494 memcpy (out_ptr, blue_array.fortran_vec (), sizeof(uint16_t) * count); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
495 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
496 tag_data_ovl(0) = octave_value (mat_out); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
497 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
498 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
499 case TIFFTAG_TRANSFERFUNCTION: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
500 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
501 uint16_t samples_per_pixel; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
502 if (! TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, &samples_per_pixel)) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
503 error ("Failed to obtain the number of samples per pixel"); |
31098
3cbd0d82167c
getTag: Implemented all special tags, only unsupported geotiff tags not implemented
magedrifaat <magedrifaat@gmail.com>
parents:
31097
diff
changeset
|
504 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
505 uint16_t bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
506 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
507 error ("Failed to obtain the number of samples per pixel"); |
31098
3cbd0d82167c
getTag: Implemented all special tags, only unsupported geotiff tags not implemented
magedrifaat <magedrifaat@gmail.com>
parents:
31097
diff
changeset
|
508 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
509 uint32_t count = 1 << bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
510 uint16_t *ch1, *ch2, *ch3; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
511 if (samples_per_pixel == 1) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
512 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
513 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP, &ch1)); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
514 tag_data_ovl(0) |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
515 = interpret_tag_data (ch1, count, TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
516 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
517 else |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
518 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
519 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP, |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
520 &ch1, &ch2, &ch3)); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
521 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
522 uint16NDArray mat_out (dim_vector (count, 3)); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
523 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
524 uint16NDArray ch1_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
525 = interpret_tag_data (ch1, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
526 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
527 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
528 uint16NDArray ch2_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
529 = interpret_tag_data (ch2, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
530 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
531 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
532 uint16NDArray ch3_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
533 = interpret_tag_data (ch3, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
534 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
535 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
536 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
537 octave_uint16 *out_ptr = mat_out.fortran_vec (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
538 memcpy (out_ptr, ch1_array.fortran_vec (), sizeof(uint16_t) * count); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
539 out_ptr += count; |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
540 memcpy (out_ptr, ch2_array.fortran_vec (), sizeof(uint16_t) * count); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
541 out_ptr += count; |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
542 memcpy (out_ptr, ch3_array.fortran_vec (), sizeof(uint16_t) * count); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
543 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
544 tag_data_ovl(0) = octave_value (mat_out); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
545 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
546 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
547 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
548 case TIFFTAG_PAGENUMBER: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
549 case TIFFTAG_HALFTONEHINTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
550 case TIFFTAG_DOTRANGE: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
551 case TIFFTAG_YCBCRSUBSAMPLING: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
552 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
553 uint16_t tag_part1, tag_part2; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
554 validate_tiff_get_field (TIFFGetField (tif, tag_id, |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
555 &tag_part1, &tag_part2)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
556 tag_data_ovl(0) |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
557 = interpret_tag_data (&tag_part1, 1, TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
558 tag_data_ovl(1) |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
559 = interpret_tag_data (&tag_part2, 1, TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
560 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
561 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
562 case TIFFTAG_SUBIFD: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
563 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
564 uint16_t count; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
565 uint64_t *offsets; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
566 validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &offsets)); |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
567 tag_data_ovl(0) = interpret_tag_data (offsets, count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
568 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
569 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
570 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
571 case TIFFTAG_EXTRASAMPLES: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
572 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
573 uint16_t count; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
574 uint16_t *types; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
575 validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &types)); |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
576 tag_data_ovl(0) = interpret_tag_data (types, count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
577 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
578 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
579 } |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
580 // TODO(maged): These tags are more complex to implement |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
581 // will be implemented and tested later. |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
582 case TIFFTAG_XMLPACKET: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
583 case TIFFTAG_RICHTIFFIPTC: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
584 case TIFFTAG_PHOTOSHOP: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
585 case TIFFTAG_ICCPROFILE: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
586 { |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
587 error ("Complex Tags not implemented"); |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
588 break; |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
589 } |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
590 // These tags are not mentioned in the LibTIFF documentation |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
591 // but are handled correctly by the library |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
592 case TIFFTAG_ZIPQUALITY: |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
593 case TIFFTAG_SGILOGDATAFMT: |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
594 case TIFFTAG_GRAYRESPONSEUNIT: |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
595 { |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
596 tag_data_ovl = get_scalar_field_data (tif, fip); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
597 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
598 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
599 default: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
600 tag_data_ovl = get_scalar_field_data (tif, fip); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
601 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
602 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
603 return tag_data_ovl; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
604 } |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
605 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
606 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
607 DEFUN_DLD (__open_tiff__, args, nargout, |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
608 "Open a Tiff file and return its handle") |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
609 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
610 #if defined (HAVE_TIFF) |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
611 int nargin = args.length (); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
612 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
613 if (nargin == 0 || nargin > 2) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
614 { |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
615 // TODO(maged): return invalid object instead?? |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
616 error ("No filename supplied\n"); |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
617 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
618 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
619 std::string filename = args (0).string_value (); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
620 std::string mode = "r"; |
31094
ab5b33e447b0
Modified getTag to account for different tag data types and multivalued tags, the current implementation is still buggy for most tags and data types
magedrifaat <magedrifaat@gmail.com>
parents:
31093
diff
changeset
|
621 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
622 // TODO(maged): check valid mode |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
623 if (nargin == 2) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
624 mode = args (1).string_value (); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
625 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
626 // TODO(maged): Look into unwind action |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
627 TIFF *tif = TIFFOpen (filename.c_str (), mode.c_str ()); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
628 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
629 if (! tif) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
630 error ("Failed to open Tiff file\n"); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
631 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
632 // TODO(maged): use inheritance of octave_base_value instead |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
633 octave_value tiff_ov = octave_value ((uint64_t)tif); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
634 return octave_value_list (tiff_ov); |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
635 #else |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
636 err_disabled_feature ("Tiff", "Tiff"); |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
637 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
638 } |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
639 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
640 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
641 DEFUN_DLD (__close_tiff__, args, nargout, |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
642 "Close a tiff file") |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
643 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
644 #if defined (HAVE_TIFF) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
645 int nargin = args.length (); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
646 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
647 if (nargin == 0) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
648 error ("No handle provided\n"); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
649 |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
650 TIFF *tif = (TIFF *)(args (0).uint64_value ()); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
651 TIFFClose (tif); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
652 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
653 return octave_value_list (); |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
654 #else |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
655 err_disabled_feature ("close", "Tiff"); |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
656 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
657 } |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
658 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
659 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
660 DEFUN_DLD (__tiff_get_tag__, args, nargout, |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
661 "Get the value of a tag from a tiff image") |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
662 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
663 #if defined (HAVE_TIFF) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
664 int nargin = args.length (); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
665 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
666 if (nargin == 0) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
667 error ("No handle provided\n"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
668 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
669 if (nargin < 2) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
670 error ("No tag name provided\n"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
671 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
672 TIFF *tif = (TIFF *)(args (0).uint64_value ()); |
31094
ab5b33e447b0
Modified getTag to account for different tag data types and multivalued tags, the current implementation is still buggy for most tags and data types
magedrifaat <magedrifaat@gmail.com>
parents:
31093
diff
changeset
|
673 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
674 uint32_t tag_id; |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
675 const TIFFField *fip; |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
676 if (args (1).type_name () == "string") |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
677 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
678 std::string tagName = args (1).string_value (); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
679 fip = TIFFFieldWithName (tif, tagName.c_str ()); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
680 if (! fip) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
681 error ("Tiff tag not found"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
682 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
683 tag_id = TIFFFieldTag (fip); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
684 } |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
685 else |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
686 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
687 tag_id = args (1).int_value (); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
688 fip = TIFFFieldWithTag (tif, tag_id); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
689 // TODO(maged): Handle other types of errors (e.g. unsupported tags) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
690 if (! fip) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
691 error ("Tiff tag not found"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
692 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
693 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
694 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
695 octave_value_list tag_data_ovl = get_field_data (tif, fip); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
696 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
697 return tag_data_ovl; |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
698 #else |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
699 err_disabled_feature ("getTag", "Tiff"); |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
700 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
701 } |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
702 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
703 DEFUN_DLD (__tiff_read__, args, nargout, |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
704 "Read the image in the current IFD") |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
705 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
706 #if defined (HAVE_TIFF) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
707 int nargin = args.length (); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
708 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
709 if (nargin == 0) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
710 error ("No handle provided\n"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
711 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
712 TIFF *tif = (TIFF *)(args (0).uint64_value ()); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
713 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
714 // Check: Strips vs Tiles |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
715 // Planar Configuration |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
716 // SamplesPerPixel and bits_per_smaple |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
717 // nargout and ycbcr |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
718 // ExtendedSamples? TransferFunction? GrayResponse? ColorMap? |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
719 // What about floating point images? |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
720 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
721 // Obtain all necessary tags |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
722 // The main purpose of this struct is to hold all the necessary tags that |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
723 // will be common among all the different cases of handling the the image |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
724 // data to avoid repeating the same calls to TIFFGetField in the different |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
725 // functions as each call is a possible point of failure |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
726 tiff_image_data image_data; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
727 if (! TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &image_data.width)) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
728 error ("Failed to read image width"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
729 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
730 if (! TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &image_data.height)) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
731 error ("Failed to read image height"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
732 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
733 if (! TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
734 &image_data.samples_per_pixel)) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
735 error ("Failed to read the SamplesPerPixel tag"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
736 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
737 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
738 &image_data.bits_per_sample)) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
739 error ("Failed to read the BitsPerSample tag"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
740 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
741 if (! TIFFGetField (tif, TIFFTAG_PLANARCONFIG, |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
742 &image_data.planar_configuration)) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
743 error ("Failed to read the PlanarConfiguration tag"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
744 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
745 image_data.is_tiled = TIFFIsTiled(tif); |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
746 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
747 octave_value_list retval; |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
748 switch (image_data.bits_per_sample) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
749 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
750 case 1: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
751 retval(0) = read_image<boolNDArray> (tif, &image_data); |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
752 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
753 case 4: |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
754 case 8: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
755 retval(0) = read_image<uint8NDArray> (tif, &image_data); |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
756 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
757 case 16: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
758 retval(0) = read_image<uint16NDArray> (tif, &image_data); |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
759 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
760 case 32: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
761 retval(0) = read_image<uint32NDArray> (tif, &image_data); |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
762 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
763 case 64: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
764 retval(0) = read_image<uint64NDArray> (tif, &image_data); |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
765 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
766 default: |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
767 error ("Unsupported bit depth"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
768 } |
31110
2daeeff33980
Tiff read fixed segfault bug for compressed images
magedrifaat <magedrifaat@gmail.com>
parents:
31109
diff
changeset
|
769 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
770 return retval; |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
771 #else |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
772 err_disabled_feature ("read", "Tiff"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
773 #endif |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
774 } |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
775 } |