Mercurial > octave-libtiff
changeset 31092:a736190ce738
Added the Tiff classdef files to octave
author | magedrifaat <magedrifaat@gmail.com> |
---|---|
date | Fri, 17 Jun 2022 16:53:43 +0200 |
parents | 6cac9f1e54b5 |
children | e2bed4daae82 |
files | libinterp/dldfcn/__tiff__.cc libinterp/dldfcn/module-files scripts/io/Tiff.m scripts/io/module.mk |
diffstat | 4 files changed, 145 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/dldfcn/__tiff__.cc Fri Jun 17 16:53:43 2022 +0200 @@ -0,0 +1,98 @@ +#include <string> + +#include "defun-dld.h" +#include "ov.h" +#include "ovl.h" + +#include <tiffio.h> + + +// TODO(maged): Tidy up the formatting to be consistant with octave + +DEFUN_DLD (__open_tiff__, args, nargout, + "Open a Tiff file and return its handle") +{ + int nargin = args.length(); + + if (nargin == 0 || nargin > 2) + { + // TODO(maged): return invalid object instead?? + error("No filename supplied\n"); + } + + std::string filename = args(0).string_value(); + std::string mode = "r"; + + // TODO(maged): check valid mode + if (nargin == 2) + mode = args(1).string_value(); + + TIFF *tif = TIFFOpen(filename.c_str(), mode.c_str()); + // TODO(maged): print a better error + if (!tif) + error("Failed to open Tiff file\n"); + + octave_value tiff_ov = octave_value((uint64_t)tif); + return octave_value_list (tiff_ov); +} + + +DEFUN_DLD (__close_tiff__, args, nargout, + "Close a tiff file") +{ + int nargin = args.length(); + + if (nargin == 0) + { + error("No handle provided\n"); + } + + TIFF *tif = (TIFF *)(args(0).uint64_value()); + TIFFClose(tif); + + return octave_value_list (); +} + + +DEFUN_DLD (__tiff_get_tag__, args, nargout, + "Get the value of a tag from a tiff image") +{ + int nargin = args.length(); + + if (nargin == 0) + { + error("No handle provided\n"); + } + + if (nargin < 2) + { + error("No tag name provided\n"); + } + + TIFF *tif = (TIFF *)(args(0).uint64_value()); + + uint32_t tag_ID; + if (args(1).type_name() == "string") + { + std::string tagName = args(1).string_value(); + const TIFFField *fip = TIFFFieldWithName(tif, tagName.c_str()); + if (!fip) + error("Tiff tag not found\n"); + + tag_ID = TIFFFieldTag(fip); + } + else + { + tag_ID = args(1).int_value(); + const TIFFField *fip = TIFFFieldWithTag(tif, tag_ID); + // TODO(maged): Handle other types of errors + if (!fip) + error("Tiff tag not found\n"); + } + + // TODO(maged): Handle different data types/ multivalued tags. + uint32_t tag_data; + TIFFGetField(tif, tag_ID, &tag_data); + + return octave_value_list (octave_value(tag_data)); +}
--- a/libinterp/dldfcn/module-files Sun Jun 12 14:37:07 2022 +0200 +++ b/libinterp/dldfcn/module-files Fri Jun 17 16:53:43 2022 +0200 @@ -5,6 +5,7 @@ __init_fltk__.cc|$(FLTK_CPPFLAGS) $(FT2_CPPFLAGS) $(FONTCONFIG_CPPFLAGS)|$(FLTK_LDFLAGS) $(FT2_LDFLAGS)|$(FLTK_LIBS) $(FT2_LIBS) $(OPENGL_LIBS) __init_gnuplot__.cc|$(FT2_CPPFLAGS) $(FONTCONFIG_CPPFLAGS)|| __ode15__.cc|$(SUNDIALS_XCPPFLAGS)|$(SUNDIALS_XLDFLAGS)|$(SUNDIALS_XLIBS) +__tiff.cc__| |-ltiff| __voronoi__.cc|$(QHULL_CPPFLAGS)|$(QHULL_LDFLAGS)|$(QHULL_LIBS) audiodevinfo.cc|$(PORTAUDIO_CPPFLAGS)|$(PORTAUDIO_LDFLAGS)|$(PORTAUDIO_LIBS) audioread.cc|$(SNDFILE_CPPFLAGS)|$(SNDFILE_LDFLAGS)|$(SNDFILE_LIBS)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/io/Tiff.m Fri Jun 17 16:53:43 2022 +0200 @@ -0,0 +1,44 @@ +classdef Tiff + properties (Constant = true) + TagID = struct( + "ImageWidth", 256, + "ImageLength", 257, + "BitsPerSample", 258, + "Compression", 259, + "PhotometricInterpretation", 262, + "StripOffsets", 273, + "SamplesPerPixel", 277, + "RowsPerStrip", 278, + "StripByteCounts", 279, + "XResolution", 282, + "YResolution", 283, + "ResolutionUnit", 296, + "ColorMap", 320 + ) + endproperties + + properties (Access = private) + tiff_handle + endproperties + + methods + function t = Tiff(filename, mode="r") + if (nargin == 0 || nargin > 2) + % print_usage(); + error("Usage: Tiff(filename[, mode])"); + endif + + t.tiff_handle = __open_tiff__(filename, mode); + endfunction + + function close(t) + __close_tiff__(t.tiff_handle); + endfunction + + function tag = getTag(t, tagName) + tag = __tiff_get_tag__(t.tiff_handle, tagName); + endfunction + + % TODO(maged): implement a print_usage + endmethods +endclassdef \ No newline at end of file
--- a/scripts/io/module.mk Sun Jun 12 14:37:07 2022 +0200 +++ b/scripts/io/module.mk Fri Jun 17 16:53:43 2022 +0200 @@ -8,7 +8,8 @@ %reldir%/dlmwrite.m \ %reldir%/fileread.m \ %reldir%/importdata.m \ - %reldir%/is_valid_file_id.m + %reldir%/is_valid_file_id.m \ + %reldir%/Tiff.m %canon_reldir%dir = $(fcnfiledir)/io