diff options
author | Albert Astals Cid <aacid@kde.org> | 2009-10-23 21:57:42 +0200 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2009-10-23 22:01:35 +0200 |
commit | b174ebd6b323c7a58a19d59c1a9e4ac4e6cba7d9 (patch) | |
tree | 8357d9648006cada574d57081b757989193f4791 | |
parent | 4a9bdd30dc353865685e03eb1c1ac6093797695a (diff) |
Move the iccColorSpaceCache from a static in GfxState to a member of Gfx
Fixes the problem that the keys are per document but we had a static
that lived as much as the library. Now the cache only lives the rendering
of a page so it's a bit slower but at least it's correct. Fixes bug 24686
-rw-r--r-- | poppler/Gfx.cc | 49 | ||||
-rw-r--r-- | poppler/Gfx.h | 13 | ||||
-rw-r--r-- | poppler/GfxState.cc | 94 | ||||
-rw-r--r-- | poppler/GfxState.h | 33 | ||||
-rw-r--r-- | poppler/Page.cc | 4 |
5 files changed, 107 insertions, 86 deletions
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc index ca9b5132..eeabd870 100644 --- a/poppler/Gfx.cc +++ b/poppler/Gfx.cc @@ -442,3 +442,3 @@ void GfxResources::lookupColorSpace(char *name, Object *obj) { -GfxPattern *GfxResources::lookupPattern(char *name) { +GfxPattern *GfxResources::lookupPattern(char *name, Gfx *gfx) { GfxResources *resPtr; @@ -450,3 +450,3 @@ GfxPattern *GfxResources::lookupPattern(char *name) { if (!resPtr->patternDict.dictLookup(name, &obj)->isNull()) { - pattern = GfxPattern::parse(&obj); + pattern = GfxPattern::parse(&obj, gfx); obj.free(); @@ -461,3 +461,3 @@ GfxPattern *GfxResources::lookupPattern(char *name) { -GfxShading *GfxResources::lookupShading(char *name) { +GfxShading *GfxResources::lookupShading(char *name, Gfx *gfx) { GfxResources *resPtr; @@ -469,3 +469,3 @@ GfxShading *GfxResources::lookupShading(char *name) { if (!resPtr->shadingDict.dictLookup(name, &obj)->isNull()) { - shading = GfxShading::parse(&obj); + shading = GfxShading::parse(&obj, gfx); obj.free(); @@ -503,3 +503,7 @@ Gfx::Gfx(XRef *xrefA, OutputDev *outA, int pageNum, Dict *resDict, Catalog *cata GBool (*abortCheckCbkA)(void *data), - void *abortCheckCbkDataA) { + void *abortCheckCbkDataA) +#ifdef USE_CMS + : iccColorSpaceCache(5) +#endif +{ int i; @@ -551,3 +555,7 @@ Gfx::Gfx(XRef *xrefA, OutputDev *outA, Dict *resDict, Catalog *catalogA, GBool (*abortCheckCbkA)(void *data), - void *abortCheckCbkDataA) { + void *abortCheckCbkDataA) + #ifdef USE_CMS + : iccColorSpaceCache(5) +#endif +{ int i; @@ -1059,3 +1067,3 @@ void Gfx::opSetExtGState(Object args[], int numArgs) { if (!obj4.dictLookup("CS", &obj5)->isNull()) { - blendingColorSpace = GfxColorSpace::parse(&obj5); + blendingColorSpace = GfxColorSpace::parse(&obj5, this); } @@ -1366,5 +1374,5 @@ void Gfx::opSetFillColorSpace(Object args[], int numArgs) { if (obj.isNull()) { - colorSpace = GfxColorSpace::parse(&args[0]); + colorSpace = GfxColorSpace::parse(&args[0], this); } else { - colorSpace = GfxColorSpace::parse(&obj); + colorSpace = GfxColorSpace::parse(&obj, this); } @@ -1408,5 +1416,5 @@ void Gfx::opSetStrokeColorSpace(Object args[], int numArgs) { if (obj.isNull()) { - colorSpace = GfxColorSpace::parse(&args[0]); + colorSpace = GfxColorSpace::parse(&args[0], this); } else { - colorSpace = GfxColorSpace::parse(&obj); + colorSpace = GfxColorSpace::parse(&obj, this); } @@ -1478,3 +1486,3 @@ void Gfx::opSetFillColorN(Object args[], int numArgs) { if (args[numArgs-1].isName() && - (pattern = res->lookupPattern(args[numArgs-1].getName()))) { + (pattern = res->lookupPattern(args[numArgs-1].getName(), this))) { state->setFillPattern(pattern); @@ -1521,3 +1529,3 @@ void Gfx::opSetStrokeColorN(Object args[], int numArgs) { if (args[numArgs-1].isName() && - (pattern = res->lookupPattern(args[numArgs-1].getName()))) { + (pattern = res->lookupPattern(args[numArgs-1].getName(), this))) { state->setStrokePattern(pattern); @@ -2151,3 +2159,3 @@ void Gfx::opShFill(Object args[], int numArgs) { - if (!(shading = res->lookupShading(args[0].getName()))) { + if (!(shading = res->lookupShading(args[0].getName(), this))) { return; @@ -3905,3 +3913,3 @@ void Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) { if (!obj1.isNull()) { - colorSpace = GfxColorSpace::parse(&obj1); + colorSpace = GfxColorSpace::parse(&obj1, this); } else if (csMode == streamCSDeviceGray) { @@ -4000,3 +4008,3 @@ void Gfx::doImage(Object *ref, Stream *str, GBool inlineImg) { } - maskColorSpace = GfxColorSpace::parse(&obj1); + maskColorSpace = GfxColorSpace::parse(&obj1, this); obj1.free(); @@ -4201,3 +4209,3 @@ void Gfx::doForm(Object *str) { if (!obj1.dictLookup("CS", &obj3)->isNull()) { - blendingColorSpace = GfxColorSpace::parse(&obj3); + blendingColorSpace = GfxColorSpace::parse(&obj3, this); } @@ -4729 +4737,8 @@ void Gfx::popResources() { } + +#ifdef USE_CMS +PopplerCache *Gfx::getIccColorSpaceCache() +{ + return &iccColorSpaceCache; +} +#endif diff --git a/poppler/Gfx.h b/poppler/Gfx.h index e03d025f..bb762600 100644 --- a/poppler/Gfx.h +++ b/poppler/Gfx.h @@ -38,2 +38,3 @@ #include "Object.h" +#include "PopplerCache.h" @@ -111,4 +112,4 @@ public: void lookupColorSpace(char *name, Object *obj); - GfxPattern *lookupPattern(char *name); - GfxShading *lookupShading(char *name); + GfxPattern *lookupPattern(char *name, Gfx *gfx); + GfxShading *lookupShading(char *name, Gfx *gfx); GBool lookupGState(char *name, Object *obj); @@ -170,2 +171,6 @@ public: void popResources(); + +#ifdef USE_CMS + PopplerCache *getIccColorSpaceCache(); +#endif @@ -198,2 +203,6 @@ private: Parser *parser; // parser for page content stream(s) + +#ifdef USE_CMS + PopplerCache iccColorSpaceCache; +#endif diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc index 85954556..0dc02b47 100644 --- a/poppler/GfxState.cc +++ b/poppler/GfxState.cc @@ -42,2 +42,3 @@ #include "Page.h" +#include "Gfx.h" #include "GfxState.h" @@ -194,3 +195,3 @@ GfxColorSpace::~GfxColorSpace() { -GfxColorSpace *GfxColorSpace::parse(Object *csObj) { +GfxColorSpace *GfxColorSpace::parse(Object *csObj, Gfx *gfx) { GfxColorSpace *cs; @@ -226,11 +227,11 @@ GfxColorSpace *GfxColorSpace::parse(Object *csObj) { } else if (obj1.isName("ICCBased")) { - cs = GfxICCBasedColorSpace::parse(csObj->getArray()); + cs = GfxICCBasedColorSpace::parse(csObj->getArray(), gfx); } else if (obj1.isName("Indexed") || obj1.isName("I")) { - cs = GfxIndexedColorSpace::parse(csObj->getArray()); + cs = GfxIndexedColorSpace::parse(csObj->getArray(), gfx); } else if (obj1.isName("Separation")) { - cs = GfxSeparationColorSpace::parse(csObj->getArray()); + cs = GfxSeparationColorSpace::parse(csObj->getArray(), gfx); } else if (obj1.isName("DeviceN")) { - cs = GfxDeviceNColorSpace::parse(csObj->getArray()); + cs = GfxDeviceNColorSpace::parse(csObj->getArray(), gfx); } else if (obj1.isName("Pattern")) { - cs = GfxPatternColorSpace::parse(csObj->getArray()); + cs = GfxPatternColorSpace::parse(csObj->getArray(), gfx); } else { @@ -1394,3 +1395,3 @@ GfxColorSpace *GfxICCBasedColorSpace::copy() { -GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr) { +GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, Gfx *gfx) { GfxICCBasedColorSpace *cs; @@ -1413,5 +1414,5 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr) { // check cache - if (iccProfileStreamA.num > 0) { + if (gfx && iccProfileStreamA.num > 0) { GfxICCBasedColorSpaceKey k(iccProfileStreamA.num, iccProfileStreamA.gen); - GfxICCBasedColorSpaceItem *item = static_cast<GfxICCBasedColorSpaceItem *>(cache->lookup(k)); + GfxICCBasedColorSpaceItem *item = static_cast<GfxICCBasedColorSpaceItem *>(gfx->getIccColorSpaceCache()->lookup(k)); if (item != NULL) @@ -1444,3 +1445,3 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr) { if (dict->lookup("Alternate", &obj2)->isNull() || - !(altA = GfxColorSpace::parse(&obj2))) { + !(altA = GfxColorSpace::parse(&obj2, gfx))) { switch (nCompsA) { @@ -1534,6 +1535,6 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr) { // put this colorSpace into cache - if (iccProfileStreamA.num > 0) { + if (gfx && iccProfileStreamA.num > 0) { GfxICCBasedColorSpaceKey *k = new GfxICCBasedColorSpaceKey(iccProfileStreamA.num, iccProfileStreamA.gen); GfxICCBasedColorSpaceItem *item = new GfxICCBasedColorSpaceItem(cs); - cache->put(k, item); + gfx->getIccColorSpaceCache()->put(k, item); } @@ -1685,6 +1686,2 @@ void GfxICCBasedColorSpace::getDefaultRanges(double *decodeLow, -#ifdef USE_CMS -PopplerCache *GfxICCBasedColorSpace::cache = new PopplerCache(5); -#endif - //------------------------------------------------------------------------ @@ -1715,3 +1712,3 @@ GfxColorSpace *GfxIndexedColorSpace::copy() { -GfxColorSpace *GfxIndexedColorSpace::parse(Array *arr) { +GfxColorSpace *GfxIndexedColorSpace::parse(Array *arr, Gfx *gfx) { GfxIndexedColorSpace *cs; @@ -1729,3 +1726,3 @@ GfxColorSpace *GfxIndexedColorSpace::parse(Array *arr) { arr->get(1, &obj1); - if (!(baseA = GfxColorSpace::parse(&obj1))) { + if (!(baseA = GfxColorSpace::parse(&obj1, gfx))) { error(-1, "Bad Indexed color space (base color space)"); @@ -1875,3 +1872,3 @@ GfxColorSpace *GfxSeparationColorSpace::copy() { //~ handle the 'All' and 'None' colorants -GfxColorSpace *GfxSeparationColorSpace::parse(Array *arr) { +GfxColorSpace *GfxSeparationColorSpace::parse(Array *arr, Gfx *gfx) { GfxSeparationColorSpace *cs; @@ -1893,3 +1890,3 @@ GfxColorSpace *GfxSeparationColorSpace::parse(Array *arr) { arr->get(2, &obj1); - if (!(altA = GfxColorSpace::parse(&obj1))) { + if (!(altA = GfxColorSpace::parse(&obj1, gfx))) { error(-1, "Bad Separation color space (alternate color space)"); @@ -1998,3 +1995,3 @@ GfxColorSpace *GfxDeviceNColorSpace::copy() { //~ handle the 'None' colorant -GfxColorSpace *GfxDeviceNColorSpace::parse(Array *arr) { +GfxColorSpace *GfxDeviceNColorSpace::parse(Array *arr, Gfx *gfx) { GfxDeviceNColorSpace *cs; @@ -2032,3 +2029,3 @@ GfxColorSpace *GfxDeviceNColorSpace::parse(Array *arr) { arr->get(2, &obj1); - if (!(altA = GfxColorSpace::parse(&obj1))) { + if (!(altA = GfxColorSpace::parse(&obj1, gfx))) { error(-1, "Bad DeviceN color space (alternate color space)"); @@ -2136,3 +2133,3 @@ GfxColorSpace *GfxPatternColorSpace::copy() { -GfxColorSpace *GfxPatternColorSpace::parse(Array *arr) { +GfxColorSpace *GfxPatternColorSpace::parse(Array *arr, Gfx *gfx) { GfxPatternColorSpace *cs; @@ -2148,3 +2145,3 @@ GfxColorSpace *GfxPatternColorSpace::parse(Array *arr) { arr->get(1, &obj1); - if (!(underA = GfxColorSpace::parse(&obj1))) { + if (!(underA = GfxColorSpace::parse(&obj1, gfx))) { error(-1, "Bad Pattern color space (underlying color space)"); @@ -2187,3 +2184,3 @@ GfxPattern::~GfxPattern() { -GfxPattern *GfxPattern::parse(Object *obj) { +GfxPattern *GfxPattern::parse(Object *obj, Gfx *gfx) { GfxPattern *pattern; @@ -2202,3 +2199,3 @@ GfxPattern *GfxPattern::parse(Object *obj) { } else if (obj1.isInt() && obj1.getInt() == 2) { - pattern = GfxShadingPattern::parse(obj); + pattern = GfxShadingPattern::parse(obj, gfx); } @@ -2330,3 +2327,3 @@ GfxPattern *GfxTilingPattern::copy() { -GfxShadingPattern *GfxShadingPattern::parse(Object *patObj) { +GfxShadingPattern *GfxShadingPattern::parse(Object *patObj, Gfx *gfx) { Dict *dict; @@ -2343,3 +2340,3 @@ GfxShadingPattern *GfxShadingPattern::parse(Object *patObj) { dict->lookup("Shading", &obj1); - shadingA = GfxShading::parse(&obj1); + shadingA = GfxShading::parse(&obj1, gfx); obj1.free(); @@ -2416,3 +2413,3 @@ GfxShading::~GfxShading() { -GfxShading *GfxShading::parse(Object *obj) { +GfxShading *GfxShading::parse(Object *obj, Gfx *gfx) { GfxShading *shading; @@ -2440,9 +2437,9 @@ GfxShading *GfxShading::parse(Object *obj) { case 1: - shading = GfxFunctionShading::parse(dict); + shading = GfxFunctionShading::parse(dict, gfx); break; case 2: - shading = GfxAxialShading::parse(dict); + shading = GfxAxialShading::parse(dict, gfx); break; case 3: - shading = GfxRadialShading::parse(dict); + shading = GfxRadialShading::parse(dict, gfx); break; @@ -2450,3 +2447,3 @@ GfxShading *GfxShading::parse(Object *obj) { if (obj->isStream()) { - shading = GfxGouraudTriangleShading::parse(4, dict, obj->getStream()); + shading = GfxGouraudTriangleShading::parse(4, dict, obj->getStream(), gfx); } else { @@ -2458,3 +2455,3 @@ GfxShading *GfxShading::parse(Object *obj) { if (obj->isStream()) { - shading = GfxGouraudTriangleShading::parse(5, dict, obj->getStream()); + shading = GfxGouraudTriangleShading::parse(5, dict, obj->getStream(), gfx); } else { @@ -2466,3 +2463,3 @@ GfxShading *GfxShading::parse(Object *obj) { if (obj->isStream()) { - shading = GfxPatchMeshShading::parse(6, dict, obj->getStream()); + shading = GfxPatchMeshShading::parse(6, dict, obj->getStream(), gfx); } else { @@ -2474,3 +2471,3 @@ GfxShading *GfxShading::parse(Object *obj) { if (obj->isStream()) { - shading = GfxPatchMeshShading::parse(7, dict, obj->getStream()); + shading = GfxPatchMeshShading::parse(7, dict, obj->getStream(), gfx); } else { @@ -2491,3 +2488,3 @@ GfxShading *GfxShading::parse(Object *obj) { -GBool GfxShading::init(Dict *dict) { +GBool GfxShading::init(Dict *dict, Gfx *gfx) { Object obj1, obj2; @@ -2496,3 +2493,3 @@ GBool GfxShading::init(Dict *dict) { dict->lookup("ColorSpace", &obj1); - if (!(colorSpace = GfxColorSpace::parse(&obj1))) { + if (!(colorSpace = GfxColorSpace::parse(&obj1, gfx))) { error(-1, "Bad color space in shading dictionary"); @@ -2593,3 +2590,3 @@ GfxFunctionShading::~GfxFunctionShading() { -GfxFunctionShading *GfxFunctionShading::parse(Dict *dict) { +GfxFunctionShading *GfxFunctionShading::parse(Dict *dict, Gfx *gfx) { GfxFunctionShading *shading; @@ -2661,3 +2658,3 @@ GfxFunctionShading *GfxFunctionShading::parse(Dict *dict) { funcsA, nFuncsA); - if (!shading->init(dict)) { + if (!shading->init(dict, gfx)) { delete shading; @@ -2751,3 +2748,3 @@ GfxAxialShading::~GfxAxialShading() { -GfxAxialShading *GfxAxialShading::parse(Dict *dict) { +GfxAxialShading *GfxAxialShading::parse(Dict *dict, Gfx *gfx) { GfxAxialShading *shading; @@ -2826,3 +2823,3 @@ GfxAxialShading *GfxAxialShading::parse(Dict *dict) { funcsA, nFuncsA, extend0A, extend1A); - if (!shading->init(dict)) { + if (!shading->init(dict, gfx)) { delete shading; @@ -2915,3 +2912,3 @@ GfxRadialShading::~GfxRadialShading() { -GfxRadialShading *GfxRadialShading::parse(Dict *dict) { +GfxRadialShading *GfxRadialShading::parse(Dict *dict, Gfx *gfx) { GfxRadialShading *shading; @@ -2994,3 +2991,3 @@ GfxRadialShading *GfxRadialShading::parse(Dict *dict) { funcsA, nFuncsA, extend0A, extend1A); - if (!shading->init(dict)) { + if (!shading->init(dict, gfx)) { delete shading; @@ -3145,3 +3142,4 @@ GfxGouraudTriangleShading *GfxGouraudTriangleShading::parse(int typeA, Dict *dict, - Stream *str) { + Stream *str, + Gfx *gfx) { GfxGouraudTriangleShading *shading; @@ -3341,3 +3339,3 @@ GfxGouraudTriangleShading *GfxGouraudTriangleShading::parse(int typeA, funcsA, nFuncsA); - if (!shading->init(dict)) { + if (!shading->init(dict, gfx)) { delete shading; @@ -3453,3 +3451,3 @@ GfxPatchMeshShading::~GfxPatchMeshShading() { GfxPatchMeshShading *GfxPatchMeshShading::parse(int typeA, Dict *dict, - Stream *str) { + Stream *str, Gfx *gfx) { GfxPatchMeshShading *shading; @@ -3954,3 +3952,3 @@ GfxPatchMeshShading *GfxPatchMeshShading::parse(int typeA, Dict *dict, funcsA, nFuncsA); - if (!shading->init(dict)) { + if (!shading->init(dict, gfx)) { delete shading; diff --git a/poppler/GfxState.h b/poppler/GfxState.h index 458db60b..7dccfd5c 100644 --- a/poppler/GfxState.h +++ b/poppler/GfxState.h @@ -38,2 +38,3 @@ class Array; +class Gfx; class GfxFont; @@ -180,3 +181,3 @@ public: // Construct a color space. Returns NULL if unsuccessful. - static GfxColorSpace *parse(Object *csObj); + static GfxColorSpace *parse(Object *csObj, Gfx *gfx); @@ -447,3 +448,3 @@ public: // Construct an ICCBased color space. Returns NULL if unsuccessful. - static GfxColorSpace *parse(Array *arr); + static GfxColorSpace *parse(Array *arr, Gfx *gfx); @@ -475,4 +476,2 @@ private: GfxColorTransform *lineTransform; // color transform for line - - static PopplerCache *cache; #endif @@ -492,3 +491,3 @@ public: // Construct a Lab color space. Returns NULL if unsuccessful. - static GfxColorSpace *parse(Array *arr); + static GfxColorSpace *parse(Array *arr, Gfx *gfx); @@ -534,3 +533,3 @@ public: // Construct a Separation color space. Returns NULL if unsuccessful. - static GfxColorSpace *parse(Array *arr); + static GfxColorSpace *parse(Array *arr, Gfx *gfx); @@ -571,3 +570,3 @@ public: // Construct a DeviceN color space. Returns NULL if unsuccessful. - static GfxColorSpace *parse(Array *arr); + static GfxColorSpace *parse(Array *arr, Gfx *gfx); @@ -610,3 +609,3 @@ public: // Construct a Pattern color space. Returns NULL if unsuccessful. - static GfxColorSpace *parse(Array *arr); + static GfxColorSpace *parse(Array *arr, Gfx *gfx); @@ -638,3 +637,3 @@ public: - static GfxPattern *parse(Object *obj); + static GfxPattern *parse(Object *obj, Gfx *gfx); @@ -694,3 +693,3 @@ public: - static GfxShadingPattern *parse(Object *patObj); + static GfxShadingPattern *parse(Object *patObj, Gfx *gfx); virtual ~GfxShadingPattern(); @@ -721,3 +720,3 @@ public: - static GfxShading *parse(Object *obj); + static GfxShading *parse(Object *obj, Gfx *gfx); @@ -735,3 +734,3 @@ protected: - GBool init(Dict *dict); + GBool init(Dict *dict, Gfx *gfx); @@ -759,3 +758,3 @@ public: - static GfxFunctionShading *parse(Dict *dict); + static GfxFunctionShading *parse(Dict *dict, Gfx *gfx); @@ -793,3 +792,3 @@ public: - static GfxAxialShading *parse(Dict *dict); + static GfxAxialShading *parse(Dict *dict, Gfx *gfx); @@ -831,3 +830,3 @@ public: - static GfxRadialShading *parse(Dict *dict); + static GfxRadialShading *parse(Dict *dict, Gfx *gfx); @@ -874,3 +873,3 @@ public: - static GfxGouraudTriangleShading *parse(int typeA, Dict *dict, Stream *str); + static GfxGouraudTriangleShading *parse(int typeA, Dict *dict, Stream *str, Gfx *gfx); @@ -911,3 +910,3 @@ public: - static GfxPatchMeshShading *parse(int typeA, Dict *dict, Stream *str); + static GfxPatchMeshShading *parse(int typeA, Dict *dict, Stream *str, Gfx *gfx); diff --git a/poppler/Page.cc b/poppler/Page.cc index 3bbfdde7..67dc6323 100644 --- a/poppler/Page.cc +++ b/poppler/Page.cc @@ -17,3 +17,3 @@ // Copyright (C) 2005 Jeff Muizelaar <jeff@infidigm.net> -// Copyright (C) 2005-2008 Albert Astals Cid <aacid@kde.org> +// Copyright (C) 2005-2009 Albert Astals Cid <aacid@kde.org> // Copyright (C) 2006-2008 Pino Toscano <pino@kde.org> @@ -556,3 +556,3 @@ GBool Page::loadThumb(unsigned char **data_out, } - colorSpace = GfxColorSpace::parse(&obj1); + colorSpace = GfxColorSpace::parse(&obj1, NULL); obj1.free(); |