From b43d07ef45012438211d2ed4b588e77b73a1994c Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Wed, 27 Jan 2010 17:41:37 -0800 Subject: [PATCH] fixed hairlines around images w/ poly2bitmap --- lib/pdf/BitmapOutputDev.cc | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/pdf/BitmapOutputDev.cc b/lib/pdf/BitmapOutputDev.cc index 32acd80..6eaea6b 100644 --- a/lib/pdf/BitmapOutputDev.cc +++ b/lib/pdf/BitmapOutputDev.cc @@ -159,6 +159,8 @@ void BitmapOutputDev::setPageMap(int*page2page, int num_pages) this->gfxdev->setPageMap(page2page, num_pages); } +void writeBitmap(SplashBitmap*bitmap, char*filename); + void BitmapOutputDev::flushBitmap() { int width = rgbdev->getBitmapWidth(); @@ -168,14 +170,22 @@ void BitmapOutputDev::flushBitmap() msg(" sizeof(SplashColor)!=3"); return; } + + /*static int counter=0; + if(!counter) { + writeBitmap(rgbdev->getBitmap(), "test.png"); + } counter++;*/ SplashColorPtr rgb = rgbbitmap->getDataPtr(); Guchar*alpha = rgbbitmap->getAlphaPtr(); - Guchar*alpha2 = boolpolybitmap->getAlphaPtr(); + + Guchar*alpha2 = boolpolybitmap->getDataPtr(); + int width8 = (boolpolybitmap->getWidth()+7)/8; ibbox_t* boxes = get_bitmap_bboxes((unsigned char*)alpha, width, height); ibbox_t*b; + for(b=boxes;b;b=b->next) { int xmin = b->xmin; int ymin = b->ymin; @@ -204,7 +214,7 @@ void BitmapOutputDev::flushBitmap() SplashColorPtr in=&rgb[((y+ymin)*width+xmin)*sizeof(SplashColor)]; gfxcolor_t*out = &img->data[y*rangex]; Guchar*ain = &alpha[(y+ymin)*width+xmin]; - Guchar*ain2 = &alpha2[(y+ymin)*width+xmin]; + Guchar*ain2 = &alpha2[(y+ymin)*width8]; if(this->emptypage) { for(x=0;x>(x&7)))) { + /* cut away pixels that we don't remember drawing (i.e., that are + not in the monochrome bitmap. Prevents some "hairlines" showing + up to the left and right of bitmaps */ out[x].r = 0;out[x].g = 0;out[x].b = 0;out[x].a = 0; - } else */ - - /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we - have to premultiply alpha (mix background and pixel according to the alpha channel). - */ - out[x].r = (in[x*3+0]*ain[x])/255; - out[x].g = (in[x*3+1]*ain[x])/255; - out[x].b = (in[x*3+2]*ain[x])/255; - out[x].a = ain[x]; + } else { + /* according to endPage()/compositeBackground() in xpdf/SplashOutputDev.cc, we + have to premultiply alpha (mix background and pixel according to the alpha channel). + */ + out[x].r = (in[x*3+0]*ain[x])/255; + out[x].g = (in[x*3+1]*ain[x])/255; + out[x].b = (in[x*3+2]*ain[x])/255; + out[x].a = ain[x]; + } } } } -- 1.7.10.4