"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "xpdf/Function.cc" between
xpdf-4.01.01.tar.gz and xpdf-4.02.tar.gz

About: Xpdf is a PDF viewer for X.

Function.cc  (xpdf-4.01.01):Function.cc  (xpdf-4.02)
skipping to change at line 44 skipping to change at line 44
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Function // Function
//------------------------------------------------------------------------ //------------------------------------------------------------------------
Function::Function() { Function::Function() {
} }
Function::~Function() { Function::~Function() {
} }
Function *Function::parse(Object *funcObj, int recursion) { Function *Function::parse(Object *funcObj, int expectedInputs,
int expectedOutputs, int recursion) {
Function *func; Function *func;
Dict *dict; Dict *dict;
int funcType; int funcType;
Object obj1; Object obj1;
if (recursion > recursionLimit) { if (recursion > recursionLimit) {
error(errSyntaxError, -1, "Loop detected in function objects"); error(errSyntaxError, -1, "Loop detected in function objects");
return NULL; return NULL;
} }
if (funcObj->isStream()) { if (funcObj->isStream()) {
dict = funcObj->streamGetDict(); dict = funcObj->streamGetDict();
} else if (funcObj->isDict()) { } else if (funcObj->isDict()) {
dict = funcObj->getDict(); dict = funcObj->getDict();
} else if (funcObj->isName("Identity")) { } else if (funcObj->isName("Identity")) {
return new IdentityFunction(); if (expectedInputs != expectedOutputs) {
error(errSyntaxError, -1, "Invalid use of identity function");
return NULL;
}
return new IdentityFunction(expectedInputs);
} else { } else {
error(errSyntaxError, -1, "Expected function dictionary or stream"); error(errSyntaxError, -1, "Expected function dictionary or stream");
return NULL; return NULL;
} }
if (!dict->lookup("FunctionType", &obj1)->isInt()) { if (!dict->lookup("FunctionType", &obj1)->isInt()) {
error(errSyntaxError, -1, "Function type is missing or wrong type"); error(errSyntaxError, -1, "Function type is missing or wrong type");
obj1.free(); obj1.free();
return NULL; return NULL;
} }
funcType = obj1.getInt(); funcType = obj1.getInt();
obj1.free(); obj1.free();
if (funcType == 0) { if (funcType == 0) {
func = new SampledFunction(funcObj, dict); func = new SampledFunction(funcObj, dict);
} else if (funcType == 2) { } else if (funcType == 2) {
func = new ExponentialFunction(funcObj, dict); func = new ExponentialFunction(funcObj, dict);
} else if (funcType == 3) { } else if (funcType == 3) {
func = new StitchingFunction(funcObj, dict, recursion); func = new StitchingFunction(funcObj, dict, expectedInputs,
expectedOutputs, recursion);
} else if (funcType == 4) { } else if (funcType == 4) {
func = new PostScriptFunction(funcObj, dict); func = new PostScriptFunction(funcObj, dict);
} else { } else {
error(errSyntaxError, -1, "Unimplemented function type ({0:d})", funcType); error(errSyntaxError, -1, "Unimplemented function type ({0:d})", funcType);
return NULL; return NULL;
} }
if (!func->isOk()) { if (!func->isOk()) {
delete func; delete func;
return NULL; return NULL;
} }
if (func->getInputSize() != expectedInputs ||
(expectedOutputs >= 0 && func->getOutputSize() != expectedOutputs)) {
error(errSyntaxError, -1,
"Incorrect number of function inputs or outputs");
delete func;
return NULL;
}
return func; return func;
} }
GBool Function::init(Dict *dict) { GBool Function::init(Dict *dict) {
Object obj1, obj2; Object obj1, obj2;
int i; int i;
//----- Domain //----- Domain
if (!dict->lookup("Domain", &obj1)->isArray()) { if (!dict->lookup("Domain", &obj1)->isArray()) {
error(errSyntaxError, -1, "Function is missing domain"); error(errSyntaxError, -1, "Function is missing domain");
skipping to change at line 172 skipping to change at line 186
obj2.free(); obj2.free();
err2: err2:
obj1.free(); obj1.free();
return gFalse; return gFalse;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// IdentityFunction // IdentityFunction
//------------------------------------------------------------------------ //------------------------------------------------------------------------
IdentityFunction::IdentityFunction() { IdentityFunction::IdentityFunction(int nInputs) {
int i; int i;
// fill these in with arbitrary values just in case they get used m = n = nInputs;
// somewhere // domain info shouldn't be used anywhere
m = funcMaxInputs; for (i = 0; i < nInputs; ++i) {
n = funcMaxOutputs;
for (i = 0; i < funcMaxInputs; ++i) {
domain[i][0] = 0; domain[i][0] = 0;
domain[i][1] = 1; domain[i][1] = 1;
} }
hasRange = gFalse; hasRange = gFalse;
} }
IdentityFunction::~IdentityFunction() { IdentityFunction::~IdentityFunction() {
} }
void IdentityFunction::transform(double *in, double *out) { void IdentityFunction::transform(double *in, double *out) {
int i; int i;
for (i = 0; i < funcMaxOutputs; ++i) { for (i = 0; i < m; ++i) {
out[i] = in[i]; out[i] = in[i];
} }
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// SampledFunction // SampledFunction
//------------------------------------------------------------------------ //------------------------------------------------------------------------
SampledFunction::SampledFunction(Object *funcObj, Dict *dict) { SampledFunction::SampledFunction(Object *funcObj, Dict *dict) {
Stream *str; Stream *str;
skipping to change at line 350 skipping to change at line 362
} else { } else {
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
decode[i][0] = range[i][0]; decode[i][0] = range[i][0];
decode[i][1] = range[i][1]; decode[i][1] = range[i][1];
} }
} }
obj1.free(); obj1.free();
//----- samples //----- samples
nSamples = n; nSamples = n;
for (i = 0; i < m; ++i) for (i = 0; i < m; ++i) {
if (nSamples > INT_MAX / sampleSize[i]) {
error(errSyntaxError, -1, "Integer overflow in sampled function setup");
goto err1;
}
nSamples *= sampleSize[i]; nSamples *= sampleSize[i];
}
samples = (double *)gmallocn(nSamples, sizeof(double)); samples = (double *)gmallocn(nSamples, sizeof(double));
buf = 0; buf = 0;
bits = 0; bits = 0;
bitMask = (sampleBits < 32) ? ((1 << sampleBits) - 1) : 0xffffffffU; bitMask = (sampleBits < 32) ? ((1 << sampleBits) - 1) : 0xffffffffU;
str->reset(); str->reset();
for (i = 0; i < nSamples; ++i) { for (i = 0; i < nSamples; ++i) {
if (sampleBits == 8) { if (sampleBits == 8) {
s = str->getChar(); s = str->getChar();
} else if (sampleBits == 16) { } else if (sampleBits == 16) {
s = str->getChar(); s = str->getChar();
skipping to change at line 626 skipping to change at line 643
} }
} }
return; return;
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// StitchingFunction // StitchingFunction
//------------------------------------------------------------------------ //------------------------------------------------------------------------
StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict, StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict,
int expectedInputs, int expectedOutputs,
int recursion) { int recursion) {
Object obj1, obj2; Object obj1, obj2;
int i; int i;
ok = gFalse; ok = gFalse;
funcs = NULL; funcs = NULL;
bounds = NULL; bounds = NULL;
encode = NULL; encode = NULL;
scale = NULL; scale = NULL;
//----- initialize the generic stuff //----- initialize the generic stuff
if (!init(dict)) { if (!init(dict)) {
goto err1; goto err1;
} }
if (m != 1) { if (m != 1) {
error(errSyntaxError, -1, "Stitching function with more than one input"); error(errSyntaxError, -1, "Stitching function with more than one input");
goto err1; goto err1;
} }
//----- Functions //----- Functions
if (!dict->lookup("Functions", &obj1)->isArray()) { if (!dict->lookup("Functions", &obj1)->isArray() ||
obj1.arrayGetLength() < 1) {
error(errSyntaxError, -1, error(errSyntaxError, -1,
"Missing 'Functions' entry in stitching function"); "Missing 'Functions' entry in stitching function");
goto err1; goto err1;
} }
k = obj1.arrayGetLength(); k = obj1.arrayGetLength();
funcs = (Function **)gmallocn(k, sizeof(Function *)); funcs = (Function **)gmallocn(k, sizeof(Function *));
bounds = (double *)gmallocn(k + 1, sizeof(double)); bounds = (double *)gmallocn(k + 1, sizeof(double));
encode = (double *)gmallocn(2 * k, sizeof(double)); encode = (double *)gmallocn(2 * k, sizeof(double));
scale = (double *)gmallocn(k, sizeof(double)); scale = (double *)gmallocn(k, sizeof(double));
for (i = 0; i < k; ++i) { for (i = 0; i < k; ++i) {
funcs[i] = NULL; funcs[i] = NULL;
} }
for (i = 0; i < k; ++i) { for (i = 0; i < k; ++i) {
if (!(funcs[i] = Function::parse(obj1.arrayGet(i, &obj2), if (!(funcs[i] = Function::parse(obj1.arrayGet(i, &obj2),
expectedInputs, expectedOutputs,
recursion + 1))) { recursion + 1))) {
goto err2; goto err2;
} }
if (funcs[i]->getInputSize() != 1 || if (i == 0) {
(i > 0 && funcs[i]->getOutputSize() != funcs[0]->getOutputSize())) { n = funcs[0]->getOutputSize();
}
if (funcs[i]->getInputSize() != 1 || funcs[i]->getOutputSize() != n) {
error(errSyntaxError, -1, error(errSyntaxError, -1,
"Incompatible subfunctions in stitching function"); "Incompatible subfunctions in stitching function");
goto err2; goto err2;
} }
obj2.free(); obj2.free();
} }
obj1.free(); obj1.free();
//----- Bounds //----- Bounds
if (!dict->lookup("Bounds", &obj1)->isArray() || if (!dict->lookup("Bounds", &obj1)->isArray() ||
skipping to change at line 1308 skipping to change at line 1330
break; break;
case psOpCvr: case psOpCvr:
if (sp >= psStackSize) { if (sp >= psStackSize) {
goto underflow; goto underflow;
} }
break; break;
case psOpDiv: case psOpDiv:
if (sp + 1 >= psStackSize) { if (sp + 1 >= psStackSize) {
goto underflow; goto underflow;
} }
if (stack[sp] == 0) {
goto invalidArg;
}
stack[sp + 1] = stack[sp + 1] / stack[sp]; stack[sp + 1] = stack[sp + 1] / stack[sp];
++sp; ++sp;
break; break;
case psOpDup: case psOpDup:
if (sp >= psStackSize) { if (sp >= psStackSize) {
goto underflow; goto underflow;
} }
if (sp < 1) { if (sp < 1) {
goto overflow; goto overflow;
} }
skipping to change at line 1374 skipping to change at line 1399
if (sp + 1 >= psStackSize) { if (sp + 1 >= psStackSize) {
goto underflow; goto underflow;
} }
stack[sp + 1] = stack[sp + 1] > stack[sp] ? 1 : 0; stack[sp + 1] = stack[sp + 1] > stack[sp] ? 1 : 0;
++sp; ++sp;
break; break;
case psOpIdiv: case psOpIdiv:
if (sp + 1 >= psStackSize) { if (sp + 1 >= psStackSize) {
goto underflow; goto underflow;
} }
stack[sp + 1] = (int)stack[sp + 1] / (int)stack[sp]; k = (int)stack[sp];
if (k == 0) {
goto invalidArg;
}
stack[sp + 1] = (int)stack[sp + 1] / k;
++sp; ++sp;
break; break;
case psOpIndex: case psOpIndex:
if (sp >= psStackSize) { if (sp >= psStackSize) {
goto underflow; goto underflow;
} }
k = (int)stack[sp]; k = (int)stack[sp];
if (k < 0) { if (k < 0) {
goto invalidArg; goto invalidArg;
} }
skipping to change at line 1420 skipping to change at line 1449
if (sp + 1 >= psStackSize) { if (sp + 1 >= psStackSize) {
goto underflow; goto underflow;
} }
stack[sp + 1] = stack[sp + 1] < stack[sp] ? 1 : 0; stack[sp + 1] = stack[sp + 1] < stack[sp] ? 1 : 0;
++sp; ++sp;
break; break;
case psOpMod: case psOpMod:
if (sp + 1 >= psStackSize) { if (sp + 1 >= psStackSize) {
goto underflow; goto underflow;
} }
stack[sp + 1] = (int)stack[sp + 1] % (int)stack[sp]; k = (int)stack[sp];
if (k == 0) {
goto invalidArg;
}
stack[sp + 1] = (int)stack[sp + 1] % k;
++sp; ++sp;
break; break;
case psOpMul: case psOpMul:
if (sp + 1 >= psStackSize) { if (sp + 1 >= psStackSize) {
goto underflow; goto underflow;
} }
stack[sp + 1] = stack[sp + 1] * stack[sp]; stack[sp + 1] = stack[sp + 1] * stack[sp];
++sp; ++sp;
break; break;
case psOpNe: case psOpNe:
skipping to change at line 1471 skipping to change at line 1504
break; break;
case psOpRoll: case psOpRoll:
if (sp + 1 >= psStackSize) { if (sp + 1 >= psStackSize) {
goto underflow; goto underflow;
} }
k = (int)stack[sp++]; k = (int)stack[sp++];
nn = (int)stack[sp++]; nn = (int)stack[sp++];
if (nn < 0) { if (nn < 0) {
goto invalidArg; goto invalidArg;
} }
if (sp + nn > psStackSize) { if (nn > 0) {
goto underflow; if (sp + nn > psStackSize) {
} goto underflow;
if (k >= 0) { }
k %= nn; if (k >= 0) {
} else { k %= nn;
k = -k % nn; } else {
if (k) { k = -k % nn;
k = nn - k; if (k) {
k = nn - k;
}
}
for (i = 0; i < nn; ++i) {
tmp[i] = stack[sp + i];
}
for (i = 0; i < nn; ++i) {
stack[sp + i] = tmp[(i + k) % nn];
} }
}
for (i = 0; i < nn; ++i) {
tmp[i] = stack[sp + i];
}
for (i = 0; i < nn; ++i) {
stack[sp + i] = tmp[(i + k) % nn];
} }
break; break;
case psOpRound: case psOpRound:
if (sp >= psStackSize) { if (sp >= psStackSize) {
goto underflow; goto underflow;
} }
t = stack[sp]; t = stack[sp];
stack[sp] = (t >= 0) ? floor(t + 0.5) : ceil(t - 0.5); stack[sp] = (t >= 0) ? floor(t + 0.5) : ceil(t - 0.5);
break; break;
case psOpSin: case psOpSin:
 End of changes. 18 change blocks. 
31 lines changed or deleted 66 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)