Mercurial > octave-libtiff
changeset 31176:c07461ca34d6
Tiff: add support for oppening tiff files in r+ mode
* __tiff__.cc (F__tif_open__): added support for r+
for opeening tiff files for both reading and writing.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Wed, 17 Aug 2022 01:57:24 +0200 |
parents | ed329571ec88 |
children | c7c79973007f |
files | libinterp/corefcn/__tiff__.cc |
diffstat | 1 files changed, 11 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/__tiff__.cc Tue Aug 16 22:57:21 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Wed Aug 17 01:57:24 2022 +0200 @@ -2053,15 +2053,17 @@ if (nargin == 2) mode = args(1).string_value (); - const std::vector<std::string> supported_modes {"r", "w", "w8", "a"}; + const std::vector<std::string> supported_modes {"r", "w", "w8", "a", "r+"}; if (std::find (supported_modes.cbegin (), supported_modes.cend (), mode) == supported_modes.cend ()) + error ("Invalid mode for openning Tiff file: %s", mode.c_str ()); + + bool is_rplus = false; + if (mode == "r+") { - if (mode == "r+") - error ("Openning files in r+ mode is not yet supported"); - else - error ("Invalid mode for openning Tiff file: %s", mode.c_str ()); + is_rplus = true; + mode = "a"; } // LibTIFF does Strip chopping by default, which makes the organization of @@ -2073,6 +2075,10 @@ if (! tif) error ("Failed to open Tiff file\n"); + + // TODO(maged): check of there is more to be done for r+ + if (is_rplus && ! TIFFSetDirectory (tif, 0)) + error ("Failed to open Tiff file\n"); // TODO(maged): use inheritance of octave_base_value instead octave_value tiff_ov = octave_value ((uint64_t)tif); @@ -3078,9 +3084,6 @@ TIFF *tif = (TIFF *)(args(0).uint64_value ()); - // TODO(maged): check if matlab requires scalar double - // matlab expects double, uint32, or uint64 - // and checks the subIFD tag first if (! args(1).is_double_type () && ! args(1).is_uint32_type () && ! args(1).is_uint64_type ()) error ("Expected offset of type double, uint32 or uint64");