Don't export color constants since that breaks with DLLs... (Issue #19)

This commit is contained in:
Michael R Sweet 2021-08-18 10:17:47 -04:00
parent 21823fb0d9
commit e71c1a7e5e
4 changed files with 58 additions and 52 deletions

View File

@ -20,22 +20,6 @@
#endif // M_PI
//
// Global constants...
//
const double pdfioAdobeRGBGamma = 2.2;
const double pdfioAdobeRGBMatrix[3][3] = { { 0.57667, 0.18556, 0.18823 }, { 0.29734, 0.62736, 0.07529 }, { 0.02703, 0.07069, 0.99134 } };
const double pdfioAdobeRGBWhitePoint[3] = { 0.9505, 1.0, 1.0890 };
const double pdfioDisplayP3Gamma = 2.2;
const double pdfioDisplayP3Matrix[3][3] = { { 0.48657, 0.26567, 0.19822 }, {
0.22897, 0.69174, 0.07929 }, { 0.00000, 0.04511, 1.04394 } };
const double pdfioDisplayP3WhitePoint[3] = { 0.9505, 1.0, 1.0890 };
const double pdfioSRGBGamma = 2.2;
const double pdfioSRGBMatrix[3][3] = { { 0.4124, 0.3576, 0.1805 }, { 0.2126, 0.7152, 0.0722 }, { 0.0193, 0.1192, 0.9505 } };
const double pdfioSRGBWhitePoint[3] = { 0.9505, 1.0, 1.0890 };
//
// Local constants...
//
@ -377,6 +361,41 @@ pdfioArrayCreateColorFromPrimaries(
}
//
// 'pdfioArrayCreateColorFromStandard()' - Create a color array for a standard color space.
//
// This function creates a color array for a standard `PDFIO_CS_` enumerated constant.
// The "num_colors" argument must be `1` for grayscale and `3` for RGB color.
//
pdfio_array_t * // O - Color array
pdfioArrayCreateColorFromStandard(
pdfio_file_t *pdf, // I - PDF file
size_t num_colors, // I - Number of colors (1 or 3)
pdfio_cs_t cs) // I - Color space enumeration
{
static const double adobe_matrix[3][3] = { { 0.57667, 0.18556, 0.18823 }, { 0.29734, 0.62736, 0.07529 }, { 0.02703, 0.07069, 0.99134 } };
static const double d65_white_point[3] = { 0.9505, 1.0, 1.0890 };
static const double p3_d65_matrix[3][3] = { { 0.48657, 0.26567, 0.19822 }, { 0.22897, 0.69174, 0.07929 }, { 0.00000, 0.04511, 1.04394 } };
static const double srgb_matrix[3][3] = { { 0.4124, 0.3576, 0.1805 }, { 0.2126, 0.7152, 0.0722 }, { 0.0193, 0.1192, 0.9505 } };
// Range check input...
if (!pdf || (num_colors != 1 && num_colors != 3) || cs < PDFIO_CS_ADOBE || cs > PDFIO_CS_SRGB)
return (NULL);
switch (cs)
{
case PDFIO_CS_ADOBE :
return (pdfioArrayCreateColorFromMatrix(pdf, num_colors, 2.2, adobe_matrix, d65_white_point));
case PDFIO_CS_P3_D65 :
return (pdfioArrayCreateColorFromMatrix(pdf, num_colors, 2.2, p3_d65_matrix, d65_white_point));
case PDFIO_CS_SRGB :
return (pdfioArrayCreateColorFromMatrix(pdf, num_colors, 2.2, srgb_matrix, d65_white_point));
}
}
//
// 'pdfioContentClip()' - Clip output to the current path.
//
@ -2245,7 +2264,7 @@ copy_jpeg(pdfio_dict_t *dict, // I - Dictionary
pdfioDictSetNumber(dict, "Width", width);
pdfioDictSetNumber(dict, "Height", height);
pdfioDictSetNumber(dict, "BitsPerComponent", 8);
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromMatrix(dict->pdf, num_colors, pdfioSRGBGamma, pdfioSRGBMatrix, pdfioSRGBWhitePoint));
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromStandard(dict->pdf, num_colors, PDFIO_CS_SRGB));
pdfioDictSetName(dict, "Filter", "DCTDecode");
obj = pdfioFileCreateObj(dict->pdf, dict);
@ -2330,7 +2349,7 @@ copy_png(pdfio_dict_t *dict, // I - Dictionary
if (wx != 0.0)
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromPrimaries(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, gamma, wx, wy, rx, ry, bx, by, gx, gy));
else
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromMatrix(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, gamma, pdfioSRGBMatrix, pdfioSRGBWhitePoint));
pdfioDictSetArray(dict, "ColorSpace", pdfioArrayCreateColorFromStandard(dict->pdf, color_type == _PDFIO_PNG_TYPE_GRAY ? 1 : 3, PDFIO_CS_SRGB));
}
obj = pdfioFileCreateObj(dict->pdf, dict);

View File

@ -30,6 +30,13 @@ extern "C" {
// Types and constants...
//
typedef enum pdfio_cs_e // Standard color spaces
{
PDFIO_CS_ADOBE, // AdobeRGB 1998
PDFIO_CS_P3_D65, // Display P3
PDFIO_CS_SRGB // sRGB
} pdfio_cs_t;
typedef enum pdfio_linecap_e // Line capping modes
{
PDFIO_LINECAP_BUTT, // Butt ends
@ -59,25 +66,6 @@ typedef enum pdfio_textrendering_e // Text rendering modes
PDFIO_TEXTRENDERING_TEXT_PATH // Add text to path (invisible)
} pdfio_textrendering_t;
extern const double pdfioAdobeRGBGamma _PDFIO_PUBLIC;
// AdobeRGB gamma
extern const double pdfioAdobeRGBMatrix[3][3] _PDFIO_PUBLIC;
// AdobeRGB matrix
extern const double pdfioAdobeRGBWhitePoint[3] _PDFIO_PUBLIC;
// AdobeRGB white point
extern const double pdfioDisplayP3Gamma _PDFIO_PUBLIC;
// Display P3 gamma
extern const double pdfioDisplayP3Matrix[3][3] _PDFIO_PUBLIC;
// Display P3 matrix
extern const double pdfioDisplayP3WhitePoint[3] _PDFIO_PUBLIC;
// Display P3 white point
extern const double pdfioSRGBGamma _PDFIO_PUBLIC;
// sRGB gamma
extern const double pdfioSRGBMatrix[3][3] _PDFIO_PUBLIC;
// sRGB matrix
extern const double pdfioSRGBWhitePoint[3] _PDFIO_PUBLIC;
// sRGB white point
//
// Functions...
@ -88,6 +76,7 @@ extern pdfio_array_t *pdfioArrayCreateColorFromICCObj(pdfio_file_t *pdf, pdfio_o
extern pdfio_array_t *pdfioArrayCreateColorFromMatrix(pdfio_file_t *pdf, size_t num_colors, double gamma, const double matrix[3][3], const double white_point[3]) _PDFIO_PUBLIC;
extern pdfio_array_t *pdfioArrayCreateColorFromPalette(pdfio_file_t *pdf, size_t num_colors, const unsigned char *colors) _PDFIO_PUBLIC;
extern pdfio_array_t *pdfioArrayCreateColorFromPrimaries(pdfio_file_t *pdf, size_t num_colors, double gamma, double wx, double wy, double rx, double ry, double gx, double gy, double bx, double by) _PDFIO_PUBLIC;
extern pdfio_array_t *pdfioArrayCreateColorFromStandard(pdfio_file_t *pdf, size_t num_colors, pdfio_cs_t cs);
// PDF content drawing functions...
extern bool pdfioContentClip(pdfio_stream_t *st, bool even_odd) _PDFIO_PUBLIC;

View File

@ -4,9 +4,6 @@ EXPORTS
_pdfioTokenInit
_pdfioValueDebug
_pdfioValueRead
pdfioAdobeRGBGamma
pdfioAdobeRGBMatrix
pdfioAdobeRGBWhitePoint
pdfioArrayAppendArray
pdfioArrayAppendBinary
pdfioArrayAppendBoolean
@ -22,6 +19,7 @@ pdfioArrayCreateColorFromICCObj
pdfioArrayCreateColorFromMatrix
pdfioArrayCreateColorFromPalette
pdfioArrayCreateColorFromPrimaries
pdfioArrayCreateColorFromStandard
pdfioArrayGetArray
pdfioArrayGetBinary
pdfioArrayGetBoolean
@ -110,9 +108,6 @@ pdfioDictSetObj
pdfioDictSetRect
pdfioDictSetString
pdfioDictSetStringf
pdfioDisplayP3Gamma
pdfioDisplayP3Matrix
pdfioDisplayP3WhitePoint
pdfioFileClose
pdfioFileCreate
pdfioFileCreateArrayObj
@ -163,9 +158,6 @@ pdfioPageCopy
pdfioPageDictAddColorSpace
pdfioPageDictAddFont
pdfioPageDictAddImage
pdfioSRGBGamma
pdfioSRGBMatrix
pdfioSRGBWhitePoint
pdfioStreamClose
pdfioStreamConsume
pdfioStreamGetToken

View File

@ -76,6 +76,12 @@ main(int argc, // I - Number of command-line arguments
}
else
{
#if _WIN32
// Windows puts executables in Platform/Configuration subdirs...
if (!_access("../../testfiles", 0))
_chdir("../..");
#endif // _WIN32
do_unit_tests();
}
@ -1079,8 +1085,8 @@ write_color_test(pdfio_file_t *pdf, // I - PDF file
else
return (1);
fputs("pdfioArrayCreateColorFromMatrix(AdobeRGB): ", stdout);
if ((cs = pdfioArrayCreateColorFromMatrix(pdf, 3, pdfioAdobeRGBGamma, pdfioAdobeRGBMatrix, pdfioAdobeRGBWhitePoint)) != NULL)
fputs("pdfioArrayCreateColorFromStandard(AdobeRGB): ", stdout);
if ((cs = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_ADOBE)) != NULL)
puts("PASS");
else
return (1);
@ -1091,8 +1097,8 @@ write_color_test(pdfio_file_t *pdf, // I - PDF file
else
return (1);
fputs("pdfioArrayCreateColorFromMatrix(DisplayP3): ", stdout);
if ((cs = pdfioArrayCreateColorFromMatrix(pdf, 3, pdfioDisplayP3Gamma, pdfioDisplayP3Matrix, pdfioDisplayP3WhitePoint)) != NULL)
fputs("pdfioArrayCreateColorFromStandard(DisplayP3): ", stdout);
if ((cs = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_P3_D65)) != NULL)
puts("PASS");
else
return (1);
@ -1115,8 +1121,8 @@ write_color_test(pdfio_file_t *pdf, // I - PDF file
else
return (1);
fputs("pdfioArrayCreateColorFromMatrix(sRGB): ", stdout);
if ((cs = pdfioArrayCreateColorFromMatrix(pdf, 3, pdfioSRGBGamma, pdfioSRGBMatrix, pdfioSRGBWhitePoint)) != NULL)
fputs("pdfioArrayCreateColorFromStandard(sRGB): ", stdout);
if ((cs = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_SRGB)) != NULL)
puts("PASS");
else
return (1);