diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc index 0bafb6d..2bf5e3b 100644 --- a/poppler/GfxState.cc +++ b/poppler/GfxState.cc @@ -1622,6 +1622,12 @@ GfxColorSpace *GfxICCBasedColorSpace::copy() { if (transform != NULL) transform->ref(); cs->lineTransform = lineTransform; if (lineTransform != NULL) lineTransform->ref(); + if (nComps <= 4) { + std::map::iterator it; + for (it = cmsCache.begin(); it != cmsCache.end(); it++) { + cs->cmsCache.insert(std::pair(it->first, it->second)); + } + } #endif return cs; } @@ -1649,7 +1655,7 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, int recu obj1.free(); #ifdef USE_CMS // check cache - if (out && iccProfileStreamA.num > 0) { + if (out && iccProfileStreamA.num > 0) { GfxICCBasedColorSpaceKey k(iccProfileStreamA.num, iccProfileStreamA.gen); GfxICCBasedColorSpaceItem *item = static_cast(out->getIccColorSpaceCache()->lookup(k)); if (item != NULL) @@ -1781,8 +1787,26 @@ void GfxICCBasedColorSpace::getGray(GfxColor *color, GfxGray *gray) { for (int i = 0;i < nComps;i++) { in[i] = colToByte(color->c[i]); } + if (nComps <= 4) { + unsigned int key = 0; + for (int j = 0; j < nComps; j++) { + key = (key << 8) + in[j]; + } + std::map::iterator it = cmsCache.find(key); + if (it != cmsCache.end()) { + *gray = byteToCol(it->second); + return; + } + } transform->doTransform(in,out,1); *gray = byteToCol(out[0]); + if (nComps <= 4) { + unsigned int key = 0; + for (int j = 0; j < nComps; j++) { + key = (key << 8) + in[j]; + } + cmsCache.insert(std::pair(key, out[0])); + } } else { GfxRGB rgb; getRGB(color,&rgb); @@ -1805,10 +1829,32 @@ void GfxICCBasedColorSpace::getRGB(GfxColor *color, GfxRGB *rgb) { for (int i = 0;i < nComps;i++) { in[i] = colToByte(color->c[i]); } + if (nComps <= 4) { + unsigned int key = 0; + for (int j = 0; j < nComps; j++) { + key = (key << 8) + in[j]; + } + std::map::iterator it = cmsCache.find(key); + if (it != cmsCache.end()) { + unsigned int value = it->second; + rgb->r = byteToCol(value >> 16); + rgb->g = byteToCol((value >> 8) & 0xff); + rgb->b = byteToCol(value & 0xff); + return; + } + } transform->doTransform(in,out,1); rgb->r = byteToCol(out[0]); rgb->g = byteToCol(out[1]); rgb->b = byteToCol(out[2]); + if (nComps <= 4) { + unsigned int key = 0; + for (int j = 0; j < nComps; j++) { + key = (key << 8) + in[j]; + } + unsigned int value = (out[0] << 16) + (out[1] << 8) + out[2]; + cmsCache.insert(std::pair(key, value)); + } } else { alt->getRGB(color, rgb); } @@ -1886,11 +1932,34 @@ void GfxICCBasedColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) { for (int i = 0;i < nComps;i++) { in[i] = colToByte(color->c[i]); } + if (nComps <= 4) { + unsigned int key = 0; + for (int j = 0; j < nComps; j++) { + key = (key << 8) + in[j]; + } + std::map::iterator it = cmsCache.find(key); + if (it != cmsCache.end()) { + unsigned int value = it->second; + cmyk->c = byteToCol(value >> 24); + cmyk->m = byteToCol((value >> 16) & 0xff); + cmyk->y = byteToCol((value >> 8) & 0xff); + cmyk->k = byteToCol(value & 0xff); + return; + } + } transform->doTransform(in,out,1); cmyk->c = byteToCol(out[0]); cmyk->m = byteToCol(out[1]); cmyk->y = byteToCol(out[2]); cmyk->k = byteToCol(out[3]); + if (nComps <= 4) { + unsigned int key = 0; + for (int j = 0; j < nComps; j++) { + key = (key << 8) + in[j]; + } + unsigned int value = (out[0] << 24) + (out[1] << 16) + (out[2] << 8) + out[3]; + cmsCache.insert(std::pair(key, value)); + } } else { GfxRGB rgb; GfxColorComp c, m, y, k; diff --git a/poppler/GfxState.h b/poppler/GfxState.h index 2f3efcf..3749f48 100644 --- a/poppler/GfxState.h +++ b/poppler/GfxState.h @@ -42,6 +42,7 @@ #include "Function.h" #include +#include class Array; class Gfx; @@ -524,6 +525,7 @@ private: #ifdef USE_CMS GfxColorTransform *transform; GfxColorTransform *lineTransform; // color transform for line + std::map cmsCache; #endif }; //------------------------------------------------------------------------