tiff2pdf: normalizePoint() macro to normalize the white point

This commit is contained in:
Thomas Bernard 2020-03-24 11:34:36 +01:00
parent dbc90f9374
commit bd49c5810f
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -4933,6 +4933,16 @@ tsize_t t2p_write_pdf_xobject_stream_dict(ttile_t tile,
return(written); 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. * This function writes a PDF Image XObject Colorspace name to output.
*/ */
@ -4993,11 +5003,7 @@ tsize_t t2p_write_pdf_xobject_cs(T2P* t2p, TIFF* output){
X_W = t2p->tiff_whitechromaticities[0]; X_W = t2p->tiff_whitechromaticities[0];
Y_W = t2p->tiff_whitechromaticities[1]; Y_W = t2p->tiff_whitechromaticities[1];
Z_W = 1.0F - (X_W + Y_W); Z_W = 1.0F - (X_W + Y_W);
if (Y_W != 0.0F) { normalizePoint(X_W, Y_W, Z_W);
X_W /= Y_W;
Z_W /= Y_W;
Y_W = 1.0F;
}
buflen=snprintf(buffer, sizeof(buffer), "[%.4f %.4f %.4f] \n", 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); check_snprintf_ret(t2p, buflen, buffer);
written += t2pWriteFile(output, (tdata_t) buffer, buflen); written += t2pWriteFile(output, (tdata_t) buffer, buflen);
@ -5126,11 +5132,7 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){
X_W = t2p->tiff_whitechromaticities[0]; X_W = t2p->tiff_whitechromaticities[0];
Y_W = t2p->tiff_whitechromaticities[1]; Y_W = t2p->tiff_whitechromaticities[1];
Z_W = 1.0F - (X_W + Y_W); Z_W = 1.0F - (X_W + Y_W);
if (Y_W != 0.0F) { normalizePoint(X_W, Y_W, Z_W);
X_W /= Y_W;
Z_W /= Y_W;
Y_W = 1.0F;
}
} }
if(t2p->pdf_colorspace & T2P_CS_CALRGB){ if(t2p->pdf_colorspace & T2P_CS_CALRGB){
written += t2pWriteFile(output, (tdata_t) "/CalRGB ", 8); written += t2pWriteFile(output, (tdata_t) "/CalRGB ", 8);
@ -5155,11 +5157,7 @@ tsize_t t2p_write_pdf_xobject_calcs(T2P* t2p, TIFF* output){
X_W = (X_R * R) + (X_G * G) + (X_B * B); X_W = (X_R * R) + (X_G * G) + (X_B * B);
Y_W = (Y_R * R) + (Y_G * G) + (Y_B * B); Y_W = (Y_R * R) + (Y_G * G) + (Y_B * B);
Z_W = (Z_R * R) + (Z_G * G) + (Z_B * B); Z_W = (Z_R * R) + (Z_G * G) + (Z_B * B);
if (Y_W != 0.0F) { normalizePoint(X_W, Y_W, Z_W);
X_W /= Y_W;
Z_W /= Y_W;
Y_W = 1.0;
}
} }
written += t2pWriteFile(output, (tdata_t) "<< \n", 4); written += t2pWriteFile(output, (tdata_t) "<< \n", 4);
if(t2p->pdf_colorspace & T2P_CS_CALGRAY){ if(t2p->pdf_colorspace & T2P_CS_CALGRAY){