diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c index 460e54c6..ecba9f8b 100644 --- a/tools/tiff2pdf.c +++ b/tools/tiff2pdf.c @@ -4942,6 +4942,16 @@ tsize_t t2p_write_pdf_xobject_stream_dict(ttile_t tile, return(written); } + +/* used to normalize the White Point */ +#define normalizePoint(x,y,z) do { \ + if (y != 0.0F) { \ + x /= y; \ + z /= y; \ + y = 1.0F; \ + } \ +} while(0) + /* * This function writes a PDF Image XObject Colorspace name to output. */ @@ -5002,9 +5012,7 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){ X_W = t2p->tiff_whitechromaticities[0]; Y_W = t2p->tiff_whitechromaticities[1]; Z_W = 1.0F - (X_W + Y_W); - X_W /= Y_W; - Z_W /= Y_W; - Y_W = 1.0F; + normalizePoint(X_W, Y_W, Z_W); buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", X_W, Y_W, Z_W); check_snprintf_ret(t2p, buflen, buffer); written += t2pWriteFile(output, (tdata_t) buffer, buflen); @@ -5133,9 +5141,7 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){ X_W = t2p->tiff_whitechromaticities[0]; Y_W = t2p->tiff_whitechromaticities[1]; Z_W = 1.0F - (X_W + Y_W); - X_W /= Y_W; - Z_W /= Y_W; - Y_W = 1.0F; + normalizePoint(X_W, Y_W, Z_W); } if(t2p->pdf_colorspace & T2P_CS_CALRGB){ written += t2pWriteFile(output, (tdata_t) "/CalRGB ", 8); @@ -5160,9 +5166,7 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){ X_W = (X_R * R) + (X_G * G) + (X_B * B); Y_W = (Y_R * R) + (Y_G * G) + (Y_B * B); Z_W = (Z_R * R) + (Z_G * G) + (Z_B * B); - X_W /= Y_W; - Z_W /= Y_W; - Y_W = 1.0; + normalizePoint(X_W, Y_W, Z_W); } written += t2pWriteFile(output, (tdata_t) "<< \n", 4); if(t2p->pdf_colorspace & T2P_CS_CALGRAY){