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 void FullBitmapOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2)
199 state->transform(crop_x1,crop_y1,&x1,&y1);
200 state->transform(crop_x2,crop_y2,&x2,&y2);
201 if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
202 if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
204 this->movex = -(int)x1 - user_movex;
205 this->movey = -(int)y1 - user_movey;
207 if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
213 this->width = (int)(x2-x1);
214 this->height = (int)(y2-y1);
216 msg("<debug> startPage");
217 rgbdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
218 gfxdev->startPage(pageNum, state, crop_x1, crop_y1, crop_x2, crop_y2);
221 void FullBitmapOutputDev::endPage()
223 msg("<verbose> endPage (FullBitmapOutputDev)");
228 GBool FullBitmapOutputDev::upsideDown()
230 return rgbdev->upsideDown();
232 GBool FullBitmapOutputDev::useDrawChar()
234 return rgbdev->useDrawChar();
236 GBool FullBitmapOutputDev::useTilingPatternFill()
238 return rgbdev->useTilingPatternFill();
240 GBool FullBitmapOutputDev::useShadedFills()
242 return rgbdev->useShadedFills();
244 GBool FullBitmapOutputDev::useDrawForm()
246 return rgbdev->useDrawForm();
248 GBool FullBitmapOutputDev::interpretType3Chars()
250 return rgbdev->interpretType3Chars();
252 GBool FullBitmapOutputDev::needNonText()
254 return rgbdev->needNonText();
256 void FullBitmapOutputDev::setDefaultCTM(double *ctm)
258 rgbdev->setDefaultCTM(ctm);
259 gfxdev->setDefaultCTM(ctm);
261 void FullBitmapOutputDev::saveState(GfxState *state)
263 rgbdev->saveState(state);
265 void FullBitmapOutputDev::restoreState(GfxState *state)
267 rgbdev->restoreState(state);
269 void FullBitmapOutputDev::updateAll(GfxState *state)
271 rgbdev->updateAll(state);
273 void FullBitmapOutputDev::updateCTM(GfxState *state, double m11, double m12, double m21, double m22, double m31, double m32)
275 rgbdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
276 gfxdev->updateCTM(state,m11,m12,m21,m22,m31,m32);
278 void FullBitmapOutputDev::updateLineDash(GfxState *state)
280 rgbdev->updateLineDash(state);
282 void FullBitmapOutputDev::updateFlatness(GfxState *state)
284 rgbdev->updateFlatness(state);
286 void FullBitmapOutputDev::updateLineJoin(GfxState *state)
288 rgbdev->updateLineJoin(state);
290 void FullBitmapOutputDev::updateLineCap(GfxState *state)
292 rgbdev->updateLineCap(state);
294 void FullBitmapOutputDev::updateMiterLimit(GfxState *state)
296 rgbdev->updateMiterLimit(state);
298 void FullBitmapOutputDev::updateLineWidth(GfxState *state)
300 rgbdev->updateLineWidth(state);
302 void FullBitmapOutputDev::updateStrokeAdjust(GfxState *state)
304 rgbdev->updateStrokeAdjust(state);
306 void FullBitmapOutputDev::updateFillColorSpace(GfxState *state)
308 rgbdev->updateFillColorSpace(state);
310 void FullBitmapOutputDev::updateStrokeColorSpace(GfxState *state)
312 rgbdev->updateStrokeColorSpace(state);
314 void FullBitmapOutputDev::updateFillColor(GfxState *state)
316 rgbdev->updateFillColor(state);
318 void FullBitmapOutputDev::updateStrokeColor(GfxState *state)
320 rgbdev->updateStrokeColor(state);
322 void FullBitmapOutputDev::updateBlendMode(GfxState *state)
324 rgbdev->updateBlendMode(state);
326 void FullBitmapOutputDev::updateFillOpacity(GfxState *state)
328 rgbdev->updateFillOpacity(state);
330 void FullBitmapOutputDev::updateStrokeOpacity(GfxState *state)
332 rgbdev->updateStrokeOpacity(state);
334 void FullBitmapOutputDev::updateFillOverprint(GfxState *state)
336 rgbdev->updateFillOverprint(state);
338 void FullBitmapOutputDev::updateStrokeOverprint(GfxState *state)
340 rgbdev->updateStrokeOverprint(state);
342 void FullBitmapOutputDev::updateTransfer(GfxState *state)
344 rgbdev->updateTransfer(state);
346 void FullBitmapOutputDev::updateFont(GfxState *state)
348 rgbdev->updateFont(state);
350 void FullBitmapOutputDev::updateTextMat(GfxState *state)
352 rgbdev->updateTextMat(state);
354 void FullBitmapOutputDev::updateCharSpace(GfxState *state)
356 rgbdev->updateCharSpace(state);
358 void FullBitmapOutputDev::updateRender(GfxState *state)
360 rgbdev->updateRender(state);
362 void FullBitmapOutputDev::updateRise(GfxState *state)
364 rgbdev->updateRise(state);
366 void FullBitmapOutputDev::updateWordSpace(GfxState *state)
368 rgbdev->updateWordSpace(state);
370 void FullBitmapOutputDev::updateHorizScaling(GfxState *state)
372 rgbdev->updateHorizScaling(state);
374 void FullBitmapOutputDev::updateTextPos(GfxState *state)
376 rgbdev->updateTextPos(state);
378 void FullBitmapOutputDev::updateTextShift(GfxState *state, double shift)
380 rgbdev->updateTextShift(state, shift);
383 void FullBitmapOutputDev::stroke(GfxState *state)
385 msg("<debug> stroke");
386 rgbdev->stroke(state);
388 void FullBitmapOutputDev::fill(GfxState *state)
393 void FullBitmapOutputDev::eoFill(GfxState *state)
395 msg("<debug> eoFill");
396 rgbdev->eoFill(state);
398 #if (xpdfMajorVersion*10000 + xpdfMinorVersion*100 + xpdfUpdateVersion) < 30207
399 void FullBitmapOutputDev::tilingPatternFill(GfxState *state, Object *str,
400 int paintType, Dict *resDict,
401 double *mat, double *bbox,
402 int x0, int y0, int x1, int y1,
403 double xStep, double yStep)
405 msg("<debug> tilingPatternFill");
406 rgbdev->tilingPatternFill(state, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
409 void FullBitmapOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Object *str,
410 int paintType, Dict *resDict,
411 double *mat, double *bbox,
412 int x0, int y0, int x1, int y1,
413 double xStep, double yStep)
415 msg("<debug> tilingPatternFill");
416 rgbdev->tilingPatternFill(state, gfx, str, paintType, resDict, mat, bbox, x0, y0, x1, y1, xStep, yStep);
420 GBool FullBitmapOutputDev::functionShadedFill(GfxState *state, GfxFunctionShading *shading)
422 msg("<debug> functionShadedFill");
423 return rgbdev->functionShadedFill(state, shading);
425 GBool FullBitmapOutputDev::axialShadedFill(GfxState *state, GfxAxialShading *shading)
427 msg("<debug> axialShadedFill");
428 return rgbdev->axialShadedFill(state, shading);
430 GBool FullBitmapOutputDev::radialShadedFill(GfxState *state, GfxRadialShading *shading)
432 msg("<debug> radialShadedFill");
433 return rgbdev->radialShadedFill(state, shading);
436 void FullBitmapOutputDev::clip(GfxState *state)
441 void FullBitmapOutputDev::eoClip(GfxState *state)
443 msg("<debug> eoClip");
444 rgbdev->eoClip(state);
446 void FullBitmapOutputDev::clipToStrokePath(GfxState *state)
448 msg("<debug> clipToStrokePath");
449 rgbdev->clipToStrokePath(state);
452 void FullBitmapOutputDev::beginStringOp(GfxState *state)
454 msg("<debug> beginStringOp");
455 rgbdev->beginStringOp(state);
457 void FullBitmapOutputDev::endStringOp(GfxState *state)
459 msg("<debug> endStringOp");
460 rgbdev->endStringOp(state);
462 void FullBitmapOutputDev::beginString(GfxState *state, GString *s)
464 msg("<debug> beginString");
465 rgbdev->beginString(state, s);
467 void FullBitmapOutputDev::endString(GfxState *state)
469 msg("<debug> endString");
470 rgbdev->endString(state);
472 void FullBitmapOutputDev::drawChar(GfxState *state, double x, double y,
473 double dx, double dy,
474 double originX, double originY,
475 CharCode code, int nBytes, Unicode *u, int uLen)
477 msg("<debug> drawChar");
478 rgbdev->drawChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
480 void FullBitmapOutputDev::drawString(GfxState *state, GString *s)
482 msg("<error> internal error: drawString not implemented");
483 rgbdev->drawString(state, s);
485 void FullBitmapOutputDev::endTextObject(GfxState *state)
487 /* FIXME: the below might render things (stroke outlines etc.) to gfxdev which
488 might end up unflushed- should be handled similarily as
491 msg("<debug> endTextObject");
492 rgbdev->endTextObject(state);
495 /* TODO: these four operations below *should* do nothing, as type3
496 chars are drawn using operations like fill() */
497 GBool FullBitmapOutputDev::beginType3Char(GfxState *state, double x, double y,
498 double dx, double dy,
499 CharCode code, Unicode *u, int uLen)
501 msg("<debug> beginType3Char");
502 return rgbdev->beginType3Char(state, x, y, dx, dy, code, u, uLen);
504 void FullBitmapOutputDev::type3D0(GfxState *state, double wx, double wy)
506 msg("<debug> type3D0");
507 rgbdev->type3D0(state, wx, wy);
509 void FullBitmapOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
511 msg("<debug> type3D1");
512 rgbdev->type3D1(state, wx, wy, llx, lly, urx, ury);
514 void FullBitmapOutputDev::endType3Char(GfxState *state)
516 msg("<debug> endType3Char");
517 rgbdev->endType3Char(state);
519 void FullBitmapOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
520 int width, int height, GBool invert,
523 msg("<debug> drawImageMask");
524 rgbdev->drawImageMask(state, ref, str, width, height, invert, inlineImg);
526 void FullBitmapOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
527 int width, int height, GfxImageColorMap *colorMap,
528 int *maskColors, GBool inlineImg)
530 msg("<debug> drawImage");
531 rgbdev->drawImage(state, ref, str, width, height, colorMap, maskColors, inlineImg);
533 void FullBitmapOutputDev::drawMaskedImage(GfxState *state, Object *ref, Stream *str,
534 int width, int height,
535 GfxImageColorMap *colorMap,
536 Stream *maskStr, int maskWidth, int maskHeight,
539 msg("<debug> drawMaskedImage");
540 rgbdev->drawMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert);
542 void FullBitmapOutputDev::drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
543 int width, int height,
544 GfxImageColorMap *colorMap,
546 int maskWidth, int maskHeight,
547 GfxImageColorMap *maskColorMap)
549 msg("<debug> drawSoftMaskedImage");
550 rgbdev->drawSoftMaskedImage(state, ref, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap);
552 void FullBitmapOutputDev::drawForm(Ref id)
554 msg("<debug> drawForm");
555 rgbdev->drawForm(id);
558 void FullBitmapOutputDev::processLink(Link *link, Catalog *catalog)
560 msg("<debug> processLink");
561 gfxdev->processLink(link, catalog);
564 void FullBitmapOutputDev::beginTransparencyGroup(GfxState *state, double *bbox,
565 GfxColorSpace *blendingColorSpace,
566 GBool isolated, GBool knockout,
569 msg("<debug> beginTransparencyGroup");
570 rgbdev->beginTransparencyGroup(state, bbox, blendingColorSpace, isolated, knockout, forSoftMask);
572 void FullBitmapOutputDev::endTransparencyGroup(GfxState *state)
574 msg("<debug> endTransparencyGroup");
575 rgbdev->endTransparencyGroup(state);
577 void FullBitmapOutputDev::paintTransparencyGroup(GfxState *state, double *bbox)
579 msg("<debug> paintTransparencyGroup");
580 rgbdev->paintTransparencyGroup(state,bbox);
582 void FullBitmapOutputDev::setSoftMask(GfxState *state, double *bbox, GBool alpha, Function *transferFunc, GfxColor *backdropColor)
584 msg("<debug> setSoftMask");
585 rgbdev->setSoftMask(state, bbox, alpha, transferFunc, backdropColor);
587 void FullBitmapOutputDev::clearSoftMask(GfxState *state)
589 msg("<debug> clearSoftMask");
590 rgbdev->clearSoftMask(state);