+void BitmapOutputDev::checkNewBitmap()
+{
+ /* similar to checkNewText() above, only in reverse */
+ msg("<trace> Testing new graphics data against current text data, state=%s, counter=%d\n", STATE_NAME[layerstate], dbg_btm_counter);
+
+ char filename1[80];
+ char filename2[80];
+ sprintf(filename1, "state%dbitmap_afternewgfx.png", dbg_btm_counter);
+ sprintf(filename2, "state%dtext_afternewgfx.png", dbg_btm_counter);
+ if(0) {
+ writeAlpha(boolpolybitmap, filename1);
+ writeAlpha(booltextbitmap, filename2);
+ }
+ dbg_btm_counter++;
+
+ if(intersection()) {
+ if(layerstate==STATE_PARALLEL) {
+ msg("<verbose> Bitmap is above current text data");
+ layerstate=STATE_BITMAP_IS_ABOVE;
+ clearBoolTextDev();
+ } else if(layerstate==STATE_TEXT_IS_ABOVE) {
+ msg("<verbose> Bitmap is above current text data (which is above some bitmap)");
+ flushBitmap();
+ layerstate=STATE_BITMAP_IS_ABOVE;
+ clearBoolTextDev();
+ clearBoolPolyDev();
+ } else {
+ msg("<verbose> Bitmap is still above current text data");
+ clearBoolTextDev();
+ }
+ }
+}
+
+//void checkNewText() {
+// Guchar*alpha = rgbbitmap->getAlphaPtr();
+// Guchar*charpixels = clip1bitmap->getDataPtr();
+// int xx,yy;
+// for(yy=0;yy<height;yy++) {
+// Guchar*aline = &alpha[yy*width];
+// Guchar*cline = &charpixels[yy*width8];
+// for(xx=0;xx<width;xx++) {
+// int bit = xx&7;
+// int bytepos = xx>>3;
+// /* TODO: is the bit order correct? */
+// if(aline[xx] && (cline[bytepos]&(1<<bit)))
+// break;
+// }
+// if(xx!=width)
+// break;
+//}
+
+GBool BitmapOutputDev::clip0and1differ()
+{
+ if(clip0bitmap->getMode()==splashModeMono1) {
+ SplashBitmap*clip0 = clip0bitmap;
+ SplashBitmap*clip1 = clip1bitmap;
+ int width8 = (clip0->getWidth()+7)/8;
+ int height = clip0->getHeight();
+ return memcmp(clip0->getDataPtr(), clip1->getDataPtr(), width8*height);
+ } else {
+ SplashBitmap*clip0 = clip0bitmap;
+ SplashBitmap*clip1 = clip1bitmap;
+ int width = clip0->getAlphaRowSize();
+ int height = clip0->getHeight();
+ return memcmp(clip0->getAlphaPtr(), clip1->getAlphaPtr(), width*height);
+ }
+}
+
+static void clearBooleanBitmap(SplashBitmap*btm)
+{
+ if(btm->getMode()==splashModeMono1) {
+ int width8 = (btm->getWidth()+7)/8;
+ int width = btm->getWidth();
+ int height = btm->getHeight();
+ memset(btm->getDataPtr(), 0, width8*height);
+ } else {
+ int width = btm->getAlphaRowSize();
+ int height = btm->getHeight();
+ memset(btm->getAlphaPtr(), 0, width*height);
+ }
+}
+
+GBool BitmapOutputDev::intersection()
+{
+ SplashBitmap*boolpoly = boolpolybitmap;
+ SplashBitmap*booltext = booltextbitmap;
+
+ if(boolpoly->getMode()==splashModeMono1) {
+ /* alternative implementation, using one bit per pixel-
+ would work if xpdf wouldn't try to dither everything */
+
+ Guchar*polypixels = boolpoly->getDataPtr();
+ Guchar*textpixels = booltext->getDataPtr();
+
+ int width8 = (width+7)/8;
+ int height = boolpoly->getHeight();
+
+ int t;
+ int len = height*width8;
+ unsigned int c=0;
+ if(len & (sizeof(unsigned int)-1)) {
+ Guchar c2=0;
+ for(t=0;t<len;t++) {
+ c2 |= polypixels[t]&textpixels[t];
+ }
+ c = c2;
+ } else {
+ len /= sizeof(unsigned int);
+ for(t=0;t<len;t++) {
+ c |= (((unsigned int*)polypixels)[t]) & (((unsigned int*)textpixels)[t]);
+ }
+ }
+ if(c)
+ /* if graphic data and the characters overlap, they have common bits */
+ return gTrue;
+ else
+ return gFalse;
+ } else {
+ Guchar*polypixels = boolpoly->getAlphaPtr();
+ Guchar*textpixels = booltext->getAlphaPtr();
+
+ int width = boolpoly->getAlphaRowSize();
+ int height = boolpoly->getHeight();
+
+ int t;
+ int len = height*width;
+ unsigned int c=0;
+ if(len & (sizeof(unsigned int)-1)) {
+ Guchar c2=0;
+ for(t=0;t<len;t++) {
+ if(polypixels[t]&&textpixels[t])
+ return gTrue;
+ }
+ } else {
+ len /= sizeof(unsigned int);
+ for(t=0;t<len;t++) {
+ if((((unsigned int*)polypixels)[t]) & (((unsigned int*)textpixels)[t]))
+ return gTrue;
+ }
+ }
+ return gFalse;
+ }
+}
+
+