TEST(fxcodec, CMYK_Rounding) { // Testing all floats from 0.0 to 1.0 takes about 35 seconds in release // builds and much longer in debug builds, so just test the known-dangerous // range. const FX_FLOAT startValue = 0.001f; const FX_FLOAT endValue = 0.003f; FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; // Iterate through floats by incrementing the representation, as discussed in // https://randomascii.wordpress.com/2012/01/23/stupid-float-tricks-2/ for (Float_t f = startValue; f.f < endValue; f.i++) { AdobeCMYK_to_sRGB(f.f, f.f, f.f, f.f, R, G, B); } // Check various other 'special' numbers. AdobeCMYK_to_sRGB(0.0f, 0.25f, 0.5f, 1.0f, R, G, B); }
FX_BOOL CPDF_ColorSpace::SetCMYK(FX_FLOAT* pBuf, FX_FLOAT c, FX_FLOAT m, FX_FLOAT y, FX_FLOAT k) const { if (v_SetCMYK(pBuf, c, m, y, k)) { return TRUE; } FX_FLOAT R, G, B; AdobeCMYK_to_sRGB(c, m, y, k, R, G, B); return SetRGB(pBuf, R, G, B); }
FX_BOOL CPDF_DeviceCS::v_SetCMYK(FX_FLOAT* pBuf, FX_FLOAT c, FX_FLOAT m, FX_FLOAT y, FX_FLOAT k) const { if (m_Family == PDFCS_DEVICERGB) { AdobeCMYK_to_sRGB(c, m, y, k, pBuf[0], pBuf[1], pBuf[2]); return TRUE; } if (m_Family == PDFCS_DEVICECMYK) { pBuf[0] = c; pBuf[1] = m; pBuf[2] = y; pBuf[3] = k; return TRUE; } return FALSE; }
FX_BOOL CPDF_DeviceCS::GetRGB(FX_FLOAT* pBuf, FX_FLOAT& R, FX_FLOAT& G, FX_FLOAT& B) const { if (m_Family == PDFCS_DEVICERGB) { R = pBuf[0]; if (R < 0) { R = 0; } else if (R > 1) { R = 1; } G = pBuf[1]; if (G < 0) { G = 0; } else if (G > 1) { G = 1; } B = pBuf[2]; if (B < 0) { B = 0; } else if (B > 1) { B = 1; } } else if (m_Family == PDFCS_DEVICEGRAY) { R = *pBuf; if (R < 0) { R = 0; } else if (R > 1) { R = 1; } G = B = R; } else if (m_Family == PDFCS_DEVICECMYK) { if (!m_dwStdConversion) { AdobeCMYK_to_sRGB(pBuf[0], pBuf[1], pBuf[2], pBuf[3], R, G, B); } else { FX_FLOAT k = pBuf[3]; R = 1.0f - FX_MIN(1.0f, pBuf[0] + k); G = 1.0f - FX_MIN(1.0f, pBuf[1] + k); B = 1.0f - FX_MIN(1.0f, pBuf[2] + k); } } else { ASSERT(m_Family == PDFCS_PATTERN); R = G = B = 0; return FALSE; } return TRUE; }