1 /* FullBitmapOutputDev.cc
3 Output Device which creates a bitmap.
5 Swftools is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 Swftools is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with swftools; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
23 #include "FullBitmapOutputDev.h"
24 #include "GFXOutputDev.h"
25 #include "SplashBitmap.h"
26 #include "SplashPattern.h"
30 #include "../devices/record.h"
32 static SplashColor splash_white = {255,255,255};
33 static SplashColor splash_black = {0,0,0};
35 FullBitmapOutputDev::FullBitmapOutputDev(InfoOutputDev*info, PDFDoc*doc)
38 this->xref = doc->getXRef();
40 msg("<verbose> Rendering everything to a bitmap");
42 /* color graphic output device, for creating bitmaps */
43 this->rgbdev = new SplashOutputDev(splashModeRGB8, 1, gFalse, splash_white, gTrue, gTrue);
45 /* device for handling links */
46 this->gfxdev = new GFXOutputDev(info, this->doc);
48 this->rgbdev->startDoc(this->xref);
50 FullBitmapOutputDev::~FullBitmapOutputDev()
53 delete this->rgbdev;this->rgbdev = 0;
56 delete this->gfxdev;this->gfxdev= 0;
60 GBool FullBitmapOutputDev::getVectorAntialias()
62 return this->rgbdev->getVectorAntialias();
64 void FullBitmapOutputDev::setVectorAntialias(GBool vaa)
66 this->rgbdev->setVectorAntialias(vaa);
68 void FullBitmapOutputDev::setDevice(gfxdevice_t*dev)
71 gfxdev->setDevice(dev);
73 void FullBitmapOutputDev::setMove(int x,int y)
79 void FullBitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
81 this->user_clipx1 = x1;
82 this->user_clipy1 = y1;
83 this->user_clipx2 = x2;
84 this->user_clipy2 = y2;
85 gfxdev->setClip(x1,y1,x2,y2);
87 void FullBitmapOutputDev::setParameter(const char*key, const char*value)
90 void FullBitmapOutputDev::setPageMap(int*pagemap, int pagemap_len)
92 gfxdev->setPageMap(pagemap, pagemap_len);
95 static void getBitmapBBox(Guchar*alpha, int width, int height, int*xmin, int*ymin, int*xmax, int*ymax)
101 for(y=0;y<height;y++) {
102 Guchar*a = &alpha[y*width];
103 for(x=0;x<width;x++) {
106 int left = x; //first occupied pixel from left
107 int right = x+1; //last non-occupied pixel from right
116 if(left<*xmin) *xmin = left;
117 if(right>*xmax) *xmax = right;
120 if(*xmin>=*xmax || *ymin>=*ymax) {
128 void FullBitmapOutputDev::flushBitmap()
130 int width = rgbdev->getBitmapWidth();
131 int height = rgbdev->getBitmapHeight();
133 SplashColorPtr rgb = rgbdev->getBitmap()->getDataPtr();
134 Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
136 int xmin,ymin,xmax,ymax;
137 getBitmapBBox(alpha, width, height, &xmin,&ymin,&xmax,&ymax);
139 /* clip against (-movex, -movey, -movex+width, -movey+height) */
140 if(xmin < -this->movex) xmin = -this->movex;
141 if(ymin < -this->movey) ymin = -this->movey;
142 if(xmax > -this->movex + width) xmax = -this->movex+this->width;
143 if(ymax > -this->movey + height) ymax = -this->movey+this->height;
145 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
147 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
150 if(sizeof(SplashColor)!=3) {
151 msg("<error> sizeof(SplashColor)!=3");
158 int rangex = xmax-xmin;
159 int rangey = ymax-ymin;
160 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
161 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
163 img->height = rangey;
165 for(y=0;y<rangey;y++) {
166 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
167 gfxcolor_t*out = &img->data[y*rangex];
168 Guchar*ain = &alpha[(y+ymin)*width+xmin];
169 for(x=0;x<rangex;x++) {
170 // blend against a white background
171 out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
172 out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
173 out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
174 out[x].a = 255;//ain[x];
177 /* transform bitmap rectangle to "device space" */
189 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
190 dev->fillbitmap(dev, line, img, &m, 0);
193 free(img->data);img->data=0;free(img);img=0;
196 GBool FullBitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
197 int rotate, GBool useMediaBox, GBool crop,
198 int sliceX, int sliceY, int sliceW, int sliceH,
199 GBool printing, Catalog *catalog,
200 GBool (*abortCheckCbk)(void *data),
201 void *abortCheckCbkData)
204 gfxdev->setPage(page);
208 void FullBitmapOutputDev::startPage(int pageNum, GfxState *state)
211 PDFRectangle *r = page->getCropBox();
212 state->transform(r->x1,r->y1,&x1,&y1);
213 state->transform(r->x2,r->y2,&x2,&y2);
214 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
215 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
217 this->movex = -(int)x1 - user_movex;
218 this->movey = -(int)y1 - user_movey;
220 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
226 this->width = (int)(x2-x1);
227 this->height = (int)(y2-y1);
229 msg("<debug> startPage");
230 rgbdev->startPage(pageNum, state);
231 gfxdev->startPage(pageNum, state);
234 void FullBitmapOutputDev::endPage()
236 msg("<verbose> endPage (FullBitmapOutputDev)");
241 GBool FullBitmapOutputDev::upsideDown()
243 return rgbdev->upsideDown();
245 GBool FullBitmapOutputDev::useDrawChar()
247 return rgbdev->useDrawChar();
249 GBool FullBitmapOutputDev::useTilingPatternFill()
251 return rgbdev->useTilingPatternFill();
253 GBool FullBitmapOutputDev::useShadedFills()
255 return rgbdev->useShadedFills();
257 GBool FullBitmapOutputDev::useDrawForm()
259 return rgbdev->useDrawForm();
261 GBool FullBitmapOutputDev::interpretType3Chars()
263 return rgbdev->interpretType3Chars();
265 GBool FullBitmapOutputDev::needNonText()
267 return rgbdev->needNonText();
269 void FullBitmapOutputDev::setDefaultCTM(double *ctm)
271 rgbdev->setDefaultCTM(ctm);
272 gfxdev->setDefaultCTM(ctm);
274 void FullBitmapOutputDev::saveState(GfxState *state)
276 rgbdev->saveState(state);
278 void FullBitmapOutputDev::restoreState(GfxState *state)
280 rgbdev->restoreState(state);
282 void FullBitmapOutputDev::updateAll(GfxState *state)
284 rgbdev->updateAll(state);
286 void FullBitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
288 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
289 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
291 void FullBitmapOutputDev::updateLineDash(GfxState *state)
293 rgbdev->updateLineDash(state);
295 void FullBitmapOutputDev::updateFlatness(GfxState *state)
297 rgbdev->updateFlatness(state);
299 void FullBitmapOutputDev::updateLineJoin(GfxState *state)
301 rgbdev->updateLineJoin(state);
303 void FullBitmapOutputDev::updateLineCap(GfxState *state)
305 rgbdev->updateLineCap(state);
307 void FullBitmapOutputDev::updateMiterLimit(GfxState *state)
309 rgbdev->updateMiterLimit(state);
311 void FullBitmapOutputDev::updateLineWidth(GfxState *state)
313 rgbdev->updateLineWidth(state);
315 void FullBitmapOutputDev::updateStrokeAdjust(GfxState *state)
317 rgbdev->updateStrokeAdjust(state);
319 void FullBitmapOutputDev::updateFillColorSpace(GfxState *state)
321 rgbdev->updateFillColorSpace(state);
323 void FullBitmapOutputDev::updateStrokeColorSpace(GfxState *state)
325 rgbdev->updateStrokeColorSpace(state);
327 void FullBitmapOutputDev::updateFillColor(GfxState *state)
329 rgbdev->updateFillColor(state);
331 void FullBitmapOutputDev::updateStrokeColor(GfxState *state)
333 rgbdev->updateStrokeColor(state);
335 void FullBitmapOutputDev::updateBlendMode(GfxState *state)
337 rgbdev->updateBlendMode(state);
339 void FullBitmapOutputDev::updateFillOpacity(GfxState *state)
341 rgbdev->updateFillOpacity(state);
343 void FullBitmapOutputDev::updateStrokeOpacity(GfxState *state)
345 rgbdev->updateStrokeOpacity(state);
347 void FullBitmapOutputDev::updateFillOverprint(GfxState *state)
349 rgbdev->updateFillOverprint(state);
351 void FullBitmapOutputDev::updateStrokeOverprint(GfxState *state)
353 rgbdev->updateStrokeOverprint(state);
355 void FullBitmapOutputDev::updateTransfer(GfxState *state)
357 rgbdev->updateTransfer(state);
359 void FullBitmapOutputDev::updateFont(GfxState *state)
361 rgbdev->updateFont(state);
363 void FullBitmapOutputDev::updateTextMat(GfxState *state)
365 rgbdev->updateTextMat(state);
367 void FullBitmapOutputDev::updateCharSpace(GfxState *state)
369 rgbdev->updateCharSpace(state);
371 void FullBitmapOutputDev::updateRender(GfxState *state)
373 rgbdev->updateRender(state);
375 void FullBitmapOutputDev::updateRise(GfxState *state)
377 rgbdev->updateRise(state);
379 void FullBitmapOutputDev::updateWordSpace(GfxState *state)
381 rgbdev->updateWordSpace(state);
383 void FullBitmapOutputDev::updateHorizScaling(GfxState *state)
385 rgbdev->updateHorizScaling(state);
387 void FullBitmapOutputDev::updateTextPos(GfxState *state)
389 rgbdev->updateTextPos(state);
391 void FullBitmapOutputDev::updateTextShift(GfxState *state, double shift)
393 rgbdev->updateTextShift(state, shift);
396 void FullBitmapOutputDev::stroke(GfxState *state)
398 msg("<debug> stroke");
399 rgbdev->stroke(state);
401 void FullBitmapOutputDev::fill(GfxState *state)
406 void FullBitmapOutputDev::eoFill(GfxState *state)
408 msg("<debug> eoFill");
409 rgbdev->eoFill(state);
411 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
412 void FullBitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
413 int paintType, Dict *resDict,
414 double *mat, double *bbox,
415 int x0, int y0, int x1, int y1,
416 double xStep, double yStep)
418 msg("<debug> tilingPatternFill");
419 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
422 void FullBitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
423 int paintType, Dict *resDict,
424 double *mat, double *bbox,
425 int x0, int y0, int x1, int y1,
426 double xStep, double yStep)
428 msg("<debug> tilingPatternFill");
429 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
433 GBool FullBitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
435 msg("<debug> functionShadedFill");
436 return rgbdev->functionShadedFill(state, shading);
438 GBool FullBitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
440 msg("<debug> axialShadedFill");
441 return rgbdev->axialShadedFill(state, shading);
443 GBool FullBitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
445 msg("<debug> radialShadedFill");
446 return rgbdev->radialShadedFill(state, shading);
449 void FullBitmapOutputDev::clip(GfxState *state)
454 void FullBitmapOutputDev::eoClip(GfxState *state)
456 msg("<debug> eoClip");
457 rgbdev->eoClip(state);
459 void FullBitmapOutputDev::clipToStrokePath(GfxState *state)
461 msg("<debug> clipToStrokePath");
462 rgbdev->clipToStrokePath(state);
465 void FullBitmapOutputDev::beginStringOp(GfxState *state)
467 msg("<debug> beginStringOp");
468 rgbdev->beginStringOp(state);
470 void FullBitmapOutputDev::endStringOp(GfxState *state)
472 msg("<debug> endStringOp");
473 rgbdev->endStringOp(state);
475 void FullBitmapOutputDev::beginString(GfxState *state, GString *s)
477 msg("<debug> beginString");
478 rgbdev->beginString(state, s);
480 void FullBitmapOutputDev::endString(GfxState *state)
482 msg("<debug> endString");
483 rgbdev->endString(state);
485 void FullBitmapOutputDev::drawChar(GfxState *state, double x, double y,
486 double dx, double dy,
487 double originX, double originY,
488 CharCode code, int nBytes, Unicode *u, int uLen)
490 msg("<debug> drawChar");
491 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
493 void FullBitmapOutputDev::drawString(GfxState *state, GString *s)
495 msg("<error> internal error: drawString not implemented");
496 rgbdev->drawString(state, s);
498 void FullBitmapOutputDev::endTextObject(GfxState *state)
500 /* FIXME: the below might render things (stroke outlines etc.) to gfxdev which
501 might end up unflushed- should be handled similarily as
504 msg("<debug> endTextObject");
505 rgbdev->endTextObject(state);
508 /* TODO: these four operations below *should* do nothing, as type3
509 chars are drawn using operations like fill() */
510 GBool FullBitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
511 double dx, double dy,
512 CharCode code, Unicode *u, int uLen)
514 msg("<debug> beginType3Char");
515 return rgbdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
517 void FullBitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
519 msg("<debug> type3D0");
520 rgbdev->type3D0(state, wx, wy);
522 void FullBitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
524 msg("<debug> type3D1");
525 rgbdev->type3D1(state, wx, wy, llx, lly, urx, ury);
527 void FullBitmapOutputDev::endType3Char(GfxState *state)
529 msg("<debug> endType3Char");
530 rgbdev->endType3Char(state);
532 void FullBitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
533 int width, int height, GBool invert,
536 msg("<debug> drawImageMask");
537 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
539 void FullBitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
540 int width, int height, GfxImageColorMap *colorMap,
541 int *maskColors, GBool inlineImg)
543 msg("<debug> drawImage");
544 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
546 void FullBitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
547 int width, int height,
548 GfxImageColorMap *colorMap,
549 Stream *maskStr, int maskWidth, int maskHeight,
552 msg("<debug> drawMaskedImage");
553 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
555 void FullBitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
556 int width, int height,
557 GfxImageColorMap *colorMap,
559 int maskWidth, int maskHeight,
560 GfxImageColorMap *maskColorMap)
562 msg("<debug> drawSoftMaskedImage");
563 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
565 void FullBitmapOutputDev::drawForm(Ref id)
567 msg("<debug> drawForm");
568 rgbdev->drawForm(id);
571 void FullBitmapOutputDev::processLink(Link *link, Catalog *catalog)
573 msg("<debug> processLink");
574 gfxdev->processLink(link, catalog);
577 void FullBitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
578 GfxColorSpace *blendingColorSpace,
579 GBool isolated, GBool knockout,
582 msg("<debug> beginTransparencyGroup");
583 rgbdev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
585 void FullBitmapOutputDev::endTransparencyGroup(GfxState *state)
587 msg("<debug> endTransparencyGroup");
588 rgbdev->endTransparencyGroup(state);
590 void FullBitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
592 msg("<debug> paintTransparencyGroup");
593 rgbdev->paintTransparencyGroup(state,bbox);
595 void FullBitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
597 msg("<debug> setSoftMask");
598 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
600 void FullBitmapOutputDev::clearSoftMask(GfxState *state)
602 msg("<debug> clearSoftMask");
603 rgbdev->clearSoftMask(state);