# HG changeset patch # User magedrifaat # Date 1660307808 -7200 # Node ID f91cd5ceaae6ab560a7afa8c2bc6ae6f6e41d2ac # Parent b8b6cc05c8eaa7e399273e2acefe132f191e779a Tiff setTag: added support for special-case tags. diff -r b8b6cc05c8ea -r f91cd5ceaae6 libinterp/corefcn/__tiff__.cc --- a/libinterp/corefcn/__tiff__.cc Fri Aug 12 01:23:07 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Fri Aug 12 14:36:48 2022 +0200 @@ -1078,7 +1078,7 @@ uint16_t bits_per_sample; if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) - error ("Failed to obtain the number of samples per pixel"); + error ("Failed to obtain the bit depth"); uint32_t count = 1 << bits_per_sample; uint16_t *ch1, *ch2, *ch3; @@ -1309,21 +1309,12 @@ 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); // TODO(maged): find/create images to test the special tags switch (tag_id) { - case TIFFTAG_STRIPBYTECOUNTS: - case TIFFTAG_STRIPOFFSETS: - set_array_field_data (tif, fip, tag_ov, TIFFNumberOfStrips (tif)); - break; - case TIFFTAG_TILEBYTECOUNTS: - case TIFFTAG_TILEOFFSETS: - set_array_field_data (tif, fip, tag_ov, TIFFNumberOfTiles (tif)); - break; case TIFFTAG_YCBCRCOEFFICIENTS: set_array_field_data (tif, fip, tag_ov, 3); break; @@ -1376,18 +1367,23 @@ uint16_t bits_per_sample; if (! TIFFGetFieldDefaulted (tif, TIFFTAG_BITSPERSAMPLE, &bits_per_sample)) - error ("Failed to obtain the number of samples per pixel"); + error ("Failed to obtain the bit depth"); uint32_t count = 1 << bits_per_sample; - uint16_t *ch1, *ch2, *ch3; + + uint16_t *data_ptr + = reinterpret_cast (tag_ov.uint16_array_value () + .fortran_vec ()); if (samples_per_pixel == 1) { - // validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP, &ch1)); + if (! TIFFSetField (tif, tag_id, data_ptr)) + error ("Failed to set field"); } else { - // validate_tiff_get_field (TIFFGetField (tif, TIFFTAG_COLORMAP, - // &ch1, &ch2, &ch3)); + if (! TIFFSetField (tif, tag_id, data_ptr, data_ptr + count, + data_ptr + 2 * count)) + error ("Failed to set field"); } break; } @@ -1396,23 +1392,26 @@ case TIFFTAG_DOTRANGE: case TIFFTAG_YCBCRSUBSAMPLING: { - uint16_t tag_part1, tag_part2; - // validate_tiff_get_field (TIFFGetField (tif, tag_id, - // &tag_part1, &tag_part2)); + // TODO(maged): what is matlab behavior for wrong dimensions + uint16NDArray array_data = tag_ov.uint16_array_value (); + if (! TIFFSetField (tif, tag_id, array_data (0), array_data (1))) + error ("Failed to set field"); break; } case TIFFTAG_SUBIFD: { - uint16_t count; - uint64_t *offsets; - // validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &offsets)); + // TODO(maged): check if matlab supports setting this tag + error ("Unsupported tag"); break; } case TIFFTAG_EXTRASAMPLES: { - uint16_t count; - uint16_t *types; - // validate_tiff_get_field (TIFFGetField (tif, tag_id, &count, &types)); + // TODO(maged): check if matlab validates dimensions/values of this tag + uint16NDArray data_array = tag_ov.uint16_array_value (); + if (! TIFFSetField (tif, tag_id, + static_cast (data_array.dim1 ()), + data_array.fortran_vec ())) + error ("Failed to set field"); break; } // TODO(maged): These tags are more complex to implement