> Would you mind to provide a sample TIFF file for proof of concept?
Sure. The file has to be a contiguous grey/palette image with more than
one sample per pixel and a non-zero fromskew, so the simplest trigger is a
tiled greyscale image with associated alpha (SamplesPerPixel=2) whose tile
width does not divide the image width - the right-hand edge tile is then
read with fromskew != 0 and dispatches to putagreytile().
Rather than a binary, here is a self-contained reproducer that writes the
sample and reads it back through the RGBA API. The grey value encodes the
true column; every pixel should read back grey = x*10+5.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "tiffio.h"
#define W 24
#define H 16
#define TW 16
int main(void)
{
uint16_t extra = EXTRASAMPLE_ASSOCALPHA;
TIFF *t = TIFFOpen("poc.tif", "w");
TIFFSetField(t, TIFFTAG_IMAGEWIDTH, W);
TIFFSetField(t, TIFFTAG_IMAGELENGTH, H);
TIFFSetField(t, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(t, TIFFTAG_SAMPLESPERPIXEL, 2);
TIFFSetField(t, TIFFTAG_EXTRASAMPLES, 1, &extra);
TIFFSetField(t, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(t, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(t, TIFFTAG_TILEWIDTH, TW);
TIFFSetField(t, TIFFTAG_TILELENGTH, H);
unsigned char *tile = calloc(TW * H, 2);
for (uint32_t tx = 0; tx < W; tx += TW) {
for (int r = 0; r < H; r++)
for (int c = 0; c < TW; c++) {
uint32_t gx = tx + c;
unsigned char *p = tile + ((size_t)r * TW + c) * 2;
p[0] = (unsigned char)(gx < W ? gx * 10 + 5 : 0);
p[1] = 255; /* opaque */
}
TIFFWriteTile(t, tile, tx, 0, 0, 0);
}
free(tile);
TIFFClose(t);
t = TIFFOpen("poc.tif", "r");
uint32_t *ras = malloc((size_t)W * H * 4);
TIFFReadRGBAImageOriented(t, W, H, ras, ORIENTATION_TOPLEFT, 0);
TIFFClose(t);
int bad = 0;
for (uint32_t y = 0; y < H; y++)
for (uint32_t x = 0; x < W; x++)
if (TIFFGetR(ras[y * W + x]) != (int)(x * 10 + 5))
bad++;
printf("%d corrupted pixel(s) of %d\n", bad, W * H);
return bad != 0;
}
Before the patch this prints "96 corrupted pixel(s) of 384": in the edge
tile (columns 16..23) every row after the first reads its grey sample from
the wrong offset, because pp is advanced by fromskew instead of
fromskew*samplesperpixel. With the patch it prints "0 corrupted pixel(s)".
The first row is correct either way, which is why the issue is easy to miss.
If you'd still prefer the actual .tif, or a work item on GitLab, I'm happy
to attach the binary or open an issue - just let me know which you prefer.
_______________________________________________
Tiff mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/tiff