Skip to content

Commit

Permalink
Implement PR #521: "TiffIO errors print state of relevant check faile…
Browse files Browse the repository at this point in the history
…d ..."

This was from 5/28/2020.
PR failed build and subsequent changes to tiffio.c required recoding.
  • Loading branch information
DanBloomberg committed Aug 30, 2021
1 parent 2f2e488 commit b7c417b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/tiffio.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,16 @@ PIXCMAP *cmap;
L_WARNING("for 2 spp, only handle 8 bps\n", procName);
return NULL;
}
if (spp == 1)
if (spp == 1) {
d = bps;
else if (spp == 2) /* gray plus alpha */
} else if (spp == 2) { /* gray plus alpha */
d = 32; /* will convert to RGBA */
else if (spp == 3 || spp == 4)
} else if (spp == 3 || spp == 4) {
d = 32;
else
return (PIX *)ERROR_PTR("spp not in set {1,2,3,4}", procName, NULL);
} else {
L_ERROR("spp = %d; not in {1,2,3,4}\n", procName, spp);
return NULL;
}

TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
Expand Down Expand Up @@ -616,7 +618,8 @@ PIXCMAP *cmap;
if (TIFFReadScanline(tif, linebuf, i, 0) < 0) {
LEPT_FREE(linebuf);
pixDestroy(&pix);
return (PIX *)ERROR_PTR("line read fail", procName, NULL);
L_ERROR("spp = 1, read fail at line %d\n", procName, i);
return NULL;
}
memcpy(data, linebuf, tiffbpl);
data += bpl;
Expand All @@ -635,7 +638,8 @@ PIXCMAP *cmap;
if (TIFFReadScanline(tif, linebuf, i, 0) < 0) {
LEPT_FREE(linebuf);
pixDestroy(&pix);
return (PIX *)ERROR_PTR("line read fail", procName, NULL);
L_ERROR("spp = 2, read fail at line %d\n", procName, i);
return NULL;
}
rowptr = linebuf;
ppixel = pixdata + i * wpl;
Expand Down Expand Up @@ -942,13 +946,16 @@ TIFF *tif;
return ERROR_INT("stream not defined", procName, 1 );
if (!pix)
return ERROR_INT("pix not defined", procName, 1 );
if (strcmp(modestr, "w") && strcmp(modestr, "a"))
return ERROR_INT("modestr not 'w' or 'a'", procName, 1 );
if (strcmp(modestr, "w") && strcmp(modestr, "a")) {
L_ERROR("modestr = %s; not 'w' or 'a'\n", procName, modestr);
return 1;
}

if (pixGetDepth(pix) != 1 && comptype != IFF_TIFF &&
comptype != IFF_TIFF_LZW && comptype != IFF_TIFF_ZIP &&
comptype != IFF_TIFF_JPEG) {
L_WARNING("invalid compression type for bpp > 1\n", procName);
L_WARNING("invalid compression type %d for bpp > 1; using TIFF_ZIP\n",
procName, comptype);
comptype = IFF_TIFF_ZIP;
}

Expand Down

0 comments on commit b7c417b

Please sign in to comment.