📄 gfxstate.cc
字号:
} obj1.free(); } return pattern;}//------------------------------------------------------------------------// GfxTilingPattern//------------------------------------------------------------------------GfxTilingPattern::GfxTilingPattern(Dict *streamDict, Object *stream): GfxPattern(1){ Object obj1, obj2; int i; if (streamDict->lookup("PaintType", &obj1)->isInt()) { paintType = obj1.getInt(); } else { paintType = 1; error(-1, "Invalid or missing PaintType in pattern"); } obj1.free(); if (streamDict->lookup("TilingType", &obj1)->isInt()) { tilingType = obj1.getInt(); } else { tilingType = 1; error(-1, "Invalid or missing TilingType in pattern"); } obj1.free(); bbox[0] = bbox[1] = 0; bbox[2] = bbox[3] = 1; if (streamDict->lookup("BBox", &obj1)->isArray() && obj1.arrayGetLength() == 4) { for (i = 0; i < 4; ++i) { if (obj1.arrayGet(i, &obj2)->isNum()) { bbox[i] = obj2.getNum(); } obj2.free(); } } else { error(-1, "Invalid or missing BBox in pattern"); } obj1.free(); if (streamDict->lookup("XStep", &obj1)->isNum()) { xStep = obj1.getNum(); } else { xStep = 1; error(-1, "Invalid or missing XStep in pattern"); } obj1.free(); if (streamDict->lookup("YStep", &obj1)->isNum()) { yStep = obj1.getNum(); } else { yStep = 1; error(-1, "Invalid or missing YStep in pattern"); } obj1.free(); if (!streamDict->lookup("Resources", &resDict)->isDict()) { resDict.free(); resDict.initNull(); error(-1, "Invalid or missing Resources in pattern"); } matrix[0] = 1; matrix[1] = 0; matrix[2] = 0; matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; if (streamDict->lookup("Matrix", &obj1)->isArray() && obj1.arrayGetLength() == 6) { for (i = 0; i < 6; ++i) { if (obj1.arrayGet(i, &obj2)->isNum()) { matrix[i] = obj2.getNum(); } obj2.free(); } } obj1.free(); stream->copy(&contentStream);}GfxTilingPattern::~GfxTilingPattern() { resDict.free(); contentStream.free();}GfxPattern *GfxTilingPattern::copy() { return new GfxTilingPattern(this);}GfxTilingPattern::GfxTilingPattern(GfxTilingPattern *pat): GfxPattern(1){ memcpy(this, pat, sizeof(GfxTilingPattern)); pat->resDict.copy(&resDict); pat->contentStream.copy(&contentStream);}//------------------------------------------------------------------------// GfxShading//------------------------------------------------------------------------GfxShading::GfxShading() {}GfxShading::~GfxShading() { delete colorSpace;}GfxShading *GfxShading::parse(Object *obj) { GfxShading *shading; int typeA; GfxColorSpace *colorSpaceA; GfxColor backgroundA; GBool hasBackgroundA; double xMinA, yMinA, xMaxA, yMaxA; GBool hasBBoxA; Object obj1, obj2; int i; shading = NULL; if (obj->isDict()) { if (!obj->dictLookup("ShadingType", &obj1)->isInt()) { error(-1, "Invalid ShadingType in shading dictionary"); obj1.free(); goto err1; } typeA = obj1.getInt(); obj1.free(); obj->dictLookup("ColorSpace", &obj1); if (!(colorSpaceA = GfxColorSpace::parse(&obj1))) { error(-1, "Bad color space in shading dictionary"); obj1.free(); goto err1; } obj1.free(); for (i = 0; i < gfxColorMaxComps; ++i) { backgroundA.c[i] = 0; } hasBackgroundA = gFalse; if (obj->dictLookup("Background", &obj1)->isArray()) { if (obj1.arrayGetLength() == colorSpaceA->getNComps()) { hasBackgroundA = gTrue; for (i = 0; i < colorSpaceA->getNComps(); ++i) { backgroundA.c[i] = obj1.arrayGet(i, &obj2)->getNum(); obj2.free(); } } else { error(-1, "Bad Background in shading dictionary"); } } obj1.free(); xMinA = yMinA = xMaxA = yMaxA = 0; hasBBoxA = gFalse; if (obj->dictLookup("BBox", &obj1)->isArray()) { if (obj1.arrayGetLength() == 4) { hasBBoxA = gTrue; xMinA = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); yMinA = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); xMaxA = obj1.arrayGet(2, &obj2)->getNum(); obj2.free(); yMaxA = obj1.arrayGet(3, &obj2)->getNum(); obj2.free(); } else { error(-1, "Bad BBox in shading dictionary"); } } obj1.free(); switch (typeA) { case 2: shading = GfxAxialShading::parse(obj->getDict()); break; case 3: shading = GfxRadialShading::parse(obj->getDict()); break; default: error(-1, "Unimplemented shading type %d", typeA); goto err1; } if (shading) { shading->type = typeA; shading->colorSpace = colorSpaceA; shading->background = backgroundA; shading->hasBackground = hasBackgroundA; shading->xMin = xMinA; shading->yMin = yMinA; shading->xMax = xMaxA; shading->yMax = yMaxA; shading->hasBBox = hasBBoxA; } else { delete colorSpaceA; } } return shading; err1: return NULL;}//------------------------------------------------------------------------// GfxAxialShading//------------------------------------------------------------------------GfxAxialShading::GfxAxialShading(double x0A, double y0A, double x1A, double y1A, double t0A, double t1A, Function **funcsA, int nFuncsA, GBool extend0A, GBool extend1A) { int i; x0 = x0A; y0 = y0A; x1 = x1A; y1 = y1A; t0 = t0A; t1 = t1A; nFuncs = nFuncsA; for (i = 0; i < nFuncs; ++i) { funcs[i] = funcsA[i]; } extend0 = extend0A; extend1 = extend1A;}GfxAxialShading::~GfxAxialShading() { int i; for (i = 0; i < nFuncs; ++i) { delete funcs[i]; }}GfxAxialShading *GfxAxialShading::parse(Dict *dict) { double x0A, y0A, x1A, y1A; double t0A, t1A; Function *funcsA[gfxColorMaxComps]; int nFuncsA; GBool extend0A, extend1A; Object obj1, obj2; int i; x0A = y0A = x1A = y1A = 0; if (dict->lookup("Coords", &obj1)->isArray() && obj1.arrayGetLength() == 4) { x0A = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); y0A = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); x1A = obj1.arrayGet(2, &obj2)->getNum(); obj2.free(); y1A = obj1.arrayGet(3, &obj2)->getNum(); obj2.free(); } else { error(-1, "Missing or invalid Coords in shading dictionary"); goto err1; } obj1.free(); t0A = 0; t1A = 1; if (dict->lookup("Domain", &obj1)->isArray() && obj1.arrayGetLength() == 2) { t0A = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); t1A = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); } obj1.free(); dict->lookup("Function", &obj1); if (obj1.isArray()) { nFuncsA = obj1.arrayGetLength(); for (i = 0; i < nFuncsA; ++i) { obj1.arrayGet(i, &obj2); if (!(funcsA[i] = Function::parse(&obj2))) { obj1.free(); obj2.free(); goto err1; } obj2.free(); } } else { nFuncsA = 1; if (!(funcsA[0] = Function::parse(&obj1))) { obj1.free(); goto err1; } } obj1.free(); extend0A = extend1A = gFalse; if (dict->lookup("Extend", &obj1)->isArray() && obj1.arrayGetLength() == 2) { extend0A = obj1.arrayGet(0, &obj2)->getBool(); obj2.free(); extend1A = obj1.arrayGet(1, &obj2)->getBool(); obj2.free(); } obj1.free(); return new GfxAxialShading(x0A, y0A, x1A, y1A, t0A, t1A, funcsA, nFuncsA, extend0A, extend1A); err1: return NULL;}void GfxAxialShading::getColor(double t, GfxColor *color) { int i; for (i = 0; i < nFuncs; ++i) { funcs[i]->transform(&t, &color->c[i]); }}//------------------------------------------------------------------------// GfxRadialShading//------------------------------------------------------------------------GfxRadialShading::GfxRadialShading(double x0A, double y0A, double r0A, double x1A, double y1A, double r1A, double t0A, double t1A, Function **funcsA, int nFuncsA, GBool extend0A, GBool extend1A) { int i; x0 = x0A; y0 = y0A; r0 = r0A; x1 = x1A; y1 = y1A; r1 = r1A; t0 = t0A; t1 = t1A; nFuncs = nFuncsA; for (i = 0; i < nFuncs; ++i) { funcs[i] = funcsA[i]; } extend0 = extend0A; extend1 = extend1A;}GfxRadialShading::~GfxRadialShading() { int i; for (i = 0; i < nFuncs; ++i) { delete funcs[i]; }}GfxRadialShading *GfxRadialShading::parse(Dict *dict) { double x0A, y0A, r0A, x1A, y1A, r1A; double t0A, t1A; Function *funcsA[gfxColorMaxComps]; int nFuncsA; GBool extend0A, extend1A; Object obj1, obj2; int i; x0A = y0A = r0A = x1A = y1A = r1A = 0; if (dict->lookup("Coords", &obj1)->isArray() && obj1.arrayGetLength() == 6) { x0A = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); y0A = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); r0A = obj1.arrayGet(2, &obj2)->getNum(); obj2.free(); x1A = obj1.arrayGet(3, &obj2)->getNum(); obj2.free(); y1A = obj1.arrayGet(4, &obj2)->getNum(); obj2.free(); r1A = obj1.arrayGet(5, &obj2)->getNum(); obj2.free(); } else { error(-1, "Missing or invalid Coords in shading dictionary"); goto err1; } obj1.free(); t0A = 0; t1A = 1; if (dict->lookup("Domain", &obj1)->isArray() && obj1.arrayGetLength() == 2) { t0A = obj1.arrayGet(0, &obj2)->getNum(); obj2.free(); t1A = obj1.arrayGet(1, &obj2)->getNum(); obj2.free(); } obj1.free(); dict->lookup("Function", &obj1); if (obj1.isArray()) { nFuncsA = obj1.arrayGetLength(); for (i = 0; i < nFuncsA; ++i) { obj1.arrayGet(i, &obj2); if (!(funcsA[i] = Function::parse(&obj2))) { obj1.free(); obj2.free(); goto err1; } obj2.free(); } } else { nFuncsA = 1; if (!(funcsA[0] = Function::parse(&obj1))) { obj1.free(); goto err1; } } obj1.free(); extend0A = extend1A = gFalse; if (dict->lookup("Extend", &obj1)->isArray() && obj1.arrayGetLength() == 2) { extend0A = obj1.arrayGet(0, &obj2)->getBool(); obj2.free(); extend1A = obj1.arrayGet(1, &obj2)->getBool(); obj2.free(); } obj1.free(); return new GfxRadialShading(x0A, y0A, r0A, x1A, y1A, r1A, t0A, t1A, funcsA, nFuncsA, extend0A, extend1A); err1: return NULL;}void GfxRadialShading::getColor(double t, GfxColor *color) { int i; for (i = 0; i < nFuncs; ++i) { funcs[i]->transform(&t, &color->c[i]); }}//------------------------------------------------------------------------// GfxImageColorMap//------------------------------------------------------------------------GfxImageColorMap::GfxImageColorMap(int bitsA, Object *decode, GfxColorSpace *colorSpaceA) { GfxIndexedColorSpace *indexedCS; GfxSeparationColorSpace *sepCS; int maxPixel, indexHigh; Guchar *lookup2; Function *sepFunc; Object obj; double x[gfxColorMaxComps]; double y[gfxColorMaxComps]; int i, j, k; ok = gTrue; // bits per component and color space bits = bitsA; maxPixel = (1 << bits) - 1; colorSpace = colorSpaceA; // get decode map if (decode->isNull()) { nComps = colorSpace->getNComps(); colorSpace->getDefaultRanges(decodeLow, decodeRange, maxPixel); } else if (decode->isArray()) { nComps = decode->arrayGetLength() / 2; if (nComps != colorSpace->getNComps()) { goto err1; } for (i = 0; i < nComps; ++i) { decode->arrayGet(2*i, &obj); if (!obj.isNum()) { goto err2; } decodeLow[i] = obj.getNum(); obj.free(); decode->arrayGet(2*i+1, &obj); if (!obj.isNum()) { goto err2; } decodeRange[i] = obj.getNum() - decodeLow[i]; obj.free(); } } else { goto err1; } // Construct a lookup table -- this stores pre-computed decoded // values for each component, i.e., the result of applying the // decode mapping to each possible image pixel component value. // // Optimization: for Indexed and Separation color spaces (which have // only one component), we store color values in the lookup table // rather than component values. colorSpace2 = NULL; nComps2 = 0; if (colorSpace->getMode() == csIndexed) { // Note that indexHigh may not be the same as maxPixel -- // Distiller will remove unused palette entries, resulting in // indexHigh < maxPixel. indexedCS = (GfxIndexedColorSpace *)colorSpace; colorSpace2 = indexedCS->getBase(); indexHigh = indexedCS->getIndexHigh(); nComps2 = colorSpace2->getNComps(); lookup = (double *)gmalloc((indexHigh + 1) * nComps2 * sizeof(double)); lookup2 = indexedCS->getLookup(); colorSpace2->getDefaultRanges(x, y, indexHigh); for (i = 0; i <= indexHigh; ++i) { j = (int)(decodeLow[0] + (i * decodeRange[0]) / maxPixel + 0.5); for (k = 0; k < nComps2; ++k) { lookup[j*nComps2 + k] = x[k] + (lookup2[i*nComps2 + k] / 255.0) * y[k]; } } } else if (colorSpace->getMode() == csSeparation) { sepCS = (GfxSeparationColorSpace *)colorSpace; colorSpace2 = sepCS->getAlt(); nComps2 = colorSpace2->getNComps(); lookup = (double *)gmalloc((maxPixel + 1) * nComps2 * sizeof(double)); sepFunc = sepCS->getFunc(); for (i = 0; i <= maxPixel; ++i) { x[0] = decodeLow[0] + (i * decodeRange[0]) / maxPixel; sepFunc->transform(x, y); for (k = 0; k < nComps2; ++k) { lookup[i*nComps2 + k] = y[k]; } } } else { lookup = (double *)gmalloc((maxPixel + 1) * nComps * sizeof(double)); for (i = 0; i <= maxPixel; ++i) { for (k = 0; k < nComps; ++k) { lookup[i*nComps + k] = decodeLow[k] + (i * decodeRange[k]) / maxPixel; } } } return; err2: obj.free(); err1: ok = gFalse;}GfxImageColorMap::~GfxImageColorMap() { delete colorSpace; gfree(lookup);}void GfxImageColorMap::getGray(Guchar *x, double *gray) { GfxColor color; double *p; int i; if (colorSpace2) { p = &lookup[x[0] * nComps2]; for (i = 0; i < nComps2; ++i) { color.c[i] = *p++; } colorSpace2->getGray(&color, gray); } else { for (i = 0; i < nComps; ++i) { color.c[i] = lookup[x[i] * nComps + i]; } colorSpace->getGray(&color, gray); }}void GfxImageColorMap::getRGB(Guchar *x, GfxRGB *rgb) { GfxColor color; double *p; int i; if (colorSpace2) { p = &lookup[x[0] * nComps2]; for (i = 0; i < nComps2; ++i) { color.c[i] = *p++; } colorSpace2->getRGB(&color, rgb); } else { for (i = 0; i < nComps; ++i) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -