# HG changeset patch # User magedrifaat # Date 1660694244 -7200 # Node ID c07461ca34d61853275b4c2a67953c3199b0b02e # Parent ed329571ec88aab5dfc79ee150f5d7b537057dd6 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. diff -r ed329571ec88 -r c07461ca34d6 libinterp/corefcn/__tiff__.cc --- 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 supported_modes {"r", "w", "w8", "a"}; + const std::vector 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");