annotate libinterp/dldfcn/__tiff__.cc @ 31119:dbca50246dfc

Tiff read: changed logic to matrix operations instead of pointer math * __tiff__.cc(read_stripped_image): changed logic of reading strip data to the output matrix to rely on matrix operations instead of pointer math.
author magedrifaat <magedrifaat@gmail.com>
date Tue, 19 Jul 2022 19:45:06 +0200
parents f8be3654caef
children 46bb98cec195
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
31115
5b3465a9c340 Tiff read: support for reading image arranged in planes (RRRGGGBBB)
magedrifaat <magedrifaat@gmail.com>
parents: 31114
diff changeset
19 // TODO(maged): Fix warnings
31092
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
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
36 // Error if status is not 1 (success status for TIFFGetField)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
37 void
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
38 validate_tiff_get_field (bool status, void *p_to_free=NULL)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
39 {
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
40 if (status != 1)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
41 {
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
42 if (p_to_free != NULL)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
43 _TIFFfree (p_to_free);
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
44 error ("Failed to read tag");
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
45 }
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
46 }
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
47
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
48 template <typename T>
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
49 octave_value
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
50 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
51 {
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
52 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
53
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
54 T img;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
55
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
56 // For 1-bit and 4-bit images, each row must be byte aligned and padding
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
57 // is added to the end of the row to reach the byte mark.
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
58 // To facilitate reading the data, the matrix is defined with the padded
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
59 // size and the padding is removed at the end.
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
60 uint32_t padded_width = image_data->width;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
61 uint8_t remove_padding = 0;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
62 if ((image_data->bits_per_sample == 1 || image_data->bits_per_sample == 4)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
63 && padded_width % 8 != 0)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
64 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
65 padded_width += (8 - padded_width % 8) % 8;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
66 remove_padding = 1;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
67 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
68
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
69 // The matrix dimensions are defined in the order that corresponds to
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
70 // the order of strip data read from LibTIFF.
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
71 // At the end, the matrix is permutated to the order expected by Octave
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
72 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
73 img = T (dim_vector (image_data->samples_per_pixel, padded_width,
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
74 image_data->height));
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
75 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
76 img = T (dim_vector (padded_width, image_data->height,
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
77 image_data->samples_per_pixel));
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
78 else
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
79 error ("Unsupported Planar Configuration");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
80
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
81 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
82
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
83 // 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
84 uint32_t strip_count = TIFFNumberOfStrips (tif);
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
85
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
86 // Can't rely on StripByteCounts because in compressed images
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
87 // the byte count reflect the actual number of bytes stored
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
88 // in the file not the size of the uncompressed strip
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
89 int64_t strip_size;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
90 uint64_t written_size = 0;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
91 uint64_t image_size = padded_width * image_data->height
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
92 * image_data->samples_per_pixel
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
93 * sizeof (P);
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
94 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
95 {
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
96 // Read the strip data into the matrix directly
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
97 // TODO(maged): Are incorrect sized strips checked internally?
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
98 strip_size = TIFFReadEncodedStrip (tif, strip, img_fvec, -1);
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
99
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
100 // Check if the strip read failed.
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
101 if (strip_size == -1)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
102 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
103
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
104 // Check if the size being read exceeds the bounds of the matrix
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
105 // In case of a corrupt image with more data than needed
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
106 if (written_size + strip_size > image_size)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
107 error ("Strip data is larger than the image size");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
108
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
109 if (image_data->bits_per_sample == 1)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
110 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
111 if (image_data->samples_per_pixel != 1)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
112 error ("Bi-Level images must have one channel only");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
113
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
114 // The strip size is multiplied by 8 to reflect tha actual
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
115 // number of bytes written to the matrix since each byte
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
116 // in the original strip contains 8 pixels of data
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
117 strip_size *= 8;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
118
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
119 // Checking bounds again with the new size
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
120 if (written_size + strip_size > image_size)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
121 error ("Strip data is larger than the image size");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
122
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
123 // Iterate over the memory region backwards to expand the bits
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
124 // to their respective bytes without overwriting the read data
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
125 for (int64_t pixel = strip_size - 1; pixel >= 0; pixel--)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
126 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
127 // TODO(maged): is it necessary to check FillOrder?
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
128 uint8_t bit_number = 7 - pixel % 8;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
129 img_fvec[pixel] = (img_fvec[pixel / 8] >> bit_number) & 0x01;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
130 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
131 break;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
132 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
133 else if (image_data->bits_per_sample == 4)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
134 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
135 if (image_data->samples_per_pixel != 1)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
136 error ("4-bit images are only supported for grayscale");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
137
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
138 // Strip size is multplied by as each byte contains 2 pixels
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
139 // and each pixel is later expanded into its own byte
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
140 strip_size *= 2;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
141
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
142 // Checking bounds again with the ne size
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
143 if (written_size + strip_size > image_size)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
144 error ("Strip data is larger than the image size");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
145
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
146 // Iterate over the memory region backwards to expand the nibbles
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
147 // to their respective bytes without overwriting the read data
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
148 for (int64_t pixel = strip_size - 1; pixel >= 0; pixel--)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
149 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
150 uint8_t shift = pixel % 2 == 0? 4: 0;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
151 img_fvec[pixel] = (img_fvec[pixel / 2] >> shift) & 0x0F;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
152 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
153 break;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
154 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
155 else if (image_data->bits_per_sample != 8 &&
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
156 image_data->bits_per_sample != 16 &&
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
157 image_data->bits_per_sample != 32 &&
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
158 image_data->bits_per_sample != 64)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
159 error ("Unsupported bit depth");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
160
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
161 // Advance the pointer by the amount of bytes read
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
162 img_fvec = (P*)((uint8_t *)img_fvec + strip_size);
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
163 written_size += strip_size;
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
164 }
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
165
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
166 // The matrices are permutated back to the shape expected by Octave
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
167 // which is height x width x channels
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
168 Array<octave_idx_type> perm (dim_vector (3, 1));
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
169 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
170 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
171 perm(0) = 2;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
172 perm(1) = 1;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
173 perm(2) = 0;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
174 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
175 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
176 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
177 perm(0) = 1;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
178 perm(1) = 0;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
179 perm(2) = 2;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
180 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
181
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
182 img = img.permute (perm);
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
183
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
184 if (remove_padding)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
185 img.resize (dim_vector (image_data->height, image_data->width));
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
186
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
187 return octave_value (img);
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
188 }
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
189
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
190 template <typename T>
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
191 octave_value
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
192 read_tiled_image (TIFF *tif, tiff_image_data *image_data)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
193 {
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
194 typedef typename T::element_type P;
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
195
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
196 T img = T (dim_vector (image_data->height, image_data->width,
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
197 image_data->samples_per_pixel));
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
198 P *img_fvec = img.fortran_vec ();
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
199
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
200 // Obtain the necessary data for handling the tiles
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
201 uint32_t tile_width, tile_height;
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
202 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_TILEWIDTH,
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
203 &tile_width));
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
204 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_TILELENGTH,
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
205 &tile_height));
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
206
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
207 tdata_t buf = _TIFFmalloc (TIFFTileSize (tif));
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
208 if (! buf)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
209 error ("Failed to allocate buffer for tile data");
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
210
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
211 // TODO(maged): implement support for ImageDepth?
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
212 uint32_t tile_size;
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
213 for (uint32_t base_row = 0; base_row < image_data->height; base_row += tile_height)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
214 for (uint32_t base_col = 0; base_col < image_data->width; base_col += tile_width)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
215 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
216 {
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
217 if ((tile_size = TIFFReadTile(tif, buf, base_col, base_row, 0, 0)) == -1)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
218 error ("Failed to read tile data");
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
219
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
220 // Boundary tiles are zero padded so we might need to stop earlier than the end of the tile
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
221 for (uint32_t sub_row = 0; sub_row < tile_height && base_row + sub_row < image_data->height; sub_row++)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
222 for (uint32_t sub_col = 0; sub_col < tile_width && base_col + sub_col < image_data->width; sub_col++)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
223 for (uint16_t sample = 0; sample < image_data->samples_per_pixel; sample++)
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
224 img_fvec[sample * image_data->width * image_data->height
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
225 + (base_col + sub_col) * image_data->height
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
226 + base_row + sub_row]
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
227 = ((P *)buf)[sub_row * tile_width * image_data->samples_per_pixel
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
228 + sub_col * image_data->samples_per_pixel
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
229 + sample];
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
230 }
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
231 else
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
232 // TODO(maged): Implement for separated planes
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
233 error ("Tiled images with separate planar configuration not supported");
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
234
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
235 _TIFFfree (buf);
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
236
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
237 return octave_value (img);
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
238 }
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
239
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
240 template <typename T>
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
241 octave_value
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
242 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
243 {
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
244 if (image_data->is_tiled)
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
245 return read_tiled_image<T> (tif, image_data);
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
246 else
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
247 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
248 }
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
249
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
250 // Convert tag value to double
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
251 octave_value
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
252 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
253 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
254 double retval;
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 switch (tag_datatype)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
257 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
258 case TIFF_BYTE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
259 case TIFF_UNDEFINED:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
260 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
261 retval = (double)(*((uint8_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
262 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
263 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
264 case TIFF_SHORT:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
265 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
266 retval = (double)(*((uint16_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
267 break;
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 case TIFF_LONG:
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 retval = (double)(*((uint32_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
272 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
273 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
274 case TIFF_LONG8:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
275 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
276 retval = (double)(*((uint64_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
277 break;
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 case TIFF_RATIONAL:
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 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
282 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
283 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
284 case TIFF_SBYTE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
285 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
286 retval = (double)(*((int8_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
287 break;
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 case TIFF_SSHORT:
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 retval = (double)(*((int16_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
292 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
293 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
294 case TIFF_SLONG:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
295 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
296 retval = (double)(*((int32_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
297 break;
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 case TIFF_SLONG8:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
300 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
301 retval = (double)(*((int64_t *)data));
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
302 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
303 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
304 case TIFF_FLOAT:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
305 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
306 retval = *((float *)data);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
307 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
308 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
309 case TIFF_DOUBLE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
310 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
311 retval = *((double *)data);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
312 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
313 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
314 case TIFF_SRATIONAL:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
315 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
316 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
317 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
318 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
319 case TIFF_IFD:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
320 case TIFF_IFD8:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
321 error ("Unimplemented IFFD data type");
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
322 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
323 default:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
324 error ("Unsupported tag data type");
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
325 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
326
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
327 return octave_value (retval);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
328 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
329
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
330 // Convert memory buffer into a suitable octave value
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
331 // depending on tag_datatype
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
332 octave_value
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
333 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
334 {
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
335 octave_value retval;
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
336 // Apparently matlab converts scalar numerical values into double
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
337 // but doesn't do the same for arrays
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
338 if (count == 1 && tag_datatype != TIFF_ASCII)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
339 {
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
340 retval = interpret_scalar_tag_data (data, tag_datatype);
31105
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 else
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
343 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
344 dim_vector arr_dims (1, count);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
345
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
346 switch (tag_datatype)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
347 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
348 case TIFF_BYTE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
349 case TIFF_UNDEFINED:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
350 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
351 uint8NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
352 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
353 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
354 arr(i) = ((uint8_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
355 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
356 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
357 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
358 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
359 case TIFF_ASCII:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
360 {
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
361 retval = octave_value (*(char **)data);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
362 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
363 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
364 case TIFF_SHORT:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
365 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
366 uint16NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
367 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
368 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
369 arr(i) = ((uint16_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
370 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
371 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
372 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
373 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
374 case TIFF_LONG:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
375 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
376 uint32NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
377 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
378 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
379 arr(i) = ((uint32_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
380 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
381 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
382 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
383 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
384 case TIFF_LONG8:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
385 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
386 uint64NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
387 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
388 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
389 arr(i) = ((uint64_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
390 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
391 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
392 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
393 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
394 case TIFF_RATIONAL:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
395 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
396 NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
397 for (uint32_t i = 0; i < count; i+=2)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
398 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
399 arr(i / 2) = (float)((uint32_t *)data)[i]
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
400 / (float)((uint32_t *)data)[i+1];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
401 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
402 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
403 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
404 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
405 case TIFF_SBYTE:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
406 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
407 int8NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
408 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
409 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
410 arr(i) = ((int8_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
411 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
412 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
413 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
414 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
415 case TIFF_SSHORT:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
416 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
417 int16NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
418 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
419 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
420 arr(i) = ((int16_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
421 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
422 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
423 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
424 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
425 case TIFF_SLONG:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
426 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
427 int32NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
428 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
429 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
430 arr(i) = ((int32_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
431 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
432 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
433 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
434 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
435 case TIFF_SLONG8:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
436 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
437 int64NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
438 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
439 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
440 arr(i) = ((int64_t *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
441 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
442 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
443 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
444 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
445 case TIFF_FLOAT:
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
446 {
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
447 NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
448 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
449 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
450 arr(i) = ((float *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
451 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
452 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
453 break;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
454 }
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
455 case TIFF_DOUBLE:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
456 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
457 NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
458 for (uint32_t i = 0; i < count; i++)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
459 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
460 arr(i) = ((double *)data)[i];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
461 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
462 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
463 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
464 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
465 case TIFF_SRATIONAL:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
466 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
467 NDArray arr (arr_dims);
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
468 for (uint32_t i = 0; i < count; i+=2)
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
469 {
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
470 arr(i / 2) = (float)((int32_t *)data)[i]
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
471 / (float)((int32_t *)data)[i+1];
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
472 }
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
473 retval = octave_value (arr);
31105
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
474 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
475 }
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
476 case TIFF_IFD:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
477 case TIFF_IFD8:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
478 // TODO(maged): implement IFD datatype?
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
479 error ("Unimplemented IFFD data type");
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
480 break;
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
481 default:
7c5b8a294f60 getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents: 31104
diff changeset
482 error ("Unsupported tag data type");
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
483 }
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
484 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
485
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
486 return retval;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
487 }
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
488
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
489 octave_value
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
490 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
491 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
492 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
493
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
494 // TIFFFieldReadCount returns VARIABLE for some scalar tags
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
495 // (e.g. Compression) But TIFFFieldPassCount seems consistent
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
496 // 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
497 // 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
498 if (TIFFFieldPassCount (fip))
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
499 error ("Unsupported tag");
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
500
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
501 // 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
502 int type_size = TIFFDataWidth (TIFFFieldDataType (fip));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
503 void *data = _TIFFmalloc (type_size);
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
504 validate_tiff_get_field (TIFFGetField (tif, tag_id, data), data);
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
505 octave_value tag_data_ov = interpret_tag_data (data, 1,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
506 TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
507 _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
508
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
509 return tag_data_ov;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
510 }
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
511
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
512 octave_value
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
513 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
514 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
515 void *data;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
516 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
517
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
518 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
519 }
31097
75ab26f147a5 getTag: Implemented single array tags, only multi-array and special tags are unimplemented
magedrifaat <magedrifaat@gmail.com>
parents: 31096
diff changeset
520
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
521 octave_value
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
522 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
523 {
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
524 octave_value tag_data_ov;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
525 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
526
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
527 // 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
528 switch (tag_id)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
529 {
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
530 case TIFFTAG_STRIPBYTECOUNTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
531 case TIFFTAG_STRIPOFFSETS:
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
532 tag_data_ov = get_array_field_data (tif, fip,
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
533 TIFFNumberOfStrips (tif));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
534 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
535 case TIFFTAG_TILEBYTECOUNTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
536 case TIFFTAG_TILEOFFSETS:
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
537 tag_data_ov = get_array_field_data (tif, fip, TIFFNumberOfTiles (tif));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
538 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
539 case TIFFTAG_YCBCRCOEFFICIENTS:
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
540 tag_data_ov = get_array_field_data (tif, fip, 3);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
541 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
542 case TIFFTAG_REFERENCEBLACKWHITE:
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
543 tag_data_ov = get_array_field_data (tif, fip, 6);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
544 break;
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
545 case TIFFTAG_GRAYRESPONSECURVE:
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
546 {
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
547 uint16_t bits_per_sample;
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
548 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample))
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
549 error ("Failed to obtain the bit depth");
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
550
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
551 tag_data_ov = get_array_field_data (tif, fip, 1<<bits_per_sample);
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
552 break;
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
553 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
554 case TIFFTAG_COLORMAP:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
555 {
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
556 // TODO(maged): Fix output formatting to be consistent with matlab
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
557 // Matlab returns a float colormap?
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
558 uint16_t bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
559 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
560 error ("Failed to obtain the bit depth");
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
561
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
562 if (bits_per_sample > 24)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
563 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
564
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
565 uint32_t count = 1 << bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
566 uint16_t *red, *green, *blue;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
567 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP,
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
568 &red, &green, &blue));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
569
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
570 uint16NDArray mat_out (dim_vector (count, 3));
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
571
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
572 uint16NDArray red_array
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
573 = interpret_tag_data (red,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
574 count,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
575 TIFFFieldDataType (fip)).uint16_array_value ();
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
576 uint16NDArray green_array
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
577 = interpret_tag_data (green,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
578 count,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
579 TIFFFieldDataType (fip)).uint16_array_value ();
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
580 uint16NDArray blue_array
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
581 = interpret_tag_data (blue,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
582 count,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
583 TIFFFieldDataType (fip)).uint16_array_value ();
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
584
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
585 octave_uint16 *out_ptr = mat_out.fortran_vec ();
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
586 memcpy (out_ptr, red_array.fortran_vec (), sizeof(uint16_t) * count);
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
587 out_ptr += count;
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
588 memcpy (out_ptr, green_array.fortran_vec (), sizeof(uint16_t) * count);
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
589 out_ptr += count;
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
590 memcpy (out_ptr, blue_array.fortran_vec (), sizeof(uint16_t) * count);
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
591
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
592 tag_data_ov = octave_value (mat_out);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
593 break;
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 case TIFFTAG_TRANSFERFUNCTION:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
596 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
597 uint16_t samples_per_pixel;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
598 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
599 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
600
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
601 uint16_t bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
602 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
603 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
604
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
605 uint32_t count = 1 << bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
606 uint16_t *ch1, *ch2, *ch3;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
607 if (samples_per_pixel == 1)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
608 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
609 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP, &ch1));
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
610 tag_data_ov = interpret_tag_data (ch1, count,
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
611 TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
612 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
613 else
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
614 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
615 validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP,
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
616 &ch1, &ch2, &ch3));
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
617
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
618 uint16NDArray mat_out (dim_vector (count, 3));
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
619
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
620 uint16NDArray ch1_array
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
621 = interpret_tag_data (ch1,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
622 count,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
623 TIFFFieldDataType (fip)).uint16_array_value ();
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
624 uint16NDArray ch2_array
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
625 = interpret_tag_data (ch2,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
626 count,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
627 TIFFFieldDataType (fip)).uint16_array_value ();
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
628 uint16NDArray ch3_array
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
629 = interpret_tag_data (ch3,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
630 count,
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
631 TIFFFieldDataType (fip)).uint16_array_value ();
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
632
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
633 octave_uint16 *out_ptr = mat_out.fortran_vec ();
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
634 memcpy (out_ptr, ch1_array.fortran_vec (), sizeof(uint16_t) * count);
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
635 out_ptr += count;
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
636 memcpy (out_ptr, ch2_array.fortran_vec (), sizeof(uint16_t) * count);
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
637 out_ptr += count;
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
638 memcpy (out_ptr, ch3_array.fortran_vec (), sizeof(uint16_t) * count);
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
639
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
640 tag_data_ov = octave_value (mat_out);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
641 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
642 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
643 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
644 case TIFFTAG_PAGENUMBER:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
645 case TIFFTAG_HALFTONEHINTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
646 case TIFFTAG_DOTRANGE:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
647 case TIFFTAG_YCBCRSUBSAMPLING:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
648 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
649 uint16_t tag_part1, tag_part2;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
650 validate_tiff_get_field (TIFFGetField (tif, tag_id,
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
651 &tag_part1, &tag_part2));
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
652
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
653 Matrix mat_out (1, 2);
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
654 mat_out(0)
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
655 = interpret_tag_data (&tag_part1, 1,
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
656 TIFFFieldDataType (fip)).double_value ();
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
657 mat_out(1)
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
658 = interpret_tag_data (&tag_part2, 1,
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
659 TIFFFieldDataType (fip)).double_value ();
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
660
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
661 tag_data_ov = octave_value (mat_out);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
662 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
663 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
664 case TIFFTAG_SUBIFD:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
665 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
666 uint16_t count;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
667 uint64_t *offsets;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
668 validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &offsets));
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
669 tag_data_ov = interpret_tag_data (offsets, count,
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
670 TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
671 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
672 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
673 case TIFFTAG_EXTRASAMPLES:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
674 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
675 uint16_t count;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
676 uint16_t *types;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
677 validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &types));
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
678 tag_data_ov = interpret_tag_data (types, count,
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
679 TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
680 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
681 }
31103
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
682 // 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
683 // will be implemented and tested later.
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
684 case TIFFTAG_XMLPACKET:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
685 case TIFFTAG_RICHTIFFIPTC:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
686 case TIFFTAG_PHOTOSHOP:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
687 case TIFFTAG_ICCPROFILE:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
688 {
31103
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
689 error ("Complex Tags not implemented");
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
690 break;
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
691 }
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
692 // 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
693 // 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
694 case TIFFTAG_ZIPQUALITY:
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
695 case TIFFTAG_SGILOGDATAFMT:
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
696 case TIFFTAG_GRAYRESPONSEUNIT:
31103
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
697 {
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
698 tag_data_ov = get_scalar_field_data (tif, fip);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
699 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
700 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
701 default:
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
702 tag_data_ov = get_scalar_field_data (tif, fip);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
703 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
704
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
705 return tag_data_ov;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
706 }
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
707 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
708
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
709 DEFUN_DLD (__open_tiff__, args, nargout,
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
710 "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
711 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
712 #if defined (HAVE_TIFF)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
713 int nargin = args.length ();
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
714
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
715 if (nargin == 0 || nargin > 2)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
716 {
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
717 // TODO(maged): return invalid object instead??
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
718 error ("No filename supplied\n");
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
719 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
720
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
721 std::string filename = args (0).string_value ();
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
722 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
723
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
724 // TODO(maged): check valid mode
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
725 if (nargin == 2)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
726 mode = args (1).string_value ();
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
727
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
728 // TODO(maged): Look into unwind action
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
729 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
730
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
731 if (! tif)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
732 error ("Failed to open Tiff file\n");
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
733
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
734 // 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
735 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
736 return octave_value_list (tiff_ov);
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
737 #else
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
738 err_disabled_feature ("Tiff", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
739 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
740 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
741
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
742
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
743 DEFUN_DLD (__close_tiff__, args, nargout,
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
744 "Close a tiff file")
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
745 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
746 #if defined (HAVE_TIFF)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
747 int nargin = args.length ();
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
748
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
749 if (nargin == 0)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
750 error ("No handle provided\n");
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
751
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
752 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
753 TIFFClose (tif);
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
754
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
755 return octave_value_list ();
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
756 #else
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
757 err_disabled_feature ("close", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
758 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
759 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
760
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
761
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
762 DEFUN_DLD (__tiff_get_tag__, args, nargout,
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
763 "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
764 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
765 #if defined (HAVE_TIFF)
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
766 int nargin = args.length ();
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
767
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
768 if (nargin == 0)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
769 error ("No handle provided\n");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
770
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
771 if (nargin < 2)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
772 error ("No tag name provided\n");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
773
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
774 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
775
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
776 uint32_t tag_id;
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
777 const TIFFField *fip;
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
778 if (args (1).type_name () == "string")
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
779 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
780 std::string tagName = args (1).string_value ();
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
781 fip = TIFFFieldWithName (tif, tagName.c_str ());
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
782 if (! fip)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
783 error ("Tiff tag not found");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
784
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
785 tag_id = TIFFFieldTag (fip);
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
786 }
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
787 else
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
788 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
789 tag_id = args (1).int_value ();
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
790 fip = TIFFFieldWithTag (tif, tag_id);
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
791 // 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
792 if (! fip)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
793 error ("Tiff tag not found");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
794 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
795
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
796 return octave_value_list (get_field_data (tif, fip));
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
797 #else
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
798 err_disabled_feature ("getTag", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
799 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
800 }
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
801
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
802 DEFUN_DLD (__tiff_read__, args, nargout,
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
803 "Read the image in the current IFD")
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
804 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
805 #if defined (HAVE_TIFF)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
806 int nargin = args.length ();
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
807
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
808 if (nargin == 0)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
809 error ("No handle provided\n");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
810
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
811 TIFF *tif = (TIFF *)(args (0).uint64_value ());
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
812
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
813 // Check: Strips vs Tiles
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
814 // Planar Configuration
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
815 // SamplesPerPixel and bits_per_smaple
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
816 // nargout and ycbcr
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
817 // SampleFormat? ExtendedSamples? TransferFunction? GrayResponse? ColorMap?
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
818 // What about floating point images?
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
819
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
820 // Obtain all necessary tags
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
821 // 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
822 // 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
823 // 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
824 // 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
825 tiff_image_data image_data;
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
826 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
827 error ("Failed to read image width");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
828
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
829 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
830 error ("Failed to read image height");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
831
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
832 if (! TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL,
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
833 &image_data.samples_per_pixel))
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
834 error ("Failed to read the SamplesPerPixel tag");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
835
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
836 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE,
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
837 &image_data.bits_per_sample))
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
838 error ("Failed to read the BitsPerSample tag");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
839
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
840 if (! TIFFGetField (tif, TIFFTAG_PLANARCONFIG,
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
841 &image_data.planar_configuration))
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
842 error ("Failed to read the PlanarConfiguration tag");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
843
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
844 image_data.is_tiled = TIFFIsTiled(tif);
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
845
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
846 octave_value_list retval;
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
847 switch (image_data.bits_per_sample)
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
848 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
849 case 1:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
850 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
851 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
852 case 4:
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
853 case 8:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
854 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
855 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
856 case 16:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
857 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
858 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
859 case 32:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
860 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
861 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
862 case 64:
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
863 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
864 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
865 default:
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
866 error ("Unsupported bit depth");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
867 }
31110
2daeeff33980 Tiff read fixed segfault bug for compressed images
magedrifaat <magedrifaat@gmail.com>
parents: 31109
diff changeset
868
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
869 return retval;
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
870 #else
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
871 err_disabled_feature ("read", "Tiff");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
872 #endif
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
873 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
874 }