Mercurial > octave-libtiff
annotate libinterp/dldfcn/__tiff__.cc @ 31128:524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Sun, 24 Jul 2022 21:21:11 +0200 |
parents | 0d9633ee715e |
children | dfab9c6982bf |
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 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
19 namespace octve |
31099
6fc4bf5e14e1
Cleaned up the interface
magedrifaat <magedrifaat@gmail.com>
parents:
31098
diff
changeset
|
20 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
21 #if defined (HAVE_TIFF) |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
22 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
23 struct tiff_image_data |
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 public: |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
26 uint32_t width; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
27 uint32_t height; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
28 uint16_t samples_per_pixel; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
29 uint16_t bits_per_sample; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
30 uint16_t planar_configuration; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
31 uint16_t is_tiled; |
31122
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
32 |
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
33 tiff_image_data (TIFF *tif) |
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 if (! TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &width)) |
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
36 error ("Failed to read image width"); |
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
37 |
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
38 if (! TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &height)) |
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
39 error ("Failed to read image height"); |
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
40 |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
41 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLESPERPIXEL, |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
42 &samples_per_pixel)) |
31122
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
43 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
|
44 |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
45 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
46 &bits_per_sample)) |
31122
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 |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
49 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_PLANARCONFIG, |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
50 &planar_configuration)) |
31122
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
51 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
|
52 |
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
53 is_tiled = TIFFIsTiled(tif); |
1662939a7a49
Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents:
31121
diff
changeset
|
54 } |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
55 }; |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
56 |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
57 // 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
|
58 void |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
59 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
|
60 { |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
61 if (status != 1) |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
62 { |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
63 if (p_to_free != NULL) |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
64 _TIFFfree (p_to_free); |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
65 error ("Failed to read tag"); |
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 } |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
68 |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
69 template <typename T> |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
70 octave_value |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
71 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
|
72 { |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
73 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
|
74 |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
75 // 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
|
76 // 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
|
77 // 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
|
78 // 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
|
79 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
|
80 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
|
81 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
|
82 && padded_width % 8 != 0) |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
83 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
84 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
|
85 remove_padding = 1; |
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 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
88 // 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
|
89 // 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
|
90 // 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
|
91 T img; |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
92 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
|
93 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
|
94 image_data->height)); |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 else |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
99 error ("Unsupported Planar Configuration"); |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
100 |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
101 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
|
102 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
103 // 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
|
104 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
|
105 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
106 // 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
|
107 // 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
|
108 // 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
|
109 int64_t strip_size; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
110 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
|
111 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
|
112 * 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
|
113 * sizeof (P); |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
114 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
|
115 { |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
116 // 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
|
117 // 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
|
118 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
|
119 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
120 // 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
|
121 if (strip_size == -1) |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
122 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
|
123 |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
124 // 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
|
125 // 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
|
126 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
|
127 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
|
128 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
129 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
|
130 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
131 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
|
132 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
|
133 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
134 // 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
|
135 // 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
|
136 // 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
|
137 strip_size *= 8; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
138 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
139 // 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
|
140 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
|
141 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
|
142 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
143 // 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
|
144 // 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
|
145 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
|
146 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
147 // 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
|
148 uint8_t bit_number = 7 - pixel % 8; |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
149 uint8_t * img_u8 = reinterpret_cast<uint8_t *> (img_fvec); |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
150 img_fvec[pixel] = (img_u8[pixel / 8] >> bit_number) & 0x01; |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
151 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
152 break; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
153 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
154 else if (image_data->bits_per_sample == 4) |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
155 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
156 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
|
157 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
|
158 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
159 // 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
|
160 // 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
|
161 strip_size *= 2; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
162 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
163 // 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
|
164 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
|
165 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
|
166 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
167 // 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
|
168 // 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
|
169 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
|
170 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
171 uint8_t shift = pixel % 2 == 0? 4: 0; |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
172 uint8_t * img_u8 = reinterpret_cast<uint8_t *> (img_fvec); |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
173 img_fvec[pixel] = (img_u8[pixel / 2] >> shift) & 0x0F; |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
174 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
175 break; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
176 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
177 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
|
178 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
|
179 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
|
180 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
|
181 error ("Unsupported bit depth"); |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
182 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
183 // Advance the pointer by the amount of bytes read |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
184 img_fvec |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
185 = reinterpret_cast<P *> (reinterpret_cast <uint8_t *> (img_fvec) |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
186 + strip_size); |
31119
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
187 written_size += strip_size; |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
188 } |
31119
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 // 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
|
191 // 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
|
192 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
|
193 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
|
194 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
195 perm(0) = 2; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
196 perm(1) = 1; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
197 perm(2) = 0; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
198 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
199 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
|
200 { |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
201 perm(0) = 1; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
202 perm(1) = 0; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
203 perm(2) = 2; |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
204 } |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
205 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
206 img = img.permute (perm); |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
207 |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
208 if (remove_padding) |
dbca50246dfc
Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents:
31118
diff
changeset
|
209 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
|
210 |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
211 return octave_value (img); |
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 |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
214 template <typename T> |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
215 octave_value |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
216 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
|
217 { |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
218 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
|
219 |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
220 // 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
|
221 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
|
222 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
|
223 &tile_width)); |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
224 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
|
225 &tile_height)); |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
226 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
|
227 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
|
228 / tile_width; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
229 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
|
230 / tile_height; |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
231 |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
232 T img; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
233 // 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
|
234 // 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
|
235 // 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
|
236 // shape expected by Octave |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 else |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
244 error ("Unsupported Planar Configuration"); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
245 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
246 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
|
247 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
248 // 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
|
249 // 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
|
250 // boundary tiles |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
255 // 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
|
256 // 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
|
257 // 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
|
258 int64_t tile_size; |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
259 uint64_t written_size = 0; |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
260 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
|
261 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
262 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
|
263 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
264 if (tile_size == -1) |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
265 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
|
266 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
267 // 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
|
268 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
|
269 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
|
270 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
271 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
|
272 { |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
273 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
|
274 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
|
275 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
276 // 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
|
277 // 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
|
278 // 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
|
279 tile_size *= 8; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
280 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
281 // 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
|
282 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
|
283 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
|
284 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
285 // 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
|
286 // 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
|
287 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
|
288 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
289 // 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
|
290 uint8_t bit_number = 7 - pixel % 8; |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
291 uint8_t * img_u8 = reinterpret_cast<uint8_t *> (img_fvec); |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
292 img_fvec[pixel]= (img_u8[pixel / 8] >> bit_number) & 0x01; |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
293 } |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
294 break; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
295 } |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
296 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
|
297 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
298 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
|
299 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
|
300 |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
301 // 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
|
302 // 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
|
303 tile_size *= 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
304 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
305 // 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
|
306 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
|
307 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
|
308 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
309 // 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
|
310 // 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
|
311 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
|
312 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
313 uint8_t shift = pixel % 2 == 0? 4: 0; |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
314 uint8_t * img_u8 = reinterpret_cast<uint8_t *> (img_fvec); |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
315 img_fvec[pixel] = (img_u8[pixel / 2] >> shift) & 0x0F; |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
316 } |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
317 break; |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
318 } |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 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
|
323 error ("Unsupported bit depth"); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
324 |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
325 img_fvec |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
326 = reinterpret_cast<P *> (reinterpret_cast<uint8_t *> (img_fvec) |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
327 + tile_size); |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
328 written_size += tile_size; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
329 } |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
330 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
331 // 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
|
332 // 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
|
333 // 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
|
334 // 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
|
335 // 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
|
336 // 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
|
337 // 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
|
338 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
|
339 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
|
340 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
|
341 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
342 perm1(0) = 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
343 perm1(1) = 1; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
344 perm1(2) = 3; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
345 perm1(3) = 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
346 perm1(4) = 4; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
347 img = img.permute (perm1); |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
348 |
31120
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
349 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
|
350 tile_width * tiles_across, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
351 tile_height * tiles_down)); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
352 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
353 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
|
354 || 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
|
355 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
|
356 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
|
357 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
358 perm2(0) = 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
359 perm2(1) = 1; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
360 perm2(2) = 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
361 img = img.permute (perm2); |
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 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
|
364 { |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
365 perm1(0) = 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
366 perm1(1) = 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
367 perm1(2) = 1; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
368 perm1(3) = 3; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
369 perm1(4) = 4; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
370 img = img.permute (perm1); |
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 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
|
373 tile_height * tiles_down, |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
374 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
|
375 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
376 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
|
377 || 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
|
378 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
|
379 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
|
380 |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
381 perm2(0) = 1; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
382 perm2(1) = 0; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
383 perm2(2) = 2; |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
384 img = img.permute (perm2); |
46bb98cec195
Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents:
31119
diff
changeset
|
385 } |
31118
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
386 |
f8be3654caef
Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents:
31117
diff
changeset
|
387 return octave_value (img); |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
388 } |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
389 |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
390 template <typename T> |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
391 octave_value |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
392 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
|
393 { |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
394 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
|
395 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
|
396 else |
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
397 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
|
398 } |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
399 |
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
400 // Convert tag value to double |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
401 octave_value |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
402 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
|
403 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
404 double retval; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
405 |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
406 switch (tag_datatype) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
407 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
408 case TIFF_BYTE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
409 case TIFF_UNDEFINED: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
410 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
411 retval = static_cast<double> (*(reinterpret_cast<uint8_t *> (data))); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
412 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
413 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
414 case TIFF_SHORT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
415 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
416 retval = static_cast<double> (*(reinterpret_cast<uint16_t *> (data))); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
417 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
418 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
419 case TIFF_LONG: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
420 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
421 retval = static_cast<double> (*(reinterpret_cast<uint32_t *> (data))); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
422 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
423 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
424 case TIFF_LONG8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
425 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
426 retval = static_cast<double> (*(reinterpret_cast<uint64_t *> (data))); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
427 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
428 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
429 case TIFF_RATIONAL: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
430 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
431 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
|
432 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
433 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
434 case TIFF_SBYTE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
435 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
436 retval = static_cast<double> (*(reinterpret_cast<int8_t *> (data))); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
437 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
438 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
439 case TIFF_SSHORT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
440 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
441 retval = static_cast<double> (*(reinterpret_cast<int16_t *> (data))); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
442 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
443 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
444 case TIFF_SLONG: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
445 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
446 retval = static_cast<double> (*(reinterpret_cast<int32_t *> (data))); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
447 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
448 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
449 case TIFF_SLONG8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
450 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
451 retval = static_cast<double> (*(reinterpret_cast<int64_t *> (data))); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
452 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
453 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
454 case TIFF_FLOAT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
455 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
456 retval = *(reinterpret_cast<float *> (data)); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
457 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
458 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
459 case TIFF_DOUBLE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
460 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
461 retval = *(reinterpret_cast<double *> (data)); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
462 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
463 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
464 case TIFF_SRATIONAL: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
465 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
466 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
|
467 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
468 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
469 case TIFF_IFD: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
470 case TIFF_IFD8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
471 error ("Unimplemented IFFD data type"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
472 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
473 default: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
474 error ("Unsupported tag data type"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
475 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
476 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
477 return octave_value (retval); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
478 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
479 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
480 // 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
|
481 // depending on tag_datatype |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
482 octave_value |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
483 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
|
484 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
485 octave_value retval; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
486 // Apparently matlab converts scalar numerical values into double |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
487 // but doesn't do the same for arrays |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
488 if (count == 1 && tag_datatype != TIFF_ASCII) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
489 { |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
490 retval = interpret_scalar_tag_data (data, tag_datatype); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
491 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
492 else |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
493 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
494 dim_vector arr_dims (1, count); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
495 |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
496 switch (tag_datatype) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
497 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
498 case TIFF_BYTE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
499 case TIFF_UNDEFINED: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
500 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
501 uint8NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
502 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
503 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
504 arr(i) = (reinterpret_cast<uint8_t *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
505 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
506 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
507 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
508 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
509 case TIFF_ASCII: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
510 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
511 retval = octave_value (*(reinterpret_cast<char **> (data))); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
512 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
513 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
514 case TIFF_SHORT: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
515 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
516 uint16NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
517 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
518 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
519 arr(i) = (reinterpret_cast<uint16_t *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
520 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
521 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
522 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
523 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
524 case TIFF_LONG: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
525 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
526 uint32NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
527 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
528 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
529 arr(i) = (reinterpret_cast<uint32_t *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
530 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
531 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
532 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
533 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
534 case TIFF_LONG8: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
535 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
536 uint64NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
537 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
538 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
539 arr(i) = (reinterpret_cast<uint64_t *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
540 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
541 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
542 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
543 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
544 case TIFF_RATIONAL: |
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 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
547 for (uint32_t i = 0; i < count; i+=2) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
548 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
549 arr(i / 2) = static_cast<float> ((reinterpret_cast<uint32_t *> (data))[i]) |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
550 / static_cast<float> ((reinterpret_cast<uint32_t *> (data))[i+1]); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
551 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
552 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
553 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
554 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
555 case TIFF_SBYTE: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
556 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
557 int8NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
558 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
559 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
560 arr(i) = (reinterpret_cast<int8_t *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
561 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
562 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
563 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
564 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
565 case TIFF_SSHORT: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
566 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
567 int16NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
568 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
569 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
570 arr(i) = (reinterpret_cast<int16_t *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
571 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
572 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
573 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
574 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
575 case TIFF_SLONG: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
576 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
577 int32NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
578 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
579 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
580 arr(i) = (reinterpret_cast<int32_t *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
581 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
582 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
583 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
584 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
585 case TIFF_SLONG8: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
586 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
587 int64NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
588 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
589 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
590 arr(i) = (reinterpret_cast<int64_t *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
591 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
592 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
593 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
594 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
595 case TIFF_FLOAT: |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
596 { |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
597 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
598 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
599 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
600 arr(i) = (reinterpret_cast<float *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
601 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
602 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
603 break; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
604 } |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
605 case TIFF_DOUBLE: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
606 { |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
607 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
608 for (uint32_t i = 0; i < count; i++) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
609 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
610 arr(i) = (reinterpret_cast<double *> (data))[i]; |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
611 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
612 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
613 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
614 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
615 case TIFF_SRATIONAL: |
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 NDArray arr (arr_dims); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
618 for (uint32_t i = 0; i < count; i+=2) |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
619 { |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
620 arr(i / 2) = static_cast<float> ((reinterpret_cast<int32_t *> (data))[i]) |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
621 / static_cast<float> ((reinterpret_cast<int32_t *> (data))[i+1]); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
622 } |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
623 retval = octave_value (arr); |
31105
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
624 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
625 } |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
626 case TIFF_IFD: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
627 case TIFF_IFD8: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
628 // TODO(maged): implement IFD datatype? |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
629 error ("Unimplemented IFFD data type"); |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
630 break; |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
631 default: |
7c5b8a294f60
getTag returns double for scalar values
magedrifaat <magedrifaat@gmail.com>
parents:
31104
diff
changeset
|
632 error ("Unsupported tag data type"); |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
633 } |
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
634 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
635 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
636 return retval; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
637 } |
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
|
638 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
639 octave_value |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
640 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
|
641 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
642 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
|
643 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
644 // TIFFFieldReadCount returns VARIABLE for some scalar tags |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
645 // (e.g. Compression) But TIFFFieldPassCount seems consistent |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
646 // 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
|
647 // 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
|
648 if (TIFFFieldPassCount (fip)) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
649 error ("Unsupported tag"); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
650 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
651 int type_size = TIFFDataWidth (TIFFFieldDataType (fip)); |
31124
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
652 // TODO(maged): use shared pointer instead of malloc |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
653 void *data = _TIFFmalloc (type_size); |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
654 // TODO(maged): check if this should be GetFieldDefaulted instead |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
655 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
|
656 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
|
657 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
658 _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
|
659 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
660 return tag_data_ov; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
661 } |
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
|
662 |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
663 octave_value |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
664 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
|
665 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
666 void *data; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
667 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
|
668 |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
669 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
|
670 } |
31097
75ab26f147a5
getTag: Implemented single array tags, only multi-array and special tags are unimplemented
magedrifaat <magedrifaat@gmail.com>
parents:
31096
diff
changeset
|
671 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
672 octave_value |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
673 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
|
674 { |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
675 octave_value tag_data_ov; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
676 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
|
677 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
678 // 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
|
679 switch (tag_id) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
680 { |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
681 case TIFFTAG_STRIPBYTECOUNTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
682 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
|
683 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
|
684 TIFFNumberOfStrips (tif)); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
685 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
686 case TIFFTAG_TILEBYTECOUNTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
687 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
|
688 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
|
689 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
690 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
|
691 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
|
692 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
693 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
|
694 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
|
695 break; |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
696 case TIFFTAG_GRAYRESPONSECURVE: |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
697 { |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
698 uint16_t bits_per_sample; |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
699 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
700 &bits_per_sample)) |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
701 error ("Failed to obtain the bit depth"); |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
702 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
703 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
|
704 break; |
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
705 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
706 case TIFFTAG_COLORMAP: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
707 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
708 uint16_t bits_per_sample; |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
709 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
710 &bits_per_sample)) |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
711 error ("Failed to obtain the bit depth"); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
712 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
713 if (bits_per_sample > 24) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
714 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
|
715 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
716 uint32_t count = 1 << bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
717 uint16_t *red, *green, *blue; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
718 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
|
719 &red, &green, &blue)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
720 |
31123
0bcb35909ef4
Tiff open: removed support for rh mode and marked r+ as not yet supported
magedrifaat <magedrifaat@gmail.com>
parents:
31122
diff
changeset
|
721 // TODO(maged): use Array<T>::cat |
31121
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
722 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
|
723 |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
724 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
|
725 count, |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
726 TIFFFieldDataType (fip)) |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
727 .uint16_array_value ()); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
728 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
|
729 count, |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
730 TIFFFieldDataType (fip)) |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
731 .uint16_array_value ()); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
732 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
|
733 count, |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
734 TIFFFieldDataType (fip)) |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
735 .uint16_array_value ()); |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
736 |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
737 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
|
738 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
|
739 out_ptr += count; |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
740 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
|
741 out_ptr += count; |
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
742 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
|
743 |
31121
341796f9efb6
Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents:
31120
diff
changeset
|
744 // 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
|
745 mat_out /= UINT16_MAX; |
31114
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
746 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
747 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
|
748 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
749 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
750 case TIFFTAG_TRANSFERFUNCTION: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
751 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
752 uint16_t samples_per_pixel; |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
753 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLESPERPIXEL, |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
754 &samples_per_pixel)) |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
755 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
|
756 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
757 uint16_t bits_per_sample; |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
758 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
759 &bits_per_sample)) |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
760 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
|
761 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
762 uint32_t count = 1 << bits_per_sample; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
763 uint16_t *ch1, *ch2, *ch3; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
764 if (samples_per_pixel == 1) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
765 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
766 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
|
767 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
|
768 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
769 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
770 else |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
771 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
772 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
|
773 &ch1, &ch2, &ch3)); |
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 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
|
776 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
777 uint16NDArray ch1_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
778 = interpret_tag_data (ch1, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
779 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
780 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
781 uint16NDArray ch2_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
782 = interpret_tag_data (ch2, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
783 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
784 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
785 uint16NDArray ch3_array |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
786 = interpret_tag_data (ch3, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
787 count, |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
788 TIFFFieldDataType (fip)).uint16_array_value (); |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
789 |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
790 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
|
791 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
|
792 out_ptr += count; |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
793 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
|
794 out_ptr += count; |
9dead1249449
Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents:
31113
diff
changeset
|
795 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
|
796 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
797 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
|
798 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
799 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
800 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
801 case TIFFTAG_PAGENUMBER: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
802 case TIFFTAG_HALFTONEHINTS: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
803 case TIFFTAG_DOTRANGE: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
804 case TIFFTAG_YCBCRSUBSAMPLING: |
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 uint16_t tag_part1, tag_part2; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
807 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
|
808 &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
|
809 |
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
810 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
|
811 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
|
812 = 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
|
813 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
|
814 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
|
815 = 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
|
816 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
|
817 |
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
818 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
|
819 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
820 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
821 case TIFFTAG_SUBIFD: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
822 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
823 uint16_t count; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
824 uint64_t *offsets; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
825 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
|
826 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
|
827 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
828 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
829 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
830 case TIFFTAG_EXTRASAMPLES: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
831 { |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
832 uint16_t count; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
833 uint16_t *types; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
834 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
|
835 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
|
836 TIFFFieldDataType (fip)); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
837 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
838 } |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
839 // 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
|
840 // will be implemented and tested later. |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
841 case TIFFTAG_XMLPACKET: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
842 case TIFFTAG_RICHTIFFIPTC: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
843 case TIFFTAG_PHOTOSHOP: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
844 case TIFFTAG_ICCPROFILE: |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
845 { |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
846 error ("Complex Tags not implemented"); |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
847 break; |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
848 } |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
849 // 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
|
850 // 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
|
851 case TIFFTAG_ZIPQUALITY: |
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
852 case TIFFTAG_SGILOGDATAFMT: |
31106
f5a88c0a61ab
Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents:
31105
diff
changeset
|
853 case TIFFTAG_GRAYRESPONSEUNIT: |
31103
76b21bed2920
Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents:
31102
diff
changeset
|
854 { |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
855 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
|
856 break; |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
857 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
858 default: |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
859 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
|
860 } |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
861 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
862 return tag_data_ov; |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
863 } |
31124
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
864 |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
865 void |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
866 set_field_data (TIFF *tif, const TIFFField *fip, octave_value tag_ov) |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
867 { |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
868 // TODO(maged): complete the implementation of this function |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
869 uint32_t tag_id = TIFFFieldTag (fip); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
870 uint32_t tag_data = tag_ov.double_value (); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
871 |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
872 if (! TIFFSetField(tif, tag_id, tag_data)) |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
873 error ("Failed to set tag value"); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
874 } |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
875 |
31126
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
876 template <typename T> |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
877 void |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
878 write_strip (TIFF *tif, uint32_t strip_no, octave_value strip_data_ov, |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
879 tiff_image_data *image_data) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
880 { |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
881 T strip_data = T (strip_data_ov.array_value ()); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
882 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
883 uint32_t rows_in_strip; |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
884 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &rows_in_strip)) |
31126
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
885 error ("Failed to obtain the RowsPerStrip tag"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
886 |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
887 // The tag has a default value of UINT32_MAX which means the entire |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
888 // image, but we need to cap it to the height for later calculations |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
889 if (rows_in_strip > image_data->height) |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
890 rows_in_strip = image_data->height; |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
891 |
31126
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
892 uint32_t strip_count = TIFFNumberOfStrips (tif); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
893 uint32_t expected_numel; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
894 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
895 // Calculate the expected number of elements in the strip data array |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
896 // All strips have equal number of rows excpet strips at the bottom |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
897 // of the image can have less number of rows |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
898 if (image_data->planar_configuration == PLANARCONFIG_CONTIG) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
899 { |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
900 // All strips have equal number of rows excpet strips at the bottom |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
901 // of the image can have less number of rows |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
902 if (strip_no == strip_count) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
903 rows_in_strip = image_data->height - rows_in_strip * (strip_no - 1); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
904 expected_numel = rows_in_strip * image_data->width |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
905 * image_data->samples_per_pixel; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
906 } |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
907 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
908 { |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
909 // For separate planes, we should check the last strip of each channel |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
910 uint32_t strips_per_channel |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
911 = strip_count / image_data->samples_per_pixel; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
912 for (uint32_t boundary_strip = strips_per_channel; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
913 boundary_strip <= strip_count; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
914 boundary_strip += strips_per_channel) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
915 if (strip_no == boundary_strip) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
916 rows_in_strip = image_data->height - rows_in_strip |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
917 * ((strip_no - 1) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
918 % (strips_per_channel)); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
919 expected_numel = rows_in_strip * image_data->width; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
920 } |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
921 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
922 error ("Planar configuration not supported"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
923 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
924 if (strip_data.numel () != expected_numel) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
925 error ("Size of strip data is different from the expected size of the strip"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
926 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
927 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
928 // Put the strip in a consistent shape for the subsequent permutation |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
929 if (image_data->planar_configuration == PLANARCONFIG_CONTIG) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
930 { |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
931 strip_data |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
932 = strip_data.reshape (dim_vector (rows_in_strip, image_data->width, |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
933 image_data->samples_per_pixel)); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
934 } |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
935 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
936 { |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
937 strip_data = strip_data.reshape (dim_vector (rows_in_strip, |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
938 image_data->width, 1)); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
939 } |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
940 |
31127
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
941 //TODO(maged): add suppot for 1-bit and 4-bit images |
0d9633ee715e
Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents:
31126
diff
changeset
|
942 |
31126
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
943 // Permute the dimesions of the strip to match the expected memory |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
944 // arrangement of LibTIFF (channel x width x height) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
945 Array<octave_idx_type> perm (dim_vector (3, 1)); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
946 perm(0) = 2; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
947 perm(1) = 1; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
948 perm(2) = 0; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
949 strip_data = strip_data.permute (perm); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
950 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
951 // LibTIFF uses zero-based indexing as opposed to Octave's 1-based |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
952 strip_no--; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
953 // Can't rely in LibTIFF's TIFFStripSize because boundary strips |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
954 // can be smaller in size |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
955 tsize_t strip_size = expected_numel * image_data->bits_per_sample / 8; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
956 if (TIFFWriteEncodedStrip (tif, strip_no, |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
957 strip_data.fortran_vec (), strip_size) == -1) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
958 error ("Failed to write strip data to image"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
959 } |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
960 |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
961 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
962 |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
963 DEFUN_DLD (__open_tiff__, args, , |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
964 "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
|
965 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
966 #if defined (HAVE_TIFF) |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
967 int nargin = args.length (); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
968 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
969 if (nargin == 0 || nargin > 2) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
970 { |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
971 // TODO(maged): return invalid object instead?? |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
972 error ("No filename supplied\n"); |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
973 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
974 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
975 std::string filename = args (0).string_value (); |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
976 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
|
977 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
978 // TODO(maged): check valid mode |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
979 if (nargin == 2) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
980 mode = args (1).string_value (); |
31123
0bcb35909ef4
Tiff open: removed support for rh mode and marked r+ as not yet supported
magedrifaat <magedrifaat@gmail.com>
parents:
31122
diff
changeset
|
981 |
0bcb35909ef4
Tiff open: removed support for rh mode and marked r+ as not yet supported
magedrifaat <magedrifaat@gmail.com>
parents:
31122
diff
changeset
|
982 std::vector<std::string> supported_modes {"r", "w", "w8", "a"}; |
0bcb35909ef4
Tiff open: removed support for rh mode and marked r+ as not yet supported
magedrifaat <magedrifaat@gmail.com>
parents:
31122
diff
changeset
|
983 |
0bcb35909ef4
Tiff open: removed support for rh mode and marked r+ as not yet supported
magedrifaat <magedrifaat@gmail.com>
parents:
31122
diff
changeset
|
984 if (std::find(supported_modes.begin(), supported_modes.end(), mode) |
0bcb35909ef4
Tiff open: removed support for rh mode and marked r+ as not yet supported
magedrifaat <magedrifaat@gmail.com>
parents:
31122
diff
changeset
|
985 == supported_modes.end()) |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
986 { |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
987 if (mode == "r+") |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
988 error ("Openning files in r+ mode is not yet supported"); |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
989 else |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
990 error ("Invalid mode for openning Tiff file: %s", mode.c_str ()); |
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
991 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
992 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
993 // TODO(maged): Look into unwind action |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
994 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
|
995 |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
996 if (! tif) |
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
997 error ("Failed to open Tiff file\n"); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
998 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
999 // 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
|
1000 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
|
1001 return octave_value_list (tiff_ov); |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1002 #else |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
1003 octave_unused_parameter (args); |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1004 err_disabled_feature ("Tiff", "Tiff"); |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1005 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
1006 } |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
1007 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
1008 |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
1009 DEFUN_DLD (__close_tiff__, args, , |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1010 "Close a tiff file") |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
1011 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1012 #if defined (HAVE_TIFF) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
1013 int nargin = args.length (); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
1014 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
1015 if (nargin == 0) |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
1016 error ("No handle provided\n"); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
1017 |
31101
f24d7bcad2d3
Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents:
31099
diff
changeset
|
1018 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
|
1019 TIFFClose (tif); |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
1020 |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
1021 return octave_value_list (); |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1022 #else |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1023 err_disabled_feature ("close", "Tiff"); |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1024 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
1025 } |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
1026 |
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
1027 |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
1028 DEFUN_DLD (__tiff_get_tag__, args, , |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1029 "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
|
1030 { |
31104
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1031 #if defined (HAVE_TIFF) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1032 int nargin = args.length (); |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
1033 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1034 if (nargin == 0) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1035 error ("No handle provided\n"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1036 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1037 if (nargin < 2) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1038 error ("No tag name provided\n"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1039 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1040 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
|
1041 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1042 uint32_t tag_id; |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1043 const TIFFField *fip; |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
1044 // TODO(maged): support sq_string as well |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1045 if (args (1).type_name () == "string") |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1046 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1047 std::string tagName = args (1).string_value (); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1048 fip = TIFFFieldWithName (tif, tagName.c_str ()); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1049 if (! fip) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1050 error ("Tiff tag not found"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1051 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1052 tag_id = TIFFFieldTag (fip); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1053 } |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1054 else |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1055 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1056 tag_id = args (1).int_value (); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1057 fip = TIFFFieldWithTag (tif, tag_id); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1058 // 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
|
1059 if (! fip) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1060 error ("Tiff tag not found"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1061 } |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
1062 |
31117
530dbd1d6b07
Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents:
31115
diff
changeset
|
1063 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
|
1064 #else |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1065 err_disabled_feature ("getTag", "Tiff"); |
b5d59c115e52
Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents:
31103
diff
changeset
|
1066 #endif |
31102
d6ecf0e8838b
Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents:
31101
diff
changeset
|
1067 } |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1068 |
31124
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1069 |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
1070 DEFUN_DLD (__tiff_set_tag__, args, , |
31124
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1071 "Set the value of a tag in a tiff image") |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1072 { |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1073 #if defined (HAVE_TIFF) |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1074 int nargin = args.length (); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1075 |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1076 if (nargin < 2) |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1077 error ("Too few arguments provided\n"); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1078 |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1079 TIFF *tif = (TIFF *)(args (0).uint64_value ()); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1080 |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1081 // TODO(maged): does matlab allow calling this function for images |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1082 // opened for reading? |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1083 if (args (1).type_name () == "struct") |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1084 error ("setTag with struct is not yet supported"); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1085 else |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1086 { |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1087 const TIFFField *fip; |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
1088 // TODO(maged): support sq_string as well |
31124
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1089 if (args (1).type_name () == "string") |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1090 { |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1091 std::string tagName = args (1).string_value (); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1092 fip = TIFFFieldWithName (tif, tagName.c_str ()); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1093 if (! fip) |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1094 error ("Tiff tag not found"); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1095 } |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1096 else |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1097 { |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1098 uint32_t tag_id = args (1).int_value (); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1099 fip = TIFFFieldWithTag (tif, tag_id); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1100 if (! fip) |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1101 error ("Tiff tag not found"); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1102 } |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1103 |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1104 if (nargin < 3) |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1105 error ("Too few arguments provided"); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1106 |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1107 set_field_data (tif, fip, args (2)); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1108 } |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1109 |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1110 return octave_value_list (); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1111 #else |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1112 err_disabled_feature ("setTag", "Tiff"); |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1113 #endif |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1114 } |
e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents:
31123
diff
changeset
|
1115 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1116 DEFUN_DLD (__tiff_read__, args, nargout, |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1117 "Read the image in the current IFD") |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1118 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1119 #if defined (HAVE_TIFF) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1120 int nargin = args.length (); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1121 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1122 if (nargin == 0) |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1123 error ("No handle provided\n"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1124 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1125 TIFF *tif = (TIFF *)(args (0).uint64_value ()); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1126 |
31126
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1127 // TODO(maged): nargout and ycbcr |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
1128 octave_unused_parameter (nargout); |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1129 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1130 // Obtain all necessary tags |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
1131 // 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
|
1132 // 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
|
1133 // 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
|
1134 // 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
|
1135 tiff_image_data image_data (tif); |
31125
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1136 |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1137 uint16_t sample_format; |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1138 if (! TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_format)) |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1139 error ("Failed to obtain a value for sample format"); |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1140 |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1141 if (sample_format == 3) |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1142 { |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1143 if (false && image_data.bits_per_sample != 32 && image_data.bits_per_sample != 64) |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1144 error ("Floating point images are only supported for bit depths of 32 and 64"); |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1145 } |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1146 else if (sample_format != 1 && sample_format != 4) |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1147 error ("Unsupported sample format"); |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1148 |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1149 octave_value_list retval; |
31112
e3d8443585fe
Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents:
31111
diff
changeset
|
1150 switch (image_data.bits_per_sample) |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1151 { |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1152 case 1: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
1153 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
|
1154 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1155 case 4: |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1156 case 8: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
1157 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
|
1158 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1159 case 16: |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
1160 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
|
1161 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1162 case 32: |
31125
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1163 if (sample_format == 3) |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1164 retval(0) = read_image<FloatNDArray> (tif, &image_data); |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1165 else |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1166 retval(0) = read_image<uint32NDArray> (tif, &image_data); |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
1167 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1168 case 64: |
31125
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1169 if (sample_format == 3) |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1170 retval(0) = read_image<NDArray> (tif, &image_data); |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1171 else |
3b775b939de4
Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents:
31124
diff
changeset
|
1172 retval(0) = read_image<uint64NDArray> (tif, &image_data); |
31113
a74059523d74
Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents:
31112
diff
changeset
|
1173 break; |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1174 default: |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1175 error ("Unsupported bit depth"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1176 } |
31110
2daeeff33980
Tiff read fixed segfault bug for compressed images
magedrifaat <magedrifaat@gmail.com>
parents:
31109
diff
changeset
|
1177 |
31109
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1178 return retval; |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1179 #else |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1180 err_disabled_feature ("read", "Tiff"); |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1181 #endif |
06814e8b5a29
add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents:
31106
diff
changeset
|
1182 } |
31126
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1183 |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
1184 DEFUN_DLD (__tiff_write_encoded_strip__, args, , |
31126
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1185 "Write an encoded strip to the image") |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1186 { |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1187 #if defined (HAVE_TIFF) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1188 int nargin = args.length (); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1189 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1190 if (nargin < 3) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1191 error ("Too few arguments provided\n"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1192 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1193 TIFF *tif = (TIFF *)(args (0).uint64_value ()); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1194 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1195 // Obtain all necessary tags |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1196 tiff_image_data image_data (tif); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1197 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1198 if (image_data.is_tiled) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1199 error ("Can't rite strips to a tiled image"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1200 |
31128
524cb3106432
__tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents:
31127
diff
changeset
|
1201 uint32_t strip_no = args (1).uint32_scalar_value (); |
31126
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1202 if (strip_no < 1 || strip_no > TIFFNumberOfStrips (tif)) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1203 error ("Strip number out of range"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1204 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1205 // SampleFormat tag is not a required field and has a default value of 1 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1206 // So we need to use TIFFGetFieldDefaulted in case it is not present in |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1207 // the file |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1208 uint16_t sample_format; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1209 if (! TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_format)) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1210 error ("Failed to obtain a value for sample format"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1211 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1212 if (sample_format == 3) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1213 { |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1214 if (image_data.bits_per_sample != 32 && image_data.bits_per_sample != 64) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1215 error ("Floating point images are only supported for bit depths of 32 and 64"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1216 } |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1217 // The standard specifies that a SampleFormat of 4 should be treated |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1218 // the same as 1 (unsigned integer) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1219 else if (sample_format != 1 && sample_format != 4) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1220 error ("Unsupported sample format"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1221 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1222 std::string type_name = args(2).type_name (); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1223 switch (image_data.bits_per_sample) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1224 { |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1225 case 1: |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1226 if (type_name == "bool matrix") |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1227 write_strip<boolNDArray> (tif, strip_no, args(2), &image_data); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1228 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1229 error ("Expected logical matrix for BiLevel image"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1230 break; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1231 case 4: |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1232 case 8: |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1233 if (type_name == "uint8 matrix" || type_name == "int8 matrix") |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1234 write_strip<uint8NDArray> (tif, strip_no, args(2), &image_data); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1235 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1236 error ("Only uint8 and int8 data are allowed for images with bit depth of 8"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1237 break; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1238 case 16: |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1239 // Type conversion from signed to unsigned is handled in the function |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1240 // TODO(maged): what is the behavior if the input matrix has |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1241 // negative numbers? |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1242 if (type_name == "uint16 matrix" || type_name == "int16 matrix") |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1243 write_strip<uint16NDArray> (tif, strip_no, args(2), &image_data); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1244 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1245 error ("Only uint16 and int16 data are allowed for images with bit depth of 16"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1246 break; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1247 case 32: |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1248 if (sample_format == 3) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1249 if (type_name == "float matrix" || type_name == "matrix") |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1250 write_strip<FloatNDArray> (tif, strip_no, args(2), &image_data); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1251 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1252 error ("Only single and double data are allowed for floating-point images"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1253 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1254 if (type_name == "uint32 matrix" || type_name == "int32 matrix") |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1255 write_strip<uint32NDArray> (tif, strip_no, args(2), &image_data); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1256 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1257 error ("Only uint32 and int32 data are allowed for images with bit depth of 32"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1258 break; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1259 case 64: |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1260 if (sample_format == 3) |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1261 if (type_name == "float matrix" || type_name == "matrix") |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1262 write_strip<NDArray> (tif, strip_no, args(2), &image_data); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1263 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1264 error ("Only single and double data are allowed for floating-point images"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1265 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1266 if (type_name == "uint64 matrix" || type_name == "int64 matrix") |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1267 write_strip<uint64NDArray> (tif, strip_no, args(2), &image_data); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1268 else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1269 error ("Only uint64 and int64 data are allowed for images with bit depth of 64"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1270 break; |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1271 default: |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1272 error ("Unsupported bit depth"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1273 } |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1274 |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1275 return octave_value_list (); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1276 #else |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1277 err_disabled_feature ("writeEncodedStrip", "Tiff"); |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1278 #endif |
7851c5b9c950
Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents:
31125
diff
changeset
|
1279 } |
31092
a736190ce738
Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff
changeset
|
1280 } |