Ignore:
Timestamp:
Jun 30, 2008, 10:13:07 AM (13 years ago)
Author:
Eugene Romanenko
Message:

PDF plugin: poppler library updated to version 0.8.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/poppler/mypoppler/poppler/Function.cc

    r27 r250  
    2323#include "Error.h"
    2424#include "Function.h"
    25 #include "UGooString.h"
     25
     26#ifndef M_PI
     27#define M_PI 3.14159265358979323846
     28#endif
    2629
    2730//------------------------------------------------------------------------
     
    192195  Guint buf, bitMask;
    193196  int bits;
    194   int s;
     197  Guint s;
    195198  int i;
    196199
    197200  samples = NULL;
     201  sBuf = NULL;
    198202  ok = gFalse;
    199203
     
    206210    goto err1;
    207211  }
     212  if (m > sampledFuncMaxInputs) {
     213    error(-1, "Sampled functions with more than %d inputs are unsupported",
     214          sampledFuncMaxInputs);
     215    goto err1;
     216  }
     217
     218  //----- buffer
     219  sBuf = (double *)gmallocn(1 << m, sizeof(double));
    208220
    209221  //----- get the stream
     
    241253  }
    242254  sampleBits = obj1.getInt();
    243   sampleMul = 1.0 / (double)((1 << sampleBits) - 1);
     255  sampleMul = 1.0 / (pow(2.0, (double)sampleBits) - 1);
    244256  obj1.free();
    245257
     
    349361    gfree(samples);
    350362  }
     363  if (sBuf) {
     364    gfree(sBuf);
     365  }
    351366}
    352367
     
    355370  samples = (double *)gmallocn(nSamples, sizeof(double));
    356371  memcpy(samples, func->samples, nSamples * sizeof(double));
     372  sBuf = (double *)gmallocn(1 << m, sizeof(double));
    357373}
    358374
     
    362378  double efrac0[funcMaxInputs];
    363379  double efrac1[funcMaxInputs];
    364   double s[1 << funcMaxInputs];
    365380  int i, j, k, idx, t;
    366381
     
    391406        idx += idxMul[k] * (e[k][t & 1]);
    392407      }
    393       if (idx >= 0 && idx < nSamples) s[j] = samples[idx];
     408      sBuf[j] = samples[idx];
    394409    }
    395410
     
    397412    for (j = 0, t = (1<<m); j < m; ++j, t >>= 1) {
    398413      for (k = 0; k < t; k += 2) {
    399         s[k >> 1] = efrac0[j] * s[k] + efrac1[j] * s[k+1];
     414        sBuf[k >> 1] = efrac0[j] * sBuf[k] + efrac1[j] * sBuf[k+1];
    400415      }
    401416    }
    402417
    403418    // map output value to range
    404     out[i] = s[0] * (decode[i][1] - decode[i][0]) + decode[i][0];
     419    out[i] = sBuf[0] * (decode[i][1] - decode[i][0]) + decode[i][0];
    405420    if (out[i] < range[i][0]) {
    406421      out[i] = range[i][0];
     
    542557  bounds = NULL;
    543558  encode = NULL;
     559  scale = NULL;
    544560
    545561  //----- initialize the generic stuff
     
    561577  bounds = (double *)gmallocn(k + 1, sizeof(double));
    562578  encode = (double *)gmallocn(2 * k, sizeof(double));
     579  scale = (double *)gmallocn(k, sizeof(double));
    563580  for (i = 0; i < k; ++i) {
    564581    funcs[i] = NULL;
     
    611628  obj1.free();
    612629
     630  //----- pre-compute the scale factors
     631  for (i = 0; i < k; ++i) {
     632    if (bounds[i] == bounds[i+1]) {
     633      // avoid a divide-by-zero -- in this situation, function i will
     634      // never be used anyway
     635      scale[i] = 0;
     636    } else {
     637      scale[i] = (encode[2*i+1] - encode[2*i]) / (bounds[i+1] - bounds[i]);
     638    }
     639  }
     640
    613641  ok = gTrue;
    614642  return;
     
    632660  encode = (double *)gmallocn(2 * k, sizeof(double));
    633661  memcpy(encode, func->encode, 2 * k * sizeof(double));
     662  scale = (double *)gmallocn(k, sizeof(double));
     663  memcpy(scale, func->scale, k * sizeof(double));
    634664  ok = gTrue;
    635665}
     
    648678  gfree(bounds);
    649679  gfree(encode);
     680  gfree(scale);
    650681}
    651682
     
    666697    }
    667698  }
    668   x = encode[2*i] + ((x - bounds[i]) / (bounds[i+1] - bounds[i])) *
    669                     (encode[2*i+1] - encode[2*i]);
     699  x = encode[2*i] + (x - bounds[i]) * scale[i];
    670700  funcs[i]->transform(&x, out);
    671701}
     
    9791009
    9801010  code = NULL;
     1011  codeString = NULL;
    9811012  codeSize = 0;
    9821013  ok = gFalse;
     
    11821213  GooString *s;
    11831214  int c;
     1215  GBool comment;
    11841216
    11851217  s = new GooString();
    1186   do {
    1187     c = str->getChar();
    1188     if (c != EOF) {
    1189       codeString->append(c);
    1190     }
    1191   } while (c != EOF && isspace(c));
     1218  comment = gFalse;
     1219  while (1) {
     1220    if ((c = str->getChar()) == EOF) {
     1221      break;
     1222    }
     1223    codeString->append(c);
     1224    if (comment) {
     1225      if (c == '\x0a' || c == '\x0d') {
     1226        comment = gFalse;
     1227      }
     1228    } else if (c == '%') {
     1229      comment = gTrue;
     1230    } else if (!isspace(c)) {
     1231      break;
     1232    }
     1233  }
    11921234  if (c == '{' || c == '}') {
    11931235    s->append((char)c);
     
    12251267void PostScriptFunction::exec(PSStack *stack, int codePtr) {
    12261268  int i1, i2;
    1227   double r1, r2;
     1269  double r1, r2, result;
    12281270  GBool b1, b2;
    12291271
     
    12701312        r2 = stack->popNum();
    12711313        r1 = stack->popNum();
    1272         stack->pushReal(atan2(r1, r2));
     1314        result = atan2(r1, r2) * 180.0 / M_PI;
     1315        if (result < 0) result += 360.0;
     1316        stack->pushReal(result);
    12731317        break;
    12741318      case psOpBitshift:
     
    12921336        break;
    12931337      case psOpCos:
    1294         stack->pushReal(cos(stack->popNum()));
     1338        stack->pushReal(cos(stack->popNum() * M_PI / 180.0));
    12951339        break;
    12961340      case psOpCvi:
     
    14731517        break;
    14741518      case psOpSin:
    1475         stack->pushReal(sin(stack->popNum()));
     1519        stack->pushReal(sin(stack->popNum() * M_PI / 180.0));
    14761520        break;
    14771521      case psOpSqrt:
Note: See TracChangeset for help on using the changeset viewer.