Mercurial > octave-libtiff
changeset 31124:e8d1cc309bc9
Tiff: added initial implementation of setTag function for scalar tags
* __tiff__.cc(F__tiff_set_tag): Added internal function for setTag.
* __tiff__.cc(set_field_data): Implemented support for scalar tags only.
* Tiff.m(setTag): Added setTag method.
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Thu, 21 Jul 2022 22:44:01 +0200 |
parents | 0bcb35909ef4 |
children | 3b775b939de4 |
files | libinterp/dldfcn/__tiff__.cc scripts/io/Tiff.m |
diffstat | 2 files changed, 65 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/dldfcn/__tiff__.cc Thu Jul 21 20:03:43 2022 +0200 +++ b/libinterp/dldfcn/__tiff__.cc Thu Jul 21 22:44:01 2022 +0200 @@ -641,6 +641,7 @@ // TODO(maged): test this function vs actual data type size int type_size = TIFFDataWidth (TIFFFieldDataType (fip)); + // TODO(maged): use shared pointer instead of malloc void *data = _TIFFmalloc (type_size); validate_tiff_get_field (TIFFGetField (tif, tag_id, data), data); octave_value tag_data_ov = interpret_tag_data (data, 1, @@ -847,6 +848,18 @@ return tag_data_ov; } + + void + set_field_data (TIFF *tif, const TIFFField *fip, octave_value tag_ov) + { + // TODO(maged): complete the implementation of this function + uint32_t tag_id = TIFFFieldTag (fip); + uint32_t tag_data = tag_ov.double_value (); + + if (! TIFFSetField(tif, tag_id, tag_data)) + error ("Failed to set tag value"); + } + #endif DEFUN_DLD (__open_tiff__, args, nargout, @@ -951,6 +964,52 @@ #endif } + + DEFUN_DLD (__tiff_set_tag__, args, nargout, + "Set the value of a tag in a tiff image") + { +#if defined (HAVE_TIFF) + int nargin = args.length (); + + if (nargin < 2) + error ("Too few arguments provided\n"); + + TIFF *tif = (TIFF *)(args (0).uint64_value ()); + + // TODO(maged): does matlab allow calling this function for images + // opened for reading? + if (args (1).type_name () == "struct") + error ("setTag with struct is not yet supported"); + else + { + const TIFFField *fip; + if (args (1).type_name () == "string") + { + std::string tagName = args (1).string_value (); + fip = TIFFFieldWithName (tif, tagName.c_str ()); + if (! fip) + error ("Tiff tag not found"); + } + else + { + uint32_t tag_id = args (1).int_value (); + fip = TIFFFieldWithTag (tif, tag_id); + if (! fip) + error ("Tiff tag not found"); + } + + if (nargin < 3) + error ("Too few arguments provided"); + + set_field_data (tif, fip, args (2)); + } + + return octave_value_list (); +#else + err_disabled_feature ("setTag", "Tiff"); +#endif + } + DEFUN_DLD (__tiff_read__, args, nargout, "Read the image in the current IFD") {
--- a/scripts/io/Tiff.m Thu Jul 21 20:03:43 2022 +0200 +++ b/scripts/io/Tiff.m Thu Jul 21 22:44:01 2022 +0200 @@ -92,8 +92,12 @@ __close_tiff__(t.tiff_handle); endfunction - function tag = getTag(t, tagName) - tag = __tiff_get_tag__(t.tiff_handle, tagName); + function tag = getTag(t, tag_name) + tag = __tiff_get_tag__(t.tiff_handle, tag_name); + endfunction + + function setTag(t, tag_name, tag_value) + __tiff_set_tag__(t.tiff_handle, tag_name, tag_value); endfunction function argout = read(t)