# HG changeset patch # User magedrifaat # Date 1656036813 -7200 # Node ID edfedae9972a1a89819d200a9172c924c09927d6 # Parent ab5b33e447b0141b0c42f6807342f6587b6a0daf Fixed getTag bug for all numerical scalar tags, still buggy for multivalued and ASCII tags diff -r ab5b33e447b0 -r edfedae9972a libinterp/dldfcn/__tiff__.cc --- a/libinterp/dldfcn/__tiff__.cc Wed Jun 22 23:32:22 2022 +0200 +++ b/libinterp/dldfcn/__tiff__.cc Fri Jun 24 04:13:33 2022 +0200 @@ -8,7 +8,6 @@ #include - // TODO(maged): Tidy up the formatting to be consistant with octave octave_value interpret_data(void *data, uint32_t count, TIFFDataType tag_datatype) @@ -43,61 +42,54 @@ } break; - // case TIFF_RATIONAL: - // uint32_t *u32data = (uint32_t *)data; - // for (uint32_t i = 0; i < count; i+=2) - // { - // ov_data(i / 2) = octave_value((float)u32data[i] / (float)u32data[i+1]); - // } - // break; + case TIFF_RATIONAL: + for (uint32_t i = 0; i < count; i+=2) + { + ov_data(i / 2) = octave_value((float)((uint32_t *)data)[i] / (float)((uint32_t *)data)[i+1]); + } + break; - // case TIFF_SBYTE: - // int8_t *s8data = (int8_t *)data; - // for (uint32_t i = 0; i < count; i++) - // { - // ov_data(i) = octave_value(s8data[i]); - // } - // break; + case TIFF_SBYTE: + for (uint32_t i = 0; i < count; i++) + { + ov_data(i) = octave_value(((int8_t *)data)[i]); + } + break; - // case TIFF_SSHORT: - // int16_t *s16data = (int16_t *)data; - // for (uint32_t i = 0; i < count; i++) - // { - // ov_data(i) = octave_value(s16data[i]); - // } - // break; + case TIFF_SSHORT: + for (uint32_t i = 0; i < count; i++) + { + ov_data(i) = octave_value(((int16_t *)data)[i]); + } + break; - // case TIFF_SLONG: - // int32_t *s32data = (int32_t *)data; - // for (uint32_t i = 0; i < count; i++) - // { - // ov_data(i) = octave_value(s32data[i]); - // } - // break; + case TIFF_SLONG: + for (uint32_t i = 0; i < count; i++) + { + ov_data(i) = octave_value(((int32_t *)data)[i]); + } + break; - // case TIFF_FLOAT: - // float *float_data = (float *)data; - // for (uint32_t i = 0; i < count; i++) - // { - // ov_data(i) = octave_value(double_data[i]); - // } - // break; + case TIFF_FLOAT: + for (uint32_t i = 0; i < count; i++) + { + ov_data(i) = octave_value(((float *)data)[i]); + } + break; - // case TIFF_DOUBLE: - // double *double_data = (double *)data; - // for (uint32_t i = 0; i < count; i++) - // { - // ov_data(i) = octave_value(double_data[i]); - // } - // break; + case TIFF_DOUBLE: + for (uint32_t i = 0; i < count; i++) + { + ov_data(i) = octave_value(((double *)data)[i]); + } + break; - // case TIFF_SRATIONAL: - // int32_t *s32data = (int32_t *)data; - // for (uint32_t i = 0; i < count; i+=2) - // { - // ov_data(i / 2) = octave_value((float)s32data[i] / (float)s32data[i+1]); - // } - // break; + case TIFF_SRATIONAL: + for (uint32_t i = 0; i < count; i+=2) + { + ov_data(i / 2) = octave_value((float)((int32_t *)data)[i] / (float)((int32_t *)data)[i+1]); + } + break; case TIFF_IFD: // TODO(maged): implement IFD datatype @@ -135,6 +127,7 @@ if (!tif) 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); return octave_value_list (tiff_ov); } @@ -194,50 +187,16 @@ error("Tiff tag not found\n"); } - TIFFDataType tag_datatype = TIFFFieldDataType(fip); - int count = TIFFFieldReadCount(fip); octave_value tag_data_ov; - void *data; - if (count == TIFF_VARIABLE) - { - uint16_t count_param; - if (TIFFGetField(tif, tag_ID, &count_param, &data)) - { - tag_data_ov = interpret_data(data, count_param, tag_datatype); - } - else - { - // TODO(maged): Give a better error message? - error("Failed to read tag"); - } - } - else if (count == TIFF_VARIABLE2) + if (!TIFFFieldPassCount(fip)) { - uint32_t count_param; - if (TIFFGetField(tif, tag_ID, &count_param, &data)) - { - tag_data_ov = interpret_data(data, count_param, tag_datatype); - } - else - { - // TODO(maged): Give a better error message? - error("Failed to read tag"); - } - } - else if (count == TIFF_SPP) - { - // TODO(maged): Handle TIFF_SPP - error("Unimplemented TIFF_SPP count"); - } - else - { - int type_size = TIFFDataWidth(tag_datatype); - data = _TIFFmalloc(type_size * count); + int type_size = TIFFDataWidth(TIFFFieldDataType(fip)); + void *data = _TIFFmalloc(type_size); // TODO(maged): This won't always work, e.g. string exepcts char ** if (TIFFGetField(tif, tag_ID, data)) { - tag_data_ov = interpret_data(data, count, tag_datatype); + tag_data_ov = interpret_data(data, 1, TIFFFieldDataType(fip)); _TIFFfree(data); } else @@ -249,6 +208,11 @@ } } + else + { + // TODO(maged): Implement support for variable read argument tags + error("Variable argument tags not implemented"); + } return octave_value_list (octave_value(tag_data_ov)); }