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 */
22 #include "FullBitmapOutputDev.h"
23 #include "GFXOutputDev.h"
26 #include "splash/SplashBitmap.h"
27 #include "splash/SplashPattern.h"
28 #include "splash/Splash.h"
30 #include "xpdf/config.h"
31 #include "SplashBitmap.h"
32 #include "SplashPattern.h"
38 #include "../devices/record.h"
40 static SplashColor splash_white = {255,255,255};
41 static SplashColor splash_black = {0,0,0};
43 FullBitmapOutputDev::FullBitmapOutputDev(InfoOutputDev*info, PDFDoc*doc)
46 this->xref = doc->getXRef();
48 msg("<verbose> Rendering everything to a bitmap");
50 /* color graphic output device, for creating bitmaps */
51 this->rgbdev = new SplashOutputDev(splashModeRGB8, 1, gFalse, splash_white, gTrue, gTrue);
53 /* device for handling links */
54 this->gfxdev = new GFXOutputDev(info, this->doc);
56 this->rgbdev->startDoc(this->xref);
58 FullBitmapOutputDev::~FullBitmapOutputDev()
61 delete this->rgbdev;this->rgbdev = 0;
64 delete this->gfxdev;this->gfxdev= 0;
68 GBool FullBitmapOutputDev::getVectorAntialias()
70 return this->rgbdev->getVectorAntialias();
72 void FullBitmapOutputDev::setVectorAntialias(GBool vaa)
74 this->rgbdev->setVectorAntialias(vaa);
76 void FullBitmapOutputDev::setDevice(gfxdevice_t*dev)
79 gfxdev->setDevice(dev);
81 void FullBitmapOutputDev::setMove(int x,int y)
87 void FullBitmapOutputDev::setClip(int x1,int y1,int x2,int y2)
89 this->user_clipx1 = x1;
90 this->user_clipy1 = y1;
91 this->user_clipx2 = x2;
92 this->user_clipy2 = y2;
93 gfxdev->setClip(x1,y1,x2,y2);
95 void FullBitmapOutputDev::setParameter(const char*key, const char*value)
98 void FullBitmapOutputDev::setPageMap(int*pagemap, int pagemap_len)
100 gfxdev->setPageMap(pagemap, pagemap_len);
103 static void getBitmapBBox(Guchar*alpha, int width, int height, int*xmin, int*ymin, int*xmax, int*ymax)
109 for(y=0;y<height;y++) {
110 Guchar*a = &alpha[y*width];
111 for(x=0;x<width;x++) {
114 int left = x; //first occupied pixel from left
115 int right = x+1; //last non-occupied pixel from right
124 if(left<*xmin) *xmin = left;
125 if(right>*xmax) *xmax = right;
128 if(*xmin>=*xmax || *ymin>=*ymax) {
136 void FullBitmapOutputDev::flushBitmap()
138 int width = rgbdev->getBitmapWidth();
139 int height = rgbdev->getBitmapHeight();
141 SplashColorPtr rgb = rgbdev->getBitmap()->getDataPtr();
142 Guchar*alpha = rgbdev->getBitmap()->getAlphaPtr();
144 int xmin,ymin,xmax,ymax;
145 getBitmapBBox(alpha, width, height, &xmin,&ymin,&xmax,&ymax);
147 /* clip against (-movex, -movey, -movex+width, -movey+height) */
148 if(xmin < -this->movex) xmin = -this->movex;
149 if(ymin < -this->movey) ymin = -this->movey;
150 if(xmax > -this->movex + width) xmax = -this->movex+this->width;
151 if(ymax > -this->movey + height) ymax = -this->movey+this->height;
153 msg("<verbose> Flushing bitmap (bbox: %d,%d,%d,%d)", xmin,ymin,xmax,ymax);
155 if((xmax-xmin)<=0 || (ymax-ymin)<=0) // no bitmap, nothing to do
158 if(sizeof(SplashColor)!=3) {
159 msg("<error> sizeof(SplashColor)!=3");
166 int rangex = xmax-xmin;
167 int rangey = ymax-ymin;
168 gfximage_t*img = (gfximage_t*)malloc(sizeof(gfximage_t));
169 img->data = (gfxcolor_t*)malloc(rangex * rangey * 4);
171 img->height = rangey;
173 for(y=0;y<rangey;y++) {
174 SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)];
175 gfxcolor_t*out = &img->data[y*rangex];
176 Guchar*ain = &alpha[(y+ymin)*width+xmin];
177 for(x=0;x<rangex;x++) {
178 // blend against a white background
179 out[x].r = (in[x*3+0]*ain[x])/255 + 255-ain[x];
180 out[x].g = (in[x*3+1]*ain[x])/255 + 255-ain[x];
181 out[x].b = (in[x*3+2]*ain[x])/255 + 255-ain[x];
182 out[x].a = 255;//ain[x];
185 /* transform bitmap rectangle to "device space" */
197 gfxline_t* line = gfxline_makerectangle(xmin, ymin, xmax, ymax);
198 dev->fillbitmap(dev, line, img, &m, 0);
201 free(img->data);img->data=0;free(img);img=0;
204 GBool FullBitmapOutputDev::checkPageSlice(Page *page, double hDPI, double vDPI,
205 int rotate, GBool useMediaBox, GBool crop,
206 int sliceX, int sliceY, int sliceW, int sliceH,
207 GBool printing, Catalog *catalog,
208 GBool (*abortCheckCbk)(void *data),
209 void *abortCheckCbkData)
212 gfxdev->setPage(page);
216 void FullBitmapOutputDev::startPage(int pageNum, GfxState *state)
219 PDFRectangle *r = page->getCropBox();
220 state->transform(r->x1,r->y1,&x1,&y1);
221 state->transform(r->x2,r->y2,&x2,&y2);
222 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
223 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
225 this->movex = -(int)x1 - user_movex;
226 this->movey = -(int)y1 - user_movey;
228 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
234 this->width = (int)(x2-x1);
235 this->height = (int)(y2-y1);
237 msg("<debug> startPage");
238 rgbdev->startPage(pageNum, state);
239 gfxdev->startPage(pageNum, state);
242 void FullBitmapOutputDev::endPage()
244 msg("<verbose> endPage (FullBitmapOutputDev)");
249 GBool FullBitmapOutputDev::upsideDown()
251 return rgbdev->upsideDown();
253 GBool FullBitmapOutputDev::useDrawChar()
255 return rgbdev->useDrawChar();
257 GBool FullBitmapOutputDev::useTilingPatternFill()
259 return rgbdev->useTilingPatternFill();
261 GBool FullBitmapOutputDev::useShadedFills()
263 return rgbdev->useShadedFills();
265 GBool FullBitmapOutputDev::useDrawForm()
267 return rgbdev->useDrawForm();
269 GBool FullBitmapOutputDev::interpretType3Chars()
271 return rgbdev->interpretType3Chars();
273 GBool FullBitmapOutputDev::needNonText()
275 return rgbdev->needNonText();
277 void FullBitmapOutputDev::setDefaultCTM(double *ctm)
279 rgbdev->setDefaultCTM(ctm);
280 gfxdev->setDefaultCTM(ctm);
282 void FullBitmapOutputDev::saveState(GfxState *state)
284 rgbdev->saveState(state);
286 void FullBitmapOutputDev::restoreState(GfxState *state)
288 rgbdev->restoreState(state);
290 void FullBitmapOutputDev::updateAll(GfxState *state)
292 rgbdev->updateAll(state);
294 void FullBitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
296 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
297 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
299 void FullBitmapOutputDev::updateLineDash(GfxState *state)
301 rgbdev->updateLineDash(state);
303 void FullBitmapOutputDev::updateFlatness(GfxState *state)
305 rgbdev->updateFlatness(state);
307 void FullBitmapOutputDev::updateLineJoin(GfxState *state)
309 rgbdev->updateLineJoin(state);
311 void FullBitmapOutputDev::updateLineCap(GfxState *state)
313 rgbdev->updateLineCap(state);
315 void FullBitmapOutputDev::updateMiterLimit(GfxState *state)
317 rgbdev->updateMiterLimit(state);
319 void FullBitmapOutputDev::updateLineWidth(GfxState *state)
321 rgbdev->updateLineWidth(state);
323 void FullBitmapOutputDev::updateStrokeAdjust(GfxState *state)
325 rgbdev->updateStrokeAdjust(state);
327 void FullBitmapOutputDev::updateFillColorSpace(GfxState *state)
329 rgbdev->updateFillColorSpace(state);
331 void FullBitmapOutputDev::updateStrokeColorSpace(GfxState *state)
333 rgbdev->updateStrokeColorSpace(state);
335 void FullBitmapOutputDev::updateFillColor(GfxState *state)
337 rgbdev->updateFillColor(state);
339 void FullBitmapOutputDev::updateStrokeColor(GfxState *state)
341 rgbdev->updateStrokeColor(state);
343 void FullBitmapOutputDev::updateBlendMode(GfxState *state)
345 rgbdev->updateBlendMode(state);
347 void FullBitmapOutputDev::updateFillOpacity(GfxState *state)
349 rgbdev->updateFillOpacity(state);
351 void FullBitmapOutputDev::updateStrokeOpacity(GfxState *state)
353 rgbdev->updateStrokeOpacity(state);
355 void FullBitmapOutputDev::updateFillOverprint(GfxState *state)
357 rgbdev->updateFillOverprint(state);
359 void FullBitmapOutputDev::updateStrokeOverprint(GfxState *state)
361 rgbdev->updateStrokeOverprint(state);
363 void FullBitmapOutputDev::updateTransfer(GfxState *state)
365 rgbdev->updateTransfer(state);
367 void FullBitmapOutputDev::updateFont(GfxState *state)
369 rgbdev->updateFont(state);
371 void FullBitmapOutputDev::updateTextMat(GfxState *state)
373 rgbdev->updateTextMat(state);
375 void FullBitmapOutputDev::updateCharSpace(GfxState *state)
377 rgbdev->updateCharSpace(state);
379 void FullBitmapOutputDev::updateRender(GfxState *state)
381 rgbdev->updateRender(state);
383 void FullBitmapOutputDev::updateRise(GfxState *state)
385 rgbdev->updateRise(state);
387 void FullBitmapOutputDev::updateWordSpace(GfxState *state)
389 rgbdev->updateWordSpace(state);
391 void FullBitmapOutputDev::updateHorizScaling(GfxState *state)
393 rgbdev->updateHorizScaling(state);
395 void FullBitmapOutputDev::updateTextPos(GfxState *state)
397 rgbdev->updateTextPos(state);
399 void FullBitmapOutputDev::updateTextShift(GfxState *state, double shift)
401 rgbdev->updateTextShift(state, shift);
404 void FullBitmapOutputDev::stroke(GfxState *state)
406 msg("<debug> stroke");
407 rgbdev->stroke(state);
409 void FullBitmapOutputDev::fill(GfxState *state)
414 void FullBitmapOutputDev::eoFill(GfxState *state)
416 msg("<debug> eoFill");
417 rgbdev->eoFill(state);
419 POPPLER_TILING_PATERN_RETURN FullBitmapOutputDev::tilingPatternFill(GfxState *state, POPPLER_TILING_PATERN_GFX
421 int paintType, Dict *resDict,
422 double *mat, double *bbox,
423 int x0, int y0, int x1, int y1,
424 double xStep, double yStep)
426 msg("<debug> tilingPatternFill");
430 rgbdev->tilingPatternFill(state, POPPLER_TILING_PATERN_GFX_ARG 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, POPPLER_INTERPOLATE
536 msg("<debug> drawImageMask");
537 rgbdev->drawImageMask(state, ref, str, width, height, invert, POPPLER_INTERPOLATE_ARG inlineImg);
539 void FullBitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
540 int width, int height, GfxImageColorMap *colorMap, POPPLER_INTERPOLATE
541 int *maskColors, GBool inlineImg)
543 msg("<debug> drawImage");
544 rgbdev->drawImage(state, ref, str, width, height, colorMap,
545 POPPLER_INTERPOLATE_ARG maskColors, inlineImg);
547 void FullBitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
548 int width, int height,
549 GfxImageColorMap *colorMap, POPPLER_INTERPOLATE
550 Stream *maskStr, int maskWidth, int maskHeight,
551 GBool maskInvert POPPLER_MASK_INTERPOLATE)
553 msg("<debug> drawMaskedImage");
554 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap,
555 POPPLER_INTERPOLATE_ARG maskStr, maskWidth, maskHeight,
556 maskInvert POPPLER_MASK_INTERPOLATE_ARG);
558 void FullBitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
559 int width, int height,
560 GfxImageColorMap *colorMap, POPPLER_INTERPOLATE
561 Stream *maskStr, int maskWidth, int maskHeight,
562 GfxImageColorMap *maskColorMap POPPLER_MASK_INTERPOLATE)
564 msg("<debug> drawSoftMaskedImage");
565 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap,
566 POPPLER_INTERPOLATE_ARG maskStr, maskWidth, maskHeight,
567 maskColorMap POPPLER_MASK_INTERPOLATE_ARG);
569 void FullBitmapOutputDev::drawForm(Ref id)
571 msg("<debug> drawForm");
572 rgbdev->drawForm(id);
575 void FullBitmapOutputDev::processLink(Link *link, Catalog *catalog)
577 msg("<debug> processLink");
578 gfxdev->processLink(link, catalog);
581 void FullBitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
582 GfxColorSpace *blendingColorSpace,
583 GBool isolated, GBool knockout,
586 msg("<debug> beginTransparencyGroup");
587 rgbdev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
589 void FullBitmapOutputDev::endTransparencyGroup(GfxState *state)
591 msg("<debug> endTransparencyGroup");
592 rgbdev->endTransparencyGroup(state);
594 void FullBitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
596 msg("<debug> paintTransparencyGroup");
597 rgbdev->paintTransparencyGroup(state,bbox);
599 void FullBitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
601 msg("<debug> setSoftMask");
602 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
604 void FullBitmapOutputDev::clearSoftMask(GfxState *state)
606 msg("<debug> clearSoftMask");
607 rgbdev->clearSoftMask(state);