Mercurial > octave-libtiff
annotate libinterp/dldfcn/__tiff__.cc @ 31121:341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
* __tiff.cc__(get_field_data): fixed the output data for the ColorMap tag
to be double and in range between 0 and 1.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Wed, 20 Jul 2022 03:44:08 +0200 |
parents | 46bb98cec195 |
children | 1662939a7a49 |
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 // 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
|
55 // 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
|
56 // 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
|
57 // 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
|
58 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
|
59 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
|
60 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
|
61 && padded_width % 8 != 0) |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
62 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
63 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
|
64 remove_padding = 1; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
65 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
66 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
67 // 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
|
68 // 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
|
69 // At the end, the matrix is permutated to the order expected by Octave |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
70 T img; |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
71 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
|
72 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
|
73 image_data->height)); |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 else |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
78 error ("Unsupported Planar Configuration"); |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
79 |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
80 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
|
81 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
82 // 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
|
83 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
|
84 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
85 // 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
|
86 // 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
|
87 // 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
|
88 int64_t strip_size; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
89 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
|
90 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
|
91 * 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
|
92 * sizeof (P); |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
93 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
|
94 { |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
95 // 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
|
96 // 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
|
97 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
|
98 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
99 // 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
|
100 if (strip_size == -1) |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
101 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
|
102 |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
103 // 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
|
104 // 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
|
105 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
|
106 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
|
107 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
108 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
|
109 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
110 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
|
111 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
|
112 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
113 // 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
|
114 // 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
|
115 // 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
|
116 strip_size *= 8; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
117 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
118 // 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
|
119 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
|
120 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
|
121 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
122 // 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
|
123 // 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
|
124 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
|
125 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
126 // 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
|
127 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
|
128 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
|
129 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
130 break; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
131 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
132 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
|
133 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
134 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
|
135 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
|
136 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
137 // 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
|
138 // 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
|
139 strip_size *= 2; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
140 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
141 // 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
|
142 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
|
143 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
|
144 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
145 // 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
|
146 // 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
|
147 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
|
148 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
149 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
|
150 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
|
151 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
152 break; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
153 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 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
|
158 error ("Unsupported bit depth"); |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
159 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
160 // 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
|
161 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
|
162 written_size += strip_size; |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
163 } |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
164 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
165 // 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
|
166 // 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
|
167 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
|
168 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
|
169 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
170 perm(0) = 2; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
171 perm(1) = 1; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
172 perm(2) = 0; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
173 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
174 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
|
175 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
176 perm(0) = 1; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
177 perm(1) = 0; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
178 perm(2) = 2; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
179 } |
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 img = img.permute (perm); |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
182 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
183 if (remove_padding) |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
184 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
|
185 |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
186 return octave_value (img); |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
187 } |
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 template <typename T> |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
190 octave_value |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
191 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
|
192 { |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
193 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
|
194 |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
195 // 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
|
196 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
|
197 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
|
198 &tile_width)); |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
199 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
|
200 &tile_height)); |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
201 uint32_t tile_count = TIFFNumberOfTiles (tif); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
202 uint32_t tiles_across = (image_data->width + tile_width - 1) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
203 / tile_width; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
204 uint32_t tiles_down = (image_data->height + tile_height - 1) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
205 / tile_height; |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
206 |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
207 T img; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
208 // The matrix dimensions are defined in the order that corresponds to |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
209 // the order of the tile data read from LibTIFF. |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
210 // At the end, the matrix is permutated, reshaped and resized to be in the |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
211 // shape expected by Octave |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
212 if (image_data->planar_configuration == PLANARCONFIG_CONTIG) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
213 img = T (dim_vector (image_data->samples_per_pixel, tile_width, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
214 tile_height, tiles_across, tiles_down)); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
215 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
216 img = T (dim_vector (tile_width, tile_height, tiles_across, tiles_down, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
217 image_data->samples_per_pixel)); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
218 else |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
219 error ("Unsupported Planar Configuration"); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
220 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
221 P *img_fvec = img.fortran_vec (); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
222 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
223 // image_size is calculated from the tile data and not from the |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
224 // image parameters to account for the additional padding in the |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
225 // boundary tiles |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
226 uint64_t image_size = tile_width * tile_height * tile_count * sizeof(P); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
227 if (image_data->planar_configuration == PLANARCONFIG_CONTIG) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
228 image_size *= image_data->samples_per_pixel; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
229 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
230 // Can't rely on TileByteCounts because compressed images will report |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
231 // the number of bytes present in the file as opposed to the actual |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
232 // number of bytes of uncompressed data that is needed here |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
233 int64_t tile_size; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
234 uint32_t written_size = 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
235 for (uint32_t tile = 0; tile < tile_count; tile++) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
236 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
237 tile_size = TIFFReadEncodedTile(tif, tile, img_fvec, -1); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
238 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
239 if (tile_size == -1) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
240 error ("Failed to read tile data"); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
241 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
242 // Checking if the read bytes would exceed the size of the matrix |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
243 if (tile_size + written_size > image_size) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
244 error ("Tile data is larger than image size"); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
245 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
246 if (image_data->bits_per_sample == 1) |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
247 { |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
248 if (image_data->samples_per_pixel != 1) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
249 error ("Bi-Level images must have one channel only"); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
250 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
251 // The tile size is multiplied by 8 to reflect tha actual |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
252 // number of bytes written to the matrix since each byte |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
253 // in the original tile contains 8 pixels of data |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
254 tile_size *= 8; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
255 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
256 // Checking bounds again with the new size |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
257 if (written_size + tile_size > image_size) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
258 error ("Tile data is larger than the image size"); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
259 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
260 // Iterate over the memory region backwards to expand the bits |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
261 // to their respective bytes without overwriting the read data |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
262 for (int64_t pixel = tile_size - 1; pixel >= 0; pixel--) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
263 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
264 // TODO(maged): is it necessary to check FillOrder? |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
265 uint8_t bit_number = 7 - pixel % 8; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
266 img_fvec[pixel] = (img_fvec[pixel / 8] >> bit_number) & 0x01; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
267 } |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
268 break; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
269 } |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
270 else if (image_data->bits_per_sample == 4) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
271 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
272 if (image_data->samples_per_pixel != 1) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
273 error ("4-bit images are only supported for grayscale"); |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
274 |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
275 // tile size is multplied by as each byte contains 2 pixels |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
276 // and each pixel is later expanded into its own byte |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
277 tile_size *= 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
278 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
279 // Checking bounds again with the ne size |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
280 if (written_size + tile_size > image_size) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
281 error ("Tile data is larger than the image size"); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
282 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
283 // Iterate over the memory region backwards to expand the nibbles |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
284 // to their respective bytes without overwriting the read data |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
285 for (int64_t pixel = tile_size - 1; pixel >= 0; pixel--) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
286 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
287 uint8_t shift = pixel % 2 == 0? 4: 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
288 img_fvec[pixel] = (img_fvec[pixel / 2] >> shift) & 0x0F; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
289 } |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
290 break; |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
291 } |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
292 else if (image_data->bits_per_sample != 8 && |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
293 image_data->bits_per_sample != 16 && |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
294 image_data->bits_per_sample != 32 && |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
295 image_data->bits_per_sample != 64) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
296 error ("Unsupported bit depth"); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
297 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
298 img_fvec = (P*)((uint8_t *)img_fvec + tile_size); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
299 written_size += tile_size; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
300 } |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
301 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
302 // The data is now in the matrix but in a different order than expected |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
303 // by Octave and with additional padding in boundary tiles. |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
304 // To get it to the right order, the dimensions are permutated to |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
305 // align tiles to their correct grid, then reshaped to remove the |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
306 // extra dimensions (tiles_across, tiles_down), then resized to |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
307 // remove any extra padding, and finally permutated to the correct |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
308 // order that is: height x width x channels |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
309 Array<octave_idx_type> perm1 (dim_vector (5, 1)); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
310 Array<octave_idx_type> perm2 (dim_vector (3, 1)); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
311 if (image_data->planar_configuration == PLANARCONFIG_CONTIG) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
312 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
313 perm1(0) = 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
314 perm1(1) = 1; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
315 perm1(2) = 3; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
316 perm1(3) = 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
317 perm1(4) = 4; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
318 img = img.permute (perm1); |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
319 |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
320 img = img.reshape (dim_vector (image_data->samples_per_pixel, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
321 tile_width * tiles_across, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
322 tile_height * tiles_down)); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
323 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
324 if (tile_width * tiles_across != image_data->width |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
325 || tile_height * tiles_down != image_data->height) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
326 img.resize (dim_vector (image_data->samples_per_pixel, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
327 image_data->width, image_data->height)); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
328 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
329 perm2(0) = 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
330 perm2(1) = 1; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
331 perm2(2) = 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
332 img = img.permute (perm2); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
333 } |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
334 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
335 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
336 perm1(0) = 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
337 perm1(1) = 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
338 perm1(2) = 1; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
339 perm1(3) = 3; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
340 perm1(4) = 4; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
341 img = img.permute (perm1); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
342 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
343 img = img.reshape (dim_vector (tile_width * tiles_across, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
344 tile_height * tiles_down, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
345 image_data->samples_per_pixel)); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
346 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
347 if (tile_width * tiles_across != image_data->width |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
348 || tile_height * tiles_down != image_data->height) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
349 img.resize (dim_vector (image_data->width, image_data->height, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
350 image_data->samples_per_pixel)); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
351 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
352 perm2(0) = 1; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
353 perm2(1) = 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
354 perm2(2) = 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
355 img = img.permute (perm2); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
356 } |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
357 |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
358 return octave_value (img); |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
359 } |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
360 |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
361 template <typename T> |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
362 octave_value |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
363 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
|
364 { |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
365 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
|
366 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
|
367 else |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
368 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
|
369 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
370 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
371 // Convert tag value to double |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
372 octave_value |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
373 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
|
374 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
375 double retval; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
376 |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
377 switch (tag_datatype) |
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 case TIFF_BYTE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
380 case TIFF_UNDEFINED: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
381 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
382 retval = (double)(*((uint8_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
383 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
384 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
385 case TIFF_SHORT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
386 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
387 retval = (double)(*((uint16_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
388 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
389 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
390 case TIFF_LONG: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
391 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
392 retval = (double)(*((uint32_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
393 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
394 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
395 case TIFF_LONG8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
396 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
397 retval = (double)(*((uint64_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
398 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
399 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
400 case TIFF_RATIONAL: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
401 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
402 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
|
403 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
404 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
405 case TIFF_SBYTE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
406 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
407 retval = (double)(*((int8_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
408 break; |
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 case TIFF_SSHORT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
411 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
412 retval = (double)(*((int16_t *)data)); |
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_SLONG: |
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 retval = (double)(*((int32_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
418 break; |
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 case TIFF_SLONG8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
421 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
422 retval = (double)(*((int64_t *)data)); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
423 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
424 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
425 case TIFF_FLOAT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
426 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
427 retval = *((float *)data); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
428 break; |
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 case TIFF_DOUBLE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
431 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
432 retval = *((double *)data); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
433 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
434 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
435 case TIFF_SRATIONAL: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
436 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
437 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
|
438 break; |
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 case TIFF_IFD: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
441 case TIFF_IFD8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
442 error ("Unimplemented IFFD data type"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
443 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
444 default: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
445 error ("Unsupported tag data type"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
446 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
447 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
448 return octave_value (retval); |
31105
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 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
451 // 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
|
452 // depending on tag_datatype |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
453 octave_value |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
454 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
|
455 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
456 octave_value retval; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
457 // Apparently matlab converts scalar numerical values into double |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
458 // but doesn't do the same for arrays |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
459 if (count == 1 && tag_datatype != TIFF_ASCII) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
460 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
461 retval = interpret_scalar_tag_data (data, tag_datatype); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
462 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
463 else |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
464 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
465 dim_vector arr_dims (1, count); |
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 switch (tag_datatype) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
468 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
469 case TIFF_BYTE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
470 case TIFF_UNDEFINED: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
471 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
472 uint8NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
473 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
474 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
475 arr(i) = ((uint8_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
476 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
477 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
478 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
479 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
480 case TIFF_ASCII: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
481 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
482 retval = octave_value (*(char **)data); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
483 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
484 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
485 case TIFF_SHORT: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
486 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
487 uint16NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
488 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
489 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
490 arr(i) = ((uint16_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
491 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
492 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
493 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
494 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
495 case TIFF_LONG: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
496 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
497 uint32NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
498 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
499 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
500 arr(i) = ((uint32_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
501 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
502 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
503 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
504 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
505 case TIFF_LONG8: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
506 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
507 uint64NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
508 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
509 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
510 arr(i) = ((uint64_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
511 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
512 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
513 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
514 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
515 case TIFF_RATIONAL: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
516 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
517 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
518 for (uint32_t i = 0; i < count; i+=2) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
519 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
520 arr(i / 2) = (float)((uint32_t *)data)[i] |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
521 / (float)((uint32_t *)data)[i+1]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
522 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
523 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
524 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
525 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
526 case TIFF_SBYTE: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
527 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
528 int8NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
529 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
530 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
531 arr(i) = ((int8_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
532 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
533 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
534 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
535 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
536 case TIFF_SSHORT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
537 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
538 int16NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
539 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
540 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
541 arr(i) = ((int16_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
542 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
543 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
544 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
545 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
546 case TIFF_SLONG: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
547 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
548 int32NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
549 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
550 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
551 arr(i) = ((int32_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
552 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
553 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
554 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
555 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
556 case TIFF_SLONG8: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
557 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
558 int64NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
559 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
560 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
561 arr(i) = ((int64_t *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
562 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
563 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
564 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
565 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
566 case TIFF_FLOAT: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
567 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
568 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
569 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
570 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
571 arr(i) = ((float *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
572 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
573 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
574 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
575 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
576 case TIFF_DOUBLE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
577 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
578 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
579 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
580 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
581 arr(i) = ((double *)data)[i]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
582 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
583 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
584 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
585 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
586 case TIFF_SRATIONAL: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
587 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
588 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
589 for (uint32_t i = 0; i < count; i+=2) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
590 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
591 arr(i / 2) = (float)((int32_t *)data)[i] |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
592 / (float)((int32_t *)data)[i+1]; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
593 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
594 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
595 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
596 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
597 case TIFF_IFD: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
598 case TIFF_IFD8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
599 // TODO(maged): implement IFD datatype? |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
600 error ("Unimplemented IFFD data type"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
601 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
602 default: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
603 error ("Unsupported tag data type"); |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
604 } |
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
605 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
606 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
607 return retval; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
608 } |
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
|
609 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
610 octave_value |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
611 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
|
612 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
613 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
|
614 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
615 // TIFFFieldReadCount returns VARIABLE for some scalar tags |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
616 // (e.g. Compression) But TIFFFieldPassCount seems consistent |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
617 // 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
|
618 // 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
|
619 if (TIFFFieldPassCount (fip)) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
620 error ("Unsupported tag"); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
621 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
622 // 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
|
623 int type_size = TIFFDataWidth (TIFFFieldDataType (fip)); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
624 void *data = _TIFFmalloc (type_size); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
625 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
|
626 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
|
627 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
628 _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
|
629 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
630 return tag_data_ov; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
631 } |
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
|
632 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
633 octave_value |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
634 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
|
635 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
636 void *data; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
637 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
|
638 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
639 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
|
640 } |
31097
75ab26f147a5
getTag: Implemented single array tags, only multi-array and special tags are unimplemented
magedrifaat <magedrifaat@gmail.com>
parents:
31096
diff
changeset
|
641 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
642 octave_value |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
643 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
|
644 { |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
645 octave_value tag_data_ov; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
646 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
|
647 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
648 // 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
|
649 switch (tag_id) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
650 { |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
651 case TIFFTAG_STRIPBYTECOUNTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
652 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
|
653 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
|
654 TIFFNumberOfStrips (tif)); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
655 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
656 case TIFFTAG_TILEBYTECOUNTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
657 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
|
658 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
|
659 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
660 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
|
661 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
|
662 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
663 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
|
664 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
|
665 break; |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
666 case TIFFTAG_GRAYRESPONSECURVE: |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
667 { |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
668 uint16_t bits_per_sample; |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
669 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
670 error ("Failed to obtain the bit depth"); |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
671 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
672 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
|
673 break; |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
674 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
675 case TIFFTAG_COLORMAP: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
676 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
677 uint16_t bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
678 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
|
679 error ("Failed to obtain the bit depth"); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
680 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
681 if (bits_per_sample > 24) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
682 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
|
683 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
684 uint32_t count = 1 << bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
685 uint16_t *red, *green, *blue; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
686 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
|
687 &red, &green, &blue)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
688 |
31121
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
689 Matrix mat_out (count, 3); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
690 |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
691 Matrix red_array (interpret_tag_data (red, |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
692 count, |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
693 TIFFFieldDataType (fip)) |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
694 .uint16_array_value ()); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
695 Matrix green_array (interpret_tag_data (green, |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
696 count, |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
697 TIFFFieldDataType (fip)) |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
698 .uint16_array_value ()); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
699 Matrix blue_array (interpret_tag_data (blue, |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
700 count, |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
701 TIFFFieldDataType (fip)) |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
702 .uint16_array_value ()); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
703 |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
704 double *out_ptr = mat_out.fortran_vec (); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
705 memcpy (out_ptr, red_array.fortran_vec (), sizeof(double)*count); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
706 out_ptr += count; |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
707 memcpy (out_ptr, green_array.fortran_vec (), sizeof(double)*count); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
708 out_ptr += count; |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
709 memcpy (out_ptr, blue_array.fortran_vec (), sizeof(double)*count); |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
710 |
31121
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
711 // Normalize the range to be between 0 and 1 |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
712 mat_out /= UINT16_MAX; |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
713 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
714 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
|
715 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
716 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
717 case TIFFTAG_TRANSFERFUNCTION: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
718 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
719 uint16_t samples_per_pixel; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
720 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
|
721 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
|
722 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
723 uint16_t bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
724 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
|
725 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
|
726 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
727 uint32_t count = 1 << bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
728 uint16_t *ch1, *ch2, *ch3; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
729 if (samples_per_pixel == 1) |
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 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
|
732 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
|
733 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
734 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
735 else |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
736 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
737 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
|
738 &ch1, &ch2, &ch3)); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
739 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
740 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
|
741 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
742 uint16NDArray ch1_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
743 = interpret_tag_data (ch1, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
744 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
745 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
746 uint16NDArray ch2_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
747 = interpret_tag_data (ch2, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
748 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
749 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
750 uint16NDArray ch3_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
751 = interpret_tag_data (ch3, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
752 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
753 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
754 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
755 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
|
756 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
|
757 out_ptr += count; |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
758 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
|
759 out_ptr += count; |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
760 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
|
761 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
762 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
|
763 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
764 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
765 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
766 case TIFFTAG_PAGENUMBER: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
767 case TIFFTAG_HALFTONEHINTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
768 case TIFFTAG_DOTRANGE: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
769 case TIFFTAG_YCBCRSUBSAMPLING: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
770 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
771 uint16_t tag_part1, tag_part2; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
772 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
|
773 &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
|
774 |
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
775 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
|
776 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
|
777 = 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
|
778 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
|
779 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
|
780 = 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
|
781 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
|
782 |
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
783 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
|
784 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
785 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
786 case TIFFTAG_SUBIFD: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
787 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
788 uint16_t count; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
789 uint64_t *offsets; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
790 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
|
791 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
|
792 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
793 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
794 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
795 case TIFFTAG_EXTRASAMPLES: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
796 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
797 uint16_t count; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
798 uint16_t *types; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
799 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
|
800 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
|
801 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
802 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
803 } |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
804 // 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
|
805 // will be implemented and tested later. |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
806 case TIFFTAG_XMLPACKET: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
807 case TIFFTAG_RICHTIFFIPTC: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
808 case TIFFTAG_PHOTOSHOP: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
809 case TIFFTAG_ICCPROFILE: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
810 { |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
811 error ("Complex Tags not implemented"); |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
812 break; |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
813 } |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
814 // 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
|
815 // 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
|
816 case TIFFTAG_ZIPQUALITY: |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
817 case TIFFTAG_SGILOGDATAFMT: |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
818 case TIFFTAG_GRAYRESPONSEUNIT: |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
819 { |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
820 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
|
821 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
822 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
823 default: |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
824 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
|
825 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
826 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
827 return tag_data_ov; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
828 } |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
829 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
830 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
831 DEFUN_DLD (__open_tiff__, args, nargout, |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
832 "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
|
833 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
834 #if defined (HAVE_TIFF) |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
835 int nargin = args.length (); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
836 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
837 if (nargin == 0 || nargin > 2) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
838 { |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
839 // TODO(maged): return invalid object instead?? |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
840 error ("No filename supplied\n"); |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
841 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
842 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
843 std::string filename = args (0).string_value (); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
844 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
|
845 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
846 // TODO(maged): check valid mode |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
847 if (nargin == 2) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
848 mode = args (1).string_value (); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
849 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
850 // TODO(maged): Look into unwind action |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
851 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
|
852 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
853 if (! tif) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
854 error ("Failed to open Tiff file\n"); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
855 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
856 // 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
|
857 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
|
858 return octave_value_list (tiff_ov); |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
859 #else |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
860 err_disabled_feature ("Tiff", "Tiff"); |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
861 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
862 } |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
863 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
864 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
865 DEFUN_DLD (__close_tiff__, args, nargout, |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
866 "Close a tiff file") |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
867 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
868 #if defined (HAVE_TIFF) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
869 int nargin = args.length (); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
870 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
871 if (nargin == 0) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
872 error ("No handle provided\n"); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
873 |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
874 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
|
875 TIFFClose (tif); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
876 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
877 return octave_value_list (); |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
878 #else |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
879 err_disabled_feature ("close", "Tiff"); |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
880 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
881 } |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
882 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
883 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
884 DEFUN_DLD (__tiff_get_tag__, args, nargout, |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
885 "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
|
886 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
887 #if defined (HAVE_TIFF) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
888 int nargin = args.length (); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
889 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
890 if (nargin == 0) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
891 error ("No handle provided\n"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
892 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
893 if (nargin < 2) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
894 error ("No tag name provided\n"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
895 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
896 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
|
897 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
898 uint32_t tag_id; |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
899 const TIFFField *fip; |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
900 if (args (1).type_name () == "string") |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
901 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
902 std::string tagName = args (1).string_value (); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
903 fip = TIFFFieldWithName (tif, tagName.c_str ()); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
904 if (! fip) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
905 error ("Tiff tag not found"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
906 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
907 tag_id = TIFFFieldTag (fip); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
908 } |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
909 else |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
910 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
911 tag_id = args (1).int_value (); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
912 fip = TIFFFieldWithTag (tif, tag_id); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
913 // 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
|
914 if (! fip) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
915 error ("Tiff tag not found"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
916 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
917 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
918 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
|
919 #else |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
920 err_disabled_feature ("getTag", "Tiff"); |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
921 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
922 } |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
923 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
924 DEFUN_DLD (__tiff_read__, args, nargout, |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
925 "Read the image in the current IFD") |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
926 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
927 #if defined (HAVE_TIFF) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
928 int nargin = args.length (); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
929 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
930 if (nargin == 0) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
931 error ("No handle provided\n"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
932 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
933 TIFF *tif = (TIFF *)(args (0).uint64_value ()); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
934 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
935 // Check: Strips vs Tiles |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
936 // Planar Configuration |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
937 // SamplesPerPixel and bits_per_smaple |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
938 // nargout and ycbcr |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
939 // SampleFormat? ExtendedSamples? TransferFunction? GrayResponse? ColorMap? |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
940 // What about floating point images? |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
941 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
942 // Obtain all necessary tags |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
943 // 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
|
944 // 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
|
945 // 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
|
946 // 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
|
947 tiff_image_data image_data; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
948 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
|
949 error ("Failed to read image width"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
950 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
951 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
|
952 error ("Failed to read image height"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
953 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
954 if (! TIFFGetField (tif, TIFFTAG_SAMPLESPERPIXEL, |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
955 &image_data.samples_per_pixel)) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
956 error ("Failed to read the SamplesPerPixel tag"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
957 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
958 if (! TIFFGetField (tif, TIFFTAG_BITSPERSAMPLE, |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
959 &image_data.bits_per_sample)) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
960 error ("Failed to read the BitsPerSample tag"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
961 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
962 if (! TIFFGetField (tif, TIFFTAG_PLANARCONFIG, |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
963 &image_data.planar_configuration)) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
964 error ("Failed to read the PlanarConfiguration tag"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
965 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
966 image_data.is_tiled = TIFFIsTiled(tif); |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
967 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
968 octave_value_list retval; |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
969 switch (image_data.bits_per_sample) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
970 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
971 case 1: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
972 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
|
973 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
974 case 4: |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
975 case 8: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
976 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
|
977 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
978 case 16: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
979 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
|
980 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
981 case 32: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
982 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
|
983 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
984 case 64: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
985 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
|
986 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
987 default: |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
988 error ("Unsupported bit depth"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
989 } |
31110
2daeeff33980
Tiff read fixed segfault bug for compressed images
magedrifaat <magedrifaat@gmail.com>
parents:
31109
diff
changeset
|
990 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
991 return retval; |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
992 #else |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
993 err_disabled_feature ("read", "Tiff"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
994 #endif |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
995 } |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
996 } |