annotate libinterp/dldfcn/__tiff__.cc @ 31113:a74059523d74

Tiff read: use template to remove repitition in filling matrices * __tiff__.cc (read_stripped_image): modified the function to be templated so it can be used for all matrix types generically, also writes directly to the underlying pointer of the matrix.
author magedrifaat <magedrifaat@gmail.com>
date Sat, 16 Jul 2022 01:26:40 +0200
parents e3d8443585fe
children 9dead1249449
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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++)
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
86 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
87 + column * image_data->height
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
88 + row_index + row_subindex]
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
89 = ((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
90 + 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
91 }
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
92 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
93 && 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
94 {
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
95 // 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
96 uint8_t nibble
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
97 = ((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
98 // 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
99 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
100 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
101 + 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
102 }
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
103 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
104 && 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
105 {
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
106 uint8_t byte
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
107 = ((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
108 // 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
109 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
110 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
111 + 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
112 }
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
113 else
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
114 error ("Unsupported bit depth");
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
115 }
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 row_index += rows_in_strip;
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
118 }
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
119 else
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
120 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
121 }
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
122 _TIFFfree (buf);
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
123
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
124 return octave_value(img);
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
125 }
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
126
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
127 template <typename T>
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
128 octave_value
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
129 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
130 {
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
131 if (image_data->is_tiled)
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
132 // TODO(maged): Implement tiled images
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
133 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
134 else
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
135 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
136 }
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
137
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
138 // 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
139 void
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
140 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
141 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
142 if (status != 1)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
143 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
144 if (p_to_free != NULL)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
145 _TIFFfree (p_to_free);
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
146 error ("Failed to read tag");
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 }
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
149
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
150 // Convert tag value to double
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
151 octave_value_list
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
152 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
153 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
154 double retval;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
155
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
156 switch (tag_datatype)
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 case TIFF_BYTE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
159 case TIFF_UNDEFINED:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
160 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
161 retval = (double)(*((uint8_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
162 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
163 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
164 case TIFF_SHORT:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
165 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
166 retval = (double)(*((uint16_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
167 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
168 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
169 case TIFF_LONG:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
170 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
171 retval = (double)(*((uint32_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
172 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
173 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
174 case TIFF_LONG8:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
175 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
176 retval = (double)(*((uint64_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
177 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
178 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
179 case TIFF_RATIONAL:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
180 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
181 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
182 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
183 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
184 case TIFF_SBYTE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
185 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
186 retval = (double)(*((int8_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
187 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
188 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
189 case TIFF_SSHORT:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
190 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
191 retval = (double)(*((int16_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
192 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
193 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
194 case TIFF_SLONG:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
195 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
196 retval = (double)(*((int32_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
197 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
198 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
199 case TIFF_SLONG8:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
200 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
201 retval = (double)(*((int64_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
202 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
203 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
204 case TIFF_FLOAT:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
205 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
206 retval = *((float *)data);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
207 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
208 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
209 case TIFF_DOUBLE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
210 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
211 retval = *((double *)data);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
212 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
213 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
214 case TIFF_SRATIONAL:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
215 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
216 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
217 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
218 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
219 case TIFF_IFD:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
220 case TIFF_IFD8:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
221 error ("Unimplemented IFFD data type");
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
222 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
223 default:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
224 error ("Unsupported tag data type");
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
225 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
226
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
227 return octave_value_list (octave_value (retval));
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
228 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
229
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
230 // Convert memory buffer into suitable octave values
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
231 // depending on tag_datatype
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
232 octave_value_list
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
233 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
234 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
235 octave_value_list ovl_data;
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
236 // Apparently matlab converts scalar numerical values into double
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
237 // but doesn't do the same for arrays
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
238 if (count == 1 && tag_datatype != TIFF_ASCII)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
239 {
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
240 ovl_data = interpret_scalar_tag_data (data, tag_datatype);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
241 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
242 else
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
243 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
244 dim_vector arr_dims (1, count);
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 switch (tag_datatype)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
247 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
248 case TIFF_BYTE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
249 case TIFF_UNDEFINED:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
250 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
251 uint8NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
252 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
253 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
254 arr(i) = ((uint8_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
255 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
256 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
257 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
258 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
259 case TIFF_ASCII:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
260 {
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
261 ovl_data(0) = octave_value (*(char **)data);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
262 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
263 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
264 case TIFF_SHORT:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
265 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
266 uint16NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
267 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
268 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
269 arr(i) = ((uint16_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
270 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
271 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
272 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
273 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
274 case TIFF_LONG:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
275 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
276 uint32NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
277 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
278 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
279 arr(i) = ((uint32_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
280 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
281 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
282 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
283 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
284 case TIFF_LONG8:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
285 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
286 uint64NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
287 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
288 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
289 arr(i) = ((uint64_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
290 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
291 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
292 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
293 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
294 case TIFF_RATIONAL:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
295 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
296 NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
297 for (uint32_t i = 0; i < count; i+=2)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
298 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
299 arr(i / 2) = (float)((uint32_t *)data)[i]
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
300 / (float)((uint32_t *)data)[i+1];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
301 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
302 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
303 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
304 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
305 case TIFF_SBYTE:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
306 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
307 int8NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
308 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
309 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
310 arr(i) = ((int8_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
311 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
312 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
313 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
314 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
315 case TIFF_SSHORT:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
316 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
317 int16NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
318 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
319 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
320 arr(i) = ((int16_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
321 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
322 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
323 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
324 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
325 case TIFF_SLONG:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
326 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
327 int32NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
328 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
329 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
330 arr(i) = ((int32_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
331 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
332 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
333 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
334 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
335 case TIFF_SLONG8:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
336 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
337 int64NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
338 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
339 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
340 arr(i) = ((int64_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
341 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
342 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
343 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
344 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
345 case TIFF_FLOAT:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
346 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
347 NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
348 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
349 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
350 arr(i) = ((float *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
351 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
352 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
353 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
354 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
355 case TIFF_DOUBLE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
356 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
357 NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
358 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
359 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
360 arr(i) = ((double *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
361 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
362 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
363 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
364 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
365 case TIFF_SRATIONAL:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
366 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
367 NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
368 for (uint32_t i = 0; i < count; i+=2)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
369 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
370 arr(i / 2) = (float)((int32_t *)data)[i]
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
371 / (float)((int32_t *)data)[i+1];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
372 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
373 ovl_data(0) = arr;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
374 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
375 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
376 case TIFF_IFD:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
377 case TIFF_IFD8:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
378 // TODO(maged): implement IFD datatype?
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
379 error ("Unimplemented IFFD data type");
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
380 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
381 default:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
382 error ("Unsupported tag data type");
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
383 }
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
384 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
385
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
386 return ovl_data;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
387 }
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
388
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
389 octave_value_list
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
390 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
391 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
392 octave_value_list tag_data_ovl;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
393 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
394
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
395 // TIFFFieldReadCount returns VARIABLE for some scalar tags
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
396 // (e.g. Compression) But TIFFFieldPassCount seems consistent
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
397 // 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
398 // 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
399 if (TIFFFieldPassCount (fip))
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
400 error ("Unsupported tag");
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
401
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
402 // 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
403 int type_size = TIFFDataWidth (TIFFFieldDataType (fip));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
404 void *data = _TIFFmalloc (type_size);
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
405 validate_tiff_get_field (TIFFGetField (tif, tag_id, data), data);
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
406 tag_data_ovl = interpret_tag_data (data, 1, TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
407 _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
408
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
409 return tag_data_ovl;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
410 }
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
411
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
412 octave_value_list
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
413 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
414 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
415 void *data;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
416 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
417
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
418 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
419 }
31097
75ab26f147a5 getTag: Implemented single array tags, only multi-array and special tags are unimplemented
magedrifaat <magedrifaat@gmail.com>
parents: 31096
diff changeset
420
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
421 octave_value_list
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
422 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
423 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
424 octave_value_list tag_data_ovl;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
425 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
426
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
427 // 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
428 switch (tag_id)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
429 {
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
430 case TIFFTAG_STRIPBYTECOUNTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
431 case TIFFTAG_STRIPOFFSETS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
432 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
433 TIFFNumberOfStrips (tif));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
434 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
435 case TIFFTAG_TILEBYTECOUNTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
436 case TIFFTAG_TILEOFFSETS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
437 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
438 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
439 case TIFFTAG_YCBCRCOEFFICIENTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
440 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
441 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
442 case TIFFTAG_REFERENCEBLACKWHITE:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
443 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
444 break;
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
445 case TIFFTAG_GRAYRESPONSECURVE:
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
446 {
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
447 uint16_t bits_per_sample;
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
448 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample))
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
449 error ("Failed to obtain the bit depth");
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 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
452 break;
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
453 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
454 case TIFFTAG_COLORMAP:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
455 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
456 uint16_t bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
457 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
458 error ("Failed to obtain the bit depth");
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
459
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
460 if (bits_per_sample > 24)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
461 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
462
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
463 uint32_t count = 1 << bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
464 uint16_t *red, *green, *blue;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
465 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP,
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
466 &red, &green, &blue));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
467 tag_data_ovl(0)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
468 = octave_value (interpret_tag_data (red, count,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
469 TIFFFieldDataType (fip)));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
470 tag_data_ovl(1)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
471 = octave_value (interpret_tag_data (green, count,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
472 TIFFFieldDataType (fip)));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
473 tag_data_ovl(2)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
474 = octave_value (interpret_tag_data (blue, count,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
475 TIFFFieldDataType (fip)));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
476
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
477 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
478 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
479 case TIFFTAG_TRANSFERFUNCTION:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
480 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
481 uint16_t samples_per_pixel;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
482 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
483 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
484
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
485 uint16_t bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
486 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
487 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
488
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
489 uint32_t count = 1 << bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
490 uint16_t *ch1, *ch2, *ch3;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
491 if (samples_per_pixel == 1)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
492 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
493 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
494 tag_data_ovl(0)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
495 = octave_value (interpret_tag_data (ch1, count,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
496 TIFFFieldDataType (fip)));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
497 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
498 else
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
499 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
500 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP,
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
501 &ch1, &ch2, &ch3));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
502 tag_data_ovl(0)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
503 = octave_value (interpret_tag_data (ch1, count,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
504 TIFFFieldDataType (fip)));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
505 tag_data_ovl(1)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
506 = octave_value (interpret_tag_data (ch2, count,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
507 TIFFFieldDataType (fip)));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
508 tag_data_ovl(2)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
509 = octave_value (interpret_tag_data (ch3, count,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
510 TIFFFieldDataType (fip)));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
511 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
512 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
513 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
514 case TIFFTAG_PAGENUMBER:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
515 case TIFFTAG_HALFTONEHINTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
516 case TIFFTAG_DOTRANGE:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
517 case TIFFTAG_YCBCRSUBSAMPLING:
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 uint16_t tag_part1, tag_part2;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
520 validate_tiff_get_field (TIFFGetField (tif, tag_id,
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
521 &tag_part1, &tag_part2));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
522 tag_data_ovl(0)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
523 = octave_value (interpret_tag_data (&tag_part1, 1,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
524 TIFFFieldDataType (fip)));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
525 tag_data_ovl(1)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
526 = octave_value (interpret_tag_data (&tag_part2, 1,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
527 TIFFFieldDataType (fip)));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
528 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
529 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
530 case TIFFTAG_SUBIFD:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
531 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
532 uint16_t count;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
533 uint64_t *offsets;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
534 validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &offsets));
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
535 tag_data_ovl = interpret_tag_data (offsets, count, TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
536 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
537 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
538 case TIFFTAG_EXTRASAMPLES:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
539 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
540 uint16_t count;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
541 uint16_t *types;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
542 validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &types));
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
543 tag_data_ovl = interpret_tag_data (types, count, TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
544 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
545 }
31103
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
546 // 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
547 // will be implemented and tested later.
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
548 case TIFFTAG_XMLPACKET:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
549 case TIFFTAG_RICHTIFFIPTC:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
550 case TIFFTAG_PHOTOSHOP:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
551 case TIFFTAG_ICCPROFILE:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
552 {
31103
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
553 error ("Complex Tags not implemented");
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
554 break;
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
555 }
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
556 // 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
557 // 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
558 case TIFFTAG_ZIPQUALITY:
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
559 case TIFFTAG_SGILOGDATAFMT:
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
560 case TIFFTAG_GRAYRESPONSEUNIT:
31103
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
561 {
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
562 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
563 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
564 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
565 default:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
566 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
567 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
568
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
569 return tag_data_ovl;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
570 }
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
571 #endif
31102
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 DEFUN_DLD (__open_tiff__, args, nargout,
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
574 "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
575 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
576 #if defined (HAVE_TIFF)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
577 int nargin = args.length ();
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
578
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
579 if (nargin == 0 || nargin > 2)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
580 {
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
581 // TODO(maged): return invalid object instead??
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
582 error ("No filename supplied\n");
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
583 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
584
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
585 std::string filename = args (0).string_value ();
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
586 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
587
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
588 // TODO(maged): check valid mode
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
589 if (nargin == 2)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
590 mode = args (1).string_value ();
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
591
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
592 // TODO(maged): Look into unwind action
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
593 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
594
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
595 if (! tif)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
596 error ("Failed to open Tiff file\n");
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
597
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
598 // 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
599 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
600 return octave_value_list (tiff_ov);
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
601 #else
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
602 err_disabled_feature ("Tiff", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
603 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
604 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
605
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
606
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
607 DEFUN_DLD (__close_tiff__, args, nargout,
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
608 "Close a tiff file")
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)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
611 int nargin = args.length ();
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
612
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
613 if (nargin == 0)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
614 error ("No handle provided\n");
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
615
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
616 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
617 TIFFClose (tif);
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
618
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
619 return octave_value_list ();
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
620 #else
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
621 err_disabled_feature ("close", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
622 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
623 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
624
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
625
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
626 DEFUN_DLD (__tiff_get_tag__, args, nargout,
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
627 "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
628 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
629 #if defined (HAVE_TIFF)
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
630 int nargin = args.length ();
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
631
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
632 if (nargin == 0)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
633 error ("No handle provided\n");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
634
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
635 if (nargin < 2)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
636 error ("No tag name provided\n");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
637
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
638 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
639
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
640 uint32_t tag_id;
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
641 const TIFFField *fip;
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
642 if (args (1).type_name () == "string")
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
643 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
644 std::string tagName = args (1).string_value ();
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
645 fip = TIFFFieldWithName (tif, tagName.c_str ());
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
646 if (! fip)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
647 error ("Tiff tag not found");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
648
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
649 tag_id = TIFFFieldTag (fip);
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
650 }
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
651 else
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
652 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
653 tag_id = args (1).int_value ();
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
654 fip = TIFFFieldWithTag (tif, tag_id);
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
655 // 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
656 if (! fip)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
657 error ("Tiff tag not found");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
658 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
659
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
660
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
661 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
662
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
663 return tag_data_ovl;
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
664 #else
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
665 err_disabled_feature ("getTag", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
666 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
667 }
31109
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 DEFUN_DLD (__tiff_read__, args, nargout,
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
670 "Read the image in the current IFD")
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 #if defined (HAVE_TIFF)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
673 int nargin = args.length ();
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
674
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
675 if (nargin == 0)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
676 error ("No handle provided\n");
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 TIFF *tif = (TIFF *)(args (0).uint64_value ());
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
679
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
680 // Check: Strips vs Tiles
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
681 // Planar Configuration
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
682 // SamplesPerPixel and bits_per_smaple
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
683 // nargout and ycbcr
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
684 // ExtendedSamples? TransferFunction? GrayResponse? ColorMap?
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
685 // What about floating point images?
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 // Obtain all necessary tags
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
688 // 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
689 // 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
690 // 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
691 // 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
692 tiff_image_data image_data;
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
693 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
694 error ("Failed to read image width");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
695
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
696 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
697 error ("Failed to read image height");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
698
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
699 if (! TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL,
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
700 &image_data.samples_per_pixel))
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
701 error ("Failed to read the SamplesPerPixel tag");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
702
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
703 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE,
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
704 &image_data.bits_per_sample))
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
705 error ("Failed to read the BitsPerSample tag");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
706
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
707 if (! TIFFGetField (tif, TIFFTAG_PLANARCONFIG,
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
708 &image_data.planar_configuration))
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
709 error ("Failed to read the PlanarConfiguration tag");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
710
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
711 image_data.is_tiled = TIFFIsTiled(tif);
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
712
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
713 octave_value_list retval;
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
714 switch (image_data.bits_per_sample)
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
715 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
716 case 1:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
717 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
718 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
719 case 4:
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
720 case 8:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
721 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
722 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
723 case 16:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
724 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
725 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
726 case 32:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
727 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
728 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
729 case 64:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
730 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
731 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
732 default:
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
733 error ("Unsupported bit depth");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
734 }
31110
2daeeff33980 Tiff read fixed segfault bug for compressed images
magedrifaat <magedrifaat@gmail.com>
parents: 31109
diff changeset
735
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
736 return retval;
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
737 #else
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
738 err_disabled_feature ("read", "Tiff");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
739 #endif
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
740 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
741 }