annotate libinterp/corefcn/__tiff__.cc @ 31217:c09f6a3597e6 default tip gsoc-libtiff

__tiff__.cc: handled unused parameter warning when Tiff is not enabled * libtinerp/corefcn/__tiff__.cc: added appropriate hadnling for unused parameters for cases when Octave is compiled without Tiff support to suppress compiler warnings in that case.
author magedrifaat <magedrifaat@gmail.com>
date Wed, 07 Sep 2022 18:39:10 +0200
parents fe776b0e904d
children
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
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
131 // 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
132 // 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
133 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
134 {"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
135 {"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
136 {"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
137 {"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
138 {"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
139 {"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
140 {"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
141 {"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
142 {"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
143 {"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
144 {"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
145 {"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
146 {"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
147 {"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
148 {"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
149 {"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
150 {"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
151 {"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
152 {"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
153 {"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
154 {"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
155 {"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
156 {"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
157 {"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
158 {"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
159 {"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
160 {"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
161 {"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
162 {"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
163 {"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
164 {"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
165 {"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
166 {"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
167 {"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
168 {"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
169 {"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
170 {"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
171 {"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
172 {"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
173 {"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
174 {"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
175 {"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
176 {"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
177 {"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
178 {"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
179 {"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
180 {"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
181 {"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
182 {"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
183 {"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
184 {"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
185 {"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
186 {"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
187 {"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
188 {"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
189 {"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
190 {"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
191 {"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
192 {"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
193 {"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
194 {"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
195 {"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
196 {"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
197 {"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
198 {"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
199 {"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
200 {"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
201 {"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
202 {"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
203 };
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
204
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
205 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
206 {
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
207 const TIFFField *fip = NULL;
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
208 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
209 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
210
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
211 // 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
212 // in LibTIFF.
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
213 if (fip == NULL)
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
214 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
215
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
216 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
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
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
219 void
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
220 check_readonly (TIFF *tif)
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
221 {
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
222 if (TIFFGetMode (tif) == octave_o_rdonly_wrapper ())
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
223 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
224 }
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
225
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
226 void
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
227 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
228 {
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
229 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
230 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
231 }
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
232
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
233 void
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
234 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
235 {
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
236 // 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
237 if (status != 1)
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
238 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
239 }
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
240
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
241 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
242 uint32_t rows_per_strip,
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
243 tiff_image_data *image_data)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
244 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
245 // 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
246 // 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
247 // 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
248 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
249 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
250 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
251 // 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
252 // 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
253 if (strip_no == strip_count - 1)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
254 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
255 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
256 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
257 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
258 // 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
259 uint32_t strips_per_channel
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
260 = strip_count / image_data->samples_per_pixel;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
261 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
262 boundary_strip <= strip_count;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
263 boundary_strip += strips_per_channel)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
264 if (strip_no == boundary_strip)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
265 rows_in_strip = image_data->height
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
266 - 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
267 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
268 else
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
269 error ("Planar Configuration not supported");
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 return rows_in_strip;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
272 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
273
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
274 void
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
275 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
276 uint32_t& tile_height)
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
277 {
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
278 if (! TIFFGetField (tif, TIFFTAG_TILELENGTH, &tile_height))
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
279 error ("Filed to read tile length");
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
280
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
281 if (! TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width))
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
282 error ("Filed to read tile length");
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
283
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
284 if (tile_height == 0 || tile_height % 16 != 0
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
285 || tile_width == 0 || tile_width % 16 != 0)
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
286 error ("Tile dimesion tags are invalid");
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
287 }
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
288
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
289 template <typename T>
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
290 octave_value
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
291 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
292 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
293 // 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
294 // index for the tif image
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
295
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
296 uint32_t rows_in_strip;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
297 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
298 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
299
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
300 // 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
301 // image height
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
302 if (rows_in_strip > image_data->height)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
303 rows_in_strip = image_data->height;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
304
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
305 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
306 // 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
307 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
308 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
309
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
310 // 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
311 dim_vector strip_dims;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
312 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
313 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
314 image_data->width, rows_in_strip);
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
315 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
316 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
317 else
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
318 error ("Unsupported bit depth");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
319
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
320 T strip_data (strip_dims);
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
321 uint8_t *strip_fvec
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
322 = 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
323
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
324 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
325 || image_data->bits_per_sample == 16
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
326 || image_data->bits_per_sample == 32
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
327 || image_data->bits_per_sample == 64)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
328 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
329 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
330 error ("Failed to read strip data");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
331 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
332 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
333 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
334 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
335 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
336
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
337 // 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
338 // 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
339 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
340 = 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
341 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
342 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
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 // 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
346 // 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
347 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
348 // Packing the pixel data into bits
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
349 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
350 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
351 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
352 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
353 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
354 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
355 shift = 7 - shift;
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
356 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
357 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
358 strip_fvec += image_data->width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
359 strip_buf += padded_width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
360 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
361 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
362 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
363 error ("Unsupported bit depth");
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
364
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
365 // 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
366 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
367 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
368 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
369 perm(0) = 2;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
370 perm(1) = 1;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
371 perm(2) = 0;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
372 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
373 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
374 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
375 perm(0) = 1;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
376 perm(1) = 0;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
377 perm(2) = 2;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
378 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
379
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
380 strip_data = strip_data.permute (perm);
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
381 return octave_value (strip_data);
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
382 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
383
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
384 template <typename T>
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
385 octave_value
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
386 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
387 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
388 // 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
389 // index for the tif image
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
390
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
391 uint32_t tile_width, tile_height;
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
392 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
393
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
394 dim_vector tile_dims;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
395 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
396 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
397 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
398 tile_height);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
399 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
400 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
401 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
402 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
403 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
404 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
405 error ("Unsupported planar configuration");
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 T tile_data (tile_dims);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
408 uint8_t *tile_fvec
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
409 = 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
410
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
411 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
412 || image_data->bits_per_sample == 16
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
413 || image_data->bits_per_sample == 32
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
414 || image_data->bits_per_sample == 64)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
415 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
416 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
417 error ("Failed to read tile data");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
418 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
419 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
420 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
421 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
422 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
423
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
424 // 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
425 // 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
426 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
427 = 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
428 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
429 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
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 // 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
433 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
434 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
435 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
436 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
437 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
438 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
439 shift = 7 - shift;
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
440 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
441 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
442 tile_fvec += tile_width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
443 tile_buf += tile_width / 8;
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 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
446 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
447 error ("Unsupported bit depth");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
448
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
449 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
450 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
451 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
452 perm(0) = 2;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
453 perm(1) = 1;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
454 perm(2) = 0;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
455 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
456 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
457 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
458 perm(0) = 1;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
459 perm(1) = 0;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
460 perm(2) = 2;
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
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
463 tile_data = tile_data.permute (perm);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
464
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
465 // 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
466 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
467 / tile_width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
468 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
469 / tile_height;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
470 uint32_t corrected_width = tile_width;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
471 uint32_t corrected_height = tile_height;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
472 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
473 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
474 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
475 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
476
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
477 dim_vector corrected_dims;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
478 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
479 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
480 image_data->samples_per_pixel);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
481 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
482 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
483
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
484 tile_data.resize (corrected_dims);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
485
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
486 return octave_value (tile_data);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
487 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
488
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
489 template <typename T>
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
490 octave_value
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
491 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
492 tiff_image_data *image_data)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
493 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
494 if (image_data->is_tiled)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
495 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
496 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
497 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
498 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
499
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
500 octave_value
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
501 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
502 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
503 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
504 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
505 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
506 case 1:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
507 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
508 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
509 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
510 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
511 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
512 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
513 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
514 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
515 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
516 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
517 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
518 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
519 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
520 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
521 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
522 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
523 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
524 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
525 error ("Unsupported bit depth");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
526 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
527 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
528
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
529 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
530 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
531 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
532 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
533 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
534 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
535 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
536 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
537 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
538 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
539 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
540 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
541 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
542 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
543 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
544 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
545 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
546 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
547 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
548 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
549 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
550 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
551 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
552 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
553
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
554 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
555 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
556 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
557 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
558 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
559 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
560 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
561 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
562 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
563 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
564 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
565 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
566 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
567 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
568 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
569 }
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 octave_value
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
572 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
573 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
574 // Obtain all necessary tags
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
575 tiff_image_data image_data (tif);
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
576
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
577 uint16_t sample_format;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
578 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
579 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
580
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
581 switch (sample_format)
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
582 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
583 case 1:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
584 case 4:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
585 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
586 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
587 case 2:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
588 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
589 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
590 case 3:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
591 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
592 break;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
593 default:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
594 error ("Unsupported 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 }
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
597
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
598 template <typename T>
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
599 octave_value
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
600 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
601 {
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
602 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
603
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
604 // 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
605 // 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
606 // 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
607 // 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
608 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
609 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
610 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
611 && padded_width % 8 != 0)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
612 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
613 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
614 remove_padding = 1;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
615 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
616
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
617 // 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
618 // 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
619 // 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
620 T img;
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
621 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
622 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
623 image_data->height));
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
624 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
625 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
626 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
627 else
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
628 error ("Unsupported Planar Configuration");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
629
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
630 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
631
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
632 // 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
633 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
634
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
635 // 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
636 // 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
637 // 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
638 int64_t strip_size;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
639 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
640 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
641 * 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
642 * sizeof (P);
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
643 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
644 {
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
645 // 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
646 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
647
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
648 // 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
649 if (strip_size == -1)
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
650 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
651
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
652 // 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
653 // 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
654 // 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
655 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
656 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
657
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
658 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
659 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
660 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
661 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
662
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
663 // 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
664 // 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
665 // 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
666 strip_size *= 8;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
667
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
668 // 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
669 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
670 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
671
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
672 // 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
673 // 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
674 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
675 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
676 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
677 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
678 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
679 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
680 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
681 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
682 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
683 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
684 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
685 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
686 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
687
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
688 // 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
689 // 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
690 strip_size *= 2;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
691
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
692 // 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
693 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
694 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
695
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
696 // 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
697 // 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
698 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
699 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
700 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
701 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
702 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
703 }
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 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
706 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
707 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
708 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
709 error ("Unsupported bit depth");
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
710
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
711 // 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
712 img_fvec
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
713 = 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
714 + strip_size);
31119
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
715 written_size += strip_size;
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
716 }
31119
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 // 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
719 // 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
720 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
721 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
722 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
723 perm(0) = 2;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
724 perm(1) = 1;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
725 perm(2) = 0;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
726 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
727 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
728 {
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
729 perm(0) = 1;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
730 perm(1) = 0;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
731 perm(2) = 2;
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
732 }
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
733
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
734 img = img.permute (perm);
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 if (remove_padding)
dbca50246dfc Tiff read: changed logic to matrix operations instead of pointer math
magedrifaat <magedrifaat@gmail.com>
parents: 31118
diff changeset
737 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
738
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
739 return octave_value (img);
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
740 }
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
741
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
742 template <typename T>
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
743 octave_value
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
744 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
745 {
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
746 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
747
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
748 // 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
749 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
750 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
751 &tile_width));
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
752 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
753 &tile_height));
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
754 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
755 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
756 / tile_width;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
757 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
758 / tile_height;
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
759
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
760 T img;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
761 // 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
762 // 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
763 // 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
764 // shape expected by Octave
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
765 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
766 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
767 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
768 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
769 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
770 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
771 else
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
772 error ("Unsupported Planar Configuration");
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
773
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
774 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
775
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
776 // 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
777 // 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
778 // boundary tiles
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
779 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
780 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
781 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
782
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
783 // 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
784 // 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
785 // 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
786 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
787 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
788 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
789 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
790 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
791
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
792 if (tile_size == -1)
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
793 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
794
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
795 // 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
796 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
797 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
798
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
799 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
800 {
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
801 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
802 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
803
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
804 // 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
805 // 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
806 // 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
807 tile_size *= 8;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
808
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
809 // 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
810 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
811 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
812
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
813 // 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
814 // 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
815 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
816 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
817 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
818 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
819 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
820 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
821 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
822 }
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
823 }
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
824 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
825 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
826 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
827 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
828
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
829 // 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
830 // 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
831 tile_size *= 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
832
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
833 // 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
834 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
835 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
836
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
837 // 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
838 // 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
839 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
840 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
841 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
842 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
843 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
844 }
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
845 }
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
846 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
847 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
848 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
849 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
850 error ("Unsupported bit depth");
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
851
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
852 img_fvec
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
853 = 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
854 + tile_size);
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
855 written_size += tile_size;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
856 }
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
857
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
858 // 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
859 // 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
860 // 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
861 // 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
862 // 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
863 // 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
864 // 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
865 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
866 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
867 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
868 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
869 perm1(0) = 0;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
870 perm1(1) = 1;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
871 perm1(2) = 3;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
872 perm1(3) = 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
873 perm1(4) = 4;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
874 img = img.permute (perm1);
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
875
31120
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
876 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
877 tile_width * tiles_across,
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
878 tile_height * tiles_down));
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
879
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
880 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
881 || 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
882 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
883 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
884
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
885 perm2(0) = 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
886 perm2(1) = 1;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
887 perm2(2) = 0;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
888 img = img.permute (perm2);
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
889 }
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
890 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
891 {
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
892 perm1(0) = 0;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
893 perm1(1) = 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
894 perm1(2) = 1;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
895 perm1(3) = 3;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
896 perm1(4) = 4;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
897 img = img.permute (perm1);
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
898
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
899 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
900 tile_height * tiles_down,
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
901 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
902
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
903 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
904 || 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
905 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
906 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
907
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
908 perm2(0) = 1;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
909 perm2(1) = 0;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
910 perm2(2) = 2;
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
911 img = img.permute (perm2);
46bb98cec195 Tiff read: implemented all cases for tiled images using matrix operations
magedrifaat <magedrifaat@gmail.com>
parents: 31119
diff changeset
912 }
31118
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
913
f8be3654caef Tiff read: Support for tiled images with normal planar configuration
magedrifaat <magedrifaat@gmail.com>
parents: 31117
diff changeset
914 return octave_value (img);
31113
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
915 }
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
916
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
917 template <typename T>
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
918 octave_value
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
919 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
920 {
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
921 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
922 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
923 else
a74059523d74 Tiff read: use template to remove repitition in filling matrices
magedrifaat <magedrifaat@gmail.com>
parents: 31112
diff changeset
924 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
925 }
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
926
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
927 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
928 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
929 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
930 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
931 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
932 case 1:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
933 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
934 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
935 case 4:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
936 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
937 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
938 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
939 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
940 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
941 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
942 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
943 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
944 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
945 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
946 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
947 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
948 error ("Unsupported bit depth");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
949 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
950 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
951
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
952 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
953 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
954 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
955 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
956 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
957 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
958 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
959 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
960 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
961 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
962 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
963 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
964 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
965 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
966 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
967 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
968 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
969 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
970 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
971 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
972
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
973 octave_value
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
974 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
975 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
976 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
977 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
978 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
979 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
980 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
981 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
982 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
983 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
984 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
985 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
986 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
987
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
988 template <typename T>
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
989 octave_value
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
990 make_array (void *data, dim_vector& arr_dims)
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
991 {
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
992 typedef typename T::element_type P;
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
993
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
994 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
995 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
996 {
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
997 arr(i) = (reinterpret_cast<P *> (data))[i];
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
998 }
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
999 return octave_value (arr);
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1000 }
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1001
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1002 octave_value
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1003 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
1004 bool convert_to_double = false)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1005 {
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1006 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
1007 switch (tag_datatype)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
1008 {
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1009 case TIFF_BYTE:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1010 case TIFF_UNDEFINED:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1011 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1012 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
1013 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1014 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1015 case TIFF_ASCII:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1016 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1017 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
1018 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1019 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1020 case TIFF_SHORT:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1021 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1022 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
1023 break;
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 case TIFF_LONG:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1026 case TIFF_IFD:
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 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
1029 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1030 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1031 case TIFF_LONG8:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1032 case TIFF_IFD8:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1033 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1034 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
1035 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1036 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1037 case TIFF_RATIONAL:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1038 case TIFF_SRATIONAL:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1039 case TIFF_FLOAT:
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<FloatNDArray> (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_SBYTE:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1045 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1046 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
1047 break;
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1048 }
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1049 case TIFF_SSHORT:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1050 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1051 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
1052 break;
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 case TIFF_SLONG:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1055 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1056 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
1057 break;
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 case TIFF_SLONG8:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1060 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1061 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
1062 break;
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 case TIFF_DOUBLE:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1065 {
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1066 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
1067 break;
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 default:
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1070 error ("Unsupported tag data type");
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
1071 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1072
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1073 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
1074 retval = retval.as_double ();
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1075 return retval;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1076 }
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
1077
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1078 octave_value
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1079 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
1080 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1081 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
1082
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1083 // TIFFFieldReadCount returns VARIABLE for some scalar tags
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1084 // (e.g. Compression) But TIFFFieldPassCount seems consistent
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1085 // 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
1086 // 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
1087 if (TIFFFieldPassCount (fip))
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1088 error ("Unsupported tag");
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1089
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1090 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
1091
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1092 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
1093 = 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
1094 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
1095 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
1096 {
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
1097 // 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
1098 // 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
1099 // 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
1100 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
1101 *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
1102 }
7349994f30f8 Tiff: fixed the first test to use a single-pixel image
magedrifaat <magedrifaat@gmail.com>
parents: 31130
diff changeset
1103 else
31181
8a4ef572077d __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr.
magedrifaat <magedrifaat@gmail.com>
parents: 31180
diff changeset
1104 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
1105
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1106 // 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
1107 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
1108 TIFFFieldDataType (fip),
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1109 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
1110
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1111 return tag_data_ov;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1112 }
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
1113
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1114 octave_value
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1115 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
1116 bool convert_to_double = false)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1117 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1118 void *data;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1119 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
1120
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1121 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
1122 convert_to_double);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1123 }
31097
75ab26f147a5 getTag: Implemented single array tags, only multi-array and special tags are unimplemented
magedrifaat <magedrifaat@gmail.com>
parents: 31096
diff changeset
1124
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1125 octave_value
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1126 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
1127 {
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1128 octave_value tag_data_ov;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1129 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
1130
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1131 switch (tag_id)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
1132 {
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1133 case TIFFTAG_STRIPBYTECOUNTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1134 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
1135 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
1136 TIFFNumberOfStrips (tif));
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1137 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1138 case TIFFTAG_TILEBYTECOUNTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1139 case TIFFTAG_TILEOFFSETS:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1140 tag_data_ov
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1141 = 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
1142 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1143 case TIFFTAG_YCBCRCOEFFICIENTS:
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1144 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
1145 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1146 case TIFFTAG_REFERENCEBLACKWHITE:
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1147 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
1148 break;
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1149 case TIFFTAG_GRAYRESPONSECURVE:
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1150 {
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1151 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
1152 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
1153 &bits_per_sample))
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1154 error ("Failed to obtain the bit depth");
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1155
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1156 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
1157 1<<bits_per_sample, true);
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1158 break;
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1159 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1160 case TIFFTAG_COLORMAP:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1161 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1162 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
1163 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
1164 &bits_per_sample))
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1165 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
1166
a68f2dadafee Tiff.m: added all remaining tests for implemented features.
magedrifaat <magedrifaat@gmail.com>
parents: 31142
diff changeset
1167 // 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
1168 // be 8 or 16 only.
a68f2dadafee Tiff.m: added all remaining tests for implemented features.
magedrifaat <magedrifaat@gmail.com>
parents: 31142
diff changeset
1169 if (bits_per_sample > 16)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1170 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
1171
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1172 uint32_t count = 1 << bits_per_sample;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1173 uint16_t *red, *green, *blue;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1174 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
1175 &red, &green, &blue));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1176
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1177 // 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
1178 // them together
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1179 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
1180 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
1181 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
1182 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1183 TIFFFieldDataType(fip))
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1184 .uint16_array_value ()
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1185 .reshape (col_dims));
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1186 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
1187 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1188 TIFFFieldDataType(fip))
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1189 .uint16_array_value ()
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1190 .reshape (col_dims));
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1191 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
1192 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1193 TIFFFieldDataType(fip))
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1194 .uint16_array_value ()
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1195 .reshape (col_dims));
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1196
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1197 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
1198 // 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
1199 mat_out /= UINT16_MAX;
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1200
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1201 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
1202 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1203 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1204 case TIFFTAG_TRANSFERFUNCTION:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1205 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1206 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
1207 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
1208 &samples_per_pixel))
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1209 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
1210
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1211 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
1212 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
1213 &bits_per_sample))
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1214 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
1215
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1216 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
1217 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
1218 // 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
1219 // 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
1220 // 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
1221 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
1222 &ch1, &ch2, &ch3));
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1223 if (ch2 == NULL)
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1224 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
1225 TIFFFieldDataType (fip), true);
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1226 else
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1227 {
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1228 // 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
1229 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
1230 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
1231 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
1232 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1233 TIFFFieldDataType (fip))
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1234 .array_value ()
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1235 .reshape (col_dims);
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1236 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
1237 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1238 TIFFFieldDataType (fip))
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1239 .array_value ()
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1240 .reshape (col_dims);
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1241 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
1242 count,
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1243 TIFFFieldDataType (fip))
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1244 .array_value ()
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1245 .reshape (col_dims);
31114
9dead1249449 Tiff getTag: fixed matrix shape for ColorMap and TransferFunction
magedrifaat <magedrifaat@gmail.com>
parents: 31113
diff changeset
1246
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1247 tag_data_ov
31184
86f91ea7a642 __tiff__.cc (get_field_data): fixed return type for some tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31183
diff changeset
1248 = 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
1249 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1250 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1251 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1252 case TIFFTAG_PAGENUMBER:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1253 case TIFFTAG_HALFTONEHINTS:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1254 case TIFFTAG_DOTRANGE:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1255 case TIFFTAG_YCBCRSUBSAMPLING:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1256 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1257 uint16_t tag_part1, tag_part2;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1258 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
1259 &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
1260
31130
8475bdb70457 Tiff getTag: changed ColorMap to use Array::cat instead of memcpy
magedrifaat <magedrifaat@gmail.com>
parents: 31129
diff changeset
1261 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
1262 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
1263 = 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
1264 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
1265 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
1266 = 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
1267 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
1268
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1269 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
1270 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1271 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1272 case TIFFTAG_SUBIFD:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1273 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1274 uint16_t count;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1275 uint64_t *offsets;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1276 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
1277 &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
1278 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
1279 TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1280 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1281 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1282 case TIFFTAG_EXTRASAMPLES:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1283 {
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1284 uint16_t count;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1285 uint16_t *types;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1286 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
1287 &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
1288 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
1289 TIFFFieldDataType (fip));
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1290 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1291 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1292 case TIFFTAG_XMLPACKET:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1293 case TIFFTAG_RICHTIFFIPTC:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1294 case TIFFTAG_PHOTOSHOP:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1295 case TIFFTAG_ICCPROFILE:
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1296 {
31186
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1297 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
1298 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
1299 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
1300 &count, &data));
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1301 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
1302 // 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
1303 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
1304 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
1305 break;
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
1306 }
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1307 // 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
1308 // 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
1309 case TIFFTAG_ZIPQUALITY:
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
1310 case TIFFTAG_SGILOGDATAFMT:
31106
f5a88c0a61ab Support for GrayResponseCurve and GrayResponseUnit tags
magedrifaat <magedrifaat@gmail.com>
parents: 31105
diff changeset
1311 case TIFFTAG_GRAYRESPONSEUNIT:
31103
76b21bed2920 Undocumented and unimplemented tags are explicilty mentioned and handled
magedrifaat <magedrifaat@gmail.com>
parents: 31102
diff changeset
1312 {
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1313 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
1314 break;
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1315 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1316 default:
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1317 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
1318 }
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1319
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
1320 return tag_data_ov;
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
1321 }
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1322
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1323 void
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1324 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
1325 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1326 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
1327
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1328 // 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
1329 // 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
1330 if (TIFFFieldPassCount (fip))
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1331 error ("Unsupported tag");
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1332
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1333 TIFFDataType tag_datatype = TIFFFieldDataType (fip);
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1334
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1335 // 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
1336 // except for strings
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1337 if (tag_datatype == TIFF_ASCII)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1338 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1339 if (! tag_ov.is_string ())
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1340 error ("Expected string for ascii tag");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1341 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
1342 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
1343 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
1344
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1345 switch (tag_datatype)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1346 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1347 case TIFF_BYTE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1348 case TIFF_UNDEFINED:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1349 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
1350 break;
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1351 case TIFF_ASCII:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1352 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
1353 break;
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1354 case TIFF_SHORT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1355 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
1356 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1357 case TIFF_LONG:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1358 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
1359 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1360 case TIFF_LONG8:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1361 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
1362 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1363 case TIFF_RATIONAL:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1364 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
1365 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1366 case TIFF_SBYTE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1367 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
1368 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1369 case TIFF_SSHORT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1370 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
1371 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1372 case TIFF_SLONG:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1373 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
1374 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1375 case TIFF_SLONG8:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1376 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
1377 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1378 case TIFF_FLOAT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1379 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
1380 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1381 case TIFF_DOUBLE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1382 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
1383 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1384 case TIFF_SRATIONAL:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1385 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
1386 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1387 case TIFF_IFD:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1388 case TIFF_IFD8:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1389 error ("Unimplemented IFFD data type");
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 default:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1392 error ("Unsupported tag data type");
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1393 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1394 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1395
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1396 template <typename T>
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1397 void
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1398 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
1399 {
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1400 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
1401
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1402 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
1403 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
1404 }
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1405
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1406 void
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1407 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
1408 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
1409 {
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1410 uint32_t tag_id = TIFFFieldTag (fip);
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1411 TIFFDataType tag_datatype = TIFFFieldDataType (fip);
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1412
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1413 // 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
1414 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
1415 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
1416
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1417 // 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
1418 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
1419 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
1420
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1421 switch (tag_datatype)
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1422 {
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1423 case TIFF_BYTE:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1424 case TIFF_UNDEFINED:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1425 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
1426 tag_ov.uint8_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1427 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1428 case TIFF_SHORT:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1429 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
1430 tag_ov.uint16_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1431 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1432 case TIFF_LONG:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1433 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
1434 tag_ov.uint32_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1435 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1436 case TIFF_LONG8:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1437 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
1438 tag_ov.uint64_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1439 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1440 case TIFF_RATIONAL:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1441 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
1442 tag_ov.float_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1443 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1444 case TIFF_SBYTE:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1445 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
1446 tag_ov.int8_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1447 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1448 case TIFF_SSHORT:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1449 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
1450 tag_ov.int16_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1451 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1452 case TIFF_SLONG:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1453 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
1454 tag_ov.int32_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1455 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1456 case TIFF_SLONG8:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1457 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
1458 tag_ov.int64_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1459 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1460 case TIFF_FLOAT:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1461 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
1462 tag_ov.float_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1463 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1464 case TIFF_DOUBLE:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1465 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
1466 tag_ov.array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1467 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1468 case TIFF_SRATIONAL:
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1469 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
1470 tag_ov.float_array_value ());
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1471 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1472 case TIFF_IFD:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1473 case TIFF_IFD8:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1474 error ("Unimplemented IFFD data type");
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1475 break;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1476 default:
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1477 error ("Unsupported tag data type");
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1478 }
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1479 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1480
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1481 void
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1482 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
1483 {
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1484 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
1485
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1486 switch (tag_id)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1487 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1488 case TIFFTAG_YCBCRCOEFFICIENTS:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1489 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
1490 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1491 case TIFFTAG_REFERENCEBLACKWHITE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1492 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
1493 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1494 case TIFFTAG_GRAYRESPONSECURVE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1495 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1496 uint16_t bits_per_sample;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1497 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE,
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1498 &bits_per_sample))
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1499 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
1500
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1501 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
1502 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1503 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1504 case TIFFTAG_COLORMAP:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1505 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1506 uint16_t bits_per_sample;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1507 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE,
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1508 &bits_per_sample))
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1509 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
1510
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1511 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
1512 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
1513
31165
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1514 // 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
1515 // be 8 or 16 only.
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1516 if (bits_per_sample > 16)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1517 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
1518
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1519 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
1520
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1521 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
1522 || 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
1523 || 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
1524 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
1525
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1526 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
1527 array_data *= UINT16_MAX;
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1528 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
1529 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
1530 = 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
1531 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
1532 data_ptr + 2 * count))
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1533 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
1534 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1535 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1536 case TIFFTAG_TRANSFERFUNCTION:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1537 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1538 uint16_t samples_per_pixel;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1539 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_SAMPLESPERPIXEL,
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1540 &samples_per_pixel))
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1541 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
1542
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1543 uint16_t bits_per_sample;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1544 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE,
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1545 &bits_per_sample))
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1546 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
1547
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1548 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
1549
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1550 // 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
1551 // 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
1552 // 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
1553 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
1554
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1555 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
1556 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
1557
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1558 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
1559 = 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
1560 if (samples_per_pixel == 1)
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1561 {
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1562 if (! TIFFSetField (tif, tag_id, data_ptr))
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1563 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
1564 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1565 else
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1566 {
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1567 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
1568 data_ptr + 2 * count))
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1569 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
1570 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1571 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1572 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1573 case TIFFTAG_PAGENUMBER:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1574 case TIFFTAG_HALFTONEHINTS:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1575 case TIFFTAG_DOTRANGE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1576 case TIFFTAG_YCBCRSUBSAMPLING:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1577 {
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1578 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
1579 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
1580 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
1581
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1582 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
1583 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
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_SUBIFD:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1587 {
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
1588 // 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
1589 // 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
1590 // 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
1591 // 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
1592 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
1593 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
1594 = 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
1595 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
1596 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
1597 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
1598 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1599 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1600 case TIFFTAG_EXTRASAMPLES:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1601 {
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1602 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
1603 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
1604 &samples_per_pixel))
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1605 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
1606
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1607 uint16NDArray data_array = tag_ov.uint16_array_value ();
31200
4e8152ccc61a libtinterp/corefcn/__tiff__.cc (set_field_data): fixed bug for ExtraSamples.
magedrifaat <magedrifaat@gmail.com>
parents: 31199
diff changeset
1608
4e8152ccc61a libtinterp/corefcn/__tiff__.cc (set_field_data): fixed bug for ExtraSamples.
magedrifaat <magedrifaat@gmail.com>
parents: 31199
diff changeset
1609 if (data_array.numel () > samples_per_pixel)
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1610 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
1611
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1612 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
1613 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
1614 data_array.data ()))
31167
f91cd5ceaae6 Tiff setTag: added support for special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31166
diff changeset
1615 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
1616 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1617 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1618 case TIFFTAG_XMLPACKET:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1619 case TIFFTAG_RICHTIFFIPTC:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1620 case TIFFTAG_PHOTOSHOP:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1621 case TIFFTAG_ICCPROFILE:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1622 {
31186
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
1623 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
1624 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
1625 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
1626 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
1627 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1628 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1629 // 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
1630 // 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
1631 case TIFFTAG_ZIPQUALITY:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1632 case TIFFTAG_SGILOGDATAFMT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1633 case TIFFTAG_GRAYRESPONSEUNIT:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1634 {
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1635 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
1636 break;
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1637 }
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1638 default:
48d46f7a640b Tiff setTag: handled scalar tags with the correct data type.
magedrifaat <magedrifaat@gmail.com>
parents: 31164
diff changeset
1639 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
1640 }
31166
b8b6cc05c8ea Tiff setTag: added support for tags with array values.
magedrifaat <magedrifaat@gmail.com>
parents: 31165
diff changeset
1641
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
1642 }
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1643
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1644 template <typename T>
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1645 void
31133
e9925d528428 Tiff writeEncodedStrip: used octave_value functions instead of type_name
magedrifaat <magedrifaat@gmail.com>
parents: 31131
diff changeset
1646 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
1647 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
1648 {
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1649 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
1650 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
1651 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
1652
31127
0d9633ee715e Tiff: fixed a bug where the default value of some tags was ignored
magedrifaat <magedrifaat@gmail.com>
parents: 31126
diff changeset
1653 // 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
1654 // 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
1655 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
1656 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
1657
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1658 // 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
1659 strip_no--;
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1660
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1661 uint32_t strip_count = TIFFNumberOfStrips (tif);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1662 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
1663 rows_in_strip, image_data);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1664
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1665 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
1666 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
1667 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
1668 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
1669 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
1670 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
1671 else
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1672 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
1673
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1674 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
1675 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
1676 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
1677 strip_data.dim1 ());
31137
233130c0b1f6 Tiff writeEncodedStrip: changed strip dimension check behavior to mimic matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31136
diff changeset
1678
31145
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1679 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
1680 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
1681 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
1682 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
1683
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1684 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
1685 {
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1686 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
1687 && 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
1688 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
1689 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
1690 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
1691 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
1692 && strip_data.dim3 () > 1)
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1693 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
1694 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
1695 }
2e11f9cb30b8 Tiff writeEncodedStrip: added warning for input data larger than the size of the strip.
magedrifaat <magedrifaat@gmail.com>
parents: 31144
diff changeset
1696
31137
233130c0b1f6 Tiff writeEncodedStrip: changed strip dimension check behavior to mimic matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31136
diff changeset
1697 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
1698
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1699 // 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
1700 // 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
1701 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
1702 perm(0) = 2;
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1703 perm(1) = 1;
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1704 perm(2) = 0;
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1705 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
1706
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1707 uint8_t *data_u8
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1708 = 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
1709 if (image_data->bits_per_sample == 8
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1710 || image_data->bits_per_sample == 16
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1711 || image_data->bits_per_sample == 32
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1712 || image_data->bits_per_sample == 64)
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1713 {
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1714 // 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
1715 // can be smaller in size
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1716 tsize_t strip_size = strip_data.numel ()
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1717 * 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
1718 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
1719 error ("Failed to write strip data to image");
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1720
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1721 }
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1722 else if (image_data->bits_per_sample == 1)
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1723 {
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1724 if (image_data->samples_per_pixel != 1)
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1725 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
1726
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1727 // 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
1728 // 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
1729 std::unique_ptr<uint8_t []> strip_ptr
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1730 = std::make_unique<uint8_t []> (TIFFStripSize (tif));
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1731 uint8_t *strip_buf = strip_ptr.get ();
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1732 // 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
1733 // 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
1734 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
1735 // Packing the pixel data into bits
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1736 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
1737 {
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1738 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
1739 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1740 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
1741 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1742 shift = 7 - shift;
31144
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1743 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
1744 }
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1745 data_u8 += image_data->width;
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1746 }
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1747 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
1748 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
1749 error ("Failed to write strip data to image");
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1750 }
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1751 else
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1752 {
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1753 error ("Unsupported bit depth");
8ba9f2326ee9 Tiff writeEncodedStrip: added support for BiLevel images
magedrifaat <magedrifaat@gmail.com>
parents: 31143
diff changeset
1754 }
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1755 }
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
1756
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1757 template <typename T>
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1758 void
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1759 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
1760 tiff_image_data *image_data)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1761 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1762 uint32_t tile_width, tile_height;
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
1763 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
1764
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1765 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
1766 error ("Tile number out of bounds");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1767
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1768 if (tile_data.dim1 () > tile_height)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1769 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
1770 tile_height, tile_data.dim1 ());
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1771 if (tile_data.dim2 () > tile_width)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1772 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
1773 tile_width, tile_data.dim2 ());
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1774 if (tile_data.ndims () > 2)
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 if (image_data->planar_configuration == PLANARCONFIG_CONTIG
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1777 && 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
1778 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
1779 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
1780 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
1781 && tile_data.dim3 () > 1)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1782 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
1783 1, tile_data.dim3 ());
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1784 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1785
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1786 dim_vector tile_dimensions;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1787 if (image_data->planar_configuration == PLANARCONFIG_CONTIG)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1788 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
1789 image_data->samples_per_pixel);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1790 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
1791 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
1792 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1793 error ("Planar configuration not supported");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1794
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1795 tile_data.resize (tile_dimensions);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1796 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
1797 perm(0) = 2;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1798 perm(1) = 1;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1799 perm(2) = 0;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1800 tile_data = tile_data.permute (perm);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1801
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1802 // 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
1803 tile_no--;
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1804 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
1805 if (image_data->bits_per_sample == 8
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1806 || image_data->bits_per_sample == 16
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1807 || image_data->bits_per_sample == 32
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1808 || image_data->bits_per_sample == 64)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1809 {
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
1810 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
1811 TIFFTileSize (tif)) == -1)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1812 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
1813
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1814 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1815 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
1816 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1817 if (image_data->samples_per_pixel != 1)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1818 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
1819
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1820 // 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
1821 // 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
1822 std::unique_ptr<uint8_t []> tile_ptr
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1823 = std::make_unique<uint8_t []> (TIFFTileSize (tif));
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1824 uint8_t *tile_buf = tile_ptr.get ();
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1825 // Packing the pixel data into bits
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1826 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
1827 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1828 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
1829 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1830 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
1831 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
1832 shift = 7 - shift;
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1833 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
1834 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1835 data_u8 += tile_width;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1836 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1837 if (TIFFWriteEncodedTile (tif, tile_no, tile_buf,
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1838 TIFFTileSize (tif)) == -1)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1839 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
1840 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1841 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1842 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1843 error ("Unsupported bit depth");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1844 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1845 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1846
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1847 template <typename T>
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1848 void
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1849 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
1850 tiff_image_data *image_data)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1851 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1852 if (image_data->is_tiled)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1853 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
1854 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1855 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
1856 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1857
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1858 void
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1859 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
1860 octave_value data_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1861 tiff_image_data *image_data)
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1862 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1863 switch (image_data->bits_per_sample)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1864 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1865 case 1:
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1866 // 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
1867 // element strip
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1868 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
1869 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
1870 data_ov.bool_array_value (),
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1871 image_data);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1872 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1873 error ("Expected logical matrix for BiLevel image");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1874 break;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1875 case 8:
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1876 if (data_ov.is_uint8_type ())
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1877 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
1878 data_ov.uint8_array_value (),
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1879 image_data);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1880 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1881 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
1882 break;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1883 case 16:
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1884 if (data_ov.is_uint16_type ())
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1885 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
1886 data_ov.uint16_array_value (),
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1887 image_data);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1888 else
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1889 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
1890 break;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1891 case 32:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1892 if (data_ov.is_uint32_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1893 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
1894 data_ov.uint32_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1895 image_data);
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1896 else
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1897 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
1898 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1899 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1900 if (data_ov.is_uint64_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1901 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
1902 data_ov.uint64_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1903 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1904 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1905 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
1906 break;
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1907 default:
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1908 error ("Unsupported bit depth");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1909 }
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
1910 }
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1911
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1912 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1913 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
1914 octave_value data_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1915 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1916 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1917 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1918 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1919 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1920 if (data_ov.is_int8_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1921 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
1922 data_ov.int8_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1923 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1924 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1925 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
1926 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1927 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1928 if (data_ov.is_int16_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1929 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
1930 data_ov.int16_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1931 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1932 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1933 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
1934 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1935 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1936 if (data_ov.is_int32_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1937 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
1938 data_ov.int32_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1939 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1940 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1941 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
1942 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1943 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1944 if (data_ov.is_int64_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1945 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
1946 data_ov.int64_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1947 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1948 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1949 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
1950 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1951 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1952 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
1953 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1954 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1955
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1956 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1957 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
1958 octave_value data_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1959 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1960 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1961 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1962 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1963 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1964 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
1965 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
1966 data_ov.float_array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1967 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1968 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1969 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
1970 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1971 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1972 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
1973 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
1974 data_ov.array_value (),
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1975 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1976 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1977 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
1978 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1979 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1980 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
1981 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1982 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1983
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1984 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1985 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
1986 octave_value data_ov,
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1987 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1988 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1989
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1990 // 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
1991 // 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
1992 // the file
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1993 uint16_t sample_format;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1994 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
1995 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
1996
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1997 switch (sample_format)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1998 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
1999 case 1:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2000 case 4:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2001 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
2002 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2003 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2004 case 2:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2005 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
2006 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2007 case 3:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2008 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
2009 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2010 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2011 error ("Unsupported 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 }
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
2014
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2015 template <typename T>
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2016 void
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2017 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
2018 {
31164
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2019 // ASSUMES pixel data dimensions are already validated
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2020
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2021 typedef typename T::element_type P;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2022
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2023 // 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
2024 // 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
2025 // 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
2026 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
2027 if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2028 {
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2029 perm(0) = 1;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2030 perm(1) = 0;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2031 perm(2) = 2;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2032 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2033 else
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 perm(0) = 2;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2036 perm(1) = 1;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2037 perm(2) = 0;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2038 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2039 pixel_data = pixel_data.permute (perm);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2040
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2041 uint32_t row_per_strip;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2042 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &row_per_strip))
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2043 error ("Failed to obtain the RowPerStrip tag");
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2044
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2045 // 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
2046 if (row_per_strip > image_data->height)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2047 row_per_strip = image_data->height;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2048
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2049 uint8_t *pixel_fvec
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2050 = 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
2051 uint32_t strip_count = TIFFNumberOfStrips (tif);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2052 tsize_t strip_size;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2053 uint32_t rows_in_strip;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2054 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
2055 {
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2056 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
2057 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
2058 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
2059 || 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
2060 || 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
2061 || 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
2062 {
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2063 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
2064 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
2065 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
2066 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
2067 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
2068 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
2069 }
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2070 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
2071 {
31156
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2072 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
2073 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
2074
31154
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2075 // 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
2076 // 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
2077 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
2078 = 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
2079 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
2080 // 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
2081 // 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
2082 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
2083 // 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
2084 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
2085 {
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2086 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
2087 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2088 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
2089 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2090 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
2091 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
2092 |= 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
2093 }
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2094 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
2095 }
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2096 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
2097 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
2098 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
2099 }
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2100 else
828b7cc9aa36 Tiff write: added support for BiLevel stripped images and added unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31153
diff changeset
2101 error ("Unsupported bit depth");
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2102 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2103 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2104
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2105 template <typename T>
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2106 void
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2107 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
2108 {
31164
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2109 // ASSUMES pixel data dimensions are already validated
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2110
31155
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2111 uint32_t tile_width, tile_height;
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2112 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
2113
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2114 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
2115 / tile_width;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2116 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
2117 / tile_height;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2118
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2119 // 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
2120 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
2121 tiles_across * tile_width,
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2122 image_data->samples_per_pixel);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2123 pixel_data.resize (padded_dims);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2124
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2125 // 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
2126 // 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
2127 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
2128 image_data->samples_per_pixel);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2129 pixel_data = pixel_data.reshape (tiled_dims);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2130
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2131 // 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
2132 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
2133 if (image_data->planar_configuration == PLANARCONFIG_SEPARATE)
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2134 {
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2135 // 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
2136 // 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
2137 // 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
2138 // 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
2139 // rows and each row contains columns.
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2140 // So the order for LibTIFF is:
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2141 // 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
2142 // 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
2143 // 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
2144 perm(0) = 2;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2145 perm(1) = 0;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2146 perm(2) = 3;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2147 perm(3) = 1;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2148 perm(4) = 4;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2149 }
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2150 else
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2151 {
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2152 // 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
2153 // 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
2154 // 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
2155 // column contains samples.
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2156 // So the order for LibTIFF is:
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2157 // 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
2158 // 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
2159 // 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
2160 perm(0) = 4;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2161 perm(1) = 2;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2162 perm(2) = 0;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2163 perm(3) = 3;
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2164 perm(4) = 1;
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 pixel_data = pixel_data.permute (perm);
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2167
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2168 uint8_t *pixel_fvec
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2169 = 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
2170 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
2171 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
2172
31155
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2173 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
2174 {
31156
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2175 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
2176 || 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
2177 || 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
2178 || 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
2179 {
31186
90eccc78d958 __tiff__.cc (get_field_data, set_field_data): added support for complex tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31185
diff changeset
2180 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
2181 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
2182 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
2183 }
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2184 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
2185 {
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2186 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
2187 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
2188
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2189 // 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
2190 // 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
2191 // constant size buffers
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2192 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
2193 = 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
2194 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
2195 // 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
2196 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
2197 {
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2198 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
2199 {
31183
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2200 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
2201 if (TIFFIsMSB2LSB (tif))
6ab628dfe2a0 __tif__.cc: added support for BiLevel Images with reversed bit ordering.
magedrifaat <magedrifaat@gmail.com>
parents: 31182
diff changeset
2202 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
2203 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
2204 |= 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
2205 }
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2206 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
2207 }
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2208 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
2209 TIFFTileSize (tif)) == -1)
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2210 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
2211 }
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2212 else
1e633a093faa Tiff write: added support for logical tile images and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31155
diff changeset
2213 error ("Unsupported bit depth");
31155
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2214 }
a30b144bc10b Tiff write: added support for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31154
diff changeset
2215
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2216 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2217
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2218 template <typename T>
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2219 void
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2220 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
2221 {
31168
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2222 // 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
2223 // way for matlab compatibility.
27ed758c1688 Tiff setTag: fixed bug for rational tags and special-case tags.
magedrifaat <magedrifaat@gmail.com>
parents: 31167
diff changeset
2224 // 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
2225 // 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
2226 // 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
2227 // 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
2228 // 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
2229 // 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
2230 // 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
2231 // 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
2232 // produced instead.
31164
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2233 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
2234 || (pixel_data.ndims () > 2
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2235 && 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
2236 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
2237 image_data->samples_per_pixel);
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2238
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2239 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
2240 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
2241 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
2242 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
2243
3155aa74c62e Tiff write: modified handling incorrect dimensions to match matlab.
magedrifaat <magedrifaat@gmail.com>
parents: 31163
diff changeset
2244 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
2245 image_data->samples_per_pixel));
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2246
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2247 if (image_data->is_tiled)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2248 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
2249 else
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2250 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
2251
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2252 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2253
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2254 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2255 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
2256 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2257 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2258 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2259 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2260 case 1:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2261 // 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
2262 // pixel image
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2263 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
2264 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
2265 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2266 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2267 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
2268 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2269 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2270 if (image_ov.is_uint8_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2271 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
2272 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2273 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2274 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
2275 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2276 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2277 if (image_ov.is_uint16_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2278 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
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 ("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
2282 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2283 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2284 if (image_ov.is_uint32_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2285 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
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 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
2289 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2290 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2291 if (image_ov.is_uint64_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2292 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
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 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
2296 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2297 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2298 error ("Unsupported bit depth");
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2299 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2300 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2301
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2302 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2303 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
2304 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2305 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2306 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2307 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2308 case 8:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2309 if (image_ov.is_int8_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2310 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
2311 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2312 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2313 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
2314 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2315 case 16:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2316 if (image_ov.is_int16_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2317 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
2318 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2319 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2320 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
2321 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2322 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2323 if (image_ov.is_int32_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2324 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
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 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
2328 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2329 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2330 if (image_ov.is_int64_type ())
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2331 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
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 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
2335 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2336 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2337 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
2338 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2339 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2340
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2341 void
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2342 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
2343 tiff_image_data *image_data)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2344 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2345 switch (image_data->bits_per_sample)
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2346 {
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2347 case 32:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2348 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
2349 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
2350 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2351 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2352 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
2353 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2354 case 64:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2355 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
2356 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
2357 image_data);
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2358 else
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2359 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
2360 break;
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2361 default:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2362 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
2363 }
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2364 }
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
2365
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2366 octave_value_list
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2367 slice_rgba (uint8NDArray rgba_data)
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2368 {
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2369 Array<idx_vector> idx (dim_vector (3, 1));
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2370 idx(0) = idx_vector (':');
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2371 idx(1) = idx_vector (':');
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2372 idx(2) = idx_vector (0, 3);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2373 uint8NDArray rgb = uint8NDArray (rgba_data.index (idx));
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2374 idx(2) = idx_vector (3);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2375 uint8NDArray alpha = uint8NDArray (rgba_data.index (idx));
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2376
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2377 octave_value_list retval (2);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2378 retval(0) = octave_value (rgb);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2379 retval(1) = octave_value (alpha);
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2380 return retval;
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2381 }
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2382 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2383
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2384 DEFUN (__open_tiff__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2385 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2386 @deftypefn {} {@var{t} =} __open_tiff__ (@var{fname})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2387 @deftypefnx {} {@var{t} =} __open_tiff__ (@var{fname}, @var{mode})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2388 Open a tiff file and return its handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2389
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2390 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2391 Use @code{Tiff} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2392
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2393 @end deftypefn */)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2394 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2395 #if defined (HAVE_TIFF)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2396 int nargin = args.length ();
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2397
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2398 if (nargin < 1 || nargin > 2)
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2399 print_usage ();
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2400
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2401 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
2402 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
2403
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2404 if (nargin == 2)
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2405 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
2406
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2407 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
2408 "r", "w", "w8", "a", "r+"
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2409 };
31123
0bcb35909ef4 Tiff open: removed support for rh mode and marked r+ as not yet supported
magedrifaat <magedrifaat@gmail.com>
parents: 31122
diff changeset
2410
31142
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2411 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
2412 == supported_modes.cend ())
31176
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2413 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
2414
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
2415 // 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
2416 // 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
2417 // 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
2418 // 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
2419 bool is_rplus = false;
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2420 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
2421 {
31176
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2422 is_rplus = true;
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2423 mode = "a";
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
2424 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2425
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2426 // 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
2427 // 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
2428 // 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
2429 mode = mode + 'c';
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2430
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2431 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2432
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2433 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
2434
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2435 if (! tif)
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2436 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
2437
c07461ca34d6 Tiff: add support for oppening tiff files in r+ mode
magedrifaat <magedrifaat@gmail.com>
parents: 31175
diff changeset
2438 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
2439 error ("Failed to open Tiff file\n");
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2440
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2441 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
2442 return octave_value_list (tiff_ov);
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2443 #else
31128
524cb3106432 __tiff__.cc: handled compiler warnings for unused params and old-style casts.
magedrifaat <magedrifaat@gmail.com>
parents: 31127
diff changeset
2444 octave_unused_parameter (args);
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2445 err_disabled_feature ("Tiff", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2446 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2447 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2448
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2449
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2450 DEFUN (__close_tiff__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2451 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2452 @deftypefn {} __close_tiff__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2453 Close the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2454
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2455 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2456 Use @code{Tiff.close} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2457
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2458 @end deftypefn */)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2459 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2460 #if defined (HAVE_TIFF)
31101
f24d7bcad2d3 Partially fixed formatting of C++ code
magedrifaat <magedrifaat@gmail.com>
parents: 31099
diff changeset
2461 int nargin = args.length ();
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2462
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2463 if (nargin == 0)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2464 print_usage ();
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2465
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2466 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
2467 = 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
2468
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2469 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2470
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2471 tiff_handle->close ();
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
2472
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2473 return octave_value_list ();
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2474 #else
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2475 octave_unused_parameter (args);
31104
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, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2482 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2483 @deftypefn {} {@var{tagValue} =} __tiff_get_tag__ (@var{t}, @var{tag_id})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2484 @deftypefnx {} {@var{tagValue} =} __tiff_get_tag__ (@var{t}, @var{tag_name})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2485 Get the value of the tag from the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2486
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2487 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2488 Use @code{Tiff.getTag} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2489
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2490 @end deftypefn */)
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2491 {
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2492 #if defined (HAVE_TIFF)
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2493 int nargin = args.length ();
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2494
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2495 if (nargin < 2)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2496 print_usage ();
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2497
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2498 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
2499 = 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
2500
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2501 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
2502
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2503 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2504
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2505 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
2506
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2507 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
2508
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2509 if (args(1).is_string ())
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2510 {
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
2511 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
2512 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
2513 if (! fip)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2514 error ("Tiff tag not found");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2515 }
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2516 else
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2517 {
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
2518 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
2519 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
2520
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2521 if (! fip)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2522 error ("Tiff tag not found");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2523 }
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2524
31117
530dbd1d6b07 Tiff getTag: fixed bug for multivalued tags where only first item is returned
magedrifaat <magedrifaat@gmail.com>
parents: 31115
diff changeset
2525 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
2526 #else
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2527 octave_unused_parameter (args);
31104
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2528 err_disabled_feature ("getTag", "Tiff");
b5d59c115e52 Use HAVE_TIFF flag to optionally disable Tiff
magedrifaat <magedrifaat@gmail.com>
parents: 31103
diff changeset
2529 #endif
31102
d6ecf0e8838b Add the new code to the octave namespace
magedrifaat <magedrifaat@gmail.com>
parents: 31101
diff changeset
2530 }
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2531
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2532
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2533 DEFUN (__tiff_set_tag__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2534 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2535 @deftypefn {} __tiff_set_tag__ (@var{t}, @var{tag_id}, @var{tag_value})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2536 @deftypefnx {} __tiff_set_tag__ (@var{t}, @var{tag_name}, @var{tag_value})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2537 @deftypefnx {} __tiff_set_tag__ (@var{t}, @var{tag_struct})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2538 Set the value of the tag in the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2539
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2540 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2541 Use @code{Tiff.setTag} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2542
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2543 @end deftypefn */)
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2544 {
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2545 #if defined (HAVE_TIFF)
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2546 int nargin = args.length ();
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2547
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2548 if (nargin == 0)
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2549 print_usage ();
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2550
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2551 if (nargin < 2)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2552 // Since this function accepts varargin from the Octave side, the
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2553 // ommitted arguments are from wrong usage of the setTag method
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2554 print_usage ("Tiff.setTag");
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2555
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2556 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
2557 = 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
2558 check_closed (tiff_handle);
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
2559
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2560 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2561
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2562 TIFF *tif = tiff_handle->get_file ();
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
2563 check_readonly (tif);
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2564
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2565 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
2566 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
2567 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
2568 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
2569 // 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
2570 // 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
2571 // 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
2572 // 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
2573 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
2574 {
31142
97e7ee3b27b7 Tiff setTag: modify the behavior with structs to be compatible with matlab
magedrifaat <magedrifaat@gmail.com>
parents: 31140
diff changeset
2575 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
2576 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
2577 if (! fip)
31140
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2578 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
2579 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
2580 }
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2581 }
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2582 else
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2583 {
31140
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2584 if (nargin < 3)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2585 print_usage ("Tiff.setTag");
31140
5f70efad6e2c Tiff setTag: added support for setting multiple tags at once using structs
magedrifaat <magedrifaat@gmail.com>
parents: 31139
diff changeset
2586
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2587 const TIFFField *fip;
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2588 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
2589 {
31182
4c8b8c400a3b __tiff__.cc (F__set_tag__, F__get_tag__): check for TagID names as well.
magedrifaat <magedrifaat@gmail.com>
parents: 31181
diff changeset
2590 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
2591 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
2592 if (! fip)
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2593 error ("Tiff tag not found");
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2594 }
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2595 else
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2596 {
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2597 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
2598 fip = TIFFFieldWithTag (tif, tag_id);
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2599 if (! fip)
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2600 error ("Tiff tag not found");
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2601 }
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2602
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
2603 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
2604 }
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2605
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2606 return octave_value_list ();
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2607 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
2608 octave_unused_parameter (args);
31124
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2609 err_disabled_feature ("setTag", "Tiff");
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2610 #endif
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2611 }
e8d1cc309bc9 Tiff: added initial implementation of setTag function for scalar tags
magedrifaat <magedrifaat@gmail.com>
parents: 31123
diff changeset
2612
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2613 DEFUN (__tiff_read__, args, nargout,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2614 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2615 @deftypefn {} {@var{imageData} =} __tiff_read__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2616 Read the image data from the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2617
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2618 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2619 Use @code{Tiff.read} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2620
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2621 @end deftypefn */)
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2622 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2623 #if defined (HAVE_TIFF)
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2624 int nargin = args.length ();
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 if (nargin == 0)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2627 print_usage ();
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2628
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2629 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
2630 = 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
2631 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
2632
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2633 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2634
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2635 TIFF *tif = tiff_handle->get_file ();
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2636
31213
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
2637 if (nargout > 1)
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
2638 error ("Tiff: Reading YCbCr image data is not supported");
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2639
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2640 // Obtain all necessary tags
31112
e3d8443585fe Tiff read refactored reading stripped images into a separate function
magedrifaat <magedrifaat@gmail.com>
parents: 31111
diff changeset
2641 // 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
2642 // 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
2643 // 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
2644 // 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
2645 tiff_image_data image_data (tif);
31125
3b775b939de4 Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents: 31124
diff changeset
2646
3b775b939de4 Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents: 31124
diff changeset
2647 uint16_t sample_format;
3b775b939de4 Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents: 31124
diff changeset
2648 if (! TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_format))
3b775b939de4 Tiff read: Added support for floating-point images
magedrifaat <magedrifaat@gmail.com>
parents: 31124
diff changeset
2649 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
2650
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2651 octave_value_list retval;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2652 switch (sample_format)
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2653 {
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2654 case 1:
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2655 case 4:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2656 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
2657 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2658 case 2:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2659 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
2660 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2661 case 3:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2662 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
2663 break;
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2664 default:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
2665 error ("Unsupported sample format");
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2666 }
31110
2daeeff33980 Tiff read fixed segfault bug for compressed images
magedrifaat <magedrifaat@gmail.com>
parents: 31109
diff changeset
2667
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2668 return retval;
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2669 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
2670 octave_unused_parameter (args);
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
2671 octave_unused_parameter (nargout);
31109
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2672 err_disabled_feature ("read", "Tiff");
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2673 #endif
06814e8b5a29 add function to read an entire image
magedrifaat <magedrifaat@gmail.com>
parents: 31106
diff changeset
2674 }
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
2675
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2676 DEFUN (__tiff_read_encoded_strip__, args, nargout,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2677 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2678 @deftypefn {} {@var{stripData} =} __tiff_read_encoded_strip__ (@var{t}, @var{stripNumber})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2679 Read the strip data from the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2680
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2681 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2682 Use @code{Tiff.readEncodedStrip} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2683
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2684 @end deftypefn */)
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2685 {
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2686 #if defined (HAVE_TIFF)
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2687 int nargin = args.length ();
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2688
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2689 if (nargin != 2)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2690 print_usage ();
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2691
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2692 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
2693 = 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
2694 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
2695
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2696 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2697
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2698 TIFF *tif = tiff_handle->get_file ();
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2699
31213
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
2700 if (nargout > 1)
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
2701 error ("Tiff: Reading YCbCr image data is not supported");
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2702
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2703 if (TIFFIsTiled (tif))
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2704 error ("The image is tiled not stripped");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2705
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2706 uint32_t strip_no;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2707 if (args(1).is_scalar_type ())
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2708 strip_no = args(1).uint32_scalar_value ();
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2709 else
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2710 error ("Expected scalar for strip number");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2711
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2712 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
2713 error ("Strip number out of bounds");
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2714
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2715 // 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
2716 strip_no--;
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2717
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2718 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
2719 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
2720 octave_unused_parameter (args);
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
2721 octave_unused_parameter (nargout);
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2722 err_disabled_feature ("readEncodedStrip", "Tiff");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2723 #endif
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2724 }
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2725
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2726 DEFUN (__tiff_read_encoded_tile__, args, nargout,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2727 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2728 @deftypefn {} {@var{tileData} =} __tiff_read_encoded_tile__ (@var{t}, @var{tileNumber})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2729 Read the tile data from the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2730
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2731 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2732 Use @code{Tiff.readEncodedTile} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2733
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2734 @end deftypefn */)
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2735 {
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2736 #if defined (HAVE_TIFF)
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2737 int nargin = args.length ();
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2738
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2739 if (nargin != 2)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2740 print_usage ();
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2741
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2742 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
2743 = 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
2744 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
2745
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2746 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2747
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2748 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
2749
31213
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
2750 if (nargout > 1)
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
2751 error ("Tiff: Reading YCbCr image data is not supported");
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2752
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2753 if (! TIFFIsTiled (tif))
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2754 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
2755
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2756 uint32_t tile_no;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2757 if (args(1).is_scalar_type ())
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2758 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
2759 else
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2760 error ("Expected scalar for tile number");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2761
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2762 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
2763 error ("Tile number out of bounds");
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2764
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2765 // 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
2766 tile_no--;
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2767
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
2768 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
2769 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
2770 octave_unused_parameter (args);
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
2771 octave_unused_parameter (nargout);
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
2772 err_disabled_feature ("readEncodedTile", "Tiff");
31157
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2773 #endif
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2774 }
dc3d2744916d Tiff: added readEncodedStrip method and corresponding unit tests
magedrifaat <magedrifaat@gmail.com>
parents: 31156
diff changeset
2775
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2776 DEFUN (__tiff_read_rgba_image__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2777 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2778 @deftypefn {} {@var{imageData} =} __tiff_read_rgba_image__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2779 Read the RGBA image data from the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2780
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2781 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2782 Use @code{Tiff.readRGBAImage} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2783
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2784 @end deftypefn */)
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2785 {
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2786 #if defined (HAVE_TIFF)
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2787 int nargin = args.length ();
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2788
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2789 if (nargin != 1)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2790 print_usage ();
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2791
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2792 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
2793 = 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
2794 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
2795
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2796 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2797
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2798 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
2799
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2800 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
2801
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2802 uint16_t orientation;
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2803 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ORIENTATION, &orientation))
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2804 orientation = ORIENTATION_LEFTTOP;
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2805
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2806 // 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
2807 // 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
2808 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
2809 uint8NDArray img (img_dims);
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2810 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
2811
31179
f294b800f002 Tiff.m: added tests for signed images and sub-directories.
magedrifaat <magedrifaat@gmail.com>
parents: 31178
diff changeset
2812 // 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
2813 // 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
2814 // 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
2815 // 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
2816 // 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
2817 // 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
2818 // useful results.
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2819 TIFFRGBAImage img_config;
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2820 char emsg[1024];
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2821 if (! TIFFRGBAImageOK (tif, emsg)
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2822 || ! TIFFRGBAImageBegin (&img_config, tif, 0, emsg))
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2823 error ("Failed to read image");
31203
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2824
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2825 if (orientation == ORIENTATION_RIGHTTOP
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2826 || orientation == ORIENTATION_LEFTBOT)
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2827 // LibTIFF can only do flips and doesn't do rotations, so if we need
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2828 // an orientation that requires a rotation before flipping
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2829 // (i.e. LeftBottom, RightTop) then the only thing we can do is start
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2830 // with an orientation that doesn't require a rotation, then permute at
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2831 // the end.
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2832 img_config.orientation = ORIENTATION_RIGHTBOT;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2833 else
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2834 img_config.orientation = ORIENTATION_TOPLEFT;
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2835
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2836 img_config.req_orientation = orientation;
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2837
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2838 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
2839 img_config.height);
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2840
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2841 TIFFRGBAImageEnd (&img_config);
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2842 if (!success)
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2843 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
2844
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2845 // 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
2846 Array<octave_idx_type> perm (dim_vector (3, 1));
31203
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2847 if (orientation >= ORIENTATION_LEFTTOP)
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2848 {
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2849 // Transpose for rotated orientations
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2850 perm(0) = 1;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2851 perm(1) = 2;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2852 perm(2) = 0;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2853 }
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2854 else
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2855 {
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2856 perm(0) = 2;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2857 perm(1) = 1;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2858 perm(2) = 0;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2859 }
31170
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2860 img = img.permute (perm);
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
2861
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2862 // Slice the data into RGB and alpha
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2863 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
2864 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
2865 octave_unused_parameter (args);
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2866 err_disabled_feature ("readRGBAImage", "Tiff");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2867 #endif
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2868 }
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2869
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2870 DEFUN (__tiff_read_rgba_strip__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2871 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2872 @deftypefn {} {@var{stripData} =} __tiff_read_rgba_strip__ (@var{t}, @var{stripNumber})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2873 Read the RGBA strip data from the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2874
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2875 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2876 Use @code{Tiff.readRGBAStrip} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2877
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2878 @end deftypefn */)
31171
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 #if defined (HAVE_TIFF)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2881 int nargin = args.length ();
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2882
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2883 if (nargin != 2)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
2884 print_usage ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2885
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2886 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
2887 = 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
2888 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
2889
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2890 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
2891
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
2892 TIFF *tif = tiff_handle->get_file ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2893
31173
0abc9779f751 Tiff: modified readRGBAImage to use the orientation tag correctly
magedrifaat <magedrifaat@gmail.com>
parents: 31172
diff changeset
2894 // 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
2895 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
2896 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
2897
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
2898 uint32_t row = args(1).uint32_scalar_value ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2899
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2900 tiff_image_data image_data (tif);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2901 if (image_data.is_tiled)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2902 error ("The image is tiled not stripped");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2903
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2904 if (row < 1 || row > image_data.height)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2905 error ("Row out of bounds of the image");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2906
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2907 // Convert from 1-based indexing to zero-based
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2908 row--;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2909
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2910 uint32_t rows_in_strip;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2911 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ROWSPERSTRIP, &rows_in_strip))
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2912 error ("Failed to obtain a value for RowsPerStrip");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2913
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2914 if (rows_in_strip > image_data.height)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2915 rows_in_strip = image_data.height;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2916
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2917 // 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
2918 // 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
2919 row -= row % rows_in_strip;
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 // 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
2922 uint32_t strip_no = TIFFComputeStrip (tif, row, 0);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2923 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
2924 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
2925
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2926 uint16_t orientation;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2927 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
2928 orientation = ORIENTATION_LEFTTOP;
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2929
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2930 // 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
2931 // permute to the correct order later
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2932 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
2933 uint8NDArray strip_data (strip_dims);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2934 uint32_t *strip_ptr
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2935 = 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
2936
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2937 TIFFRGBAImage img_config;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2938 char emsg[1024];
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2939 if (! TIFFRGBAImageOK (tif, emsg)
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2940 || ! 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
2941 error ("Failed to read strip");
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2942
31203
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2943 if (orientation == ORIENTATION_RIGHTTOP
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2944 || orientation == ORIENTATION_LEFTBOT)
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2945 // LibTIFF can only do flips and doesn't do rotations, so if we need
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2946 // an orientation that requires a rotation before flipping
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2947 // (i.e. LeftBottom, RightTop) then the only thing we can do is start
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2948 // with an orientation that doesn't require a rotation, then permute at
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2949 // the end.
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2950 img_config.orientation = ORIENTATION_RIGHTBOT;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2951 else
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2952 img_config.orientation = ORIENTATION_TOPLEFT;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2953
31174
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2954 img_config.req_orientation = orientation;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2955 img_config.row_offset = row;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2956 img_config.col_offset = 0;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2957
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2958 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
2959 rows_in_strip);
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2960
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2961 TIFFRGBAImageEnd (&img_config);
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
2962 if (!success)
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2963 error ("Failed to read strip");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2964
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2965 // Permute to the correct order of dimensions for Octave
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2966 Array<octave_idx_type> perm (dim_vector (3, 1));
31203
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2967 if (orientation >= ORIENTATION_LEFTTOP)
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2968 {
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2969 // Transpose for rotated orientations
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2970 perm(0) = 1;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2971 perm(1) = 2;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2972 perm(2) = 0;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2973 }
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2974 else
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2975 {
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2976 perm(0) = 2;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2977 perm(1) = 1;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2978 perm(2) = 0;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
2979 }
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2980 strip_data = strip_data.permute (perm);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2981
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2982 // Slice the data into RGB and alpha
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
2983 return slice_rgba (strip_data);
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2984 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
2985 octave_unused_parameter (args);
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2986 err_disabled_feature ("readRGBAStrip", "Tiff");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2987 #endif
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2988 }
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2989
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2990 DEFUN (__tiff_read_rgba_tile__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2991 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2992 @deftypefn {} {@var{tileData} =} __tiff_read_rgba_tile__ (@var{t}, @var{tileNumber})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2993 Read the RGBA tile data from the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2994
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2995 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2996 Use @code{Tiff.readRGBATile} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2997
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
2998 @end deftypefn */)
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
2999 {
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3000 #if defined (HAVE_TIFF)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3001 int nargin = args.length ();
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3002
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3003 if (nargin != 3)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3004 print_usage ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3005
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3006 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
3007 = 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
3008 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
3009
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3010 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3011
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3012 TIFF *tif = tiff_handle->get_file ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3013
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3014 if (! args(1).is_double_type ())
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3015 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
3016 if (! args(2).is_double_type ())
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3017 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
3018
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3019 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
3020 uint32_t col = args(2).uint32_scalar_value ();
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3021
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3022 tiff_image_data image_data (tif);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3023 if (! image_data.is_tiled)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3024 error ("The image is stripped not tiled");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3025
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3026 if (row < 1 || row > image_data.height)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3027 error ("Row out of bounds of the image");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3028 if (col < 1 || col > image_data.width)
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3029 error ("Column out of bounds of the image");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3030
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3031 // Convert from 1-based indexing to zero-based
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3032 row--;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3033 col--;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3034
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3035 uint32_t tile_width, tile_height;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3036 if (! TIFFGetField (tif, TIFFTAG_TILELENGTH, &tile_height))
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3037 error ("Failed to obtain a value for TileLength");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3038 if (! TIFFGetField (tif, TIFFTAG_TILEWIDTH, &tile_width))
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3039 error ("Failed to obtain a value for TileWidth");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3040
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3041 // 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
3042 // 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
3043 // of the tile
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3044 row -= row % tile_height;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3045 col -= col % tile_width;
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3046
31174
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3047 uint16_t orientation;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3048 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
3049 orientation = ORIENTATION_LEFTTOP;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3050
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3051 // 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
3052 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
3053 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
3054 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
3055 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
3056 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
3057 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
3058
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3059 // 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
3060 // 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
3061 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
3062 uint8NDArray tile_data (tile_dims);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3063 uint32_t *tile_ptr
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3064 = 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
3065
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3066 TIFFRGBAImage img_config;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3067 char emsg[1024];
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3068 if (! TIFFRGBAImageOK (tif, emsg)
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3069 || ! 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
3070 error ("Failed to read tile");
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3071
31203
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3072 if (orientation == ORIENTATION_RIGHTTOP
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3073 || orientation == ORIENTATION_LEFTBOT)
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3074 // LibTIFF can only do flips and doesn't do rotations, so if we need
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3075 // an orientation that requires a rotation before flipping
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3076 // (i.e. LeftBottom, RightTop) then the only thing we can do is start
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3077 // with an orientation that doesn't require a rotation, then permute at
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3078 // the end.
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3079 img_config.orientation = ORIENTATION_RIGHTBOT;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3080 else
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3081 img_config.orientation = ORIENTATION_TOPLEFT;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3082
31174
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3083 img_config.req_orientation = orientation;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3084 img_config.row_offset = row;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3085 img_config.col_offset = col;
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3086
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3087 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
3088 corrected_height);
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3089
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3090 TIFFRGBAImageEnd (&img_config);
1f19e9a06f2d Tiff: modified readRGBAStrip/Tile to correctly use the orientation tag
magedrifaat <magedrifaat@gmail.com>
parents: 31173
diff changeset
3091 if (!success)
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3092 error ("Failed to read tile");
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3093
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3094 // Permute to the correct order of dimensions for Octave
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3095 Array<octave_idx_type> perm (dim_vector (3, 1));
31203
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3096 if (orientation >= ORIENTATION_LEFTTOP)
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3097 {
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3098 // Transpose for rotated orientations
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3099 perm(0) = 1;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3100 perm(1) = 2;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3101 perm(2) = 0;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3102 }
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3103 else
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3104 {
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3105 perm(0) = 2;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3106 perm(1) = 1;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3107 perm(2) = 0;
fa50e2c17568 Tiff: fixed bug RGBA incorrect orientation handling for rotated orientations
magedrifaat <magedrifaat@gmail.com>
parents: 31202
diff changeset
3108 }
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3109 tile_data = tile_data.permute (perm);
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3110
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3111 // Slice the data into RGB and alpha
31180
ae78937e24d2 __tiff__.cc: refactored repititive code into functions.
magedrifaat <magedrifaat@gmail.com>
parents: 31179
diff changeset
3112 return slice_rgba (tile_data);
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3113 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3114 octave_unused_parameter (args);
31171
8bf3fa6b6977 Tiff: added readRGBAStrip and readRGBATile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31170
diff changeset
3115 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
3116 #endif
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
3117 }
72a159bc5a4c Tiff: added readRGBAImage method to read image using the RGBA interface
magedrifaat <magedrifaat@gmail.com>
parents: 31168
diff changeset
3118
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3119 DEFUN (__tiff_write__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3120 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3121 @deftypefn {} __tiff_write__ (@var{t}, @var{imageData})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3122 Write the image data to the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3123
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3124 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3125 Use @code{Tiff.write} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3126
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3127 @end deftypefn */)
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3128 {
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3129 #if defined (HAVE_TIFF)
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3130 int nargin = args.length ();
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3131
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3132 if (nargin < 2)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3133 print_usage ();
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3134
31213
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
3135 if (nargin > 2)
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
3136 error ("Tiff: Writing YCbCr image data is not supported");
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
3137
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3138 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
3139 = 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
3140 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
3141
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3142 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3143
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3144 TIFF *tif = tiff_handle->get_file ();
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3145
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
3146 check_readonly (tif);
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3147
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3148 // Obtain all necessary tags
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3149 tiff_image_data image_data (tif);
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3150
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3151 uint16_t sample_format;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3152 if (! TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLEFORMAT, &sample_format))
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3153 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
3154
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3155 switch (sample_format)
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3156 {
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3157 case 1:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3158 case 4:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3159 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
3160 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3161 case 2:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3162 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
3163 break;
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3164 case 3:
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3165 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
3166 break;
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3167 default:
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3168 error ("Unsupported sample format");
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3169 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3170
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3171 return octave_value_list ();
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3172 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3173 octave_unused_parameter (args);
31153
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3174 err_disabled_feature ("write", "Tiff");
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3175 #endif
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3176 }
c66d6c7f025e Tiff: implemented write method for stripped images
magedrifaat <magedrifaat@gmail.com>
parents: 31152
diff changeset
3177
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3178 DEFUN (__tiff_write_encoded_strip__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3179 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3180 @deftypefn {} __tiff_write_encoded_strip__ (@var{t}, @var{stripNumber}, @var{stripData})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3181 Write the strip data to the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3182
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3183 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3184 Use @code{Tiff.writeEncodedStrip} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3185
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3186 @end deftypefn */)
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3187 {
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3188 #if defined (HAVE_TIFF)
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3189 int nargin = args.length ();
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3190
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3191 if (nargin < 3)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3192 print_usage ();
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3193
31213
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
3194 if (nargin > 3)
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
3195 error ("Tiff: Writing YCbCr image data is not supported");
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
3196
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3197 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
3198 = 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
3199 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
3200
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3201 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3202
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3203 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
3204
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
3205 check_readonly (tif);
31138
68762676dab1 Tiff writeEncodedStrip: prevent writing to a read-only file
magedrifaat <magedrifaat@gmail.com>
parents: 31137
diff changeset
3206
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3207 // Obtain all necessary tags
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3208 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
3209
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3210 if (image_data.is_tiled)
31143
a68f2dadafee Tiff.m: added all remaining tests for implemented features.
magedrifaat <magedrifaat@gmail.com>
parents: 31142
diff changeset
3211 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
3212
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3213 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
3214 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
3215 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
3216
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
3217 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
3218
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3219 return octave_value_list ();
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3220 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3221 octave_unused_parameter (args);
31126
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3222 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
3223 #endif
7851c5b9c950 Tiff: implemented writeEncodedStrip function for writing a strip to an image
magedrifaat <magedrifaat@gmail.com>
parents: 31125
diff changeset
3224 }
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3225
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3226 DEFUN (__tiff_write_encoded_tile__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3227 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3228 @deftypefn {} __tiff_write_encoded_tile__ (@var{t}, @var{tileNumber}, @var{tileData})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3229 Write the tile data to the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3230
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3231 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3232 Use @code{Tiff.writeEncodedTile} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3233
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3234 @end deftypefn */)
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3235 {
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3236 #if defined (HAVE_TIFF)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3237 int nargin = args.length ();
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3238
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3239 if (nargin < 3)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3240 print_usage ();
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3241
31213
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
3242 if (nargin > 3)
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
3243 error ("Tiff: Writing YCbCr image data is not supported");
f1c1efd356c8 Tiff: added an error for reading and writing YCbCr images
magedrifaat <magedrifaat@gmail.com>
parents: 31203
diff changeset
3244
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3245 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
3246 = 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
3247 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
3248
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3249 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3250
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3251 TIFF *tif = tiff_handle->get_file ();
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3252
31162
28817158ca86 Tiff: changed write functions to use fcntl wrappers.
magedrifaat <magedrifaat@gmail.com>
parents: 31161
diff changeset
3253 check_readonly (tif);
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3254
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3255 // Obtain all necessary tags
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3256 tiff_image_data image_data (tif);
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3257
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3258 if (! image_data.is_tiled)
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3259 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
3260
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3261 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
3262 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
3263 error ("Tile number out of range");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3264
31158
f2ae7763739a Tiff: added writeEncodedTile method to read tiles from image
magedrifaat <magedrifaat@gmail.com>
parents: 31157
diff changeset
3265 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
3266
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3267 return octave_value_list ();
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3268 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3269 octave_unused_parameter (args);
31146
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3270 err_disabled_feature ("writeEncodedTile", "Tiff");
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3271 #endif
50402b8dfb4a Tiff: added writeEncodedTile function for writing tiled images
magedrifaat <magedrifaat@gmail.com>
parents: 31145
diff changeset
3272 }
31148
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3273
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3274 DEFUN (__tiff_is_tiled__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3275 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3276 @deftypefn {} {@var{tf} =} __tiff_is_tiled__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3277 Get whether the tiff image of the given handle is tiled.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3278
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3279 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3280 Use @code{Tiff.isTiled} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3281
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3282 @end deftypefn */)
31148
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3283 {
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3284 #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
3285 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
3286
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3287 if (nargin == 0)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3288 print_usage ();
31148
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3289
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3290 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
3291 = 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
3292 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
3293
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3294 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3295
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3296 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
3297
31148
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3298 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
3299 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
3300 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3301 octave_unused_parameter (args);
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3302 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
3303 #endif
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3304 }
4bc9a1938f9a Tiff: added isTiled method to check if the image is tiled or stripped
magedrifaat <magedrifaat@gmail.com>
parents: 31147
diff changeset
3305
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3306 DEFUN (__tiff_number_of_strips__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3307 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3308 @deftypefn {} {@var{numStrips} =} __tiff_number_of_strips__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3309 Get the number of strips of the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3310
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3311 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3312 Use @code{Tiff.numberOfStrips} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3313
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3314 @end deftypefn */)
31149
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3315 {
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3316 #if defined (HAVE_TIFF)
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3317 int nargin = args.length ();
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3318
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3319 if (nargin == 0)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3320 print_usage ();
31149
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3321
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3322 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
3323 = 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
3324 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
3325
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3326 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3327
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3328 TIFF *tif = tiff_handle->get_file ();
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3329
31149
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3330 if (TIFFIsTiled (tif))
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3331 error ("The image is tiled not stripped");
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3332
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3333 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
3334 return ovl (strip_count);
31149
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3335 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3336 octave_unused_parameter (args);
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3337 err_disabled_feature ("numberOfStrips", "Tiff");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3338 #endif
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3339 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3340
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3341 DEFUN (__tiff_number_of_tiles__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3342 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3343 @deftypefn {} {@var{numTiles} =} __tiff_number_of_tiles__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3344 Get the number of tiles of the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3345
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3346 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3347 Use @code{Tiff.numberOfTiles} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3348
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3349 @end deftypefn */)
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3350 {
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3351 #if defined (HAVE_TIFF)
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3352 int nargin = args.length ();
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3353
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3354 if (nargin == 0)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3355 print_usage ();
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3356
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3357 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
3358 = 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
3359 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
3360
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3361 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3362
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3363 TIFF *tif = tiff_handle->get_file ();
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3364
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3365 if (! TIFFIsTiled (tif))
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3366 error ("The image is stripped not tiled");
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3367
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3368 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
3369 return ovl (tile_count);
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3370 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3371 octave_unused_parameter (args);
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3372 err_disabled_feature ("numberOfTiles", "Tiff");
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3373 #endif
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3374 }
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3375
31197
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3376 DEFUN (__tiff_number_of_directories__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3377 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3378 @deftypefn {} {@var{numDirs} =} __tiff_number_of_directories__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3379 Get the number of directories of the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3380
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3381 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3382 Use @code{Tiff.numberOfDirectories} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3383
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3384 @end deftypefn */)
31197
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3385 {
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3386 #if defined (HAVE_TIFF)
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3387 int nargin = args.length ();
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3388
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3389 if (nargin == 0)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3390 print_usage ();
31197
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3391
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3392 octave_tiff_handle *tiff_handle
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3393 = octave_tiff_handle::get_tiff_handle (args(0));
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3394 check_closed (tiff_handle);
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3395
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3396 set_internal_handlers ();
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3397
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3398 TIFF *tif = tiff_handle->get_file ();
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3399
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3400 double dir_count = static_cast<double> (TIFFNumberOfDirectories (tif));
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3401 return ovl (dir_count);
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3402 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3403 octave_unused_parameter (args);
31197
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3404 err_disabled_feature ("numberOfDirectories", "Tiff");
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3405 #endif
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3406 }
1604c8812b67 Tiff: added numberOfDirectories method.
magedrifaat <magedrifaat@gmail.com>
parents: 31196
diff changeset
3407
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3408 DEFUN (__tiff_compute_strip__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3409 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3410 @deftypefn {} {@var{stripNumber} =} __tiff_compute_strip__ (@var{t}, @var{row})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3411 @deftypefnx {} {@var{stripNumber} =} __tiff_compute_strip__ (@var{t}, @var{row}, @var{plane})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3412 Get the strip number containing the given row.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3413
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3414 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3415 Use @code{Tiff.computeStrip} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3416
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3417 @end deftypefn */)
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3418 {
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3419 #if defined (HAVE_TIFF)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3420 int nargin = args.length ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3421
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3422 if (nargin == 0)
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3423 print_usage ();
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3424
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3425 if (nargin < 2 || nargin > 3)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3426 // Since this function accepts varargin from the Octave side, the
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3427 // ommitted arguments are from wrong usage of the computeStrip method
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3428 print_usage ("Tiff.computeStrip");
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3429
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3430 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
3431 = 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
3432 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
3433
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3434 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
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 TIFF *tif = tiff_handle->get_file ();
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3437
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3438 if (TIFFIsTiled (tif))
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3439 error ("The image is tiled not stripped");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3440
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3441 tiff_image_data image_data (tif);
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3442
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3443 uint32_t row = args(1).uint32_scalar_value ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3444 if (row > image_data.height)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3445 row = image_data.height;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3446
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3447 // 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
3448 if (row > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3449 row--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3450
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3451 uint16_t plane;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3452 if (nargin > 2)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3453 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3454 if (image_data.planar_configuration == PLANARCONFIG_CONTIG)
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3455 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
3456 plane = args(2).uint16_scalar_value ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3457 if (plane > image_data.samples_per_pixel)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3458 plane = image_data.samples_per_pixel;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3459 if (plane > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3460 plane--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3461 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3462 else
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3463 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3464 if (image_data.planar_configuration == PLANARCONFIG_SEPARATE)
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3465 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
3466 plane = 0;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3467 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3468
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3469 double strip_number = TIFFComputeStrip (tif, row, plane) + 1;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3470 if (strip_number > TIFFNumberOfStrips (tif))
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3471 strip_number = TIFFNumberOfStrips (tif);
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3472 return ovl (strip_number);
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3473 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3474 octave_unused_parameter (args);
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3475 err_disabled_feature ("computeStrip", "Tiff");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3476 #endif
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3477 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3478
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3479 DEFUN (__tiff_compute_tile__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3480 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3481 @deftypefn {} {@var{tileNumber} =} __tiff_compute_strip__ (@var{t}, [@var{row}, @var{col}])
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3482 @deftypefnx {} {@var{tileNumber} =} __tiff_compute_strip__ (@var{t}, [@var{row}, @var{col}], @var{plane})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3483 Get the tile number containing the given row and col.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3484
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3485 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3486 Use @code{Tiff.computeTile} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3487
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3488 @end deftypefn */)
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3489 {
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3490 #if defined (HAVE_TIFF)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3491 int nargin = args.length ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3492
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3493 if (nargin == 0)
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3494 print_usage ();
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3495
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3496 if (nargin < 2 || nargin > 3)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3497 // Since this function accepts varargin from the Octave side, the
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3498 // ommitted arguments are from wrong usage of the computeTile method
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3499 print_usage ("Tiff.computeTile");
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3500
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3501 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
3502 = 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
3503 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
3504
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3505 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3506
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3507 TIFF *tif = tiff_handle->get_file ();
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3508
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3509 if (! TIFFIsTiled (tif))
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3510 error ("The image is stripped not tiled");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3511
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3512 uint32NDArray coords = args(1).uint32_array_value ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3513 if (coords.dim2() < 2)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3514 error ("Coordinates must be in the shape [row, col]");
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3515 uint32_t row = coords(0, 0);
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3516 uint32_t col = coords(0, 1);
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3517
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3518 tiff_image_data image_data (tif);
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3519
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3520 if (col > image_data.width)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3521 col = image_data.width;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3522 if (row > image_data.height)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3523 row = image_data.height;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3524
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3525 // 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
3526 if (row > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3527 row--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3528 if (col > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3529 col--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3530
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3531 uint16_t plane;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3532 if (nargin > 2)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3533 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3534 if (image_data.planar_configuration == PLANARCONFIG_CONTIG)
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3535 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
3536 plane = args(2).uint16_scalar_value ();
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3537 if (plane > image_data.samples_per_pixel)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3538 plane = image_data.samples_per_pixel;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3539 if (plane > 0)
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3540 plane--;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3541 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3542 else
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3543 {
31152
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3544 if (image_data.planar_configuration == PLANARCONFIG_SEPARATE)
2244617f4da5 Tiff computeStrip: fixed inconsistency in checking plane argument.
magedrifaat <magedrifaat@gmail.com>
parents: 31151
diff changeset
3545 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
3546 plane = 0;
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3547 }
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3548
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3549 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
3550 if (tile_number > TIFFNumberOfTiles (tif))
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3551 tile_number = TIFFNumberOfTiles (tif);
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3552 return ovl (tile_number);
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3553 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3554 octave_unused_parameter (args);
31150
6bede2d6f273 Tiff: added computeStrip and computeTile methods
magedrifaat <magedrifaat@gmail.com>
parents: 31149
diff changeset
3555 err_disabled_feature ("computeTile", "Tiff");
31149
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3556 #endif
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3557 }
d4dbc69f301e Tiff: implemented numberOfStrips method
magedrifaat <magedrifaat@gmail.com>
parents: 31148
diff changeset
3558
31199
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3559 DEFUN (__tiff_default_strip_length__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3560 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3561 @deftypefn {} {@var{stripLen} =} __tiff_compute_strip__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3562 Get the length of a reasonably sized strip.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3563
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3564 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3565 Use @code{Tiff.getDsefaultStripLength} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3566
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3567 @end deftypefn */)
31199
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3568 {
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3569 #if defined (HAVE_TIFF)
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3570 int nargin = args.length ();
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3571
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3572 if (nargin == 0)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3573 print_usage ();
31199
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3574
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3575 octave_tiff_handle *tiff_handle
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3576 = octave_tiff_handle::get_tiff_handle (args(0));
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3577 check_closed (tiff_handle);
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3578
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3579 set_internal_handlers ();
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3580
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3581 TIFF *tif = tiff_handle->get_file ();
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3582
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3583 if (TIFFIsTiled (tif))
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3584 error ("getDefaultStripLength: the image is tiled not stripped");
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3585
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3586 double strip_len = static_cast<double> (TIFFDefaultStripSize (tif, 0));
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3587 return ovl (strip_len);
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3588 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3589 octave_unused_parameter (args);
31199
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3590 err_disabled_feature ("getDefaultStripLength", "Tiff");
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3591 #endif
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3592 }
30b28458bb06 Tiff: added method getDefaultStripLength
magedrifaat <magedrifaat@gmail.com>
parents: 31198
diff changeset
3593
31202
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3594 DEFUN (__tiff_is_big_endian__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3595 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3596 @deftypefn {} {@var{tf} =} __tiff_is_big_endian__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3597 Get whether the tiff image of the given handle is big-endian.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3598
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3599 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3600 Use @code{Tiff.isBigEndian} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3601
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3602 @end deftypefn */)
31202
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3603 {
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3604 #if defined (HAVE_TIFF)
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3605 int nargin = args.length ();
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3606
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3607 if (nargin != 1)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3608 print_usage ();
31202
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3609
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3610 octave_tiff_handle *tiff_handle
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3611 = octave_tiff_handle::get_tiff_handle (args(0));
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3612 check_closed (tiff_handle);
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3613
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3614 set_internal_handlers ();
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3615
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3616 TIFF *tif = tiff_handle->get_file ();
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3617
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3618 bool is_big_endian = TIFFIsBigEndian (tif);
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3619
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3620 return ovl (is_big_endian);
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3621 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3622 octave_unused_parameter (args);
31202
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3623 err_disabled_feature ("isBigEndian", "Tiff");
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3624 #endif
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3625 }
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3626
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3627 DEFUN (__tiff_current_directory__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3628 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3629 @deftypefn {} {@var{dirNumber} =} __tiff_current_directory__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3630 Get the index of the current directory.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3631
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3632 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3633 Use @code{Tiff.currentDirectory} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3634
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3635 @end deftypefn */)
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3636 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3637 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3638 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3639
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3640 if (nargin != 1)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3641 print_usage ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3642
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3643 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
3644 = 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
3645 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
3646
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3647 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3648
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3649 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3650
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3651 uint16_t dir = TIFFCurrentDirectory (tif);
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3652 dir++;
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3653
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3654 return ovl (static_cast<double> (dir));
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3655 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3656 octave_unused_parameter (args);
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3657 err_disabled_feature ("currentDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3658 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3659 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3660
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3661 DEFUN (__tiff_last_directory__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3662 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3663 @deftypefn {} {@var{isLast} =} __tiff_last_directory__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3664 Get whether the current directory is the last directory.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3665
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3666 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3667 Use @code{Tiff.lastDirectory} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3668
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3669 @end deftypefn */)
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3670 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3671 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3672 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3673
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3674 if (nargin != 1)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3675 print_usage ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3676
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3677 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
3678 = 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
3679 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
3680
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3681 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3682
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3683 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3684
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3685 bool is_last = TIFFLastDirectory (tif);
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3686
31194
0cdb7f35641e Tiff: added handler for imfinfo that uses the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31193
diff changeset
3687 return ovl (is_last);
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3688 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3689 octave_unused_parameter (args);
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3690 err_disabled_feature ("lastDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3691 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3692 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3693
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3694 DEFUN (__tiff_next_directory__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3695 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3696 @deftypefn {} __tiff_next_directory__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3697 Switch to the next directory in the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3698
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3699 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3700 Use @code{Tiff.nextDirectory} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3701
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3702 @end deftypefn */)
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3703 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3704 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3705 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3706
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3707 if (nargin != 1)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3708 print_usage ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3709
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3710 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
3711 = 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
3712 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
3713
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3714 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3715
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3716 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3717
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3718 bool is_last = TIFFLastDirectory (tif);
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3719 if (is_last)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3720 error ("Current directory is the last directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3721
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3722 if (! TIFFReadDirectory (tif))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3723 error ("Failed to read the next directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3724
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3725 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3726 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3727 octave_unused_parameter (args);
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3728 err_disabled_feature ("nextDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3729 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3730 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3731
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3732 DEFUN (__tiff_set_directory__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3733 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3734 @deftypefn {} __tiff_set_directory__ (@var{t}, @var{dirNumber})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3735 Switch to the given directory in the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3736
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3737 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3738 Use @code{Tiff.setDirectory} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3739
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3740 @end deftypefn */)
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3741 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3742 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3743 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3744
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3745 if (nargin != 2)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3746 print_usage ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3747
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3748 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
3749 = 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
3750 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
3751
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3752 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3753
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3754 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3755
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3756 uint16_t dir = args(1).uint16_scalar_value ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3757 if (dir < 1 || dir > TIFFNumberOfDirectories (tif))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3758 error ("Directory index out of bounds");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3759
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3760 dir--;
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3761
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3762 if (! TIFFSetDirectory(tif, dir))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3763 error ("Failed to read directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3764
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3765 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3766 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3767 octave_unused_parameter (args);
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3768 err_disabled_feature ("setDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3769 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3770 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3771
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3772 DEFUN (__tiff_write_directory__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3773 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3774 @deftypefn {} __tiff_write_directory__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3775 Write the contents of the current directory and create a new one.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3776
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3777 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3778 Use @code{Tiff.writeDirectory} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3779
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3780 @end deftypefn */)
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3781 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3782 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3783 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3784
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3785 if (nargin != 1)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3786 print_usage ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3787
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3788 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
3789 = 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
3790 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
3791
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3792 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
3793
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3794 if (! TIFFWriteDirectory(tif))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3795 error ("Failed to write directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3796
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3797 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3798 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3799 octave_unused_parameter (args);
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3800 err_disabled_feature ("writeDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3801 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3802 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3803
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3804 DEFUN (__tiff_rewrite_directory__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3805 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3806 @deftypefn {} __tiff_rewrite_directory__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3807 Rewrite the modifications of the current directory and create a new one.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3808
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3809 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3810 Use @code{Tiff.rewriteDirectory} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3811
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3812 @end deftypefn */)
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3813 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3814 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3815 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3816
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3817 if (nargin != 1)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3818 print_usage ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3819
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3820 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
3821 = 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
3822 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
3823
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3824 set_internal_handlers ();
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3825
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3826 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
3827
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3828 if (! TIFFRewriteDirectory(tif))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3829 error ("Failed to rewrite directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3830
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3831 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3832 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3833 octave_unused_parameter (args);
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3834 err_disabled_feature ("rewriteDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3835 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3836 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3837
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3838 DEFUN (__tiff_set_sub_directory__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3839 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3840 @deftypefn {} __tiff_write_directory__ (@var{t}, @var{offset})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3841 Set the current directory to the sub-directory with given offset.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3842
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3843 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3844 Use @code{Tiff.setSubDirectory} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3845
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3846 @end deftypefn */)
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3847 {
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3848 #if defined (HAVE_TIFF)
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3849 int nargin = args.length ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3850
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3851 if (nargin != 2)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3852 print_usage ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3853
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3854 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
3855 = 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
3856 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
3857
31189
6a9d985e7474 Tiff: fixed bug graphicsmagick error handler colliding with our handler
magedrifaat <magedrifaat@gmail.com>
parents: 31187
diff changeset
3858 set_internal_handlers ();
31190
a91f2f79e58c Tiff: added internal handler for imread using the Tiff interface
magedrifaat <magedrifaat@gmail.com>
parents: 31189
diff changeset
3859
31177
c7c79973007f Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
magedrifaat <magedrifaat@gmail.com>
parents: 31176
diff changeset
3860 TIFF *tif = tiff_handle->get_file ();
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3861
31175
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3862 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
3863 && ! args(1).is_uint64_type ())
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3864 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
3865
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3866 uint16_t count;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3867 uint64_t *offsets;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3868 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
3869 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
3870
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3871 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
3872
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3873 int found = 0;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3874 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
3875 if (offset == offsets[i])
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3876 {
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3877 found = 1;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3878 break;
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3879 }
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3880
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3881 if (! found)
ed329571ec88 Tiff: added support for creating and reading sub-directories
magedrifaat <magedrifaat@gmail.com>
parents: 31174
diff changeset
3882 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
3883
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3884 if (! TIFFSetSubDirectory (tif, offset))
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3885 error ("Failed to switch to the sub directory");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3886
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3887 return octave_value_list ();
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3888 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3889 octave_unused_parameter (args);
31172
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3890 err_disabled_feature ("setSubDirectory", "Tiff");
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3891 #endif
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3892 }
3f5f1404af8a Tiff: added directory methods (currentDirectory, nextDirectory, ...)
magedrifaat <magedrifaat@gmail.com>
parents: 31171
diff changeset
3893
31202
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3894 DEFUN (__tiff_get_directory_offset__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3895 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3896 @deftypefn {} {@var{offset} =} __tiff_get_directory_offset__ (@var{t})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3897 Get the offset of the current directory of the tiff file of the given handle.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3898
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3899 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3900 Use @code{Tiff.getDirectoryOffset} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3901
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3902 @end deftypefn */)
31202
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3903 {
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3904 #if defined (HAVE_TIFF)
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3905 int nargin = args.length ();
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3906
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3907 if (nargin != 1)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3908 print_usage ();
31202
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3909
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3910 octave_tiff_handle *tiff_handle
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3911 = octave_tiff_handle::get_tiff_handle (args(0));
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3912 check_closed (tiff_handle);
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3913
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3914 set_internal_handlers ();
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3915
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3916 TIFF *tif = tiff_handle->get_file ();
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3917
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3918 uint64_t offset = TIFFCurrentDirOffset (tif);
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3919
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3920 return ovl (offset);
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3921 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3922 octave_unused_parameter (args);
31202
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3923 err_disabled_feature ("getDirectoryOffset", "Tiff");
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3924 #endif
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3925 }
be6ccdcd5775 Tiff: added isBigEndian and getDirectoryOffset methods to the class
magedrifaat <magedrifaat@gmail.com>
parents: 31201
diff changeset
3926
31160
5f0c3da75926 Tiff: moved internal functions to corefcn.
magedrifaat <magedrifaat@gmail.com>
parents: 31159
diff changeset
3927 DEFUN (__tiff_version__, , ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3928 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3929 @deftypefn {} {@var{verStr} =} __tiff_version__ ()
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3930 Get a string with the version information of LibTIFF
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3931
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3932 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3933 Use @code{Tiff.getVersion} instead.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3934
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3935 @end deftypefn */)
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3936 {
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3937 #if defined (HAVE_TIFF)
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3938 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
3939 return ovl (version);
31151
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3940 #else
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3941 err_disabled_feature ("getVersion", "Tiff");
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3942 #endif
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3943 }
6fb54834aa93 Tiff: added numberOfTiles and getVersion methods
magedrifaat <magedrifaat@gmail.com>
parents: 31150
diff changeset
3944
31161
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3945 DEFUN (__tiff_set_errors_enabled__, args, ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3946 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3947 @deftypefn {} __tiff_set_errors_enabled__ (@var{state})
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3948 Sets whether or not to relay LibTIFF's errors and warning.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3949
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3950 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3951
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3952 @end deftypefn */)
31161
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3953 {
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3954 #if defined (HAVE_TIFF)
31163
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3955 if (args.length () == 0)
31216
fe776b0e904d __tiff__.cc: added appropriate print_usage checks for internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31215
diff changeset
3956 print_usage ();
31163
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3957
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3958 if (! args(0).is_bool_scalar ())
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3959 error ("Expected logical value as argument");
d701c6a4cda1 Tiff: improved handling LibTIFF error output silencing.
magedrifaat <magedrifaat@gmail.com>
parents: 31162
diff changeset
3960
31178
14edd6b09efe Tiff: added support for reading and writing signed images
magedrifaat <magedrifaat@gmail.com>
parents: 31177
diff changeset
3961 // 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
3962 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
3963 set_internal_handlers ();
31161
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3964
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3965 return octave_value_list ();
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3966 #else
31217
c09f6a3597e6 __tiff__.cc: handled unused parameter warning when Tiff is not enabled
magedrifaat <magedrifaat@gmail.com>
parents: 31216
diff changeset
3967 octave_unused_parameter (args);
31161
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3968 err_disabled_feature ("setErrorEnabled", "Tiff");
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3969 #endif
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3970 }
b731c8f6db95 Tiff: added setLibTIFFErrorsEnabled method to enable/disable LibTIFF errors
magedrifaat <magedrifaat@gmail.com>
parents: 31160
diff changeset
3971
31185
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3972 DEFUN (__tiff_make_tagid__, , ,
31215
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3973 doc: /* -*- texinfo -*-
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3974 @deftypefn {} {@var{tagstruct} =} __tiff_make_tagid__ ()
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3975 Get a struct of the supported tags and their IDs.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3976
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3977 This is a private internal function not intended for direct use.
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3978
0fb5ca242d66 __tiff__.cc: added documentation to all internal functions
magedrifaat <magedrifaat@gmail.com>
parents: 31213
diff changeset
3979 @end deftypefn */)
31185
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3980 {
31187
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
3981 #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
3982 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
3983 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
3984 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
3985 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
3986 #else
2bff8446484c imformats: added logic to use Tiff interface for image functions
magedrifaat <magedrifaat@gmail.com>
parents: 31186
diff changeset
3987 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
3988 #endif
31185
a1145ac2ce9b Tiff: populated TagID from the C++ map to avoid having two copies
magedrifaat <magedrifaat@gmail.com>
parents: 31184
diff changeset
3989 }
31092
a736190ce738 Added the Tiff classdef files to octave
magedrifaat <magedrifaat@gmail.com>
parents:
diff changeset
3990 }