Mercurial > octave-libtiff
comparison libinterp/corefcn/__tiff__.cc @ 31177:c7c79973007f
Tiff: added octave_tiff_handle class to wrap the Tiff file pointer
* __tiff__.cc (octave_tiff_handle): implemented a new class octave_tiff_handle
as a child of octave_base_value to be a wrapper for the Tiff file handle to
be passed to Octave instead of passing a pointer around.
* __tiff__.cc (F__open_tiff__, F__tiff_close__): modified handling TIFF file
pointer to use the new class (Other internal functions were modified as well).
* Tiff.m: removed checking for closed file, it is now handled internally.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Wed, 17 Aug 2022 18:51:16 +0200 |
parents | c07461ca34d6 |
children | 14edd6b09efe |
comparison
equal
deleted
inserted
replaced
31176:c07461ca34d6 | 31177:c7c79973007f |
---|---|
21 #endif | 21 #endif |
22 | 22 |
23 namespace octave | 23 namespace octave |
24 { | 24 { |
25 #if defined (HAVE_TIFF) | 25 #if defined (HAVE_TIFF) |
26 class OCTINTERP_API octave_tiff_handle : public octave_base_value | |
27 { | |
28 public: | |
29 octave_tiff_handle (TIFF *tif) | |
30 : tiff_file (tif), closed (false) | |
31 { } | |
32 | |
33 TIFF *get_file(void) { return tiff_file; } | |
34 | |
35 bool is_defined (void) const { return true; } | |
36 bool is_constant (void) const { return true; } | |
37 | |
38 void close(void) | |
39 { | |
40 if (! closed) | |
41 { | |
42 closed = true; | |
43 TIFFClose (tiff_file); | |
44 } | |
45 } | |
46 | |
47 bool is_closed (void) { return closed; } | |
48 | |
49 ~octave_tiff_handle (void) | |
50 { | |
51 if (! closed) | |
52 close (); | |
53 } | |
54 | |
55 static octave_tiff_handle * | |
56 get_tiff_handle (const octave_value& ov) | |
57 { | |
58 octave_base_value *rep = ov.internal_rep (); | |
59 octave_tiff_handle *handle = dynamic_cast<octave_tiff_handle *> (rep); | |
60 if (! handle) | |
61 error ("get_tiff_handle: dynamic_cast to octave_tiff_handle failed"); | |
62 | |
63 return handle; | |
64 } | |
65 private: | |
66 TIFF *tiff_file; | |
67 bool closed; | |
68 }; | |
26 | 69 |
27 struct tiff_image_data | 70 struct tiff_image_data |
28 { | 71 { |
29 public: | 72 public: |
30 uint32_t width; | 73 uint32_t width; |
63 }; | 106 }; |
64 | 107 |
65 void | 108 void |
66 check_readonly (TIFF *tif) | 109 check_readonly (TIFF *tif) |
67 { | 110 { |
68 // This can't use O_RDONLY directly because its header file "fcntl.h" | |
69 // isn't available on Windows. The wrapper, however, seems to return | |
70 // the right thing even on Windows. | |
71 if (TIFFGetMode (tif) == octave_o_rdonly_wrapper ()) | 111 if (TIFFGetMode (tif) == octave_o_rdonly_wrapper ()) |
72 error ("Can't write data to a file opened in read-only mode"); | 112 error ("Can't write data to a file opened in read-only mode"); |
113 } | |
114 | |
115 void | |
116 check_closed (octave_tiff_handle *tiff_handle) | |
117 { | |
118 if (tiff_handle->is_closed ()) | |
119 error ("The image file was closed"); | |
73 } | 120 } |
74 | 121 |
75 // Error if status is not 1 (success status for TIFFGetField) | 122 // Error if status is not 1 (success status for TIFFGetField) |
76 void | 123 void |
77 validate_tiff_get_field (bool status, void *p_to_free=NULL) | 124 validate_tiff_get_field (bool status, void *p_to_free=NULL) |
2078 | 2125 |
2079 // TODO(maged): check of there is more to be done for r+ | 2126 // TODO(maged): check of there is more to be done for r+ |
2080 if (is_rplus && ! TIFFSetDirectory (tif, 0)) | 2127 if (is_rplus && ! TIFFSetDirectory (tif, 0)) |
2081 error ("Failed to open Tiff file\n"); | 2128 error ("Failed to open Tiff file\n"); |
2082 | 2129 |
2083 // TODO(maged): use inheritance of octave_base_value instead | 2130 octave_value tiff_ov = octave_value (new octave_tiff_handle (tif)); |
2084 octave_value tiff_ov = octave_value ((uint64_t)tif); | |
2085 return octave_value_list (tiff_ov); | 2131 return octave_value_list (tiff_ov); |
2086 #else | 2132 #else |
2087 octave_unused_parameter (args); | 2133 octave_unused_parameter (args); |
2088 err_disabled_feature ("Tiff", "Tiff"); | 2134 err_disabled_feature ("Tiff", "Tiff"); |
2089 #endif | 2135 #endif |
2097 int nargin = args.length (); | 2143 int nargin = args.length (); |
2098 | 2144 |
2099 if (nargin == 0) | 2145 if (nargin == 0) |
2100 error ("No handle provided\n"); | 2146 error ("No handle provided\n"); |
2101 | 2147 |
2102 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2148 octave_tiff_handle *tiff_handle |
2103 TIFFClose (tif); | 2149 = octave_tiff_handle::get_tiff_handle (args(0)); |
2150 | |
2151 tiff_handle->close (); | |
2104 | 2152 |
2105 return octave_value_list (); | 2153 return octave_value_list (); |
2106 #else | 2154 #else |
2107 err_disabled_feature ("close", "Tiff"); | 2155 err_disabled_feature ("close", "Tiff"); |
2108 #endif | 2156 #endif |
2109 } | 2157 } |
2110 | 2158 |
2111 | 2159 |
2112 DEFUN (__tiff_get_tag__, args, , | 2160 DEFUN (__tiff_get_tag__, args, , |
2113 "Get the value of a tag from a tiff image") | 2161 "Get the value of a tag from a tiff image") |
2114 { | 2162 { |
2115 #if defined (HAVE_TIFF) | 2163 #if defined (HAVE_TIFF) |
2116 int nargin = args.length (); | 2164 int nargin = args.length (); |
2117 | 2165 |
2118 if (nargin == 0) | 2166 if (nargin == 0) |
2119 error ("No handle provided\n"); | 2167 error ("No handle provided\n"); |
2120 | 2168 |
2121 if (nargin < 2) | 2169 if (nargin < 2) |
2122 error ("No tag name provided\n"); | 2170 error ("No tag name provided\n"); |
2123 | 2171 |
2124 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2172 octave_tiff_handle *tiff_handle |
2173 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2174 | |
2175 check_closed (tiff_handle); | |
2176 | |
2177 TIFF *tif = tiff_handle->get_file (); | |
2125 | 2178 |
2126 uint32_t tag_id; | 2179 uint32_t tag_id; |
2127 const TIFFField *fip; | 2180 const TIFFField *fip; |
2128 | 2181 |
2129 if (args(1).is_string ()) | 2182 if (args(1).is_string ()) |
2158 int nargin = args.length (); | 2211 int nargin = args.length (); |
2159 | 2212 |
2160 if (nargin < 2) | 2213 if (nargin < 2) |
2161 error ("Too few arguments provided\n"); | 2214 error ("Too few arguments provided\n"); |
2162 | 2215 |
2163 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2216 octave_tiff_handle *tiff_handle |
2164 | 2217 = octave_tiff_handle::get_tiff_handle (args(0)); |
2218 check_closed (tiff_handle); | |
2219 | |
2220 TIFF *tif = tiff_handle->get_file (); | |
2165 check_readonly (tif); | 2221 check_readonly (tif); |
2166 | 2222 |
2167 if (args(1).isstruct ()) | 2223 if (args(1).isstruct ()) |
2168 { | 2224 { |
2169 octave_scalar_map tags = args(1).xscalar_map_value ("__tiff_set_tag__: struct argument must be a scalar structure"); | 2225 octave_scalar_map tags = args(1).xscalar_map_value ("__tiff_set_tag__: struct argument must be a scalar structure"); |
2220 int nargin = args.length (); | 2276 int nargin = args.length (); |
2221 | 2277 |
2222 if (nargin == 0) | 2278 if (nargin == 0) |
2223 error ("No handle provided\n"); | 2279 error ("No handle provided\n"); |
2224 | 2280 |
2225 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2281 octave_tiff_handle *tiff_handle |
2282 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2283 check_closed (tiff_handle); | |
2284 | |
2285 TIFF *tif = tiff_handle->get_file (); | |
2226 | 2286 |
2227 // TODO(maged): nargout and ycbcr | 2287 // TODO(maged): nargout and ycbcr |
2228 octave_unused_parameter (nargout); | 2288 octave_unused_parameter (nargout); |
2229 | 2289 |
2230 // Obtain all necessary tags | 2290 // Obtain all necessary tags |
2288 int nargin = args.length (); | 2348 int nargin = args.length (); |
2289 | 2349 |
2290 if (nargin != 2) | 2350 if (nargin != 2) |
2291 error ("Wrong number of arguments"); | 2351 error ("Wrong number of arguments"); |
2292 | 2352 |
2293 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2353 octave_tiff_handle *tiff_handle |
2354 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2355 check_closed (tiff_handle); | |
2356 | |
2357 TIFF *tif = tiff_handle->get_file (); | |
2294 | 2358 |
2295 // TODO(maged): nargout and ycbcr | 2359 // TODO(maged): nargout and ycbcr |
2296 octave_unused_parameter (nargout); | 2360 octave_unused_parameter (nargout); |
2297 | 2361 |
2298 if (TIFFIsTiled (tif)) | 2362 if (TIFFIsTiled (tif)) |
2323 int nargin = args.length (); | 2387 int nargin = args.length (); |
2324 | 2388 |
2325 if (nargin != 2) | 2389 if (nargin != 2) |
2326 error ("Wrong number of arguments"); | 2390 error ("Wrong number of arguments"); |
2327 | 2391 |
2328 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2392 octave_tiff_handle *tiff_handle |
2393 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2394 check_closed (tiff_handle); | |
2395 | |
2396 TIFF *tif = tiff_handle->get_file (); | |
2329 | 2397 |
2330 // TODO(maged): nargout and ycbcr | 2398 // TODO(maged): nargout and ycbcr |
2331 octave_unused_parameter (nargout); | 2399 octave_unused_parameter (nargout); |
2332 | 2400 |
2333 if (! TIFFIsTiled (tif)) | 2401 if (! TIFFIsTiled (tif)) |
2358 int nargin = args.length (); | 2426 int nargin = args.length (); |
2359 | 2427 |
2360 if (nargin != 1) | 2428 if (nargin != 1) |
2361 error ("Wrong number of arguments"); | 2429 error ("Wrong number of arguments"); |
2362 | 2430 |
2363 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2431 octave_tiff_handle *tiff_handle |
2432 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2433 check_closed (tiff_handle); | |
2434 | |
2435 TIFF *tif = tiff_handle->get_file (); | |
2364 | 2436 |
2365 tiff_image_data image_data (tif); | 2437 tiff_image_data image_data (tif); |
2366 | 2438 |
2367 uint16_t orientation; | 2439 uint16_t orientation; |
2368 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ORIENTATION, &orientation)) | 2440 if (! TIFFGetFieldDefaulted (tif, TIFFTAG_ORIENTATION, &orientation)) |
2422 int nargin = args.length (); | 2494 int nargin = args.length (); |
2423 | 2495 |
2424 if (nargin != 2) | 2496 if (nargin != 2) |
2425 error ("Wrong number of arguments"); | 2497 error ("Wrong number of arguments"); |
2426 | 2498 |
2427 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2499 octave_tiff_handle *tiff_handle |
2500 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2501 check_closed (tiff_handle); | |
2502 | |
2503 TIFF *tif = tiff_handle->get_file (); | |
2428 | 2504 |
2429 // Matlab (R2022a) requires row to be double | 2505 // Matlab (R2022a) requires row to be double |
2430 if (! args(1).is_double_type ()) | 2506 if (! args(1).is_double_type ()) |
2431 error ("row should be of type double"); | 2507 error ("row should be of type double"); |
2432 | 2508 |
2520 int nargin = args.length (); | 2596 int nargin = args.length (); |
2521 | 2597 |
2522 if (nargin != 3) | 2598 if (nargin != 3) |
2523 error ("Wrong number of arguments"); | 2599 error ("Wrong number of arguments"); |
2524 | 2600 |
2525 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2601 octave_tiff_handle *tiff_handle |
2602 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2603 check_closed (tiff_handle); | |
2604 | |
2605 TIFF *tif = tiff_handle->get_file (); | |
2526 | 2606 |
2527 if (! args(1).is_double_type ()) | 2607 if (! args(1).is_double_type ()) |
2528 error ("row should be of type double"); | 2608 error ("row should be of type double"); |
2529 if (! args(2).is_double_type ()) | 2609 if (! args(2).is_double_type ()) |
2530 error ("col should be of type double"); | 2610 error ("col should be of type double"); |
2626 int nargin = args.length (); | 2706 int nargin = args.length (); |
2627 | 2707 |
2628 if (nargin < 2) | 2708 if (nargin < 2) |
2629 error ("Wrong number of arguments\n"); | 2709 error ("Wrong number of arguments\n"); |
2630 | 2710 |
2631 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2711 octave_tiff_handle *tiff_handle |
2712 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2713 check_closed (tiff_handle); | |
2714 | |
2715 TIFF *tif = tiff_handle->get_file (); | |
2632 | 2716 |
2633 check_readonly (tif); | 2717 check_readonly (tif); |
2634 | 2718 |
2635 // Obtain all necessary tags | 2719 // Obtain all necessary tags |
2636 tiff_image_data image_data (tif); | 2720 tiff_image_data image_data (tif); |
2718 | 2802 |
2719 // TODO(maged): add support for YCbCr data | 2803 // TODO(maged): add support for YCbCr data |
2720 if (nargin < 3) | 2804 if (nargin < 3) |
2721 error ("Too few arguments provided\n"); | 2805 error ("Too few arguments provided\n"); |
2722 | 2806 |
2723 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2807 octave_tiff_handle *tiff_handle |
2808 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2809 check_closed (tiff_handle); | |
2810 | |
2811 TIFF *tif = tiff_handle->get_file (); | |
2724 | 2812 |
2725 check_readonly (tif); | 2813 check_readonly (tif); |
2726 | 2814 |
2727 // Obtain all necessary tags | 2815 // Obtain all necessary tags |
2728 tiff_image_data image_data (tif); | 2816 tiff_image_data image_data (tif); |
2750 | 2838 |
2751 // TODO(maged): add support for YCbCr data | 2839 // TODO(maged): add support for YCbCr data |
2752 if (nargin < 3) | 2840 if (nargin < 3) |
2753 error ("Too few arguments provided\n"); | 2841 error ("Too few arguments provided\n"); |
2754 | 2842 |
2755 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2843 octave_tiff_handle *tiff_handle |
2844 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2845 check_closed (tiff_handle); | |
2846 | |
2847 TIFF *tif = tiff_handle->get_file (); | |
2756 | 2848 |
2757 check_readonly (tif); | 2849 check_readonly (tif); |
2758 | 2850 |
2759 // Obtain all necessary tags | 2851 // Obtain all necessary tags |
2760 tiff_image_data image_data (tif); | 2852 tiff_image_data image_data (tif); |
2781 int nargin = args.length (); | 2873 int nargin = args.length (); |
2782 | 2874 |
2783 if (nargin == 0) | 2875 if (nargin == 0) |
2784 error ("No handle provided\n"); | 2876 error ("No handle provided\n"); |
2785 | 2877 |
2786 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2878 octave_tiff_handle *tiff_handle |
2879 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2880 check_closed (tiff_handle); | |
2881 | |
2882 TIFF *tif = tiff_handle->get_file (); | |
2883 | |
2787 bool is_tiled = static_cast<bool> (TIFFIsTiled (tif)); | 2884 bool is_tiled = static_cast<bool> (TIFFIsTiled (tif)); |
2788 return octave_value_list (octave_value (is_tiled)); | 2885 return octave_value_list (octave_value (is_tiled)); |
2789 #else | 2886 #else |
2790 err_disabled_feature ("isTiled", "Tiff"); | 2887 err_disabled_feature ("isTiled", "Tiff"); |
2791 #endif | 2888 #endif |
2798 int nargin = args.length (); | 2895 int nargin = args.length (); |
2799 | 2896 |
2800 if (nargin == 0) | 2897 if (nargin == 0) |
2801 error ("No handle provided\n"); | 2898 error ("No handle provided\n"); |
2802 | 2899 |
2803 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2900 octave_tiff_handle *tiff_handle |
2901 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2902 check_closed (tiff_handle); | |
2903 | |
2904 TIFF *tif = tiff_handle->get_file (); | |
2804 | 2905 |
2805 if (TIFFIsTiled (tif)) | 2906 if (TIFFIsTiled (tif)) |
2806 error ("The image is tiled not stripped"); | 2907 error ("The image is tiled not stripped"); |
2807 | 2908 |
2808 double strip_count = static_cast<double> (TIFFNumberOfStrips (tif)); | 2909 double strip_count = static_cast<double> (TIFFNumberOfStrips (tif)); |
2819 int nargin = args.length (); | 2920 int nargin = args.length (); |
2820 | 2921 |
2821 if (nargin == 0) | 2922 if (nargin == 0) |
2822 error ("No handle provided\n"); | 2923 error ("No handle provided\n"); |
2823 | 2924 |
2824 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2925 octave_tiff_handle *tiff_handle |
2926 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2927 check_closed (tiff_handle); | |
2928 | |
2929 TIFF *tif = tiff_handle->get_file (); | |
2825 | 2930 |
2826 if (! TIFFIsTiled (tif)) | 2931 if (! TIFFIsTiled (tif)) |
2827 error ("The image is stripped not tiled"); | 2932 error ("The image is stripped not tiled"); |
2828 | 2933 |
2829 double tile_count = static_cast<double> (TIFFNumberOfTiles (tif)); | 2934 double tile_count = static_cast<double> (TIFFNumberOfTiles (tif)); |
2840 int nargin = args.length (); | 2945 int nargin = args.length (); |
2841 | 2946 |
2842 if (nargin < 2 || nargin > 3) | 2947 if (nargin < 2 || nargin > 3) |
2843 error ("Wrong number of arguments\n"); | 2948 error ("Wrong number of arguments\n"); |
2844 | 2949 |
2845 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 2950 octave_tiff_handle *tiff_handle |
2951 = octave_tiff_handle::get_tiff_handle (args(0)); | |
2952 check_closed (tiff_handle); | |
2953 | |
2954 TIFF *tif = tiff_handle->get_file (); | |
2846 | 2955 |
2847 if (TIFFIsTiled (tif)) | 2956 if (TIFFIsTiled (tif)) |
2848 error ("The image is tiled not stripped"); | 2957 error ("The image is tiled not stripped"); |
2849 | 2958 |
2850 tiff_image_data image_data (tif); | 2959 tiff_image_data image_data (tif); |
2891 int nargin = args.length (); | 3000 int nargin = args.length (); |
2892 | 3001 |
2893 if (nargin < 2 || nargin > 3) | 3002 if (nargin < 2 || nargin > 3) |
2894 error ("Wrong number of arguments\n"); | 3003 error ("Wrong number of arguments\n"); |
2895 | 3004 |
2896 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 3005 octave_tiff_handle *tiff_handle |
3006 = octave_tiff_handle::get_tiff_handle (args(0)); | |
3007 check_closed (tiff_handle); | |
3008 | |
3009 TIFF *tif = tiff_handle->get_file (); | |
2897 | 3010 |
2898 if (! TIFFIsTiled (tif)) | 3011 if (! TIFFIsTiled (tif)) |
2899 error ("The image is stripped not tiled"); | 3012 error ("The image is stripped not tiled"); |
2900 | 3013 |
2901 uint32NDArray coords = args(1).uint32_array_value (); | 3014 uint32NDArray coords = args(1).uint32_array_value (); |
2951 int nargin = args.length (); | 3064 int nargin = args.length (); |
2952 | 3065 |
2953 if (nargin != 1) | 3066 if (nargin != 1) |
2954 error ("Wrong number of arguments\n"); | 3067 error ("Wrong number of arguments\n"); |
2955 | 3068 |
2956 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 3069 octave_tiff_handle *tiff_handle |
3070 = octave_tiff_handle::get_tiff_handle (args(0)); | |
3071 check_closed (tiff_handle); | |
3072 | |
3073 TIFF *tif = tiff_handle->get_file (); | |
2957 | 3074 |
2958 uint16_t dir = TIFFCurrentDirectory (tif); | 3075 uint16_t dir = TIFFCurrentDirectory (tif); |
2959 dir++; | 3076 dir++; |
2960 | 3077 |
2961 return octave_value_list (octave_value (static_cast<double> (dir))); | 3078 return octave_value_list (octave_value (static_cast<double> (dir))); |
2971 int nargin = args.length (); | 3088 int nargin = args.length (); |
2972 | 3089 |
2973 if (nargin != 1) | 3090 if (nargin != 1) |
2974 error ("Wrong number of arguments\n"); | 3091 error ("Wrong number of arguments\n"); |
2975 | 3092 |
2976 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 3093 octave_tiff_handle *tiff_handle |
3094 = octave_tiff_handle::get_tiff_handle (args(0)); | |
3095 check_closed (tiff_handle); | |
3096 | |
3097 TIFF *tif = tiff_handle->get_file (); | |
2977 | 3098 |
2978 bool is_last = TIFFLastDirectory (tif); | 3099 bool is_last = TIFFLastDirectory (tif); |
2979 | 3100 |
2980 return octave_value_list (octave_value (is_last)); | 3101 return octave_value_list (octave_value (is_last)); |
2981 #else | 3102 #else |
2990 int nargin = args.length (); | 3111 int nargin = args.length (); |
2991 | 3112 |
2992 if (nargin != 1) | 3113 if (nargin != 1) |
2993 error ("Wrong number of arguments\n"); | 3114 error ("Wrong number of arguments\n"); |
2994 | 3115 |
2995 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 3116 octave_tiff_handle *tiff_handle |
3117 = octave_tiff_handle::get_tiff_handle (args(0)); | |
3118 check_closed (tiff_handle); | |
3119 | |
3120 TIFF *tif = tiff_handle->get_file (); | |
2996 | 3121 |
2997 bool is_last = TIFFLastDirectory (tif); | 3122 bool is_last = TIFFLastDirectory (tif); |
2998 if (is_last) | 3123 if (is_last) |
2999 error ("Current directory is the last directory"); | 3124 error ("Current directory is the last directory"); |
3000 | 3125 |
3014 int nargin = args.length (); | 3139 int nargin = args.length (); |
3015 | 3140 |
3016 if (nargin != 2) | 3141 if (nargin != 2) |
3017 error ("Wrong number of arguments\n"); | 3142 error ("Wrong number of arguments\n"); |
3018 | 3143 |
3019 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 3144 octave_tiff_handle *tiff_handle |
3145 = octave_tiff_handle::get_tiff_handle (args(0)); | |
3146 check_closed (tiff_handle); | |
3147 | |
3148 TIFF *tif = tiff_handle->get_file (); | |
3020 | 3149 |
3021 uint16_t dir = args(1).uint16_scalar_value (); | 3150 uint16_t dir = args(1).uint16_scalar_value (); |
3022 if (dir < 1 || dir > TIFFNumberOfDirectories (tif)) | 3151 if (dir < 1 || dir > TIFFNumberOfDirectories (tif)) |
3023 error ("Directory index out of bounds"); | 3152 error ("Directory index out of bounds"); |
3024 | 3153 |
3040 int nargin = args.length (); | 3169 int nargin = args.length (); |
3041 | 3170 |
3042 if (nargin != 1) | 3171 if (nargin != 1) |
3043 error ("Wrong number of arguments\n"); | 3172 error ("Wrong number of arguments\n"); |
3044 | 3173 |
3045 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 3174 octave_tiff_handle *tiff_handle |
3175 = octave_tiff_handle::get_tiff_handle (args(0)); | |
3176 check_closed (tiff_handle); | |
3177 | |
3178 TIFF *tif = tiff_handle->get_file (); | |
3046 | 3179 |
3047 if (! TIFFWriteDirectory(tif)) | 3180 if (! TIFFWriteDirectory(tif)) |
3048 error ("Failed to write directory"); | 3181 error ("Failed to write directory"); |
3049 | 3182 |
3050 return octave_value_list (); | 3183 return octave_value_list (); |
3060 int nargin = args.length (); | 3193 int nargin = args.length (); |
3061 | 3194 |
3062 if (nargin != 1) | 3195 if (nargin != 1) |
3063 error ("Wrong number of arguments\n"); | 3196 error ("Wrong number of arguments\n"); |
3064 | 3197 |
3065 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 3198 octave_tiff_handle *tiff_handle |
3199 = octave_tiff_handle::get_tiff_handle (args(0)); | |
3200 check_closed (tiff_handle); | |
3201 | |
3202 TIFF *tif = tiff_handle->get_file (); | |
3066 | 3203 |
3067 if (! TIFFRewriteDirectory(tif)) | 3204 if (! TIFFRewriteDirectory(tif)) |
3068 error ("Failed to rewrite directory"); | 3205 error ("Failed to rewrite directory"); |
3069 | 3206 |
3070 return octave_value_list (); | 3207 return octave_value_list (); |
3080 int nargin = args.length (); | 3217 int nargin = args.length (); |
3081 | 3218 |
3082 if (nargin != 2) | 3219 if (nargin != 2) |
3083 error ("Wrong number of arguments\n"); | 3220 error ("Wrong number of arguments\n"); |
3084 | 3221 |
3085 TIFF *tif = (TIFF *)(args(0).uint64_value ()); | 3222 octave_tiff_handle *tiff_handle |
3223 = octave_tiff_handle::get_tiff_handle (args(0)); | |
3224 check_closed (tiff_handle); | |
3225 | |
3226 TIFF *tif = tiff_handle->get_file (); | |
3086 | 3227 |
3087 if (! args(1).is_double_type () && ! args(1).is_uint32_type () | 3228 if (! args(1).is_double_type () && ! args(1).is_uint32_type () |
3088 && ! args(1).is_uint64_type ()) | 3229 && ! args(1).is_uint64_type ()) |
3089 error ("Expected offset of type double, uint32 or uint64"); | 3230 error ("Expected offset of type double, uint32 or uint64"); |
3090 | 3231 |