⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splash.cc

📁 这是一个做pdf阅读器的源代码文件,是大家学习阅读器资料的很好参考
💻 CC
📖 第 1 页 / 共 5 页
字号:
      }      // blend fill color with background      if (pixAcc != 0) {	pipe.shape = (pixAcc == n * m)	                 ? (SplashCoord)1	                 : (SplashCoord)pixAcc / (SplashCoord)(n * m);	if (vectorAntialias && clipRes2 != splashClipAllInside) {	  drawAAPixel(&pipe, tx + x2, ty + y2);	} else {	  drawPixel(&pipe, tx + x2, ty + y2, clipRes2 == splashClipAllInside);	}      }      // x scale Bresenham      xSrc += xStep;      // x shear      x1 += xSign;      // y shear      y1 += yShear1;    }  }  // free memory  gfree(pixBuf);  return splashOk;}SplashError Splash::drawImage(SplashImageSource src, void *srcData,			      SplashColorMode srcMode, GBool srcAlpha,			      int w, int h, SplashCoord *mat) {  SplashPipe pipe;  GBool ok, rot;  SplashCoord xScale, yScale, xShear, yShear, yShear1;  int tx, tx2, ty, ty2, scaledWidth, scaledHeight, xSign, ySign;  int ulx, uly, llx, lly, urx, ury, lrx, lry;  int ulx1, uly1, llx1, lly1, urx1, ury1, lrx1, lry1;  int xMin, xMax, yMin, yMax;  SplashClipResult clipRes, clipRes2;  int yp, yq, yt, yStep, lastYStep;  int xp, xq, xt, xStep, xSrc;  int k1, spanXMin, spanXMax, spanY;  SplashColorPtr colorBuf, p;  SplashColor pix;  Guchar *alphaBuf, *q;#if SPLASH_CMYK  int pixAcc0, pixAcc1, pixAcc2, pixAcc3;#else  int pixAcc0, pixAcc1, pixAcc2;#endif  int alphaAcc;  SplashCoord pixMul, alphaMul, alpha;  int x, y, x1, x2, y2;  SplashCoord y1;  int nComps, n, m, i, j;  if (debugMode) {    printf("drawImage: srcMode=%d srcAlpha=%d w=%d h=%d mat=[%.2f %.2f %.2f %.2f %.2f %.2f]\n",	   srcMode, srcAlpha, w, h, (double)mat[0], (double)mat[1], (double)mat[2],	   (double)mat[3], (double)mat[4], (double)mat[5]);  }  // check color modes  ok = gFalse; // make gcc happy  nComps = 0; // make gcc happy  switch (bitmap->mode) {  case splashModeMono1:  case splashModeMono8:    ok = srcMode == splashModeMono8;    nComps = 1;    break;  case splashModeRGB8:    ok = srcMode == splashModeRGB8;    nComps = 3;    break;  case splashModeBGR8:    ok = srcMode == splashModeBGR8;    nComps = 3;    break;#if SPLASH_CMYK  case splashModeCMYK8:    ok = srcMode == splashModeCMYK8;    nComps = 4;    break;#endif  }  if (!ok) {    return splashErrModeMismatch;  }  // check for singular matrix  if (splashAbs(mat[0] * mat[3] - mat[1] * mat[2]) < 0.000001) {    return splashErrSingularMatrix;  }  // compute scale, shear, rotation, translation parameters  rot = splashAbs(mat[1]) > splashAbs(mat[0]);  if (rot) {    xScale = -mat[1];    yScale = mat[2] - (mat[0] * mat[3]) / mat[1];    xShear = -mat[3] / yScale;    yShear = -mat[0] / mat[1];  } else {    xScale = mat[0];    yScale = mat[3] - (mat[1] * mat[2]) / mat[0];    xShear = mat[2] / yScale;    yShear = mat[1] / mat[0];  }  // Note 1: The PDF spec says that all pixels whose *centers* lie  // within the region get painted -- but that doesn't seem to match  // up with what Acrobat actually does: it ends up leaving gaps  // between image stripes.  So we use the same rule here as for  // fills: any pixel that overlaps the region gets painted.  // Note 2: The +/-0.01 in these computations is to avoid floating  // point precision problems which can lead to gaps between image  // stripes (it can cause image stripes to overlap, but that's a much  // less visible problem).  if (xScale >= 0) {    tx = splashFloor(mat[4] - 0.01);    tx2 = splashFloor(mat[4] + xScale + 0.01);  } else {    tx = splashFloor(mat[4] + 0.01);    tx2 = splashFloor(mat[4] + xScale - 0.01);  }  scaledWidth = abs(tx2 - tx) + 1;  if (yScale >= 0) {    ty = splashFloor(mat[5] - 0.01);    ty2 = splashFloor(mat[5] + yScale + 0.01);  } else {    ty = splashFloor(mat[5] + 0.01);    ty2 = splashFloor(mat[5] + yScale - 0.01);  }  scaledHeight = abs(ty2 - ty) + 1;  xSign = (xScale < 0) ? -1 : 1;  ySign = (yScale < 0) ? -1 : 1;  yShear1 = (SplashCoord)xSign * yShear;  // clipping  ulx1 = 0;  uly1 = 0;  urx1 = xSign * (scaledWidth - 1);  ury1 = (int)(yShear * urx1);  llx1 = splashRound(xShear * ySign * (scaledHeight - 1));  lly1 = ySign * (scaledHeight - 1) + (int)(yShear * llx1);  lrx1 = xSign * (scaledWidth - 1) +           splashRound(xShear * ySign * (scaledHeight - 1));  lry1 = ySign * (scaledHeight - 1) + (int)(yShear * lrx1);  if (rot) {    ulx = tx + uly1;    uly = ty - ulx1;    urx = tx + ury1;    ury = ty - urx1;    llx = tx + lly1;    lly = ty - llx1;    lrx = tx + lry1;    lry = ty - lrx1;  } else {    ulx = tx + ulx1;    uly = ty + uly1;    urx = tx + urx1;    ury = ty + ury1;    llx = tx + llx1;    lly = ty + lly1;    lrx = tx + lrx1;    lry = ty + lry1;  }  xMin = (ulx < urx) ? (ulx < llx) ? (ulx < lrx) ? ulx : lrx                                   : (llx < lrx) ? llx : lrx		     : (urx < llx) ? (urx < lrx) ? urx : lrx                                   : (llx < lrx) ? llx : lrx;  xMax = (ulx > urx) ? (ulx > llx) ? (ulx > lrx) ? ulx : lrx                                   : (llx > lrx) ? llx : lrx		     : (urx > llx) ? (urx > lrx) ? urx : lrx                                   : (llx > lrx) ? llx : lrx;  yMin = (uly < ury) ? (uly < lly) ? (uly < lry) ? uly : lry                                   : (lly < lry) ? lly : lry		     : (ury < lly) ? (ury < lry) ? ury : lry                                   : (lly < lry) ? lly : lry;  yMax = (uly > ury) ? (uly > lly) ? (uly > lry) ? uly : lry                                   : (lly > lry) ? lly : lry		     : (ury > lly) ? (ury > lry) ? ury : lry                                   : (lly > lry) ? lly : lry;  clipRes = state->clip->testRect(xMin, yMin, xMax, yMax);  opClipRes = clipRes;  if (clipRes == splashClipAllOutside) {    return splashOk;  }  // compute Bresenham parameters for x and y scaling  yp = h / scaledHeight;  yq = h % scaledHeight;  xp = w / scaledWidth;  xq = w % scaledWidth;  // allocate pixel buffers  colorBuf = (SplashColorPtr)gmalloc((yp + 1) * w * nComps);  if (srcAlpha) {    alphaBuf = (Guchar *)gmalloc((yp + 1) * w);  } else {    alphaBuf = NULL;  }  pixAcc0 = pixAcc1 = pixAcc2 = 0; // make gcc happy#if SPLASH_CMYK  pixAcc3 = 0; // make gcc happy#endif  // initialize the pixel pipe  pipeInit(&pipe, 0, 0, NULL, pix, state->fillAlpha,	   srcAlpha || (vectorAntialias && clipRes != splashClipAllInside),	   gFalse);  if (vectorAntialias) {    drawAAPixelInit();  }  if (srcAlpha) {    // init y scale Bresenham    yt = 0;    lastYStep = 1;    for (y = 0; y < scaledHeight; ++y) {      // y scale Bresenham      yStep = yp;      yt += yq;      if (yt >= scaledHeight) {	yt -= scaledHeight;	++yStep;      }      // read row(s) from image      n = (yp > 0) ? yStep : lastYStep;      if (n > 0) {	p = colorBuf;	q = alphaBuf;	for (i = 0; i < n; ++i) {	  (*src)(srcData, p, q);	  p += w * nComps;	  q += w;	}      }      lastYStep = yStep;      // loop-invariant constants      k1 = splashRound(xShear * ySign * y);      // clipping test      if (clipRes != splashClipAllInside &&	  !rot &&	  (int)(yShear * k1) ==	    (int)(yShear * (xSign * (scaledWidth - 1) + k1))) {	if (xSign > 0) {	  spanXMin = tx + k1;	  spanXMax = spanXMin + (scaledWidth - 1);	} else {	  spanXMax = tx + k1;	  spanXMin = spanXMax - (scaledWidth - 1);	}	spanY = ty + ySign * y + (int)(yShear * k1);	clipRes2 = state->clip->testSpan(spanXMin, spanXMax, spanY);	if (clipRes2 == splashClipAllOutside) {	  continue;	}      } else {	clipRes2 = clipRes;      }      // init x scale Bresenham      xt = 0;      xSrc = 0;      // x shear      x1 = k1;      // y shear      y1 = (SplashCoord)ySign * y + yShear * x1;      // this is a kludge: if yShear1 is negative, then (int)y1 would      // change immediately after the first pixel, which is not what      // we want      if (yShear1 < 0) {	y1 += 0.999;      }      // loop-invariant constants      n = yStep > 0 ? yStep : 1;      switch (srcMode) {      case splashModeMono1:      case splashModeMono8:	for (x = 0; x < scaledWidth; ++x) {	  // x scale Bresenham	  xStep = xp;	  xt += xq;	  if (xt >= scaledWidth) {	    xt -= scaledWidth;	    ++xStep;	  }	  // rotation	  if (rot) {	    x2 = (int)y1;	    y2 = -x1;	  } else {	    x2 = x1;	    y2 = (int)y1;	  }	  // compute the filtered pixel at (x,y) after the x and y scaling	  // operations	  m = xStep > 0 ? xStep : 1;	  alphaAcc = 0;	  p = colorBuf + xSrc;	  q = alphaBuf + xSrc;	  pixAcc0 = 0;	  for (i = 0; i < n; ++i) {	    for (j = 0; j < m; ++j) {	      pixAcc0 += *p++;	      alphaAcc += *q++;	    }	    p += w - m;	    q += w - m;	  }	  pixMul = (SplashCoord)1 / (SplashCoord)(n * m);	  alphaMul = pixMul * (1.0 / 255.0);	  alpha = (SplashCoord)alphaAcc * alphaMul;	  if (alpha > 0) {	    pix[0] = (int)((SplashCoord)pixAcc0 * pixMul);	    // set pixel	    pipe.shape = alpha;	    if (vectorAntialias && clipRes != splashClipAllInside) {	      drawAAPixel(&pipe, tx + x2, ty + y2);	    } else {	      drawPixel(&pipe, tx + x2, ty + y2,			clipRes2 == splashClipAllInside);	    }	  }	  // x scale Bresenham	  xSrc += xStep;	  // x shear	  x1 += xSign;	  // y shear	  y1 += yShear1;	}	break;      case splashModeRGB8:      case splashModeBGR8:	for (x = 0; x < scaledWidth; ++x) {	  // x scale Bresenham	  xStep = xp;	  xt += xq;	  if (xt >= scaledWidth) {	    xt -= scaledWidth;	    ++xStep;	  }	  // rotation	  if (rot) {	    x2 = (int)y1;	    y2 = -x1;	  } else {	    x2 = x1;	    y2 = (int)y1;	  }	  // compute the filtered pixel at (x,y) after the x and y scaling	  // operations	  m = xStep > 0 ? xStep : 1;	  alphaAcc = 0;	  p = colorBuf + xSrc * 3;	  q = alphaBuf + xSrc;	  pixAcc0 = pixAcc1 = pixAcc2 = 0;	  for (i = 0; i < n; ++i) {	    for (j = 0; j < m; ++j) {	      pixAcc0 += *p++;	      pixAcc1 += *p++;	      pixAcc2 += *p++;	      alphaAcc += *q++;	    }	    p += 3 * (w - m);	    q += w - m;	  }	  pixMul = (SplashCoord)1 / (SplashCoord)(n * m);	  alphaMul = pixMul * (1.0 / 255.0);	  alpha = (SplashCoord)alphaAcc * alphaMul;	  if (alpha > 0) {	    pix[0] = (int)((SplashCoord)pixAcc0 * pixMul);	    pix[1] = (int)((SplashCoord)pixAcc1 * pixMul);	    pix[2] = (int)((SplashCoord)pixAcc2 * pixMul);	    // set pixel	    pipe.shape = alpha;	    if (vectorAntialias && clipRes != splashClipAllInside) {	      drawAAPixel(&pipe, tx + x2, ty + y2);	    } else {	      drawPixel(&pipe, tx + x2, ty + y2,			clipRes2 == splashClipAllInside);	    }	  }	  // x scale Bresenham	  xSrc += xStep;	  // x shear	  x1 += xSign;	  // y shear	  y1 += yShear1;	}	break;#if SPLASH_CMYK      case splashModeCMYK8:	for (x = 0; x < scaledWidth; ++x) {	  // x scale Bresenham	  xStep = xp;	  xt += xq;	  if (xt >= scaledWidth) {	    xt -= scaledWidth;	    ++xStep;	  }	  // rotation	  if (rot) {	    x2 = (int)y1;	    y2 = -x1;	  } else {	    x2 = x1;	    y2 = (int)y1;	  }	  // compute the filtered pixel at (x,y) after the x and y scaling	  // operations	  m = xStep > 0 ? xStep : 1;	  alphaAcc = 0;	  p = colorBuf + xSrc * 4;	  q = alphaBuf + xSrc;	  pixAcc0 = pixAcc1 = pixAcc2 = pixAcc3 = 0;	  for (i = 0; i < n; ++i) {	    for (j = 0; j < m; ++j) {	      pixAcc0 += *p++;	      pixAcc1 += *p++;	      pixAcc2 += *p++;	      pixAcc3 += *p++;	      alphaAcc += *q++;	    }	    p += 4 * (w - m);	    q += w - m;	  }	  pixMul = (SplashCoord)1 / (SplashCoord)(n * m);	  alphaMul = pixMul * (1.0 / 255.0);	  alpha = (SplashCoord)alphaAcc * alphaMul;	  if (alpha > 0) {	    pix[0] = (int)((SplashCoord)pixAcc0 * pixMul);	    pix[1] = (int)((SplashCoord)pixAcc1 * pixMul);	    pix[2] = (int)((SplashCoord)pixAcc2 * pixMul);	    pix[3] = (int)((SplashCoord)pixAcc3 * pixMul);	    // set pixel	    pipe.shape = alpha;	    if (vectorAntialias && clipRes != splashClipAllInside) {	      drawAAPixel(&pipe, tx + x2, ty + y2);	    } else {	      drawPixel(&pipe, tx + x2, ty + y2,			clipRes2 == splashClipAllInside);	    }	  }	  // x scale Bresenham	  xSrc += xStep;	  // x shear	  x1 += xSign;	  // y shear	  y1 += yShear1;	}	break;#endif // SPLASH_CMYK      }    }  } else {    // init y scale Bresenham    yt = 0;    lastYStep = 1;    for (y = 0; y < scaledHeight; ++y) {      // y scale Bresenham      yStep = yp;      yt += yq;      if (yt >= scaledHeight) {	yt -= s

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -