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