Mercurial > octave-libtiff
comparison libinterp/corefcn/__tiff__.cc @ 31162:28817158ca86
Tiff: changed write functions to use fcntl wrappers.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Wed, 10 Aug 2022 20:46:56 +0200 |
parents | b731c8f6db95 |
children | d701c6a4cda1 |
comparison
equal
deleted
inserted
replaced
31161:b731c8f6db95 | 31162:28817158ca86 |
---|---|
2 # include "config.h" | 2 # include "config.h" |
3 #endif | 3 #endif |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 #include <iostream> | 6 #include <iostream> |
7 | |
8 // Workaround to not have to include fcntl which doesn't exist on windows | |
9 // TODO(maged): see what octave does for this (fcntl) | |
10 #ifndef O_RDONLY | |
11 #define O_RDONLY 0 | |
12 #endif | |
13 | 7 |
14 #include "defun.h" | 8 #include "defun.h" |
15 #include "ov.h" | 9 #include "ov.h" |
16 #include "ovl.h" | 10 #include "ovl.h" |
17 #include "error.h" | 11 #include "error.h" |
18 | 12 |
19 #include "errwarn.h" | 13 #include "errwarn.h" |
14 | |
15 #include "fcntl-wrappers.h" | |
20 | 16 |
21 #if defined (HAVE_TIFF) | 17 #if defined (HAVE_TIFF) |
22 # include <tiffio.h> | 18 # include <tiffio.h> |
23 TIFFErrorHandler tiff_default_handler = NULL; | 19 TIFFErrorHandler tiff_default_handler = NULL; |
24 #endif | 20 #endif |
62 planar_configuration = 1; | 58 planar_configuration = 1; |
63 | 59 |
64 is_tiled = TIFFIsTiled(tif); | 60 is_tiled = TIFFIsTiled(tif); |
65 } | 61 } |
66 }; | 62 }; |
63 | |
64 void | |
65 check_readonly (TIFF *tif) | |
66 { | |
67 // This can't use O_RDONLY directly because its header file "fcntl.h" | |
68 // isn't available on Windows. The wrapper, however, seems to return | |
69 // the right thing even on Windows. | |
70 if (TIFFGetMode (tif) == octave_o_rdonly_wrapper ()) | |
71 error ("Can't write data to a file opened in read-only mode"); | |
72 } | |
67 | 73 |
68 // Error if status is not 1 (success status for TIFFGetField) | 74 // Error if status is not 1 (success status for TIFFGetField) |
69 void | 75 void |
70 validate_tiff_get_field (bool status, void *p_to_free=NULL) | 76 validate_tiff_get_field (bool status, void *p_to_free=NULL) |
71 { | 77 { |
1835 | 1841 |
1836 if (nargin < 2) | 1842 if (nargin < 2) |
1837 error ("Too few arguments provided\n"); | 1843 error ("Too few arguments provided\n"); |
1838 | 1844 |
1839 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 1845 TIFF *tif = (TIFF *)(args(0).uint64_value ()); |
1846 | |
1847 check_readonly (tif); | |
1840 | 1848 |
1841 if (args(1).isstruct ()) | 1849 if (args(1).isstruct ()) |
1842 { | 1850 { |
1843 octave_scalar_map tags = args(1).xscalar_map_value ("__tiff_set_tag__: struct argument must be a scalar structure"); | 1851 octave_scalar_map tags = args(1).xscalar_map_value ("__tiff_set_tag__: struct argument must be a scalar structure"); |
1844 string_vector keys = tags.fieldnames (); | 1852 string_vector keys = tags.fieldnames (); |
2034 if (nargin < 2) | 2042 if (nargin < 2) |
2035 error ("Wrong number of arguments\n"); | 2043 error ("Wrong number of arguments\n"); |
2036 | 2044 |
2037 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2045 TIFF *tif = (TIFF *)(args(0).uint64_value ()); |
2038 | 2046 |
2039 // TODO(maged): check on windows | 2047 check_readonly (tif); |
2040 if (TIFFGetMode (tif) == O_RDONLY) | |
2041 error ("Can't write data to a file opened in read-only mode"); | |
2042 | 2048 |
2043 // Obtain all necessary tags | 2049 // Obtain all necessary tags |
2044 tiff_image_data image_data (tif); | 2050 tiff_image_data image_data (tif); |
2045 | 2051 |
2046 uint16_t sample_format; | 2052 uint16_t sample_format; |
2128 if (nargin < 3) | 2134 if (nargin < 3) |
2129 error ("Too few arguments provided\n"); | 2135 error ("Too few arguments provided\n"); |
2130 | 2136 |
2131 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2137 TIFF *tif = (TIFF *)(args(0).uint64_value ()); |
2132 | 2138 |
2133 // TODO(maged): check on windows | 2139 check_readonly (tif); |
2134 if (TIFFGetMode (tif) == O_RDONLY) | |
2135 error ("Can't write data to a file opened in read-only mode"); | |
2136 | 2140 |
2137 // Obtain all necessary tags | 2141 // Obtain all necessary tags |
2138 tiff_image_data image_data (tif); | 2142 tiff_image_data image_data (tif); |
2139 | 2143 |
2140 if (image_data.is_tiled) | 2144 if (image_data.is_tiled) |
2162 if (nargin < 3) | 2166 if (nargin < 3) |
2163 error ("Too few arguments provided\n"); | 2167 error ("Too few arguments provided\n"); |
2164 | 2168 |
2165 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2169 TIFF *tif = (TIFF *)(args(0).uint64_value ()); |
2166 | 2170 |
2167 // TODO(maged): check on windows | 2171 check_readonly (tif); |
2168 if (TIFFGetMode (tif) == O_RDONLY) | |
2169 error ("Can't write data to a file opened in read-only mode"); | |
2170 | 2172 |
2171 // Obtain all necessary tags | 2173 // Obtain all necessary tags |
2172 tiff_image_data image_data (tif); | 2174 tiff_image_data image_data (tif); |
2173 | 2175 |
2174 if (! image_data.is_tiled) | 2176 if (! image_data.is_tiled) |