annotate libinterp/corefcn/__tiff__.cc @ 31196:1da6d747bf78

__tiff_imread__: converted to private octave function * libinterp/corefcn/__tiff__.cc: removed internal function __tiff_imread__. * scripts/image/private/__tiff_imread__.m: added private function __tiff_imread__. * scripts/image/module.mk: added entry for the private function __tiff_imread__.
author magedrifaat <magedrifaat@gmail.com>
date Thu, 01 Sep 2022 00:10:37 +0200
parents f8baeb850b36
children 1604c8812b67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
1 #if defined (HAVE_CONFIG_H)
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2 # include "config.h"
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
3 #endif
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
4
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
5 #include <string>
31094
ab5b33e447b0 Modified getTag to account for different tag data types and multivalued tags, the current implementation is still buggy for most tags and data types
magedrifaat <magedrifaat@gmail.com>
parents: 31093
diff changeset
6 #include <iostream>
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
7 #include <fstream>
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
8
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
9 #include "defun.h"
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
10 #include "ov.h"
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
11 #include "ovl.h"
31093
e2bed4daae82 Fix typo in module-files
magedrifaat <magedrifaat@gmail.com>
parents: 31092
diff changeset
12 #include "error.h"
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
13
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
14 #include "errwarn.h"
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
15
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
16 #include "fcntl-wrappers.h"
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
17 #include "file-stat.h"
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
18 #include "file-ops.h"
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
19 #include "str-vec.h"
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
20 #include "oct-time.h"
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
21
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
22 #if defined (HAVE_TIFF)
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
23 # include <tiffio.h>
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
24 bool handlers_set = true;
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
25 #endif
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
26
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
27 namespace octave
31099
6fc4bf5e14e1 Cleaned up the interface
magedrifaat <magedrifaat@gmail.com>
parents: 31098
diff changeset
28 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
29 #if defined (HAVE_TIFF)
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
30 class OCTINTERP_API octave_tiff_handle : public octave_base_value
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
31 {
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
32 public:
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
33 octave_tiff_handle (TIFF *tif)
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
34 : tiff_file (tif), closed (false)
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
35 { }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
36
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
37 TIFF *get_file(void) { return tiff_file; }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
38
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
39 bool is_defined (void) const { return true; }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
40 bool is_constant (void) const { return true; }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
41
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
42 void close(void)
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
43 {
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
44 if (! closed)
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
45 {
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
46 closed = true;
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
47 TIFFClose (tiff_file);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
48 }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
49 }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
50
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
51 bool is_closed (void) { return closed; }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
52
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
53 ~octave_tiff_handle (void)
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
54 {
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
55 if (! closed)
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
56 close ();
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
57 }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
58
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
59 static octave_tiff_handle *
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
60 get_tiff_handle (const octave_value& ov)
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
61 {
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
62 octave_base_value *rep = ov.internal_rep ();
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
63 octave_tiff_handle *handle = dynamic_cast<octave_tiff_handle *> (rep);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
64 if (! handle)
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
65 error ("get_tiff_handle: dynamic_cast to octave_tiff_handle failed");
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
66
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
67 return handle;
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
68 }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
69 private:
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
70 TIFF *tiff_file;
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
71 bool closed;
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
72 };
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
73
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
74 struct tiff_image_data
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
75 {
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
76 public:
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
77 uint32_t width;
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
78 uint32_t height;
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
79 uint16_t samples_per_pixel;
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
80 uint16_t bits_per_sample;
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
81 uint16_t planar_configuration;
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
82 uint16_t is_tiled;
31122
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
83
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
84 tiff_image_data (TIFF *tif)
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
85 {
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
86 if (! TIFFGetField (tif, TIFFTAG_IMAGEWIDTH, &width))
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
87 error ("Failed to read image width");
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
88
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
89 if (! TIFFGetField (tif, TIFFTAG_IMAGELENGTH, &height))
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
90 error ("Failed to read image height");
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
91
31127
0d9633ee715e Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents: 31126
diff changeset
92 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
93 &samples_per_pixel))
31122
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
94 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
95
31127
0d9633ee715e Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents: 31126
diff changeset
96 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
97 &bits_per_sample))
31122
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
98 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
99
31131
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
100 if (! TIFFGetField (tif, TIFFTAG_PLANARCONFIG,
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
101 &planar_configuration))
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
102 // LibTIFF has a bug where it incorrectly returns 0 as a default
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
103 // value for PlanarConfiguration although the default value is 1
31185
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
104 // This doesn't completely solve the issue as LibTIFF will refuse
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
105 // to write data to images of the tag is not set.
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
106 // see: https://www.asmail.be/msg0054918184.html
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
107 // This is now solved by this commit:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
108 // https://gitlab.com/libtiff/libtiff/-/commit/ac6ddaf678fff597610cb217705b55508240f065
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
109 // So this shouldn't be needed for future LibTIFF releases > 4.4.0
31131
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
110 planar_configuration = 1;
31122
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
111
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
112 is_tiled = TIFFIsTiled(tif);
1662939a7a49 Tiff read: moved image_date initialization into a constructor
magedrifaat <magedrifaat@gmail.com>
parents: 31121
diff changeset
113 }
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
114 };
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
115
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
116 void
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
117 set_internal_handlers (void)
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
118 {
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
119 if (handlers_set)
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
120 {
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
121 TIFFSetErrorHandler (verror_with_id);
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
122 TIFFSetWarningHandler (vwarning_with_id);
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
123 }
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
124 else
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
125 {
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
126 TIFFSetErrorHandler (NULL);
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
127 TIFFSetWarningHandler (NULL);
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
128 }
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
129 }
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
130
31190
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
131 bool
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
132 is_numeric_scalar (octave_value ov)
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
133 {
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
134 return ov.isnumeric () && ov.isreal () && ov.is_scalar_type ();
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
135 }
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
136
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
137 bool
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
138 is_colormap (octave_value ov)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
139 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
140 return ov.isnumeric () && ov.isreal () && ov.isfloat ()
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
141 && ov.ndims () == 2 && ov.columns () == 3;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
142 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
143
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
144 // A map of tag names supported by matlab, there are some differences
31195
f8baeb850b36 Tiff: Moved PKG_ADD logic to Tiff.m.
magedrifaat <magedrifaat@gmail.com>
parents: 31194
diff changeset
145 // than LibTIFF's names (e.g. Photometric vs PhotometricInterpretation)
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
146 static const std::map<std::string, ttag_t> tag_name_map = {
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
147 {"SubFileType", 254},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
148 {"ImageWidth", 256},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
149 {"ImageLength", 257},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
150 {"BitsPerSample", 258},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
151 {"Compression", 259},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
152 {"Photometric", 262},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
153 {"Thresholding", 263},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
154 {"FillOrder", 266},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
155 {"DocumentName", 269},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
156 {"ImageDescription", 270},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
157 {"Make", 271},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
158 {"Model", 272},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
159 {"StripOffsets", 273},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
160 {"Orientation", 274},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
161 {"SamplesPerPixel", 277},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
162 {"RowsPerStrip", 278},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
163 {"StripByteCounts", 279},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
164 {"MinSampleValue", 280},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
165 {"MaxSampleValue", 281},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
166 {"XResolution", 282},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
167 {"YResolution", 283},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
168 {"PlanarConfiguration", 284},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
169 {"PageName", 285},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
170 {"XPosition", 286},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
171 {"YPosition", 287},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
172 {"GrayResponseUnit", 290},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
173 {"GrayResponseCurve", 291},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
174 {"Group3Options", 292},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
175 {"Group4Options", 293},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
176 {"ResolutionUnit", 296},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
177 {"PageNumber", 297},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
178 {"TransferFunction", 301},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
179 {"Software", 305},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
180 {"DateTime", 306},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
181 {"Artist", 315},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
182 {"HostComputer", 316},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
183 {"WhitePoint", 318},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
184 {"PrimaryChromaticities", 319},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
185 {"ColorMap", 320},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
186 {"HalfToneHints", 321},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
187 {"TileWidth", 322},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
188 {"TileLength", 323},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
189 {"TileOffsets", 324},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
190 {"TileByteCounts", 325},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
191 {"SubIFD", 330},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
192 {"InkSet", 332},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
193 {"InkNames", 333},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
194 {"NumberOfInks", 334},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
195 {"DotRange", 336},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
196 {"TargetPrinter", 337},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
197 {"ExtraSamples", 338},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
198 {"SampleFormat", 339},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
199 {"SMinSampleValue", 340},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
200 {"SMaxSampleValue", 341},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
201 {"YCbCrCoefficients", 529},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
202 {"YCbCrSubSampling", 530},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
203 {"YCbCrPositioning", 531},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
204 {"ReferenceBlackWhite", 532},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
205 {"XMP", 700},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
206 {"ImageDepth", 32997},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
207 {"Copyright", 33432},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
208 {"RichTIFFIPTC", 33723},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
209 {"Photoshop", 34377},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
210 {"ICCProfile", 34675},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
211 {"SToNits", 37439},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
212 {"JPEGQuality", 65537},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
213 {"JPEGColorMode", 65538},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
214 {"ZipQuality", 65557},
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
215 {"SGILogDataFmt", 6556}
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
216 };
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
217
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
218 const TIFFField *get_fip_with_name (TIFF *tif, std::string& tag_name)
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
219 {
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
220 const TIFFField *fip = NULL;
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
221 if (tag_name_map.find (tag_name) != tag_name_map.cend ())
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
222 fip = TIFFFieldWithTag (tif, tag_name_map.at (tag_name));
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
223
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
224 // If the tag name is not found, fallback to the names defined
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
225 // in LibTIFF.
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
226 if (fip == NULL)
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
227 fip = TIFFFieldWithName (tif, tag_name.c_str ());
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
228
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
229 return fip;
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
230 }
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
231
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
232 void
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
233 check_readonly (TIFF *tif)
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
234 {
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
235 if (TIFFGetMode (tif) == octave_o_rdonly_wrapper ())
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
236 error ("Can't write data to a file opened in read-only mode");
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
237 }
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
238
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
239 void
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
240 check_closed (octave_tiff_handle *tiff_handle)
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
241 {
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
242 if (tiff_handle->is_closed ())
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
243 error ("The image file was closed");
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
244 }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
245
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
246 void
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
247 validate_tiff_get_field (bool status)
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
248 {
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
249 // Check if the return status of TIFFGetField is not 1
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
250 if (status != 1)
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
251 error ("Failed to read tag");
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
252 }
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
253
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
254 uint32_t get_rows_in_strip (uint32_t strip_no, uint32_t strip_count,
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
255 uint32_t rows_per_strip,
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
256 tiff_image_data *image_data)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
257 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
258 // Calculate the expected number of elements in the strip data array
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
259 // All strips have equal number of rows except strips at the bottom
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
260 // of the image can have less number of rows
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
261 uint32_t rows_in_strip = rows_per_strip;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
262 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
263 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
264 // All strips have equal number of rows excpet strips at the bottom
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
265 // of the image can have less number of rows
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
266 if (strip_no == strip_count - 1)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
267 rows_in_strip = image_data->height - rows_in_strip * strip_no;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
268 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
269 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
270 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
271 // For separate planes, we should check the last strip of each channel
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
272 uint32_t strips_per_channel
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
273 = strip_count / image_data->samples_per_pixel;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
274 for (uint32_t boundary_strip = strips_per_channel - 1;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
275 boundary_strip <= strip_count;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
276 boundary_strip += strips_per_channel)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
277 if (strip_no == boundary_strip)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
278 rows_in_strip = image_data->height
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
279 - rows_in_strip * (strip_no % strips_per_channel);
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
280 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
281 else
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
282 error ("Planar Configuration not supported");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
283
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
284 return rows_in_strip;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
285 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
286
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
287 void
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
288 get_tile_dimensions_validated (TIFF *tif, uint32_t& tile_width,
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
289 uint32_t& tile_height)
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
290 {
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
291 if (! TIFFGetField (tif, TIFFTAG_TILELENGTH, &tile_height))
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
292 error ("Filed to read tile length");
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
293
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
294 if (! TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width))
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
295 error ("Filed to read tile length");
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
296
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
297 if (tile_height == 0 || tile_height % 16 != 0
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
298 || tile_width == 0 || tile_width % 16 != 0)
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
299 error ("Tile dimesion tags are invalid");
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
300 }
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
301
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
302 template <typename T>
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
303 octave_value
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
304 read_strip (TIFF *tif, uint32_t strip_no, tiff_image_data * image_data)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
305 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
306 // ASSUMES stripped image and strip_no is a valid zero-based strip
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
307 // index for the tif image
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
308
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
309 uint32_t rows_in_strip;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
310 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &rows_in_strip))
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
311 error ("Failed to obtain a value for RowsPerStrip");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
312
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
313 // The default for RowsPerStrip is INT_MAX so it should be capped to the
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
314 // image height
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
315 if (rows_in_strip > image_data->height)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
316 rows_in_strip = image_data->height;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
317
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
318 uint32_t strip_count = TIFFNumberOfStrips (tif);
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
319 // Get the actual number of rows in the strip
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
320 rows_in_strip = get_rows_in_strip (strip_no, strip_count,
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
321 rows_in_strip, image_data);
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
322
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
323 // Set the strip dimensions depending on the planar configuration
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
324 dim_vector strip_dims;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
325 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
326 strip_dims = dim_vector (image_data->samples_per_pixel,
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
327 image_data->width, rows_in_strip);
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
328 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
329 strip_dims = dim_vector (image_data->width, rows_in_strip, 1);
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
330 else
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
331 error ("Unsupported bit depth");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
332
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
333 T strip_data (strip_dims);
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
334 uint8_t *strip_fvec
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
335 = reinterpret_cast<uint8_t *> (strip_data.fortran_vec ());
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
336
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
337 if (image_data->bits_per_sample == 8
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
338 || image_data->bits_per_sample == 16
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
339 || image_data->bits_per_sample == 32
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
340 || image_data->bits_per_sample == 64)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
341 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
342 if (TIFFReadEncodedStrip (tif, strip_no, strip_fvec, -1) == -1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
343 error ("Failed to read strip data");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
344 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
345 else if (image_data->bits_per_sample == 1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
346 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
347 if (image_data->samples_per_pixel != 1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
348 error ("Bi-Level images must have one channel only");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
349
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
350 // Create a buffer to hold the packed strip data
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
351 // Unique pointers are faster than vectors for constant size buffers
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
352 std::unique_ptr<uint8_t []> strip_ptr
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
353 = std::make_unique<uint8_t []> (TIFFStripSize (tif));
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
354 uint8_t *strip_buf = strip_ptr.get ();
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
355 if (TIFFReadEncodedStrip (tif, strip_no, strip_buf, -1) == -1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
356 error ("Failed to read strip data");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
357
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
358 // According to the format specification, the row should be byte
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
359 // aligned so the number of bytes is rounded up to the nearest byte
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
360 uint32_t padded_width = (image_data->width + 7) / 8;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
361 // Packing the pixel data into bits
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
362 for (uint32_t row = 0; row < rows_in_strip; row++)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
363 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
364 for (uint32_t col = 0; col < image_data->width; col++)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
365 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
366 uint8_t shift = col % 8;
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
367 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
368 shift = 7 - shift;
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
369 strip_fvec[col] = (strip_buf[col / 8] >> shift) & 0x1;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
370 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
371 strip_fvec += image_data->width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
372 strip_buf += padded_width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
373 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
374 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
375 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
376 error ("Unsupported bit depth");
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
377
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
378 // Reorder the dimensions to the order expected by Octave
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
379 Array<octave_idx_type> perm (dim_vector (3, 1));
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
380 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
381 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
382 perm(0) = 2;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
383 perm(1) = 1;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
384 perm(2) = 0;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
385 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
386 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
387 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
388 perm(0) = 1;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
389 perm(1) = 0;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
390 perm(2) = 2;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
391 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
392
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
393 strip_data = strip_data.permute (perm);
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
394 return octave_value (strip_data);
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
395 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
396
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
397 template <typename T>
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
398 octave_value
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
399 read_tile (TIFF *tif, uint32_t tile_no, tiff_image_data *image_data)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
400 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
401 // ASSUMES tiled image and tile_no is a valid zero-based tile
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
402 // index for the tif image
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
403
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
404 uint32_t tile_width, tile_height;
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
405 get_tile_dimensions_validated (tif, tile_width, tile_height);
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
406
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
407 dim_vector tile_dims;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
408 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
409 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
410 tile_dims = dim_vector (image_data->samples_per_pixel, tile_width,
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
411 tile_height);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
412 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
413 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
414 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
415 tile_dims = dim_vector (tile_width, tile_height, 1);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
416 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
417 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
418 error ("Unsupported planar configuration");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
419
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
420 T tile_data (tile_dims);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
421 uint8_t *tile_fvec
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
422 = reinterpret_cast<uint8_t *> (tile_data.fortran_vec ());
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
423
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
424 if (image_data->bits_per_sample == 8
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
425 || image_data->bits_per_sample == 16
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
426 || image_data->bits_per_sample == 32
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
427 || image_data->bits_per_sample == 64)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
428 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
429 if (TIFFReadEncodedTile (tif, tile_no, tile_fvec, -1) == -1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
430 error ("Failed to read tile data");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
431 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
432 else if (image_data->bits_per_sample == 1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
433 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
434 if (image_data->samples_per_pixel != 1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
435 error ("Bi-Level images must have one channel only");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
436
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
437 // Create a buffer to hold the packed tile data
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
438 // Unique pointers are faster than vectors for constant size buffers
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
439 std::unique_ptr<uint8_t []> tile_ptr
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
440 = std::make_unique<uint8_t []> (TIFFTileSize (tif));
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
441 uint8_t *tile_buf = tile_ptr.get ();
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
442 if (TIFFReadEncodedTile (tif, tile_no, tile_buf, -1) == -1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
443 error ("Failed to read tile data");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
444
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
445 // unpack tile bits into output matrix cells
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
446 for (uint32_t row = 0; row < tile_height; row++)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
447 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
448 for (uint32_t col = 0; col < tile_width; col++)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
449 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
450 uint8_t shift = col % 8;
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
451 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
452 shift = 7 - shift;
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
453 tile_fvec[col] = (tile_buf [col / 8] >> shift) & 0x1;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
454 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
455 tile_fvec += tile_width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
456 tile_buf += tile_width / 8;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
457 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
458 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
459 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
460 error ("Unsupported bit depth");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
461
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
462 Array<octave_idx_type> perm (dim_vector (3, 1));
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
463 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
464 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
465 perm(0) = 2;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
466 perm(1) = 1;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
467 perm(2) = 0;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
468 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
469 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
470 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
471 perm(0) = 1;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
472 perm(1) = 0;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
473 perm(2) = 2;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
474 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
475
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
476 tile_data = tile_data.permute (perm);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
477
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
478 // Get the actual tile dimensions for boundary tiles
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
479 uint32_t tiles_across = (image_data->width + tile_width - 1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
480 / tile_width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
481 uint32_t tiles_down = (image_data->height + tile_height - 1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
482 / tile_height;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
483 uint32_t corrected_width = tile_width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
484 uint32_t corrected_height = tile_height;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
485 if (tile_no % tiles_across == tiles_across - 1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
486 corrected_width = image_data->width - tile_width * (tiles_across - 1);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
487 if ((tile_no / tiles_across) % tiles_down == tiles_down - 1)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
488 corrected_height = image_data->height - tile_height * (tiles_down - 1);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
489
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
490 dim_vector corrected_dims;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
491 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
492 corrected_dims = dim_vector (corrected_height, corrected_width,
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
493 image_data->samples_per_pixel);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
494 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
495 corrected_dims = dim_vector (corrected_height, corrected_width);
31159
e960e3a3b3f6 Tiff.m: added structs for tag value enums to the Tiff class.
magedrifaat <magedrifaat@gmail.com>
parents: 31158
diff changeset
496
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
497 tile_data.resize (corrected_dims);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
498
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
499 return octave_value (tile_data);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
500 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
501
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
502 template <typename T>
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
503 octave_value
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
504 read_strip_or_tile (TIFF *tif, uint32_t strip_tile_no,
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
505 tiff_image_data *image_data)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
506 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
507 if (image_data->is_tiled)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
508 return read_tile<T> (tif, strip_tile_no, image_data);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
509 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
510 return read_strip<T> (tif, strip_tile_no, image_data);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
511 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
512
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
513 octave_value
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
514 read_unsigned_strip_or_tile (TIFF *tif, uint32_t strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
515 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
516 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
517 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
518 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
519 case 1:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
520 return read_strip_or_tile<boolNDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
521 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
522 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
523 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
524 return read_strip_or_tile<uint8NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
525 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
526 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
527 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
528 return read_strip_or_tile<uint16NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
529 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
530 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
531 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
532 return read_strip_or_tile<uint32NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
533 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
534 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
535 return read_strip_or_tile<uint64NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
536 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
537 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
538 error ("Unsupported bit depth");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
539 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
540 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
541
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
542 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
543 read_signed_strip_or_tile (TIFF *tif, uint32_t strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
544 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
545 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
546 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
547 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
548 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
549 return read_strip_or_tile<int8NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
550 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
551 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
552 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
553 return read_strip_or_tile<int16NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
554 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
555 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
556 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
557 return read_strip_or_tile<int32NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
558 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
559 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
560 return read_strip_or_tile<int64NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
561 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
562 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
563 error ("Unsupported bit depth for signed images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
564 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
565 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
566
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
567 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
568 read_float_strip_or_tile (TIFF *tif, uint32_t strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
569 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
570 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
571 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
572 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
573 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
574 return read_strip_or_tile<FloatNDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
575 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
576 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
577 return read_strip_or_tile<NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
578 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
579 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
580 error ("Unsupported bit depth for floating-point images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
581 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
582 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
583
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
584 octave_value
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
585 handle_read_strip_or_tile (TIFF *tif, uint32_t strip_tile_no)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
586 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
587 // Obtain all necessary tags
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
588 tiff_image_data image_data (tif);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
589
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
590 uint16_t sample_format;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
591 if (! TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_format))
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
592 error ("Failed to obtain a value for sample format");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
593
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
594 switch (sample_format)
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
595 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
596 case 1:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
597 case 4:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
598 return read_unsigned_strip_or_tile (tif, strip_tile_no, &image_data);
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
599 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
600 case 2:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
601 return read_signed_strip_or_tile (tif, strip_tile_no, &image_data);
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
602 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
603 case 3:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
604 return read_float_strip_or_tile (tif, strip_tile_no, &image_data);
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
605 break;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
606 default:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
607 error ("Unsupported sample format");
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
608 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
609 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
610
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
611 template <typename T>
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
612 octave_value
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
613 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
614 {
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
615 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
616
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
617 // 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
618 // 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
619 // 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
620 // 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
621 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
622 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
623 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
624 && padded_width % 8 != 0)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
625 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
626 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
627 remove_padding = 1;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
628 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
629
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
630 // 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
631 // 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
632 // 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
633 T img;
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
634 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
635 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
636 image_data->height));
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
637 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
638 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
639 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
640 else
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
641 error ("Unsupported Planar Configuration");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
642
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
643 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
644
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
645 // 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
646 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
647
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
648 // 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
649 // 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
650 // 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
651 int64_t strip_size;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
652 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
653 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
654 * 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
655 * sizeof (P);
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
656 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
657 {
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
658 // 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
659 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
660
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
661 // 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
662 if (strip_size == -1)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
663 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
664
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
665 // 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
666 // In case of a corrupt image with more data than needed
31129
dfab9c6982bf Tiff getTag: added support for single quotes string fo the tag name
magedrifaat <magedrifaat@gmail.com>
parents: 31128
diff changeset
667 // This is probably redundant as LibTIFF checks sizes internally
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
668 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
669 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
670
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
671 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
672 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
673 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
674 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
675
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
676 // 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
677 // 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
678 // 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
679 strip_size *= 8;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
680
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
681 // 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
682 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
683 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
684
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
685 // 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
686 // 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
687 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
688 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
689 uint8_t bit_number = pixel % 8;
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
690 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
691 bit_number = 7 - bit_number;
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
692 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
693 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
694 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
695 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
696 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
697 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
698 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
699 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
700
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
701 // 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
702 // 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
703 strip_size *= 2;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
704
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
705 // 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
706 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
707 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
708
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
709 // 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
710 // 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
711 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
712 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
713 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
714 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
715 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
716 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
717 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
718 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
719 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
720 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
721 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
722 error ("Unsupported bit depth");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
723
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
724 // 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
725 img_fvec
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
726 = 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
727 + strip_size);
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
728 written_size += strip_size;
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
729 }
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
730
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
731 // 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
732 // 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
733 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
734 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
735 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
736 perm(0) = 2;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
737 perm(1) = 1;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
738 perm(2) = 0;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
739 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
740 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
741 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
742 perm(0) = 1;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
743 perm(1) = 0;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
744 perm(2) = 2;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
745 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
746
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
747 img = img.permute (perm);
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
748
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
749 if (remove_padding)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
750 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
751
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
752 return octave_value (img);
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
753 }
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
754
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
755 template <typename T>
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
756 octave_value
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
757 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
758 {
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
759 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
760
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
761 // 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
762 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
763 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
764 &tile_width));
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
765 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
766 &tile_height));
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
767 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
768 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
769 / tile_width;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
770 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
771 / tile_height;
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
772
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
773 T img;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
774 // 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
775 // 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
776 // 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
777 // shape expected by Octave
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
778 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
779 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
780 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
781 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
782 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
783 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
784 else
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
785 error ("Unsupported Planar Configuration");
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
786
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
787 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
788
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
789 // 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
790 // 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
791 // boundary tiles
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
792 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
793 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
794 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
795
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
796 // 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
797 // 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
798 // 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
799 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
800 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
801 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
802 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
803 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
804
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
805 if (tile_size == -1)
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
806 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
807
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
808 // 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
809 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
810 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
811
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
812 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
813 {
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
814 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
815 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
816
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
817 // 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
818 // 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
819 // 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
820 tile_size *= 8;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
821
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
822 // 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
823 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
824 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
825
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
826 // 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
827 // 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
828 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
829 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
830 uint8_t bit_number = pixel % 8;
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
831 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
832 bit_number = 7 - bit_number;
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
833 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
834 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
835 }
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
836 }
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
837 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
838 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
839 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
840 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
841
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
842 // 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
843 // 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
844 tile_size *= 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
845
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
846 // 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
847 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
848 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
849
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
850 // 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
851 // 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
852 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
853 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
854 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
855 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
856 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
857 }
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
858 }
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
859 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
860 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
861 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
862 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
863 error ("Unsupported bit depth");
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
864
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
865 img_fvec
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
866 = 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
867 + tile_size);
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
868 written_size += tile_size;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
869 }
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
870
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
871 // 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
872 // 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
873 // 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
874 // 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
875 // 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
876 // 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
877 // 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
878 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
879 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
880 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
881 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
882 perm1(0) = 0;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
883 perm1(1) = 1;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
884 perm1(2) = 3;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
885 perm1(3) = 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
886 perm1(4) = 4;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
887 img = img.permute (perm1);
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
888
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
889 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
890 tile_width * tiles_across,
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
891 tile_height * tiles_down));
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
892
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
893 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
894 || 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
895 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
896 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
897
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
898 perm2(0) = 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
899 perm2(1) = 1;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
900 perm2(2) = 0;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
901 img = img.permute (perm2);
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
902 }
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
903 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
904 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
905 perm1(0) = 0;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
906 perm1(1) = 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
907 perm1(2) = 1;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
908 perm1(3) = 3;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
909 perm1(4) = 4;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
910 img = img.permute (perm1);
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
911
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
912 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
913 tile_height * tiles_down,
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
914 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
915
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
916 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
917 || 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
918 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
919 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
920
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
921 perm2(0) = 1;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
922 perm2(1) = 0;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
923 perm2(2) = 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
924 img = img.permute (perm2);
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
925 }
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
926
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
927 return octave_value (img);
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
928 }
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
929
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
930 template <typename T>
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
931 octave_value
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
932 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
933 {
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
934 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
935 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
936 else
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
937 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
938 }
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
939
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
940 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
941 read_unsigned_image (TIFF *tif, tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
942 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
943 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
944 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
945 case 1:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
946 return read_image<boolNDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
947 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
948 case 4:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
949 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
950 return read_image<uint8NDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
951 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
952 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
953 return read_image<uint16NDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
954 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
955 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
956 return read_image<uint32NDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
957 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
958 return read_image<uint64NDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
959 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
960 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
961 error ("Unsupported bit depth");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
962 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
963 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
964
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
965 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
966 read_signed_image (TIFF *tif, tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
967 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
968 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
969 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
970 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
971 return read_image<int8NDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
972 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
973 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
974 return read_image<int16NDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
975 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
976 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
977 return read_image<int32NDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
978 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
979 return read_image<int64NDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
980 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
981 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
982 error ("Unsupported bit depth for signed images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
983 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
984 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
985
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
986 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
987 read_float_image (TIFF *tif, tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
988 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
989 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
990 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
991 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
992 return read_image<FloatNDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
993 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
994 return read_image<NDArray> (tif, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
995 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
996 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
997 error ("Unsupported bit depth for floating-point images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
998 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
999 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1000
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1001 template <typename T>
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1002 octave_value
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1003 make_array (void *data, dim_vector& arr_dims)
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1004 {
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1005 typedef typename T::element_type P;
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1006
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1007 T arr (arr_dims);
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1008 for (uint32_t i = 0; i < arr_dims.numel (); i++)
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1009 {
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1010 arr(i) = (reinterpret_cast<P *> (data))[i];
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1011 }
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1012 return octave_value (arr);
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1013 }
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1014
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1015 octave_value
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1016 interpret_tag_data (void *data, uint32_t count, TIFFDataType tag_datatype,
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1017 bool convert_to_double = false)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1018 {
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1019 octave_value retval;dim_vector arr_dims (1, count);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1020 switch (tag_datatype)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
1021 {
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1022 case TIFF_BYTE:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1023 case TIFF_UNDEFINED:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1024 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1025 retval = make_array<uint8NDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1026 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1027 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1028 case TIFF_ASCII:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1029 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1030 retval = octave_value (*(reinterpret_cast<char **> (data)));
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1031 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1032 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1033 case TIFF_SHORT:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1034 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1035 retval = make_array<uint16NDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1036 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1037 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1038 case TIFF_LONG:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1039 case TIFF_IFD:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1040 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1041 retval = make_array<uint32NDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1042 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1043 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1044 case TIFF_LONG8:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1045 case TIFF_IFD8:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1046 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1047 retval = make_array<uint64NDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1048 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1049 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1050 case TIFF_RATIONAL:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1051 case TIFF_SRATIONAL:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1052 case TIFF_FLOAT:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1053 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1054 retval = make_array<FloatNDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1055 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1056 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1057 case TIFF_SBYTE:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1058 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1059 retval = make_array<int8NDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1060 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1061 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1062 case TIFF_SSHORT:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1063 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1064 retval = make_array<int16NDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1065 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1066 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1067 case TIFF_SLONG:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1068 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1069 retval = make_array<int32NDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1070 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1071 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1072 case TIFF_SLONG8:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1073 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1074 retval = make_array<int64NDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1075 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1076 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1077 case TIFF_DOUBLE:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1078 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1079 retval = make_array<NDArray> (data, arr_dims);
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1080 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1081 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1082 default:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1083 error ("Unsupported tag data type");
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
1084 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1085
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1086 if (tag_datatype != TIFF_ASCII && convert_to_double)
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1087 retval = retval.as_double ();
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1088 return retval;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1089 }
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
1090
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1091 octave_value
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1092 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
1093 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1094 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
1095
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1096 // TIFFFieldReadCount returns VARIABLE for some scalar tags
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1097 // (e.g. Compression) But TIFFFieldPassCount seems consistent
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1098 // 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
1099 // 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
1100 if (TIFFFieldPassCount (fip))
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1101 error ("Unsupported tag");
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1103 int type_size = TIFFDataWidth (TIFFFieldDataType (fip));
31129
dfab9c6982bf Tiff getTag: added support for single quotes string fo the tag name
magedrifaat <magedrifaat@gmail.com>
parents: 31128
diff changeset
1104
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1105 std::unique_ptr<uint8_t []> data
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1106 = std::make_unique<uint8_t []> (type_size);
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1107 uint8_t *data_ptr = data.get ();
31131
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
1108 if (tag_id == TIFFTAG_PLANARCONFIG)
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
1109 {
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
1110 // Workaround for a bug in LibTIFF where it incorrectly returns
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
1111 // zero as the default value for PlanaConfiguration
31185
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
1112 // See: https://www.asmail.be/msg0054918184.html
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1113 if (! TIFFGetField(tif, tag_id, data_ptr))
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1114 *reinterpret_cast<uint16_t *> (data_ptr) = 1;
31131
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
1115 }
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
1116 else
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1117 validate_tiff_get_field (TIFFGetFieldDefaulted (tif, tag_id, data_ptr));
31131
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
1118
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1119 // All scalar tags are returned as double
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1120 octave_value tag_data_ov = interpret_tag_data (data_ptr, 1,
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1121 TIFFFieldDataType (fip),
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1122 true);
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
1123
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1124 return tag_data_ov;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1125 }
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
1126
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1127 octave_value
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1128 get_array_field_data (TIFF *tif, const TIFFField *fip, uint32_t array_size,
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1129 bool convert_to_double = false)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1130 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1131 void *data;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1132 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
1133
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1134 return interpret_tag_data (data, array_size, TIFFFieldDataType (fip),
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1135 convert_to_double);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1136 }
31097
75ab26f147a5 getTag: Implemented single array tags, only multi-array and special tags are unimplemented
magedrifaat <magedrifaat@gmail.com>
parents: 31096
diff changeset
1137
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1138 octave_value
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1139 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
1140 {
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1141 octave_value tag_data_ov;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1142 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
1143
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1144 switch (tag_id)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
1145 {
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1146 case TIFFTAG_STRIPBYTECOUNTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1147 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
1148 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
1149 TIFFNumberOfStrips (tif));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1150 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1151 case TIFFTAG_TILEBYTECOUNTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1152 case TIFFTAG_TILEOFFSETS:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1153 tag_data_ov
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1154 = 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
1155 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1156 case TIFFTAG_YCBCRCOEFFICIENTS:
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1157 tag_data_ov = get_array_field_data (tif, fip, 3, true);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1158 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1159 case TIFFTAG_REFERENCEBLACKWHITE:
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1160 tag_data_ov = get_array_field_data (tif, fip, 6, true);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1161 break;
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1162 case TIFFTAG_GRAYRESPONSECURVE:
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1163 {
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1164 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
1165 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
1166 &bits_per_sample))
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1167 error ("Failed to obtain the bit depth");
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1168
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1169 tag_data_ov = get_array_field_data (tif, fip,
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1170 1<<bits_per_sample, true);
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1171 break;
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1172 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1173 case TIFFTAG_COLORMAP:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1174 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1175 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
1176 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
1177 &bits_per_sample))
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1178 error ("Failed to obtain the bit depth");
31143
a68f2dadafee Tiff.m: added all remaining tests for implemented features.
magedrifaat <magedrifaat@gmail.com>
parents: 31142
diff changeset
1179
a68f2dadafee Tiff.m: added all remaining tests for implemented features.
magedrifaat <magedrifaat@gmail.com>
parents: 31142
diff changeset
1180 // According to the format specification, this field should
a68f2dadafee Tiff.m: added all remaining tests for implemented features.
magedrifaat <magedrifaat@gmail.com>
parents: 31142
diff changeset
1181 // be 8 or 16 only.
a68f2dadafee Tiff.m: added all remaining tests for implemented features.
magedrifaat <magedrifaat@gmail.com>
parents: 31142
diff changeset
1182 if (bits_per_sample > 16)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1183 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
1184
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1185 uint32_t count = 1 << bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1186 uint16_t *red, *green, *blue;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1187 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
1188 &red, &green, &blue));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1189
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1190 // Retrieving the data of the three channels and concatenating
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1191 // them together
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1192 OCTAVE_LOCAL_BUFFER (NDArray, array_list, 3);
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1193 dim_vector col_dims(count, 1);
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1194 array_list[0] = NDArray (interpret_tag_data (red,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1195 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1196 TIFFFieldDataType(fip))
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1197 .uint16_array_value ()
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1198 .reshape (col_dims));
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1199 array_list[1] = NDArray (interpret_tag_data (green,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1200 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1201 TIFFFieldDataType(fip))
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1202 .uint16_array_value ()
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1203 .reshape (col_dims));
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1204 array_list[2] = NDArray (interpret_tag_data (blue,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1205 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1206 TIFFFieldDataType(fip))
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1207 .uint16_array_value ()
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1208 .reshape (col_dims));
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1209
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1210 NDArray mat_out = NDArray::cat(1, 3, array_list);
31121
341796f9efb6 Tiff getTag: converted colormap tag data to the correct type and range
magedrifaat <magedrifaat@gmail.com>
parents: 31120
diff changeset
1211 // 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
1212 mat_out /= UINT16_MAX;
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1213
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1214 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
1215 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1216 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1217 case TIFFTAG_TRANSFERFUNCTION:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1218 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1219 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
1220 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
1221 &samples_per_pixel))
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1222 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
1223
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1224 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
1225 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
1226 &bits_per_sample))
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1227 error ("Failed to obtain the bit depth");
31098
3cbd0d82167c getTag: Implemented all special tags, only unsupported geotiff tags not implemented
magedrifaat <magedrifaat@gmail.com>
parents: 31097
diff changeset
1228
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1229 uint32_t count = 1 << bits_per_sample;
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1230 uint16_t *ch1 = NULL, *ch2 = NULL, *ch3 = NULL;
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1231 // TransferFunction can have 1 or 3 channels depending on the
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1232 // SamplesPerPixel but the library still expects three pointers
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1233 // to be passed and sets only the needed ones
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1234 validate_tiff_get_field (TIFFGetField (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1235 &ch1, &ch2, &ch3));
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1236 if (ch2 == NULL)
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1237 tag_data_ov = interpret_tag_data (ch1, count,
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1238 TIFFFieldDataType (fip), true);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1239 else
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1240 {
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1241 // Concatenate the channels into an n by 3 array
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1242 OCTAVE_LOCAL_BUFFER (NDArray, array_list, 3);
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1243 dim_vector col_dims(count, 1);
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1244 array_list[0] = interpret_tag_data (ch1,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1245 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1246 TIFFFieldDataType (fip))
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1247 .array_value ()
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1248 .reshape (col_dims);
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1249 array_list[1] = interpret_tag_data (ch2,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1250 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1251 TIFFFieldDataType (fip))
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1252 .array_value ()
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1253 .reshape (col_dims);
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1254 array_list[2] = interpret_tag_data (ch3,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1255 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1256 TIFFFieldDataType (fip))
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1257 .array_value ()
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1258 .reshape (col_dims);
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1259
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1260 tag_data_ov
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1261 = octave_value (NDArray::cat (1, 3, array_list));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1262 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1263 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1264 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1265 case TIFFTAG_PAGENUMBER:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1266 case TIFFTAG_HALFTONEHINTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1267 case TIFFTAG_DOTRANGE:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1268 case TIFFTAG_YCBCRSUBSAMPLING:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1269 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1270 uint16_t tag_part1, tag_part2;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1271 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
1272 &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
1273
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1274 NDArray mat_out (dim_vector (1, 2));
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1275 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
1276 = 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
1277 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
1278 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
1279 = 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
1280 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
1281
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1282 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
1283 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1284 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1285 case TIFFTAG_SUBIFD:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1286 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1287 uint16_t count;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1288 uint64_t *offsets;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1289 validate_tiff_get_field (TIFFGetField (tif, tag_id,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1290 &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
1291 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
1292 TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1293 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1294 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1295 case TIFFTAG_EXTRASAMPLES:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1296 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1297 uint16_t count;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1298 uint16_t *types;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1299 validate_tiff_get_field (TIFFGetField (tif, tag_id,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1300 &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
1301 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
1302 TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1303 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1304 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1305 case TIFFTAG_XMLPACKET:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1306 case TIFFTAG_RICHTIFFIPTC:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1307 case TIFFTAG_PHOTOSHOP:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1308 case TIFFTAG_ICCPROFILE:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1309 {
31186
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1310 uint32_t count;
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1311 uint8_t *data;
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1312 validate_tiff_get_field (TIFFGetField (tif, tag_id,
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1313 &count, &data));
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1314 tag_data_ov = interpret_tag_data (data, count, TIFF_BYTE);
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1315 // Matlab returns XMP tag as char array not byte array
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1316 if (tag_id == TIFFTAG_XMLPACKET)
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1317 tag_data_ov = octave_value (tag_data_ov.char_array_value ());
31103
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
1318 break;
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
1319 }
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1320 // 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
1321 // 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
1322 case TIFFTAG_ZIPQUALITY:
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
1323 case TIFFTAG_SGILOGDATAFMT:
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1324 case TIFFTAG_GRAYRESPONSEUNIT:
31103
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
1325 {
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1326 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
1327 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1328 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1329 default:
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1330 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
1331 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1332
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1333 return tag_data_ov;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1334 }
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1335
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1336 void
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1337 set_scalar_field_data (TIFF *tif, const TIFFField *fip, octave_value tag_ov)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1338 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1339 uint32_t tag_id = TIFFFieldTag (fip);
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1340
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1341 // Since scalar tags are the last to be handled, any tag that
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1342 // require a count to be passed is an unsupported tag.
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1343 if (TIFFFieldPassCount (fip))
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1344 error ("Unsupported tag");
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1345
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1346 TIFFDataType tag_datatype = TIFFFieldDataType (fip);
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1347
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1348 // According to matlab, the value must be a scalar double
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1349 // except for strings
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1350 if (tag_datatype == TIFF_ASCII)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1351 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1352 if (! tag_ov.is_string ())
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1353 error ("Expected string for ascii tag");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1354 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1355 else if (! tag_ov.is_scalar_type () || ! tag_ov.is_double_type ())
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1356 error ("Tag value must be a scalar double");
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1357
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1358 switch (tag_datatype)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1359 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1360 case TIFF_BYTE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1361 case TIFF_UNDEFINED:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1362 TIFFSetField (tif, tag_id, tag_ov.uint8_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1363 break;
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1364 case TIFF_ASCII:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1365 TIFFSetField (tif, tag_id, tag_ov.string_value ().c_str ());
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1366 break;
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1367 case TIFF_SHORT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1368 TIFFSetField (tif, tag_id, tag_ov.uint16_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1369 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1370 case TIFF_LONG:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1371 TIFFSetField (tif, tag_id, tag_ov.uint32_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1372 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1373 case TIFF_LONG8:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1374 TIFFSetField (tif, tag_id, tag_ov.uint64_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1375 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1376 case TIFF_RATIONAL:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1377 TIFFSetField (tif, tag_id, tag_ov.float_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1378 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1379 case TIFF_SBYTE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1380 TIFFSetField (tif, tag_id, tag_ov.int8_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1381 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1382 case TIFF_SSHORT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1383 TIFFSetField (tif, tag_id, tag_ov.int16_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1384 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1385 case TIFF_SLONG:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1386 TIFFSetField (tif, tag_id, tag_ov.int32_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1387 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1388 case TIFF_SLONG8:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1389 TIFFSetField (tif, tag_id, tag_ov.int64_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1390 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1391 case TIFF_FLOAT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1392 TIFFSetField (tif, tag_id, tag_ov.float_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1393 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1394 case TIFF_DOUBLE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1395 TIFFSetField (tif, tag_id, tag_ov.double_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1396 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1397 case TIFF_SRATIONAL:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1398 TIFFSetField (tif, tag_id, tag_ov.float_scalar_value ());
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1399 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1400 case TIFF_IFD:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1401 case TIFF_IFD8:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1402 error ("Unimplemented IFFD data type");
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1403 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1404 default:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1405 error ("Unsupported tag data type");
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1406 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1407 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1408
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1409 template <typename T>
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1410 void
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1411 set_array_field_helper (TIFF *tif, uint32_t tag_id, T data_arr)
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1412 {
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1413 const void *data_ptr = data_arr.data ();
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1414
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1415 if (! TIFFSetField (tif, tag_id, data_ptr))
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1416 error ("Failed to set tag");
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1417 }
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1418
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1419 void
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1420 set_array_field_data (TIFF *tif, const TIFFField *fip,
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1421 octave_value tag_ov, uint32_t count)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1422 {
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1423 uint32_t tag_id = TIFFFieldTag (fip);
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1424 TIFFDataType tag_datatype = TIFFFieldDataType (fip);
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1425
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1426 // Array type must be double in matlab
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1427 if (! tag_ov.is_double_type ())
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1428 error ("Tag data must be double");
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1429
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1430 // Matlab checks number of elements not dimensions
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1431 if (tag_ov.array_value ().numel () != count)
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1432 error ("Expected an array with %u elements", count);
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1433
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1434 switch (tag_datatype)
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1435 {
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1436 case TIFF_BYTE:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1437 case TIFF_UNDEFINED:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1438 set_array_field_helper<uint8NDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1439 tag_ov.uint8_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1440 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1441 case TIFF_SHORT:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1442 set_array_field_helper<uint16NDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1443 tag_ov.uint16_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1444 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1445 case TIFF_LONG:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1446 set_array_field_helper<uint32NDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1447 tag_ov.uint32_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1448 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1449 case TIFF_LONG8:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1450 set_array_field_helper<uint64NDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1451 tag_ov.uint64_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1452 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1453 case TIFF_RATIONAL:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1454 set_array_field_helper<FloatNDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1455 tag_ov.float_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1456 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1457 case TIFF_SBYTE:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1458 set_array_field_helper<int8NDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1459 tag_ov.int8_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1460 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1461 case TIFF_SSHORT:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1462 set_array_field_helper<int16NDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1463 tag_ov.int16_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1464 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1465 case TIFF_SLONG:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1466 set_array_field_helper<int32NDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1467 tag_ov.int32_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1468 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1469 case TIFF_SLONG8:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1470 set_array_field_helper<int64NDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1471 tag_ov.int64_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1472 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1473 case TIFF_FLOAT:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1474 set_array_field_helper<FloatNDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1475 tag_ov.float_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1476 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1477 case TIFF_DOUBLE:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1478 set_array_field_helper<NDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1479 tag_ov.array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1480 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1481 case TIFF_SRATIONAL:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1482 set_array_field_helper<FloatNDArray> (tif, tag_id,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1483 tag_ov.float_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1484 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1485 case TIFF_IFD:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1486 case TIFF_IFD8:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1487 error ("Unimplemented IFFD data type");
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1488 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1489 default:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1490 error ("Unsupported tag data type");
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1491 }
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1492 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1493
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1494 void
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1495 set_field_data (TIFF *tif, const TIFFField *fip, octave_value tag_ov)
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1496 {
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1497 uint32_t tag_id = TIFFFieldTag (fip);
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1498
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1499 switch (tag_id)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1500 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1501 case TIFFTAG_YCBCRCOEFFICIENTS:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1502 set_array_field_data (tif, fip, tag_ov, 3);
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1503 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1504 case TIFFTAG_REFERENCEBLACKWHITE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1505 set_array_field_data (tif, fip, tag_ov, 6);
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1506 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1507 case TIFFTAG_GRAYRESPONSECURVE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1508 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1509 uint16_t bits_per_sample;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1510 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE,
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1511 &bits_per_sample))
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1512 error ("Failed to obtain the bit depth");
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1513
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1514 set_array_field_data (tif, fip, tag_ov, 1<<bits_per_sample);
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1515 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1516 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1517 case TIFFTAG_COLORMAP:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1518 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1519 uint16_t bits_per_sample;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1520 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE,
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1521 &bits_per_sample))
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1522 error ("Failed to obtain the bit depth");
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1523
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1524 if (! tag_ov.is_double_type ())
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1525 error ("Tag data must be double");
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1526
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1527 // According to the format specification, this field should
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1528 // be 8 or 16 only.
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1529 if (bits_per_sample > 16)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1530 error ("Too high bit depth for a palette image");
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1531
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1532 uint32_t count = 1 << bits_per_sample;
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1533
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1534 if (tag_ov.is_scalar_type ()
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1535 || tag_ov.array_value ().dim1 () != count
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1536 || tag_ov.array_value ().dim2 () != 3)
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1537 error ("Expected matrix with %u rows and 3 columns", count);
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1538
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1539 NDArray array_data = tag_ov.array_value ();
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1540 array_data *= UINT16_MAX;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1541 uint16NDArray u16_array = uint16NDArray (array_data);
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1542 const uint16_t *data_ptr
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1543 = reinterpret_cast<const uint16_t *> (u16_array.data ());
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1544 if (! TIFFSetField (tif, tag_id, data_ptr, data_ptr + count,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1545 data_ptr + 2 * count))
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1546 error ("Failed to set tag");
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1547 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1548 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1549 case TIFFTAG_TRANSFERFUNCTION:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1550 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1551 uint16_t samples_per_pixel;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1552 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLESPERPIXEL,
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1553 &samples_per_pixel))
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1554 error ("Failed to obtain the number of samples per pixel");
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1555
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1556 uint16_t bits_per_sample;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1557 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE,
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1558 &bits_per_sample))
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1559 error ("Failed to obtain the bit depth");
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1560
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1561 uint32_t count = 1 << bits_per_sample;
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1562
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1563 // An intermediate variable is required for storing the return of
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1564 // uint16_array_value so that the object remains in scope and the
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1565 // pointer returned from data () is not a dangling pointer
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1566 uint16NDArray data_arr = tag_ov.uint16_array_value ();
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1567
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1568 if (data_arr.numel () != count)
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1569 error ("Tag data should be and array of %u elements", count);
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1570
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1571 const uint16_t *data_ptr
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1572 = reinterpret_cast<const uint16_t *> (data_arr.data ());
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1573 if (samples_per_pixel == 1)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1574 {
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1575 if (! TIFFSetField (tif, tag_id, data_ptr))
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1576 error ("Failed to set field");
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1577 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1578 else
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1579 {
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1580 if (! TIFFSetField (tif, tag_id, data_ptr, data_ptr + count,
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1581 data_ptr + 2 * count))
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1582 error ("Failed to set field");
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1583 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1584 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1585 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1586 case TIFFTAG_PAGENUMBER:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1587 case TIFFTAG_HALFTONEHINTS:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1588 case TIFFTAG_DOTRANGE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1589 case TIFFTAG_YCBCRSUBSAMPLING:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1590 {
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1591 uint16NDArray array_data = tag_ov.uint16_array_value ();
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1592 if (array_data.numel () != 2)
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1593 error ("Tag data should be an array with 2 elements");
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1594
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1595 if (! TIFFSetField (tif, tag_id, array_data (0), array_data (1)))
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1596 error ("Failed to set field");
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1597 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1598 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1599 case TIFFTAG_SUBIFD:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1600 {
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1601 // Setting the SubIFD invloves setting their count only
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1602 // and the library will set the offsets correctly in
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1603 // the next calls to writeDirectory, but an array of offsets
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1604 // is still required so an array of zeroes is passed
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
1605 uint16_t subifd_count = tag_ov.uint16_scalar_value ();
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
1606 std::unique_ptr<uint64_t []> subifd_offsets
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
1607 = std::make_unique<uint64_t []> (subifd_count);
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
1608 uint64_t *offfsets_ptr = subifd_offsets.get ();
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
1609 if (! TIFFSetField (tif, tag_id, subifd_count, offfsets_ptr))
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
1610 error ("Failed to set tag");
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1611 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1612 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1613 case TIFFTAG_EXTRASAMPLES:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1614 {
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1615 uint16_t samples_per_pixel;
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1616 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLESPERPIXEL,
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1617 &samples_per_pixel))
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1618 error ("Failed to obtain the number of samples per pixel");
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1619
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1620 uint16NDArray data_array = tag_ov.uint16_array_value ();
31190
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
1621 // FIXME: this only works for RGB images. Need to handle grayscale,
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
1622 // palette, cmyk and ycbcr
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1623 if (data_array.numel () > samples_per_pixel - 3)
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1624 error ("Failed to set field, too many values");
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1625
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1626 if (! TIFFSetField (tif, tag_id,
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1627 static_cast<uint16_t> (data_array.numel ()),
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1628 data_array.data ()))
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1629 error ("Failed to set field");
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1630 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1631 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1632 case TIFFTAG_XMLPACKET:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1633 case TIFFTAG_RICHTIFFIPTC:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1634 case TIFFTAG_PHOTOSHOP:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1635 case TIFFTAG_ICCPROFILE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1636 {
31186
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1637 uint8NDArray data_array = tag_ov.uint8_array_value ();
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1638 uint32_t count = data_array.numel ();
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1639 if (! TIFFSetField (tif, tag_id, count, data_array.data ()))
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1640 error ("Failed to set field");
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1641 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1642 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1643 // These tags are not mentioned in the LibTIFF documentation
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1644 // but are handled correctly by the library
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1645 case TIFFTAG_ZIPQUALITY:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1646 case TIFFTAG_SGILOGDATAFMT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1647 case TIFFTAG_GRAYRESPONSEUNIT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1648 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1649 set_scalar_field_data (tif, fip, tag_ov);
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1650 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1651 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1652 default:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1653 set_scalar_field_data (tif, fip, tag_ov);
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1654 }
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1655
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1656 }
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1657
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1658 template <typename T>
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1659 void
31133
e9925d528428 Tiff writeEncodedStrip: used octave_value functions instead of type_name
magedrifaat <magedrifaat@gmail.com>
parents: 31131
diff changeset
1660 write_strip (TIFF *tif, uint32_t strip_no, T strip_data,
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1661 tiff_image_data *image_data)
31133
e9925d528428 Tiff writeEncodedStrip: used octave_value functions instead of type_name
magedrifaat <magedrifaat@gmail.com>
parents: 31131
diff changeset
1662 {
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1663 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
1664 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
1665 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
1666
31127
0d9633ee715e Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents: 31126
diff changeset
1667 // 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
1668 // 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
1669 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
1670 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
1671
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1672 // LibTIFF uses zero-based indexing as opposed to Octave's 1-based
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1673 strip_no--;
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1674
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1675 uint32_t strip_count = TIFFNumberOfStrips (tif);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1676 rows_in_strip = get_rows_in_strip (strip_no, strip_count,
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1677 rows_in_strip, image_data);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1678
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1679 dim_vector strip_dimensions;
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1680 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1681 strip_dimensions = dim_vector (rows_in_strip, image_data->width,
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1682 image_data->samples_per_pixel);
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1683 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1684 strip_dimensions = dim_vector (rows_in_strip, image_data->width, 1);
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1685 else
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1686 error ("Planar configuration not supported");
31145
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1687
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1688 if (strip_data.dim1 () > rows_in_strip)
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1689 warning ("The strip is composed of %u rows but the input has %ld rows.",
31145
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1690 rows_in_strip,
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1691 strip_data.dim1 ());
31137
233130c0b1f6 Tiff writeEncodedStrip: changed strip dimension check behavior to mimic matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31136
diff changeset
1692
31145
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1693 if (strip_data.dim2 () > image_data->width)
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1694 warning ("The image width is %u but the input has %ld columns.",
31145
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1695 image_data->width,
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1696 strip_data.dim2 ());
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1697
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1698 if (strip_data.ndims () > 2)
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1699 {
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1700 if (image_data->planar_configuration == PLANARCONFIG_CONTIG
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1701 && strip_data.dim3 () > image_data->samples_per_pixel)
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1702 warning ("The strip is composed of %u channels but the input has %ld channels.",
31145
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1703 image_data->samples_per_pixel,
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1704 strip_data.dim3 ());
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1705 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1706 && strip_data.dim3 () > 1)
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1707 warning ("The strip is composed of %u channel but the input has %ld channels.",
31145
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1708 1, strip_data.dim3 ());
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1709 }
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1710
31137
233130c0b1f6 Tiff writeEncodedStrip: changed strip dimension check behavior to mimic matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31136
diff changeset
1711 strip_data.resize (strip_dimensions);
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1712
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1713 // 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
1714 // 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
1715 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
1716 perm(0) = 2;
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1717 perm(1) = 1;
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1718 perm(2) = 0;
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1719 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
1720
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1721 uint8_t *data_u8
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1722 = reinterpret_cast<uint8_t *> (strip_data.fortran_vec ());
31144
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1723 if (image_data->bits_per_sample == 8
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1724 || image_data->bits_per_sample == 16
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1725 || image_data->bits_per_sample == 32
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1726 || image_data->bits_per_sample == 64)
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1727 {
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1728 // Can't rely on LibTIFF's TIFFStripSize because boundary strips
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1729 // can be smaller in size
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1730 tsize_t strip_size = strip_data.numel ()
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1731 * image_data->bits_per_sample / 8;
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1732 if (TIFFWriteEncodedStrip (tif, strip_no, data_u8, strip_size) == -1)
31144
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1733 error ("Failed to write strip data to image");
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1734
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1735 }
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1736 else if (image_data->bits_per_sample == 1)
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1737 {
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1738 if (image_data->samples_per_pixel != 1)
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1739 error ("Bi-Level images must have one channel only");
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1740
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1741 // Create a buffer to hold the packed strip data
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1742 // Unique pointers are faster than vectors for constant size buffers
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1743 std::unique_ptr<uint8_t []> strip_ptr
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1744 = std::make_unique<uint8_t []> (TIFFStripSize (tif));
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1745 uint8_t *strip_buf = strip_ptr.get ();
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1746 // According to the format specification, the row should be byte
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1747 // aligned so the number of bytes is rounded up to the nearest byte
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1748 uint32_t padded_width = (image_data->width + 7) / 8;
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1749 // Packing the pixel data into bits
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1750 for (uint32_t row = 0; row < rows_in_strip; row++)
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1751 {
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1752 for (uint32_t col = 0; col < image_data->width; col++)
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1753 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1754 uint8_t shift = col % 8;
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1755 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1756 shift = 7 - shift;
31144
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1757 strip_buf[row * padded_width + col / 8] |= data_u8[col] << shift;
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1758 }
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1759 data_u8 += image_data->width;
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1760 }
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1761 tsize_t strip_size = padded_width * rows_in_strip;
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1762 if (TIFFWriteEncodedStrip (tif, strip_no, strip_buf, strip_size) == -1)
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1763 error ("Failed to write strip data to image");
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1764 }
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1765 else
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1766 {
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1767 error ("Unsupported bit depth");
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1768 }
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1769 }
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1770
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1771 template <typename T>
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1772 void
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1773 write_tile (TIFF *tif, uint32_t tile_no, T tile_data,
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1774 tiff_image_data *image_data)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1775 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1776 uint32_t tile_width, tile_height;
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1777 get_tile_dimensions_validated (tif, tile_width, tile_height);
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1778
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1779 if (tile_no < 1 || tile_no > TIFFNumberOfTiles (tif))
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1780 error ("Tile number out of bounds");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1781
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1782 if (tile_data.dim1 () > tile_height)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1783 warning ("The tile is composed of %u rows but input has %ld rows",
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1784 tile_height, tile_data.dim1 ());
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1785 if (tile_data.dim2 () > tile_width)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1786 warning ("The tile is composed of %u columns but input has %ld columns",
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1787 tile_width, tile_data.dim2 ());
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1788 if (tile_data.ndims () > 2)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1789 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1790 if (image_data->planar_configuration == PLANARCONFIG_CONTIG
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1791 && tile_data.dim3 () > image_data->samples_per_pixel)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1792 warning ("The tile is composed of %u channels but input has %ld channels",
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1793 image_data->samples_per_pixel, tile_data.dim3 ());
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1794 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1795 && tile_data.dim3 () > 1)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1796 warning ("The tile is composed of %u channels but input has %ld channels",
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1797 1, tile_data.dim3 ());
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1798 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1799
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1800 dim_vector tile_dimensions;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1801 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1802 tile_dimensions = dim_vector (tile_height, tile_width,
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1803 image_data->samples_per_pixel);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1804 else if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1805 tile_dimensions = dim_vector (tile_height, tile_width, 1);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1806 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1807 error ("Planar configuration not supported");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1808
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1809 tile_data.resize (tile_dimensions);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1810 Array<octave_idx_type> perm (dim_vector (3, 1));
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1811 perm(0) = 2;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1812 perm(1) = 1;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1813 perm(2) = 0;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1814 tile_data = tile_data.permute (perm);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1815
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1816 // Octave indexing is 1-based while LibTIFF is zero-based
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1817 tile_no--;
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1818 uint8_t *data_u8 = reinterpret_cast<uint8_t *> (tile_data.fortran_vec ());
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1819 if (image_data->bits_per_sample == 8
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1820 || image_data->bits_per_sample == 16
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1821 || image_data->bits_per_sample == 32
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1822 || image_data->bits_per_sample == 64)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1823 {
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1824 if (TIFFWriteEncodedTile (tif, tile_no, data_u8,
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1825 TIFFTileSize (tif)) == -1)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1826 error ("Failed to write tile data to image");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1827
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1828 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1829 else if (image_data->bits_per_sample == 1)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1830 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1831 if (image_data->samples_per_pixel != 1)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1832 error ("Bi-Level images must have one channel only");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1833
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1834 // Create a buffer to hold the packed tile data
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1835 // Unique pointers are faster than vectors for constant size buffers
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1836 std::unique_ptr<uint8_t []> tile_ptr
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1837 = std::make_unique<uint8_t []> (TIFFTileSize (tif));
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1838 uint8_t *tile_buf = tile_ptr.get ();
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1839 // Packing the pixel data into bits
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1840 for (uint32_t row = 0; row < tile_height; row++)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1841 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1842 for (uint32_t col = 0; col < tile_width; col++)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1843 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1844 uint8_t shift = col % 8;
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1845 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1846 shift = 7 - shift;
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1847 tile_buf[row * tile_width/8 + col/8] |= data_u8[col] << shift;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1848 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1849 data_u8 += tile_width;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1850 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1851 if (TIFFWriteEncodedTile (tif, tile_no, tile_buf,
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1852 TIFFTileSize (tif)) == -1)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1853 error ("Failed to write tile data to image");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1854 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1855 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1856 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1857 error ("Unsupported bit depth");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1858 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1859 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1860
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1861 template <typename T>
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1862 void
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1863 write_strip_or_tile (TIFF *tif, uint32_t strip_tile_no, T strip_data,
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1864 tiff_image_data *image_data)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1865 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1866 if (image_data->is_tiled)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1867 write_tile<T> (tif, strip_tile_no, strip_data, image_data);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1868 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1869 write_strip<T> (tif, strip_tile_no, strip_data, image_data);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1870 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1871
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1872 void
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1873 write_unsigned_strip_or_tile (TIFF *tif, uint32_t strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1874 octave_value data_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1875 tiff_image_data *image_data)
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1876 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1877 switch (image_data->bits_per_sample)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1878 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1879 case 1:
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1880 // We need to check for both scalar and matrix types to handle single
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1881 // element strip
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1882 if (data_ov.is_bool_scalar () || data_ov.is_bool_matrix ())
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1883 write_strip_or_tile<boolNDArray> (tif, strip_tile_no,
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1884 data_ov.bool_array_value (),
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1885 image_data);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1886 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1887 error ("Expected logical matrix for BiLevel image");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1888 break;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1889 case 8:
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1890 if (data_ov.is_uint8_type ())
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1891 write_strip_or_tile<uint8NDArray> (tif, strip_tile_no,
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1892 data_ov.uint8_array_value (),
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1893 image_data);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1894 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1895 error ("Only uint8 data is allowed for uint images with bit depth of 8");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1896 break;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1897 case 16:
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1898 if (data_ov.is_uint16_type ())
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1899 write_strip_or_tile<uint16NDArray> (tif, strip_tile_no,
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1900 data_ov.uint16_array_value (),
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1901 image_data);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1902 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1903 error ("Only uint16 data is allowed for uint images with bit depth of 16");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1904 break;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1905 case 32:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1906 if (data_ov.is_uint32_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1907 write_strip_or_tile<uint32NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1908 data_ov.uint32_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1909 image_data);
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1910 else
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1911 error ("Only uint32 data is allowed for uint images with bit depth of 32");
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1912 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1913 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1914 if (data_ov.is_uint64_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1915 write_strip_or_tile<uint64NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1916 data_ov.uint64_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1917 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1918 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1919 error ("Only uint64 data is allowed for uint images with bit depth of 64");
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1920 break;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1921 default:
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1922 error ("Unsupported bit depth");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1923 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1924 }
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1925
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1926 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1927 write_signed_strip_or_tile (TIFF *tif, uint32_t strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1928 octave_value data_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1929 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1930 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1931 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1932 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1933 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1934 if (data_ov.is_int8_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1935 write_strip_or_tile<int8NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1936 data_ov.int8_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1937 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1938 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1939 error ("Only int8 data is allowed for int images with bit depth of 8");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1940 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1941 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1942 if (data_ov.is_int16_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1943 write_strip_or_tile<int16NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1944 data_ov.int16_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1945 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1946 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1947 error ("Only int16 data is allowed for int images with bit depth of 16");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1948 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1949 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1950 if (data_ov.is_int32_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1951 write_strip_or_tile<int32NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1952 data_ov.int32_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1953 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1954 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1955 error ("Only int32 data is allowed for int images with bit depth of 32");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1956 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1957 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1958 if (data_ov.is_int64_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1959 write_strip_or_tile<int64NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1960 data_ov.int64_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1961 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1962 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1963 error ("Only int64 data is allowed for int images with bit depth of 64");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1964 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1965 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1966 error ("Unsupported bit depth for signed images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1967 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1968 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1969
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1970 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1971 write_float_strip_or_tile (TIFF *tif, uint32_t strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1972 octave_value data_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1973 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1974 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1975 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1976 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1977 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1978 if (data_ov.is_single_type () || data_ov.is_double_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1979 write_strip_or_tile<FloatNDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1980 data_ov.float_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1981 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1982 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1983 error ("Only single and double data are allowed for floating-point images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1984 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1985 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1986 if (data_ov.is_single_type () || data_ov.is_double_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1987 write_strip_or_tile<NDArray> (tif, strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1988 data_ov.array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1989 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1990 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1991 error ("Only single and double data are allowed for floating-point images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1992 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1993 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1994 error ("Unsupported bit depth for floating-point images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1995 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1996 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1997
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1998 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1999 handle_write_strip_or_tile (TIFF *tif, uint32_t strip_tile_no,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2000 octave_value data_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2001 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2002 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2003
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2004 // SampleFormat tag is not a required field and has a default value of 1
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2005 // So we need to use TIFFGetFieldDefaulted in case it is not present in
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2006 // the file
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2007 uint16_t sample_format;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2008 if (! TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_format))
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2009 error ("Failed to obtain a value for sample format");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2010
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2011 switch (sample_format)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2012 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2013 case 1:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2014 case 4:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2015 write_unsigned_strip_or_tile (tif, strip_tile_no, data_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2016 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2017 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2018 case 2:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2019 write_signed_strip_or_tile (tif, strip_tile_no, data_ov, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2020 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2021 case 3:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2022 write_float_strip_or_tile (tif, strip_tile_no, data_ov, image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2023 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2024 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2025 error ("Unsupported sample format");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2026 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2027 }
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
2028
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2029 template <typename T>
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2030 void
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2031 write_stripped_image (TIFF *tif, T pixel_data, tiff_image_data *image_data)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2032 {
31164
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2033 // ASSUMES pixel data dimensions are already validated
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2034
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2035 typedef typename T::element_type P;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2036
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2037 // Permute pixel data to be aligned in memory to the way LibTIFF
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2038 // expects the data to be (i.e. channel x width x height for chunky
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2039 // and width x height x channel for separate planes)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2040 Array<octave_idx_type> perm (dim_vector (3, 1));
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2041 if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2042 {
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2043 perm(0) = 1;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2044 perm(1) = 0;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2045 perm(2) = 2;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2046 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2047 else
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2048 {
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2049 perm(0) = 2;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2050 perm(1) = 1;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2051 perm(2) = 0;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2052 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2053 pixel_data = pixel_data.permute (perm);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2054
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2055 uint32_t row_per_strip;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2056 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &row_per_strip))
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2057 error ("Failed to obtain the RowPerStrip tag");
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2058
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2059 // The default value is INT_MAX so we need to cap it to the image height
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2060 if (row_per_strip > image_data->height)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2061 row_per_strip = image_data->height;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2062
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2063 uint8_t *pixel_fvec
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2064 = reinterpret_cast<uint8_t *> (pixel_data.fortran_vec ());
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2065 uint32_t strip_count = TIFFNumberOfStrips (tif);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2066 tsize_t strip_size;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2067 uint32_t rows_in_strip;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2068 for (uint32_t strip = 0; strip < strip_count; strip++)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2069 {
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2070 rows_in_strip = get_rows_in_strip (strip, strip_count,
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2071 row_per_strip, image_data);
31154
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2072 if (image_data->bits_per_sample == 8
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2073 || image_data->bits_per_sample == 16
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2074 || image_data->bits_per_sample == 32
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2075 || image_data->bits_per_sample == 64)
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2076 {
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2077 strip_size = rows_in_strip * image_data->width * sizeof (P);
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2078 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2079 strip_size *= image_data->samples_per_pixel;
31186
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
2080 if (TIFFWriteEncodedStrip (tif, strip, pixel_fvec, strip_size) == -1)
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
2081 error ("Failed to write strip data");
31154
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2082 pixel_fvec += strip_size;
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2083 }
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2084 else if (image_data->bits_per_sample == 1)
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2085 {
31156
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2086 if (image_data->samples_per_pixel != 1)
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2087 error ("Bi-Level images must have one channel only");
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2088
31154
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2089 // Create a buffer to hold the packed strip data
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2090 // Unique pointers are faster than vectors for constant size buffers
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2091 std::unique_ptr<uint8_t []> strip_ptr
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2092 = std::make_unique<uint8_t []> (TIFFStripSize (tif));
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2093 uint8_t *strip_buf = strip_ptr.get ();
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2094 // According to the format specification, the row should be byte
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2095 // aligned so the number of bytes is rounded up to the nearest byte
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2096 uint32_t padded_width = (image_data->width + 7) / 8;
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2097 // Packing the pixel data into bits
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2098 for (uint32_t row = 0; row < rows_in_strip; row++)
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2099 {
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2100 for (uint32_t col = 0; col < image_data->width; col++)
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2101 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2102 uint8_t shift = col % 8;
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2103 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2104 shift = 7 - shift;
31154
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2105 strip_buf[row * padded_width + col / 8]
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2106 |= pixel_fvec[col] << shift;
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2107 }
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2108 pixel_fvec += image_data->width;
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2109 }
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2110 strip_size = padded_width * rows_in_strip;
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2111 if (TIFFWriteEncodedStrip (tif, strip, strip_buf, strip_size) == -1)
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2112 error ("Failed to write strip data to image");
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2113 }
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2114 else
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2115 error ("Unsupported bit depth");
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2116 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2117 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2118
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2119 template <typename T>
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2120 void
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2121 write_tiled_image (TIFF *tif, T pixel_data, tiff_image_data *image_data)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2122 {
31164
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2123 // ASSUMES pixel data dimensions are already validated
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2124
31155
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2125 uint32_t tile_width, tile_height;
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2126 get_tile_dimensions_validated (tif, tile_width, tile_height);
31155
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2127
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2128 uint32_t tiles_across = (image_data->width + tile_width - 1)
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2129 / tile_width;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2130 uint32_t tiles_down = (image_data->height + tile_height - 1)
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2131 / tile_height;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2132
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2133 // Resize the image data to add tile padding
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2134 dim_vector padded_dims (tiles_down * tile_height,
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2135 tiles_across * tile_width,
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2136 image_data->samples_per_pixel);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2137 pixel_data.resize (padded_dims);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2138
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2139 // Reshape the image to separate tiles into their own dimension
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2140 // so we can permute them to the right order
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2141 dim_vector tiled_dims (tile_height, tiles_down, tile_width, tiles_across,
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2142 image_data->samples_per_pixel);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2143 pixel_data = pixel_data.reshape (tiled_dims);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2144
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2145 // Permute the dimesnions to get the memory alignment to match LibTIFF
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2146 Array<octave_idx_type> perm (dim_vector (5, 1));
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2147 if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2148 {
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2149 // For separate planes, the data coming from libtiff will have all
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2150 // tiles of the first sample then all tiles of the second sample
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2151 // and so on. Tiles of each sample will be ordered from left to right
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2152 // and from top to bottom. And data inside each tile is organised as
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2153 // rows and each row contains columns.
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2154 // So the order for LibTIFF is:
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2155 // samples x tiles_down x tiles_across x tile_height x tile_width
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2156 // But memory orientation of Octave arrays is reversed so we set it to
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2157 // tile_width x tile_height x tiles_across x tiles_down x samples
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2158 perm(0) = 2;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2159 perm(1) = 0;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2160 perm(2) = 3;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2161 perm(3) = 1;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2162 perm(4) = 4;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2163 }
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2164 else
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2165 {
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2166 // For chunky planes, the data coming from libtiff will be ordered
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2167 // from left to right and from top to bottom. And data inside each
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2168 // tile is organised as rows and each row contains columns and each
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2169 // column contains samples.
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2170 // So the order for LibTIFF is:
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2171 // tiles_down x tiles_across x tile_height x tile_width x samples
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2172 // But memory orientation of Octave arrays is reversed so we set it to
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2173 // samples x tile_width x tile_height x tiles_across x tiles_down
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2174 perm(0) = 4;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2175 perm(1) = 2;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2176 perm(2) = 0;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2177 perm(3) = 3;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2178 perm(4) = 1;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2179 }
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2180 pixel_data = pixel_data.permute (perm);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2181
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2182 uint8_t *pixel_fvec
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2183 = reinterpret_cast<uint8_t *> (pixel_data.fortran_vec ());
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2184 uint32_t tile_count = TIFFNumberOfTiles (tif);
31156
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2185 tsize_t tile_size = TIFFTileSize (tif);
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2186
31155
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2187 for (uint32_t tile = 0; tile <tile_count; tile++)
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2188 {
31156
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2189 if (image_data->bits_per_sample == 8
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2190 || image_data->bits_per_sample == 16
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2191 || image_data->bits_per_sample == 32
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2192 || image_data->bits_per_sample == 64)
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2193 {
31186
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
2194 if (TIFFWriteEncodedTile (tif, tile, pixel_fvec, tile_size) == -1)
31156
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2195 error ("Failed to write tile data");
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2196 pixel_fvec += tile_size;
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2197 }
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2198 else if (image_data->bits_per_sample == 1)
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2199 {
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2200 if (image_data->samples_per_pixel != 1)
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2201 error ("Bi-Level images must have one channel only");
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2202
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2203 // Create a buffer to hold the packed tile data
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2204 // Unique pointers are faster than vectors for
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2205 // constant size buffers
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2206 std::unique_ptr<uint8_t []> tile_ptr
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2207 = std::make_unique<uint8_t []> (tile_size);
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2208 uint8_t *tile_buf = tile_ptr.get ();
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2209 // Packing the pixel data into bits
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2210 for (uint32_t row = 0; row < tile_height; row++)
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2211 {
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2212 for (uint32_t col = 0; col < tile_width; col++)
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2213 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2214 uint8_t shift = col % 8;
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2215 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2216 shift = 7 - shift;
31156
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2217 tile_buf[row * tile_width / 8 + col / 8]
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2218 |= pixel_fvec[col] << shift;
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2219 }
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2220 pixel_fvec += tile_width;
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2221 }
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2222 if (TIFFWriteEncodedTile (tif, tile, tile_buf,
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2223 TIFFTileSize (tif)) == -1)
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2224 error ("Failed to write tile data to image");
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2225 }
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2226 else
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2227 error ("Unsupported bit depth");
31155
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2228 }
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2229
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2230 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2231
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2232 template <typename T>
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2233 void
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2234 write_image (TIFF *tif, T pixel_data, tiff_image_data *image_data)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2235 {
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2236 // This dimensions checking is intentially done in this non-homogeneous
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2237 // way for matlab compatibility.
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2238 // In Matlab R2022a, If the width or height of the input matrix is less
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2239 // than needed, the data is silently padded with zeroes to fit.
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2240 // If the width is larger than needed, a warning is issued and the excess
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2241 // data is truncated. If the height is larger than needed, no warning is
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2242 // issued and the image data is wrong. If the number of channels is less
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2243 // or more than needed an error is produced.
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2244 // We chose to deviate from matlab in the larger height case to avoid
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2245 // errors resulting from silently corrupting image data, a warning is
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2246 // produced instead.
31164
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2247 if ((image_data->samples_per_pixel > 1 && pixel_data.ndims () < 3)
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2248 || (pixel_data.ndims () > 2
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2249 && image_data->samples_per_pixel != pixel_data.dim3 ()))
31164
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2250 error ("Incorrect number of channels, expected %u",
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2251 image_data->samples_per_pixel);
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2252
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2253 if (pixel_data.dim1 () > image_data->height)
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2254 warning ("Input has more rows than the image length, data will be truncated");
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2255 if (pixel_data.dim2 () > image_data->width)
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2256 warning ("Input has more columns than the image width, data will be truncated");
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2257
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2258 pixel_data.resize (dim_vector (image_data->height, image_data->width,
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2259 image_data->samples_per_pixel));
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2260
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2261 if (image_data->is_tiled)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2262 write_tiled_image<T> (tif, pixel_data, image_data);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2263 else
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2264 write_stripped_image<T> (tif, pixel_data, image_data);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2265
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2266 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2267
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2268 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2269 write_unsigned_image (TIFF *tif, octave_value image_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2270 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2271 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2272 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2273 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2274 case 1:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2275 // We need to check for both scalar and matrix types to handle single
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2276 // pixel image
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2277 if (image_ov.is_bool_scalar () || image_ov.is_bool_matrix ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2278 write_image<boolNDArray> (tif, image_ov.bool_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2279 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2280 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2281 error ("Expected logical matrix for BiLevel image");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2282 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2283 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2284 if (image_ov.is_uint8_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2285 write_image<uint8NDArray> (tif, image_ov.uint8_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2286 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2287 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2288 error ("Only uint8 data is allowed for uint images with bit depth of 8");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2289 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2290 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2291 if (image_ov.is_uint16_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2292 write_image<uint16NDArray> (tif, image_ov.uint16_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2293 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2294 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2295 error ("Only uint16 data is allowed for uint images with bit depth of 16");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2296 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2297 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2298 if (image_ov.is_uint32_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2299 write_image<uint32NDArray> (tif, image_ov.uint32_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2300 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2301 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2302 error ("Only uint32 data is allowed for uint images with bit depth of 32");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2303 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2304 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2305 if (image_ov.is_uint64_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2306 write_image<uint64NDArray> (tif, image_ov.uint64_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2307 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2308 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2309 error ("Only uint64 data is allowed for uint images with bit depth of 64");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2310 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2311 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2312 error ("Unsupported bit depth");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2313 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2314 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2315
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2316 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2317 write_signed_image (TIFF *tif, octave_value image_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2318 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2319 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2320 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2321 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2322 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2323 if (image_ov.is_int8_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2324 write_image<int8NDArray> (tif, image_ov.int8_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2325 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2326 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2327 error ("Only int8 data is allowed for int images with bit depth of 8");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2328 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2329 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2330 if (image_ov.is_int16_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2331 write_image<int16NDArray> (tif, image_ov.int16_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2332 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2333 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2334 error ("Only int16 data is allowed for int images with bit depth of 16");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2335 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2336 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2337 if (image_ov.is_int32_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2338 write_image<int32NDArray> (tif, image_ov.int32_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2339 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2340 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2341 error ("Only int32 data is allowed for int images with bit depth of 32");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2342 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2343 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2344 if (image_ov.is_int64_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2345 write_image<int64NDArray> (tif, image_ov.int64_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2346 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2347 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2348 error ("Only int64 data is allowed for int images with bit depth of 64");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2349 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2350 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2351 error ("Unsupported bit depth for signed images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2352 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2353 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2354
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2355 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2356 write_float_image (TIFF *tif, octave_value image_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2357 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2358 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2359 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2360 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2361 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2362 if (image_ov.is_single_type () || image_ov.is_double_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2363 write_image<FloatNDArray> (tif, image_ov.float_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2364 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2365 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2366 error ("Only single or double data are allowed for float images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2367 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2368 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2369 if (image_ov.is_single_type () || image_ov.is_double_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2370 write_image<NDArray> (tif, image_ov.array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2371 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2372 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2373 error ("Only single or double data are allowed for float images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2374 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2375 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2376 error ("Unsupported bit depth for floating-point images");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2377 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2378 }
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2379
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2380 octave_value_list
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2381 slice_rgba (uint8NDArray rgba_data)
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2382 {
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2383 Array<idx_vector> idx (dim_vector (3, 1));
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2384 idx(0) = idx_vector (':');
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2385 idx(1) = idx_vector (':');
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2386 idx(2) = idx_vector (0, 3);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2387 uint8NDArray rgb = uint8NDArray (rgba_data.index (idx));
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2388 idx(2) = idx_vector (3);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2389 uint8NDArray alpha = uint8NDArray (rgba_data.index (idx));
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2390
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2391 octave_value_list retval (2);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2392 retval(0) = octave_value (rgb);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2393 retval(1) = octave_value (alpha);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2394 return retval;
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2395 }
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2396 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2397
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2398 DEFUN (__open_tiff__, args, ,
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2399 "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
2400 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2401 #if defined (HAVE_TIFF)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2402 int nargin = args.length ();
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2403
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2404 if (nargin == 0 || nargin > 2)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
2405 {
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2406 error ("No filename supplied\n");
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
2407 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2408
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2409 std::string filename = args(0).string_value ();
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2410 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
2411
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2412 if (nargin == 2)
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2413 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
2414
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2415 const std::vector<std::string> supported_modes {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2416 "r", "w", "w8", "a", "r+"
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2417 };
31123
0bcb35909ef4 Tiff open: removed support for rh mode and marked r+ as not yet supported
magedrifaat <magedrifaat@gmail.com>
parents: 31122
diff changeset
2418
31142
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2419 if (std::find (supported_modes.cbegin (), supported_modes.cend (), mode)
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2420 == supported_modes.cend ())
31176
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2421 error ("Invalid mode for openning Tiff file: %s", mode.c_str ());
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2422
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
2423 // LibTIFF doesn't support r+ mode but it appears that the difference
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
2424 // between "a" and "r+" in the context of LibTIFF is that in "a" mode
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
2425 // the directory is not set while in r+ the directory is set to the
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
2426 // first directory in the file
31176
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2427 bool is_rplus = false;
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2428 if (mode == "r+")
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
2429 {
31176
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2430 is_rplus = true;
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2431 mode = "a";
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
2432 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2433
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2434 // LibTIFF does Strip chopping by default, which makes the organization of
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2435 // data exposed to the user different from the actual file, so we need to
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2436 // force disable this behavior by adding 'c' flag to the mode
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2437 mode = mode + 'c';
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2438
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2439 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2440
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2441 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
2442
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2443 if (! tif)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2444 error ("Failed to open Tiff file\n");
31176
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2445
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2446 if (is_rplus && ! TIFFSetDirectory (tif, 0))
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2447 error ("Failed to open Tiff file\n");
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2448
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2449 octave_value tiff_ov = octave_value (new octave_tiff_handle (tif));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2450 return octave_value_list (tiff_ov);
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2451 #else
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
2452 octave_unused_parameter (args);
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2453 err_disabled_feature ("Tiff", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2454 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2455 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2456
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2457
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2458 DEFUN (__close_tiff__, args, ,
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2459 "Close a tiff file")
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2460 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2461 #if defined (HAVE_TIFF)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
2462 int nargin = args.length ();
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2463
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2464 if (nargin == 0)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
2465 error ("No handle provided\n");
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2466
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2467 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2468 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2469
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2470 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2471
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2472 tiff_handle->close ();
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2473
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2474 return octave_value_list ();
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2475 #else
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2476 err_disabled_feature ("close", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2477 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2478 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2479
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2480
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2481 DEFUN (__tiff_get_tag__, args, ,
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2482 "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
2483 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2484 #if defined (HAVE_TIFF)
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2485 int nargin = args.length ();
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2486
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2487 if (nargin == 0)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2488 error ("No handle provided\n");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2489
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2490 if (nargin < 2)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2491 error ("No tag name provided\n");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2492
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2493 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2494 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2495
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2496 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2497
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2498 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2499
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2500 TIFF *tif = tiff_handle->get_file ();
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
2501
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2502 const TIFFField *fip;
31129
dfab9c6982bf Tiff getTag: added support for single quotes string fo the tag name
magedrifaat <magedrifaat@gmail.com>
parents: 31128
diff changeset
2503
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2504 if (args(1).is_string ())
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2505 {
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
2506 std::string tag_name = args(1).string_value ();
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
2507 fip = get_fip_with_name (tif, tag_name);
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2508 if (! fip)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2509 error ("Tiff tag not found");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2510 }
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2511 else
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2512 {
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
2513 ttag_t tag_id = args(1).int_value ();
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2514 fip = TIFFFieldWithTag (tif, tag_id);
31129
dfab9c6982bf Tiff getTag: added support for single quotes string fo the tag name
magedrifaat <magedrifaat@gmail.com>
parents: 31128
diff changeset
2515
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2516 if (! fip)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2517 error ("Tiff tag not found");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2518 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2519
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
2520 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
2521 #else
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2522 err_disabled_feature ("getTag", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2523 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2524 }
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2525
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2526
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2527 DEFUN (__tiff_set_tag__, args, ,
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2528 "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
2529 {
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2530 #if defined (HAVE_TIFF)
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2531 int nargin = args.length ();
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2532
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2533 if (nargin < 2)
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2534 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
2535
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2536 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2537 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2538 check_closed (tiff_handle);
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
2539
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2540 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2541
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2542 TIFF *tif = tiff_handle->get_file ();
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
2543 check_readonly (tif);
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2544
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2545 if (args(1).isstruct ())
31140
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2546 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
2547 octave_scalar_map tags = args(1).xscalar_map_value ("__tiff_set_tag__: struct argument must be a scalar structure");
31142
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2548 string_vector keys = tags.fieldnames ();
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2549 // Using iterators instead of this loop method seems to process
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2550 // the elements of the struct in a different order than they were
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2551 // assigned which makes the behavior here incompatible with matlab
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2552 // in case of errors.
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2553 for (octave_idx_type i = 0; i < keys.numel (); i++)
31140
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2554 {
31142
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2555 std::string key = keys[i];
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
2556 const TIFFField *fip = get_fip_with_name (tif, key);
31142
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2557 if (! fip)
31140
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2558 error ("Tag %s not found", key.c_str ());
31142
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2559 set_field_data (tif, fip, tags.contents (key));
31140
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2560 }
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2561 }
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2562 else
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2563 {
31140
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2564 if (nargin < 3)
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2565 error ("Too few arguments provided");
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2566
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2567 const TIFFField *fip;
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2568 if (args(1).is_string ())
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2569 {
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
2570 std::string tag_name = args(1).string_value ();
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
2571 fip = get_fip_with_name (tif, tag_name);
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2572 if (! fip)
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2573 error ("Tiff tag not found");
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2574 }
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2575 else
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2576 {
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2577 uint32_t tag_id = args(1).int_value ();
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2578 fip = TIFFFieldWithTag (tif, tag_id);
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2579 if (! fip)
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2580 error ("Tiff tag not found");
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2581 }
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2582
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2583 set_field_data (tif, fip, args(2));
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2584 }
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2585
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2586 return octave_value_list ();
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2587 #else
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2588 err_disabled_feature ("setTag", "Tiff");
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2589 #endif
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2590 }
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2591
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2592 DEFUN (__tiff_read__, args, nargout,
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2593 "Read the image in the current IFD")
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2594 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2595 #if defined (HAVE_TIFF)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2596 int nargin = args.length ();
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2597
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2598 if (nargin == 0)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2599 error ("No handle provided\n");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2600
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2601 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2602 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2603 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2604
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2605 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2606
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2607 TIFF *tif = tiff_handle->get_file ();
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2608
31187
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
2609 // FIXME: add support for reading in YCbCr mode
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
2610 octave_unused_parameter (nargout);
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2611
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2612 // Obtain all necessary tags
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
2613 // 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
2614 // 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
2615 // 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
2616 // 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
2617 tiff_image_data image_data (tif);
31125
3b775b939de4 Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents: 31124
diff changeset
2618
3b775b939de4 Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents: 31124
diff changeset
2619 uint16_t sample_format;
3b775b939de4 Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents: 31124
diff changeset
2620 if (! TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_format))
3b775b939de4 Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents: 31124
diff changeset
2621 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
2622
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2623 octave_value_list retval;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2624 switch (sample_format)
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2625 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2626 case 1:
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2627 case 4:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2628 retval (0) = read_unsigned_image (tif, &image_data);
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
2629 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2630 case 2:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2631 retval (0) = read_signed_image (tif, &image_data);
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
2632 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2633 case 3:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2634 retval (0) = read_float_image (tif, &image_data);
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
2635 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2636 default:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2637 error ("Unsupported sample format");
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2638 }
31110
2daeeff33980 Tiff read fixed segfault bug for compressed images
magedrifaat <magedrifaat@gmail.com>
parents: 31109
diff changeset
2639
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2640 return retval;
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2641 #else
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2642 err_disabled_feature ("read", "Tiff");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2643 #endif
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2644 }
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
2645
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2646 DEFUN (__tiff_read_encoded_strip__, args, nargout,
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2647 "Read a strip from the image in the current IFD")
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2648 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2649 #if defined (HAVE_TIFF)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2650 int nargin = args.length ();
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2651
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2652 if (nargin != 2)
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2653 error ("Wrong number of arguments");
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2654
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2655 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2656 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2657 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2658
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2659 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2660
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2661 TIFF *tif = tiff_handle->get_file ();
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2662
31187
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
2663 // FIXME: add support for reading in YCbCr mode
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2664 octave_unused_parameter (nargout);
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2665
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2666 if (TIFFIsTiled (tif))
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2667 error ("The image is tiled not stripped");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2668
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2669 uint32_t strip_no;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2670 if (args(1).is_scalar_type ())
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2671 strip_no = args(1).uint32_scalar_value ();
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2672 else
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2673 error ("Expected scalar for strip number");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2674
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2675 if (strip_no < 1 || strip_no > TIFFNumberOfStrips (tif))
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2676 error ("Strip number out of bounds");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2677
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2678 // Convert from Octave's 1-based indexing to zero-based indexing
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2679 strip_no--;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2680
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2681 return octave_value_list (handle_read_strip_or_tile (tif, strip_no));
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2682 #else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2683 err_disabled_feature ("readEncodedStrip", "Tiff");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2684 #endif
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2685 }
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2686
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2687 DEFUN (__tiff_read_encoded_tile__, args, nargout,
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2688 "Read a tile from the image in the current IFD")
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2689 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2690 #if defined (HAVE_TIFF)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2691 int nargin = args.length ();
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2692
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2693 if (nargin != 2)
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2694 error ("Wrong number of arguments");
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2695
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2696 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2697 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2698 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2699
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2700 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2701
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2702 TIFF *tif = tiff_handle->get_file ();
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2703
31187
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
2704 // FIXME: add support for reading in YCbCr mode
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2705 octave_unused_parameter (nargout);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2706
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2707 if (! TIFFIsTiled (tif))
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2708 error ("The image is stripped not tiled");
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2709
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2710 uint32_t tile_no;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2711 if (args(1).is_scalar_type ())
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2712 tile_no = args(1).uint32_scalar_value ();
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2713 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2714 error ("Expected scalar for tile number");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2715
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2716 if (tile_no < 1 || tile_no > TIFFNumberOfTiles (tif))
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2717 error ("Tile number out of bounds");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2718
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2719 // Convert from Octave's 1-based indexing to zero-based indexing
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2720 tile_no--;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2721
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2722 return octave_value_list (handle_read_strip_or_tile (tif, tile_no));
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2723 #else
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2724 err_disabled_feature ("readEncodedTile", "Tiff");
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2725 #endif
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2726 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2727
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2728 DEFUN (__tiff_read_rgba_image__, args, ,
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2729 "Read the image data in rgba mode")
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2730 {
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2731 #if defined (HAVE_TIFF)
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2732 int nargin = args.length ();
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2733
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2734 if (nargin != 1)
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2735 error ("Wrong number of arguments");
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2736
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2737 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2738 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2739 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2740
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2741 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2742
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2743 TIFF *tif = tiff_handle->get_file ();
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2744
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2745 tiff_image_data image_data (tif);
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2746
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2747 uint16_t orientation;
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2748 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ORIENTATION, &orientation))
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2749 orientation = ORIENTATION_LEFTTOP;
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2750
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2751 // Start with reversed dimensions to be aligned with LibTIFF and
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2752 // permute to the correct order later
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2753 dim_vector img_dims (4, image_data.width, image_data.height);
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2754 uint8NDArray img (img_dims);
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2755 uint32_t *img_ptr = reinterpret_cast <uint32_t *> (img.fortran_vec ());
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2756
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
2757 // The TIFFRGBAImageGet interface is used instead of TIFFReadRGBAImage
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
2758 // to have control on the requested orientation of the image
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
2759 // Matlab R2022a handles the orientation for each individual strip
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
2760 // or tile on its own, this results in a distorted image which is
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
2761 // not useful, and is probably a bug. So this deviated from matlab
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
2762 // by applying the orientation to the entire image to produce more
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
2763 // useful results.
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2764 TIFFRGBAImage img_config;
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2765 char emsg[1024];
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2766 if (! TIFFRGBAImageOK (tif, emsg)
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2767 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg))
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2768 error ("Failed to read image");
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2769
31196
1da6d747bf78 __tiff_imread__: converted to private octave function
magedrifaat <magedrifaat@gmail.com>
parents: 31195
diff changeset
2770 // FIXME: rotated orientation don't work correctly (e.g. LeftTop)
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2771 img_config.orientation = ORIENTATION_TOPLEFT;
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2772 img_config.req_orientation = orientation;
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2773
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2774 bool success = TIFFRGBAImageGet (&img_config, img_ptr, img_config.width,
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2775 img_config.height);
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2776
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2777 TIFFRGBAImageEnd (&img_config);
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2778 if (!success)
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2779 error ("Failed to read image");
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2780
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2781 // Permute to the correct Octave dimension order
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2782 Array<octave_idx_type> perm (dim_vector (3, 1));
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2783 perm(0) = 2;
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2784 perm(1) = 1;
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2785 perm(2) = 0;
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2786 img = img.permute (perm);
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2787
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2788 // Slice the data into RGB and alpha
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2789 return slice_rgba (img);
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2790 #else
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2791 err_disabled_feature ("readRGBAImage", "Tiff");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2792 #endif
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2793 }
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2794
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2795 DEFUN (__tiff_read_rgba_strip__, args, ,
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2796 "Read the strip data containing the given row in rgba mode")
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2797 {
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2798 #if defined (HAVE_TIFF)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2799 int nargin = args.length ();
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2800
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2801 if (nargin != 2)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2802 error ("Wrong number of arguments");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2803
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2804 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2805 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2806 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2807
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2808 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2809
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2810 TIFF *tif = tiff_handle->get_file ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2811
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2812 // Matlab (R2022a) requires row to be double
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2813 if (! args(1).is_double_type ())
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2814 error ("row should be of type double");
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2815
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2816 uint32_t row = args(1).uint32_scalar_value ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2817
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2818 tiff_image_data image_data (tif);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2819 if (image_data.is_tiled)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2820 error ("The image is tiled not stripped");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2821
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2822 if (row < 1 || row > image_data.height)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2823 error ("Row out of bounds of the image");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2824
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2825 // Convert from 1-based indexing to zero-based
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2826 row--;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2827
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2828 uint32_t rows_in_strip;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2829 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &rows_in_strip))
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2830 error ("Failed to obtain a value for RowsPerStrip");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2831
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2832 if (rows_in_strip > image_data.height)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2833 rows_in_strip = image_data.height;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2834
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2835 // LibTIFF requires the row to be the first row in the strip
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2836 // so this removes any offset to reach the first row
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2837 row -= row % rows_in_strip;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2838
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2839 // The exact number of rows in the strip is needed for boundary strips
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2840 uint32_t strip_no = TIFFComputeStrip (tif, row, 0);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2841 rows_in_strip = get_rows_in_strip (strip_no, TIFFNumberOfStrips (tif),
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2842 rows_in_strip, &image_data);
31174
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2843
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2844 uint16_t orientation;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2845 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ORIENTATION, &orientation))
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2846 orientation = ORIENTATION_LEFTTOP;
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2847
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2848 // Start with reversed dimensions to be aligned with LibTIFF and
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2849 // permute to the correct order later
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2850 dim_vector strip_dims (4, image_data.width, rows_in_strip);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2851 uint8NDArray strip_data (strip_dims);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2852 uint32_t *strip_ptr
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2853 = reinterpret_cast <uint32_t *> (strip_data.fortran_vec ());
31174
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2854
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2855 TIFFRGBAImage img_config;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2856 char emsg[1024];
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2857 if (! TIFFRGBAImageOK (tif, emsg)
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2858 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg))
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2859 error ("Failed to read strip");
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2860
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2861 img_config.orientation = ORIENTATION_TOPLEFT;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2862 img_config.req_orientation = orientation;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2863 img_config.row_offset = row;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2864 img_config.col_offset = 0;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2865
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2866 bool success = TIFFRGBAImageGet (&img_config, strip_ptr, img_config.width,
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2867 rows_in_strip);
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2868
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2869 TIFFRGBAImageEnd (&img_config);
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2870 if (!success)
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2871 error ("Failed to read strip");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2872
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2873 // Permute to the correct order of dimensions for Octave
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2874 Array<octave_idx_type> perm (dim_vector (3, 1));
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2875 perm(0) = 2;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2876 perm(1) = 1;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2877 perm(2) = 0;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2878 strip_data = strip_data.permute (perm);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2879
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2880 // Slice the data into RGB and alpha
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2881 return slice_rgba (strip_data);
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2882 #else
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2883 err_disabled_feature ("readRGBAStrip", "Tiff");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2884 #endif
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2885 }
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2886
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2887 DEFUN (__tiff_read_rgba_tile__, args, ,
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2888 "Read the stile data containing the given row and column in rgba mode")
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2889 {
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2890 #if defined (HAVE_TIFF)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2891 int nargin = args.length ();
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2892
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2893 if (nargin != 3)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2894 error ("Wrong number of arguments");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2895
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2896 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2897 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2898 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2899
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2900 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2901
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2902 TIFF *tif = tiff_handle->get_file ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2903
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2904 if (! args(1).is_double_type ())
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2905 error ("row should be of type double");
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2906 if (! args(2).is_double_type ())
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2907 error ("col should be of type double");
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2908
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2909 uint32_t row = args(1).uint32_scalar_value ();
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2910 uint32_t col = args(2).uint32_scalar_value ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2911
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2912 tiff_image_data image_data (tif);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2913 if (! image_data.is_tiled)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2914 error ("The image is stripped not tiled");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2915
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2916 if (row < 1 || row > image_data.height)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2917 error ("Row out of bounds of the image");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2918 if (col < 1 || col > image_data.width)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2919 error ("Column out of bounds of the image");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2920
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2921 // Convert from 1-based indexing to zero-based
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2922 row--;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2923 col--;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2924
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2925 uint32_t tile_width, tile_height;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2926 if (! TIFFGetField (tif, TIFFTAG_TILELENGTH, &tile_height))
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2927 error ("Failed to obtain a value for TileLength");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2928 if (! TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width))
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2929 error ("Failed to obtain a value for TileWidth");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2930
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2931 // LibTIFF requires the row and columns to be the top-left corner of the
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2932 // tile, so this removes any offset to reach the top-left row and column
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2933 // of the tile
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2934 row -= row % tile_height;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2935 col -= col % tile_width;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2936
31174
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2937 uint16_t orientation;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2938 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ORIENTATION, &orientation))
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2939 orientation = ORIENTATION_LEFTTOP;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2940
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2941 // Calculate the correct dimensions for boundary tiles
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2942 uint32_t corrected_height = tile_height;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2943 uint32_t corrected_width = tile_width;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2944 if (row + tile_height > image_data.height)
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2945 corrected_height = image_data.height - row;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2946 if (col + tile_width > image_data.width)
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2947 corrected_width = image_data.width - col;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2948
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2949 // Start with reversed dimensions to be aligned with LibTIFF and
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2950 // permute to the correct order later
31174
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2951 dim_vector tile_dims (4, corrected_width, corrected_height);
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2952 uint8NDArray tile_data (tile_dims);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2953 uint32_t *tile_ptr
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2954 = reinterpret_cast <uint32_t *> (tile_data.fortran_vec ());
31174
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2955
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2956 TIFFRGBAImage img_config;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2957 char emsg[1024];
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2958 if (! TIFFRGBAImageOK (tif, emsg)
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2959 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg))
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2960 error ("Failed to read tile");
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2961
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2962 img_config.orientation = ORIENTATION_TOPLEFT;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2963 img_config.req_orientation = orientation;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2964 img_config.row_offset = row;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2965 img_config.col_offset = col;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2966
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2967 bool success = TIFFRGBAImageGet (&img_config, tile_ptr, corrected_width,
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2968 corrected_height);
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2969
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2970 TIFFRGBAImageEnd (&img_config);
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2971 if (!success)
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2972 error ("Failed to read tile");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2973
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2974 // Permute to the correct order of dimensions for Octave
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2975 Array<octave_idx_type> perm (dim_vector (3, 1));
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2976 perm(0) = 2;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2977 perm(1) = 1;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2978 perm(2) = 0;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2979 tile_data = tile_data.permute (perm);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2980
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2981 // Slice the data into RGB and alpha
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2982 return slice_rgba (tile_data);
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2983 #else
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2984 err_disabled_feature ("readRGBATile", "Tiff");
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2985 #endif
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2986 }
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2987
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2988 DEFUN (__tiff_write__, args, ,
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2989 "Write the image data to the current IFD")
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2990 {
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2991 #if defined (HAVE_TIFF)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2992 int nargin = args.length ();
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2993
31187
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
2994 // FIXME: add support for writing in YCbCr mode
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2995 if (nargin < 2)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2996 error ("Wrong number of arguments\n");
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2997
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2998 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2999 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3000 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3001
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3002 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3003
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3004 TIFF *tif = tiff_handle->get_file ();
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3005
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
3006 check_readonly (tif);
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3007
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3008 // Obtain all necessary tags
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3009 tiff_image_data image_data (tif);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3010
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3011 uint16_t sample_format;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3012 if (! TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_format))
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3013 error ("Failed to obtain a value for sample format");
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3014
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3015 switch (sample_format)
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3016 {
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3017 case 1:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3018 case 4:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3019 write_unsigned_image (tif, args(1), &image_data);
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3020 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3021 case 2:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3022 write_signed_image (tif, args(1), &image_data);
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3023 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3024 case 3:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3025 write_float_image (tif, args(1), &image_data);
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3026 break;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3027 default:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3028 error ("Unsupported sample format");
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3029 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3030
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3031 return octave_value_list ();
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3032 #else
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3033 err_disabled_feature ("write", "Tiff");
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3034 #endif
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3035 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3036
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3037 DEFUN (__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
3038 "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
3039 {
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3040 #if defined (HAVE_TIFF)
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3041 int nargin = args.length ();
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3042
31187
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
3043 // FIXME: add support for writing in YCbCr mode
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3044 if (nargin < 3)
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3045 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
3046
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3047 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3048 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3049 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3050
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3051 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3052
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3053 TIFF *tif = tiff_handle->get_file ();
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3054
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
3055 check_readonly (tif);
31138
68762676dab1 Tiff writeEncodedStrip: prevent writing to a read-only file
magedrifaat <magedrifaat@gmail.com>
parents: 31137
diff changeset
3056
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3057 // Obtain all necessary tags
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3058 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
3059
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3060 if (image_data.is_tiled)
31143
a68f2dadafee Tiff.m: added all remaining tests for implemented features.
magedrifaat <magedrifaat@gmail.com>
parents: 31142
diff changeset
3061 error ("Can't write strips to a tiled image");
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3062
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3063 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
3064 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
3065 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
3066
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
3067 handle_write_strip_or_tile (tif, strip_no, args(2), &image_data);
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3068
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3069 return octave_value_list ();
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3070 #else
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3071 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
3072 #endif
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3073 }
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3074
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3075 DEFUN (__tiff_write_encoded_tile__, args, ,
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3076 "Write an encoded tile to the image")
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3077 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3078 #if defined (HAVE_TIFF)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3079 int nargin = args.length ();
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3080
31187
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
3081 // FIXME: add support for writing in YCbCr mode
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3082 if (nargin < 3)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3083 error ("Too few arguments provided\n");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3084
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3085 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3086 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3087 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3088
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3089 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3090
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3091 TIFF *tif = tiff_handle->get_file ();
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3092
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
3093 check_readonly (tif);
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3094
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3095 // Obtain all necessary tags
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3096 tiff_image_data image_data (tif);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3097
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3098 if (! image_data.is_tiled)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3099 error ("Can't write tiles to a stripped image");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3100
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3101 uint32_t tile_no = args(1).uint32_scalar_value ();
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3102 if (tile_no < 1 || tile_no > TIFFNumberOfTiles (tif))
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3103 error ("Tile number out of range");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3104
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
3105 handle_write_strip_or_tile (tif, tile_no, args(2), &image_data);
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3106
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3107 return octave_value_list ();
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3108 #else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3109 err_disabled_feature ("writeEncodedTile", "Tiff");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3110 #endif
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3111 }
31148
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3112
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3113 DEFUN (__tiff_is_tiled__, args, ,
31148
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3114 "Get whether the image is tiled")
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3115 {
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3116 #if defined (HAVE_TIFF)
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3117 int nargin = args.length ();
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3118
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3119 if (nargin == 0)
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3120 error ("No handle provided\n");
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3121
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3122 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3123 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3124 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3125
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3126 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3127
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3128 TIFF *tif = tiff_handle->get_file ();
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3129
31148
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3130 bool is_tiled = static_cast<bool> (TIFFIsTiled (tif));
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3131 return ovl (is_tiled);
31148
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3132 #else
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3133 err_disabled_feature ("isTiled", "Tiff");
31148
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3134 #endif
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3135 }
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3136
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3137 DEFUN (__tiff_number_of_strips__, args, ,
31149
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3138 "Get the number of strips in the image")
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3139 {
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3140 #if defined (HAVE_TIFF)
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3141 int nargin = args.length ();
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3142
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3143 if (nargin == 0)
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3144 error ("No handle provided\n");
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3145
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3146 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3147 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3148 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3149
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3150 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3151
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3152 TIFF *tif = tiff_handle->get_file ();
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3153
31149
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3154 if (TIFFIsTiled (tif))
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3155 error ("The image is tiled not stripped");
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3156
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3157 double strip_count = static_cast<double> (TIFFNumberOfStrips (tif));
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3158 return ovl (strip_count);
31149
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3159 #else
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3160 err_disabled_feature ("numberOfStrips", "Tiff");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3161 #endif
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3162 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3163
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3164 DEFUN (__tiff_number_of_tiles__, args, ,
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3165 "Get the number of tiles in the image")
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3166 {
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3167 #if defined (HAVE_TIFF)
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3168 int nargin = args.length ();
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3169
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3170 if (nargin == 0)
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3171 error ("No handle provided\n");
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3172
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3173 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3174 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3175 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3176
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3177 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3178
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3179 TIFF *tif = tiff_handle->get_file ();
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3180
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3181 if (! TIFFIsTiled (tif))
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3182 error ("The image is stripped not tiled");
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3183
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3184 double tile_count = static_cast<double> (TIFFNumberOfTiles (tif));
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3185 return ovl (tile_count);
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3186 #else
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3187 err_disabled_feature ("numberOfTiles", "Tiff");
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3188 #endif
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3189 }
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3190
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3191 DEFUN (__tiff_compute_strip__, args, ,
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3192 "Get the strip index containing the given row")
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3193 {
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3194 #if defined (HAVE_TIFF)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3195 int nargin = args.length ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3196
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3197 if (nargin < 2 || nargin > 3)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3198 error ("Wrong number of arguments\n");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3199
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3200 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3201 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3202 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3203
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3204 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3205
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3206 TIFF *tif = tiff_handle->get_file ();
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3207
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3208 if (TIFFIsTiled (tif))
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3209 error ("The image is tiled not stripped");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3210
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3211 tiff_image_data image_data (tif);
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3212
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3213 uint32_t row = args(1).uint32_scalar_value ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3214 if (row > image_data.height)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3215 row = image_data.height;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3216
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3217 // Convert from 1-based to zero-based indexing but avoid underflow
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3218 if (row > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3219 row--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3220
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3221 uint16_t plane;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3222 if (nargin > 2)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3223 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3224 if (image_data.planar_configuration == PLANARCONFIG_CONTIG)
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3225 error ("Can't use plane argument for images with chunky PlanarConfiguration");
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3226 plane = args(2).uint16_scalar_value ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3227 if (plane > image_data.samples_per_pixel)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3228 plane = image_data.samples_per_pixel;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3229 if (plane > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3230 plane--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3231 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3232 else
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3233 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3234 if (image_data.planar_configuration == PLANARCONFIG_SEPARATE)
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3235 error ("The plane argument is required for images with separate PlanarConfiguration");
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3236 plane = 0;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3237 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3238
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3239 double strip_number = TIFFComputeStrip (tif, row, plane) + 1;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3240 if (strip_number > TIFFNumberOfStrips (tif))
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3241 strip_number = TIFFNumberOfStrips (tif);
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3242 return ovl (strip_number);
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3243 #else
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3244 err_disabled_feature ("computeStrip", "Tiff");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3245 #endif
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3246 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3247
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3248 DEFUN (__tiff_compute_tile__, args, ,
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3249 "Get the tile index containing the given row and column")
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3250 {
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3251 #if defined (HAVE_TIFF)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3252 int nargin = args.length ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3253
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3254 if (nargin < 2 || nargin > 3)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3255 error ("Wrong number of arguments\n");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3256
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3257 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3258 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3259 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3260
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3261 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3262
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3263 TIFF *tif = tiff_handle->get_file ();
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3264
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3265 if (! TIFFIsTiled (tif))
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3266 error ("The image is stripped not tiled");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3267
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3268 uint32NDArray coords = args(1).uint32_array_value ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3269 if (coords.dim2() < 2)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3270 error ("Coordinates must be in the shape [row, col]");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3271 uint32_t row = coords(0, 0);
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3272 uint32_t col = coords(0, 1);
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3273
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3274 tiff_image_data image_data (tif);
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3275
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3276 if (col > image_data.width)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3277 col = image_data.width;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3278 if (row > image_data.height)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3279 row = image_data.height;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3280
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3281 // Convert from 1-based to zero-based indexing but avoid underflow
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3282 if (row > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3283 row--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3284 if (col > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3285 col--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3286
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3287 uint16_t plane;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3288 if (nargin > 2)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3289 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3290 if (image_data.planar_configuration == PLANARCONFIG_CONTIG)
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3291 error ("Can't use plane argument for images with chunky PlanarConfiguration");
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3292 plane = args(2).uint16_scalar_value ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3293 if (plane > image_data.samples_per_pixel)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3294 plane = image_data.samples_per_pixel;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3295 if (plane > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3296 plane--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3297 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3298 else
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3299 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3300 if (image_data.planar_configuration == PLANARCONFIG_SEPARATE)
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3301 error ("The plane argument is required for images with separate PlanarConfiguration");
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3302 plane = 0;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3303 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3304
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3305 double tile_number = TIFFComputeTile (tif, col, row, 0, plane) + 1;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3306 if (tile_number > TIFFNumberOfTiles (tif))
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3307 tile_number = TIFFNumberOfTiles (tif);
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3308 return ovl (tile_number);
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3309 #else
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3310 err_disabled_feature ("computeTile", "Tiff");
31149
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3311 #endif
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3312 }
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3313
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3314 DEFUN (__tiff_current_directory__, args, ,
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3315 "Get the index of the current directory")
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3316 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3317 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3318 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3319
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3320 if (nargin != 1)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3321 error ("Wrong number of arguments\n");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3322
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3323 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3324 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3325 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3326
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3327 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3328
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3329 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3330
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3331 uint16_t dir = TIFFCurrentDirectory (tif);
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3332 dir++;
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3333
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3334 return ovl (static_cast<double> (dir));
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3335 #else
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3336 err_disabled_feature ("currentDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3337 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3338 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3339
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3340 DEFUN (__tiff_last_directory__, args, ,
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3341 "Get the whether the current directory is the last")
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3342 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3343 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3344 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3345
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3346 if (nargin != 1)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3347 error ("Wrong number of arguments\n");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3348
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3349 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3350 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3351 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3352
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3353 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3354
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3355 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3356
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3357 bool is_last = TIFFLastDirectory (tif);
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3358
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3359 return ovl (is_last);
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3360 #else
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3361 err_disabled_feature ("lastDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3362 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3363 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3364
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3365 DEFUN (__tiff_next_directory__, args, ,
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3366 "Set the next IFD as the current IFD")
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3367 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3368 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3369 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3370
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3371 if (nargin != 1)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3372 error ("Wrong number of arguments\n");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3373
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3374 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3375 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3376 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3377
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3378 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3379
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3380 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3381
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3382 bool is_last = TIFFLastDirectory (tif);
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3383 if (is_last)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3384 error ("Current directory is the last directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3385
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3386 if (! TIFFReadDirectory (tif))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3387 error ("Failed to read the next directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3388
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3389 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3390 #else
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3391 err_disabled_feature ("nextDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3392 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3393 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3394
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3395 DEFUN (__tiff_set_directory__, args, ,
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3396 "Set the current IFD using the given index")
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3397 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3398 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3399 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3400
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3401 if (nargin != 2)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3402 error ("Wrong number of arguments\n");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3403
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3404 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3405 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3406 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3407
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3408 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3409
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3410 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3411
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3412 uint16_t dir = args(1).uint16_scalar_value ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3413 if (dir < 1 || dir > TIFFNumberOfDirectories (tif))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3414 error ("Directory index out of bounds");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3415
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3416 dir--;
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3417
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3418 if (! TIFFSetDirectory(tif, dir))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3419 error ("Failed to read directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3420
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3421 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3422 #else
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3423 err_disabled_feature ("setDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3424 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3425 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3426
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3427 DEFUN (__tiff_write_directory__, args, ,
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3428 "Write the current IFD to file and create a new one")
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3429 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3430 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3431 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3432
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3433 if (nargin != 1)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3434 error ("Wrong number of arguments\n");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3435
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3436 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3437 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3438 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3439
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3440 TIFF *tif = tiff_handle->get_file ();
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3441
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3442 if (! TIFFWriteDirectory(tif))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3443 error ("Failed to write directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3444
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3445 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3446 #else
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3447 err_disabled_feature ("writeDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3448 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3449 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3450
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3451 DEFUN (__tiff_rewrite_directory__, args, ,
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3452 "Rewrite modifications to the current IFD")
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3453 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3454 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3455 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3456
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3457 if (nargin != 1)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3458 error ("Wrong number of arguments\n");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3459
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3460 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3461 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3462 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3463
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3464 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3465
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3466 TIFF *tif = tiff_handle->get_file ();
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
3467
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3468 if (! TIFFRewriteDirectory(tif))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3469 error ("Failed to rewrite directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3470
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3471 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3472 #else
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3473 err_disabled_feature ("rewriteDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3474 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3475 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3476
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3477 DEFUN (__tiff_set_sub_directory__, args, ,
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3478 "Set the given offset directory as the current IFD")
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3479 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3480 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3481 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3482
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3483 if (nargin != 2)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3484 error ("Wrong number of arguments\n");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3485
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3486 octave_tiff_handle *tiff_handle
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3487 = octave_tiff_handle::get_tiff_handle (args(0));
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3488 check_closed (tiff_handle);
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3489
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3490 set_internal_handlers ();
31190
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
3491
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3492 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3493
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3494 if (! args(1).is_double_type () && ! args(1).is_uint32_type ()
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3495 && ! args(1).is_uint64_type ())
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3496 error ("Expected offset of type double, uint32 or uint64");
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3497
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3498 uint16_t count;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3499 uint64_t *offsets;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3500 if (! TIFFGetField (tif, TIFFTAG_SUBIFD, &count, &offsets))
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3501 error ("The current directory doesn't have sub directories");
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3502
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3503 uint64_t offset = args(1).uint64_scalar_value ();
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3504
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3505 int found = 0;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3506 for (uint16_t i = 0; i < count; i++)
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3507 if (offset == offsets[i])
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3508 {
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3509 found = 1;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3510 break;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3511 }
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3512
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3513 if (! found)
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3514 error ("No Sub directory with the given offset");
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3515
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3516 if (! TIFFSetSubDirectory (tif, offset))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3517 error ("Failed to switch to the sub directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3518
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3519 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3520 #else
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3521 err_disabled_feature ("setSubDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3522 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3523 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3524
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3525 DEFUN (__tiff_version__, , ,
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3526 "Get the version stamp of LibTIFF")
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3527 {
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3528 #if defined (HAVE_TIFF)
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3529 std::string version = std::string (TIFFGetVersion ());
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3530 return ovl (version);
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3531 #else
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3532 err_disabled_feature ("getVersion", "Tiff");
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3533 #endif
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3534 }
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3535
31161
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3536 DEFUN (__tiff_set_errors_enabled__, args, ,
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3537 "Enables or Disables error output from LibTIFF")
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3538 {
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3539 #if defined (HAVE_TIFF)
31163
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3540 if (args.length () == 0)
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3541 error ("No state argument provided");
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3542
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3543 if (! args(0).is_bool_scalar ())
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3544 error ("Expected logical value as argument");
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3545
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3546 // Set the error and warning handlers according to the bool parameter
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3547 handlers_set = args(0).bool_value ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3548 set_internal_handlers ();
31161
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3549
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3550 return octave_value_list ();
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3551 #else
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3552 err_disabled_feature ("setErrorEnabled", "Tiff");
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3553 #endif
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3554 }
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3555
31185
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3556 DEFUN (__tiff_make_tagid__, , ,
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3557 "Create the TagID structure from the internal map")
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3558 {
31187
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
3559 #if defined (HAVE_TIFF)
31185
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3560 std::map<std::string, octave_value> tag_ov_map;
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3561 for (auto it = tag_name_map.cbegin (); it != tag_name_map.cend (); it++)
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3562 tag_ov_map[it->first] = octave_value (it->second);
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3563 return octave_value_list(octave_scalar_map (tag_ov_map));
31187
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
3564 #else
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
3565 err_disabled_feature ("F__tiff_make_tagid__", "Tiff");
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
3566 #endif
31185
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3567 }
31190
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
3568
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3569 DEFUN (__tiff_imwrite__, args, ,
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3570 "Handler for imwrite that uses Tiff interface")
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3571 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3572 #if defined (HAVE_TIFF)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3573 int nargin = args.length ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3574
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3575 if (nargin < 2)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3576 error ("imwrite: Wrong number of arguments");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3577
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3578 if (! (args(0).isnumeric () || args(0).is_bool_matrix ()
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3579 || args(0).is_bool_scalar ()))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3580 error ("imwrite: Expected image matrix as first argument");
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3581
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3582 // The argument checks here are very similar to the ones found in
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3583 // __imwrite__.m and imwrite_filename.m, the code is duplicated here since
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3584 // the original code is tailored to the generic library graphicsmagick
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3585 // so it is not suitable to be used directly for this case
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3586 uint16_t offset = 1;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3587 std::string filename;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3588 octave_value cmap = octave_value (NDArray ());
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3589 if (args(1).is_string ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3590 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3591 filename = args(1).string_value ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3592 offset++;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3593 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3594 else if (nargin > 2 && is_colormap (args(1)) && args(2).is_string ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3595 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3596 filename = args(2).string_value ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3597 cmap = args(1);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3598 offset += 2;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3599 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3600 else
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3601 error ("imwrite: no FILENAME specified");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3602
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3603 filename = sys::file_ops::tilde_expand (filename);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3604
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3605 if (nargin > offset && (nargin - offset) % 2 != 0
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3606 && args(offset).is_string ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3607 offset++;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3608
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3609 if ((nargin - offset) % 2 != 0)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3610 error ("imwrite: no pair for all arguments (odd number left)");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3611
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3612 // Setting the default value for the rest of the parameters
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3613 bool append = false;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3614 uint16_t compression = COMPRESSION_NONE;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3615 uint32_t rows_per_strip = UINT32_MAX;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3616 float x_res = 72, y_res = 72;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3617 std::string description = "";
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3618
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3619 // Extract the values for the paramters provided
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3620 for (uint16_t arg_idx = offset; arg_idx < nargin; arg_idx+=2)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3621 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3622 if (! args(arg_idx).is_string ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3623 error ("imwrite: PARAM in PARAM/VALUE pair must be string");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3624
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3625 const char *param_cstr = args(arg_idx).string_value ().c_str ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3626 if (strcasecmp (param_cstr, "colorspace") == 0)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3627 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3628 // Matlab specifies three colorspaces: RGB, CIELAB and ICCLAB.
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3629 // Of the three, only RGB is currently supported so this tag
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3630 // can be ignored.
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3631 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3632 else if (strcasecmp (param_cstr, "compression") == 0)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3633 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3634 if (! args(arg_idx + 1).is_string ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3635 error ("imwrite: value for %s option must be a string",
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3636 param_cstr);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3637 std::string comp = args(arg_idx + 1).string_value ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3638 if (comp == "packbits")
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3639 compression = COMPRESSION_PACKBITS;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3640 else if (comp == "lzw")
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3641 compression = COMPRESSION_LZW;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3642 else if (comp == "deflate")
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3643 compression = COMPRESSION_DEFLATE;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3644 else if (comp == "jpeg")
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3645 compression = COMPRESSION_JPEG;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3646 else if (comp == "ccitt")
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3647 compression = COMPRESSION_CCITTRLE;
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3648 else if (comp == "fax3")
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3649 compression = COMPRESSION_CCITTFAX3;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3650 else if (comp == "fax4")
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3651 compression = COMPRESSION_CCITTFAX4;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3652 else
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3653 error ("imwrite: invalid compression '%s'", comp.c_str ());
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3654 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3655 else if (strcasecmp (param_cstr, "Description") == 0)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3656 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3657 if (! args(arg_idx + 1).is_string ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3658 error ("imwrite: value for %s option must be a string",
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3659 param_cstr);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3660 description = args(arg_idx + 1).string_value ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3661 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3662 else if (strcasecmp (param_cstr, "resolution") == 0)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3663 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3664 if (! args(arg_idx + 1).isnumeric ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3665 error ("imwrite: value for %s option must be numeric",
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3666 param_cstr);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3667 NDArray res = args(arg_idx + 1).array_value ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3668 if (res.numel () == 1)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3669 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3670 x_res = res(0);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3671 y_res = res(0);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3672 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3673 else if (res.numel () == 2)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3674 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3675 x_res = res(0);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3676 y_res = res(1);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3677 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3678 else
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3679 error ("imwrite: value for %s option must be either a scalar value or a two-element vector",
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3680 param_cstr);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3681 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3682 else if (strcasecmp (param_cstr, "RowsPerStrip") == 0)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3683 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3684 if (! args(arg_idx + 1).isnumeric ()
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3685 || ! args(arg_idx + 1).is_scalar_type ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3686 error ("imwrite: value for %s option must be a scalar value",
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3687 param_cstr);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3688 rows_per_strip = args(arg_idx + 1).uint32_scalar_value ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3689 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3690 else if (strcasecmp (param_cstr, "WriteMode") == 0)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3691 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3692 if (! args(arg_idx + 1).is_string ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3693 error ("imwrite: value for %s option must be a string",
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3694 param_cstr);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3695 std::string wmode = args(arg_idx + 1).string_value ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3696 if (wmode == "overwrite")
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3697 append = false;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3698 else if (wmode == "append")
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3699 append = true;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3700 else
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3701 error ("imwrite: value for %s option must be either 'overwrite' or 'append'",
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3702 param_cstr);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3703 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3704 else
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3705 error ("imread: invalid PARAMETER '%s'", param_cstr);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3706 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3707
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3708 // Matlab specifies that JPEG compression must also specify RowsPerStrip
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3709 // and must be a value divisible by 8
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3710 if (compression == COMPRESSION_JPEG
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3711 && (rows_per_strip == UINT32_MAX || rows_per_strip % 8 != 0))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3712 error ("imwrite: RowsPerStrip option must be specified for jpeg compression and must be divisible by 8");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3713
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3714 // These compression schemes are only available for binary images
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3715 if (! (args(0).is_bool_matrix () || args(0).is_bool_scalar ())
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3716 && (compression == COMPRESSION_CCITTRLE
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3717 || compression == COMPRESSION_CCITTFAX3
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3718 || compression == COMPRESSION_CCITTFAX4))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3719 error ("imwrite: the specified compression scheme is for binary images only");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3720
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3721 // Matlab rejects 4D data for TIFF images
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3722 dim_vector img_dims = args(0).dims ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3723 if (args(0).ndims () != 2 && args(0).ndims () != 3)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3724 error ("imwrite: expected 2-dimensional or 3-dimensional image matrix");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3725
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3726 if (args(0).ndims () > 2 && img_dims(2) > 1 && cmap.numel () > 0)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3727 error ("imwrite: palette images must be 1 channel only");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3728
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3729 TIFF *tif;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3730 if (append)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3731 tif = TIFFOpen (filename.c_str (), "a");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3732 else
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3733 tif = TIFFOpen (filename.c_str (), "w");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3734
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3735 if (! tif)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3736 error ("Failed to open file %s", filename.c_str ());
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3737
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3738 // A simple way to make sure the file will be closed when the function
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3739 // returns or when an error occurs as the destructor will always be called
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3740 octave_tiff_handle tiff_handle (tif);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3741
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3742 // Set all necessary tags
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3743 if (! TIFFSetField (tif, TIFFTAG_IMAGELENGTH,
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3744 static_cast<uint32_t>(img_dims(0)))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3745 || ! TIFFSetField (tif, TIFFTAG_IMAGEWIDTH,
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3746 static_cast<uint32_t>(img_dims(1))))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3747 error ("Failed to set image dimensions");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3748
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3749 if (img_dims.ndims () > 2)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3750 if (! TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, img_dims(2)))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3751 error ("Failed to set the number of samples");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3752
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3753 if (! TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3754 error ("Failed to set the planar configuration");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3755
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3756 if (! TIFFSetField (tif, TIFFTAG_COMPRESSION, compression))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3757 error ("Failed to set the compressoin tag");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3758
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3759 if (! TIFFSetField (tif, TIFFTAG_XRESOLUTION, x_res)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3760 || ! TIFFSetField (tif, TIFFTAG_YRESOLUTION, y_res))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3761 error ("Failed to set resolution tag");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3762
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3763 if (! TIFFSetField (tif, TIFFTAG_IMAGEDESCRIPTION, description.c_str ()))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3764 error ("Failed to set description tag");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3765
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3766 if (rows_per_strip == UINT32_MAX)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3767 rows_per_strip = TIFFDefaultStripSize (tif, 0);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3768
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3769 if (! TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3770 error ("Failed to set the RowsPerStrip tag");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3771
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3772 uint16_t bits_per_sample;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3773 if (args(0).is_bool_matrix () || args(0).is_bool_scalar ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3774 bits_per_sample = 1;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3775 else if (args(0).is_uint8_type ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3776 bits_per_sample = 8;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3777 else if (args(0).is_uint16_type ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3778 bits_per_sample = 16;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3779 else if (args(0).is_uint32_type () || args(0).is_single_type ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3780 bits_per_sample = 32;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3781 else if (args(0).is_double_type ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3782 bits_per_sample = 64;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3783 else
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3784 error ("imwrite: unsupported image data type");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3785
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3786 if (! TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, bits_per_sample))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3787 error ("Failed to set BitsPerSample tag");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3788
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3789 // Infer the photometric interpretation of the image from the color map
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3790 // and the number of channels of the input
31193
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3791 uint16_t photometric = PHOTOMETRIC_MINISBLACK;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3792 if (cmap.numel () > 0)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3793 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3794 photometric = PHOTOMETRIC_PALETTE;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3795 set_field_data (tif, TIFFFieldWithTag (tif, TIFFTAG_COLORMAP),
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3796 cmap);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3797 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3798 else if (img_dims(2) == 3)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3799 photometric = PHOTOMETRIC_RGB;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3800 else if (img_dims(2) == 4)
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3801 photometric = PHOTOMETRIC_SEPARATED;
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3802
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3803 if (! TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, photometric))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3804 error ("Failed to set the photometric tag");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3805
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3806 tiff_image_data image_data (tif);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3807 if (args(0).is_bool_scalar () || args(0).is_bool_matrix ()
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3808 || args(0).is_uint8_type () || args(0).is_uint16_type ()
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3809 || args(0).is_uint32_type ())
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3810 write_unsigned_image (tif, args(0), &image_data);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3811 else
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3812 {
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3813 if (!TIFFSetField (tif, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_IEEEFP))
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3814 error ("Failed to set SampleFormat tag");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3815 write_float_image (tif, args(0).as_double (), &image_data);
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3816 }
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3817
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3818 return octave_value_list ();
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3819 #else
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3820 err_disabled_feature ("imwrite", "Tiff");
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3821 #endif
c142c153034c Tiff: implemented imwrite handler that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31192
diff changeset
3822 }
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3823
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3824 DEFUN (__tiff_imfinfo__, args, ,
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3825 "Handler for imfinfo that uses Tiff interface")
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3826 {
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3827 #if defined (HAVE_TIFF)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3828 int nargin = args.length ();
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3829
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3830 if (nargin < 1)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3831 error ("imfinfo: missing filename argument");
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3832
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3833 if (! args(0).is_string ())
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3834 error ("imfinfo: filename must be a string");
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3835
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3836 std::string filename = args(0).string_value ();
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3837
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3838 const sys::file_stat fs (filename);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3839 if (! fs)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3840 error ("imfinfo: error reading '%s': %s", filename.c_str (),
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3841 fs.error ().c_str ());
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3842
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3843 TIFF *tif = TIFFOpen (filename.c_str (), "rc");
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3844 if (! tif)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3845 error ("imfinfo: error reading '%s': LibTIFF failed to read file",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3846 filename.c_str ());
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3847
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3848 // The destructor for this object will be called when the function returnd
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3849 // or in case of an error so the file will always get closed at the end
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3850 octave_tiff_handle tiff_handle (tif);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3851
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3852 // A lot of the logic here is copied from __magick_finfo__ due to the
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3853 // great similarity between the two functions but this function is
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3854 // format specific so a lot of the details are different
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3855 uint16_t dir_count = TIFFNumberOfDirectories (tif);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3856
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3857 // Null terminated char* list to be used to create a string_vector
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3858 static const char *fields[] = {
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3859 "Filename",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3860 "FileModDate",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3861 "FileSize",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3862 "Format",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3863 "FormatVersion",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3864 "Width",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3865 "Height",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3866 "BitDepth",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3867 "ColorType",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3868 "FormatSignature",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3869 "ByteOrder",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3870 "NewSubFileType",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3871 "BitsPerSample",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3872 "Compression",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3873 "PhotometricInterpretation",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3874 "StripOffsets",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3875 "SamplesPerPixel",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3876 "RowsPerStrip",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3877 "StripByteCounts",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3878 "XResolution",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3879 "YResolution",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3880 "ResolutionUnit",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3881 "Colormap",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3882 "PlanarConfiguration",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3883 "TileWidth",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3884 "TileLength",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3885 "TileOffsets",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3886 "TileByteCounts",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3887 "Orientation",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3888 "FillOrder",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3889 "GrayResponseUnit",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3890 "MaxSampleValue",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3891 "MinSampleValue",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3892 "Thresholding",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3893 "Offset",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3894 "ImageDescription",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3895 nullptr
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3896 };
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3897
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3898 // A map to be used as a struct array to hold a scalar_map for each
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3899 // directory
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3900 octave_map info (dim_vector (dir_count, 1), string_vector (fields));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3901
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3902 // populate template_info with the info that is common between all
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3903 // directories in the file
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3904 octave_scalar_map template_info = (string_vector (fields));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3905 template_info.setfield ("Format", octave_value ("tif"));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3906 template_info.setfield ("FormatVersion", octave_value (""));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3907 const sys::localtime mtime (fs.mtime ());
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3908 const std::string filetime = mtime.strftime ("%e-%b-%Y %H:%M:%S");
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3909 template_info.setfield ("Filename", octave_value (filename));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3910 template_info.setfield ("FileModDate", octave_value (filetime));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3911 template_info.setfield ("FileSize", octave_value (fs.size ()));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3912
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3913 // Extract the image signature (first 4 bytes in file)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3914 std::ifstream tif_file;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3915 #if defined (OCTAVE_USE_WINDOWS_API)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3916 std::wstring wname = sys::u8_to_wstring (filename);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3917 tif_file.open (wname.c_str (), std::ios_base::binary);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3918 #else
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3919 tif_file.open (filename.c_str (), std::ios_base::binary);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3920 #endif
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3921 uint8NDArray signature (dim_vector (1, 4));;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3922 tif_file.read (reinterpret_cast<char *> (signature.fortran_vec ()), 4);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3923 tif_file.close ();
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3924 template_info.setfield ("FormatSignature", octave_value (signature));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3925
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3926 std::string byte_order
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3927 = TIFFIsBigEndian (tif)? "big-endian": "little-endian";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3928 template_info.setfield ("ByteOrder", octave_value (byte_order));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3929
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3930 // Extract directory specific information
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3931 for (uint16_t dir = 0; dir < dir_count; dir++)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3932 {
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3933 octave_scalar_map dir_info (template_info);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3934
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3935 // Switch to the directory
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3936 if (! TIFFSetDirectory (tif, dir))
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3937 error ("imfinfo: Failed to access frame %d\n", dir);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3938
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3939 tiff_image_data image_data (tif);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3940 dir_info.setfield ("Width", octave_value (image_data.width));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3941
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3942 dir_info.setfield ("Height", octave_value (image_data.height));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3943
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3944 uint16_t bit_depth = image_data.samples_per_pixel
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3945 * image_data.bits_per_sample;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3946 dir_info.setfield ("BitDepth", octave_value (bit_depth));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3947
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3948 std::string planar = "unrecognized";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3949 if (image_data.planar_configuration == 1)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3950 planar = "Chunky";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3951 else if (image_data.planar_configuration == 2)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3952 planar = "Separate";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3953 dir_info.setfield ("PlanarConfiguration", octave_value (planar));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3954
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3955 // Extract photometric information as well as color map if exists
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3956 std::string color_str, photometric_str;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3957 uint16_t photometric = PHOTOMETRIC_MINISBLACK;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3958 octave_value cmap = octave_value (Matrix ());
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3959 const TIFFField *fip;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3960 TIFFGetField (tif, TIFFTAG_PHOTOMETRIC, &photometric);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3961 switch (photometric)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3962 {
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3963 case PHOTOMETRIC_MINISBLACK:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3964 color_str = "grayscale";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3965 photometric_str = "BlasckIsZero";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3966 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3967 case PHOTOMETRIC_MINISWHITE:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3968 color_str = "grayscale";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3969 photometric_str = "WhiteIsZero";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3970 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3971 case PHOTOMETRIC_RGB:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3972 color_str = "truecolor";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3973 photometric_str = "RGB";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3974 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3975 case PHOTOMETRIC_PALETTE:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3976 color_str = "indexed";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3977 photometric_str = "RGB Palette";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3978 fip = TIFFFieldWithTag (tif, TIFFTAG_COLORMAP);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3979 cmap = get_field_data (tif, fip);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3980 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3981 case PHOTOMETRIC_SEPARATED:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3982 color_str = "CMYK";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3983 photometric_str = "CMYK";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3984 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3985 default:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3986 color_str = "undefined";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3987 photometric_str = "undefined";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3988 }
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3989 dir_info.setfield ("ColorType", octave_value(color_str));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3990 dir_info.setfield ("PhotometricInterpretation",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3991 octave_value(photometric_str));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3992 dir_info.setfield ("Colormap", octave_value (cmap));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3993
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3994 fip = TIFFFieldWithTag (tif, TIFFTAG_SUBFILETYPE);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3995 dir_info.setfield ("NewSubFileType", get_field_data (tif, fip));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3996
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3997 fip = TIFFFieldWithTag (tif, TIFFTAG_BITSPERSAMPLE);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3998 dir_info.setfield ("BitsPerSample", get_field_data (tif, fip));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3999
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4000 fip = TIFFFieldWithTag (tif, TIFFTAG_SAMPLESPERPIXEL);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4001 dir_info.setfield ("SamplesPerPixel", get_field_data (tif, fip));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4002
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4003 // Use LibTIFF's compression codec to extract compression scheme name
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4004 uint16_t compression;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4005 TIFFGetFieldDefaulted (tif, TIFFTAG_COMPRESSION, &compression);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4006 std::string comp_str = "unrecognized";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4007 const TIFFCodec *codec = TIFFFindCODEC (compression);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4008 if (codec)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4009 comp_str = codec->name;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4010 dir_info.setfield ("Compression", octave_value (comp_str));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4011
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4012 // Set strip-specific and tile-specific fields accordingly
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4013 bool tiled = TIFFIsTiled (tif);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4014 fip = TIFFFieldWithTag (tif, TIFFTAG_TILELENGTH);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4015 dir_info.setfield ("TileLength", tiled? get_field_data (tif, fip)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4016 : octave_value (Matrix ()));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4017 fip = TIFFFieldWithTag (tif, TIFFTAG_TILEWIDTH);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4018 dir_info.setfield ("TileWidth", tiled? get_field_data (tif, fip)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4019 : octave_value (Matrix ()));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4020 fip = TIFFFieldWithTag (tif, TIFFTAG_TILEOFFSETS);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4021 dir_info.setfield ("TileOffsets", tiled? get_field_data (tif, fip)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4022 : octave_value (Matrix ()));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4023 fip = TIFFFieldWithTag (tif, TIFFTAG_TILEBYTECOUNTS);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4024 dir_info.setfield ("TileByteCounts", tiled? get_field_data (tif, fip)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4025 : octave_value (Matrix ()));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4026 fip = TIFFFieldWithTag (tif, TIFFTAG_ROWSPERSTRIP);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4027 dir_info.setfield ("RowsPerStrip", tiled? octave_value (Matrix ())
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4028 : get_field_data (tif, fip));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4029 fip = TIFFFieldWithTag (tif, TIFFTAG_STRIPOFFSETS);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4030 dir_info.setfield ("StripOffsets", tiled? octave_value (Matrix ())
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4031 : get_field_data (tif, fip));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4032 fip = TIFFFieldWithTag (tif, TIFFTAG_STRIPBYTECOUNTS);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4033 dir_info.setfield ("StripByteCounts", tiled? octave_value (Matrix ())
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4034 : get_field_data (tif, fip));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4035
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4036 uint16_t res;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4037 if (TIFFGetField (tif, TIFFTAG_XRESOLUTION, &res))
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4038 dir_info.setfield ("XResolution", octave_value (res));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4039 else
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4040 dir_info.setfield ("XResolution", octave_value (Matrix ()));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4041
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4042 if (TIFFGetField (tif, TIFFTAG_YRESOLUTION, &res))
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4043 dir_info.setfield ("YResolution", octave_value (res));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4044 else
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4045 dir_info.setfield ("YResolution", octave_value (Matrix ()));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4046
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4047 TIFFGetFieldDefaulted (tif, TIFFTAG_RESOLUTIONUNIT, &res);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4048 std::string res_unit = "Inch";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4049 if (res == 1)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4050 res_unit = "None";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4051 else if (res == 3)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4052 res_unit = "Centimeter";
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4053 dir_info.setfield ("ResolutionUnit", octave_value(res_unit));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4054
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4055 fip = TIFFFieldWithTag (tif, TIFFTAG_ORIENTATION);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4056 dir_info.setfield ("Orientation", get_field_data (tif, fip));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4057
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4058 fip = TIFFFieldWithTag (tif, TIFFTAG_FILLORDER);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4059 dir_info.setfield ("FillOrder", get_field_data (tif, fip));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4060
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4061 // The current version of LibTIFF (4.4.0) doesn't set the deafult
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4062 // value for GrayResponseUnit corectly, so we can't use
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4063 // TIFFGetFieldDefaulted, instead we set the default value ourselves
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4064 double gray_response_unit = 0.01;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4065 uint16_t gray_unit_val;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4066 if (TIFFGetField (tif, TIFFTAG_GRAYRESPONSEUNIT, &gray_unit_val))
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4067 {
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4068 switch (gray_unit_val)
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4069 {
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4070 case GRAYRESPONSEUNIT_10S:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4071 gray_response_unit = 0.1;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4072 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4073 case GRAYRESPONSEUNIT_100S:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4074 gray_response_unit = 0.01;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4075 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4076 case GRAYRESPONSEUNIT_1000S:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4077 gray_response_unit = 0.001;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4078 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4079 case GRAYRESPONSEUNIT_10000S:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4080 gray_response_unit = 0.0001;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4081 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4082 case GRAYRESPONSEUNIT_100000S:
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4083 gray_response_unit = 0.00001;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4084 break;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4085 }
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4086 }
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4087 dir_info.setfield ("GrayResponseUnit",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4088 octave_value (gray_response_unit));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4089
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4090 // The current version of LibTIFF (4.4.0) doesn't set the deafult
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4091 // value for MinSampleValue and MaxSampleValue, so we can't use
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4092 // TIFFGetFieldDefaulted, instead we set the default value ourselves
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4093 uint16_t min_sample_value = 0;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4094 uint16_t max_sample_value = (1<<image_data.bits_per_sample) - 1;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4095 TIFFGetField (tif, TIFFTAG_MINSAMPLEVALUE, &min_sample_value);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4096 TIFFGetField (tif, TIFFTAG_MAXSAMPLEVALUE, &max_sample_value);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4097 dim_vector vector_dims = dim_vector (1, image_data.samples_per_pixel);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4098 NDArray min_sample_values (vector_dims, min_sample_value);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4099 NDArray max_sample_values (vector_dims, max_sample_value);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4100 dir_info.setfield ("MinSampleValue",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4101 octave_value (min_sample_values));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4102 dir_info.setfield ("MaxSampleValue",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4103 octave_value (max_sample_values));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4104
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4105 fip = TIFFFieldWithTag (tif, TIFFTAG_THRESHHOLDING);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4106 dir_info.setfield ("Thresholding", get_field_data (tif, fip));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4107
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4108 dir_info.setfield ("Offset",
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4109 octave_value (TIFFCurrentDirOffset (tif)));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4110
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4111 char *desc = NULL;
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4112 if (TIFFGetField (tif, TIFFTAG_IMAGEDESCRIPTION, &desc))
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4113 dir_info.setfield ("ImageDescription", octave_value (desc));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4114 else
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4115 dir_info.setfield ("ImageDescription", octave_value (""));
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4116
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4117 // Insert the directory information into the map
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4118 info.fast_elem_insert (dir, dir_info);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4119 }
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4120
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4121 return ovl (info);
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4122 #else
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4123 err_disabled_feature ("imfinfo", "Tiff");
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4124 #endif
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
4125 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
4126 }