? mkinstalldirs Index: glib/test-poppler-glib.c =================================================================== RCS file: /cvs/poppler/poppler/glib/test-poppler-glib.c,v retrieving revision 1.33 diff -u -r1.33 test-poppler-glib.c --- glib/test-poppler-glib.c 27 Jul 2007 09:17:40 -0000 1.33 +++ glib/test-poppler-glib.c 29 Jul 2007 20:59:19 -0000 @@ -1,6 +1,7 @@ #include #include #include +#include #include "poppler.h" #define FAIL(msg) \ Index: poppler/CairoOutputDev.cc =================================================================== RCS file: /cvs/poppler/poppler/poppler/CairoOutputDev.cc,v retrieving revision 1.49 diff -u -r1.49 CairoOutputDev.cc --- poppler/CairoOutputDev.cc 21 May 2007 21:35:10 -0000 1.49 +++ poppler/CairoOutputDev.cc 29 Jul 2007 20:59:20 -0000 @@ -497,6 +497,14 @@ double llx, double lly, double urx, double ury) { } + +static inline void printMatrix(cairo_matrix_t *matrix){ + printf("%f %f, %f %f (%f %f)\n", matrix->xx, matrix->yx, + matrix->xy, matrix->yy, + matrix->x0, matrix->y0); +} + + void CairoOutputDev::endTextObject(GfxState *state) { if (textClipPath) { // clip the accumulated text path @@ -508,6 +516,187 @@ } +cairo_pattern_t *group; +cairo_pattern_t *mask; +struct ColorSpaceStack { + GfxColorSpace *cs; + struct ColorSpaceStack *next; +} * groupColorSpaceStack = NULL; +void CairoOutputDev::beginTransparencyGroup(GfxState * /*state*/, double * /*bbox*/, + GfxColorSpace * blendingColorSpace, + GBool /*isolated*/, GBool /*knockout*/, + GBool forSoftMask) { + printf("push group\n"); + + /* push color space */ + ColorSpaceStack* css = new ColorSpaceStack; + css->cs = blendingColorSpace; + css->next = groupColorSpaceStack; + groupColorSpaceStack = css; + + if (0 && forSoftMask) + cairo_push_group_with_content (cairo, CAIRO_CONTENT_ALPHA); + else + cairo_push_group (cairo); +} +void CairoOutputDev::endTransparencyGroup(GfxState * /*state*/) { + printf("pop group\n"); + group = cairo_pop_group (cairo); +} +void CairoOutputDev::paintTransparencyGroup(GfxState * /*state*/, double * /*bbox*/) { + cairo_set_source (cairo, group); + if (!mask) { + printf("paint group: %g\n", fill_opacity); + static int count; + //if (count++) + cairo_paint_with_alpha (cairo, fill_opacity); + } else { + printf("paint group w/ mask %x\n", mask); + //cairo_set_source_rgb(cairo, 1.0, 0, 0); + cairo_matrix_t mat; + cairo_get_matrix(cairo, &mat); + printMatrix(&mat); + cairo_pattern_get_matrix(group, &mat); + printMatrix(&mat); + int paint_the_mask = 0; + if (paint_the_mask) { + cairo_set_source (cairo, mask); + cairo_paint(cairo); + } else { + cairo_mask(cairo, mask); + } + mask = NULL; + } + + /* pop color space */ + ColorSpaceStack *css = groupColorSpaceStack; + groupColorSpaceStack = css->next; + delete css; +} +typedef unsigned int uint32_t; +static uint32_t luminocity(uint32_t x) +{ + int a = (x >> 24) & 0xff; + int r = (x >> 16) & 0xff; + int g = (x >> 8) & 0xff; + int b = (x >> 0) & 0xff; + int y = 0.3 * r + 0.59 * g + 0.11 * b; + return y << 24; +} + + +void CairoOutputDev::setSoftMask(GfxState * state, double * bbox, GBool alpha, + Function * transferFunc, GfxColor * backdropColor) { + printf("set soft mask\n"); + //XXX we don't proplery deal with luminocity (e.g. alpha = false) masks + if (alpha == false) { + //XXX: we can do the computation in the ARGB32 buffer to avoid having to have two of them + double x1, y1, x2, y2; + cairo_clip_extents(cairo, &x1, &y1, &x2, &y2); + int width = ceil(x2) - floor(x1); + int height = ceil(y2) - floor(y1); + + //XXX: hopefully this uses the correct color space */ + GfxRGB backdropColorRGB; + groupColorSpaceStack->cs->getRGB(backdropColor, &backdropColorRGB); + + cairo_surface_t *source = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + cairo_t *maskCtx = cairo_create(source); + /* paint the backdrop */ + cairo_set_source_rgb(maskCtx, backdropColorRGB.r / 65535.0, + backdropColorRGB.g / 65535.0, + backdropColorRGB.b / 65535.0); + //cairo_paint(maskCtx); + + /* paint the group */ + printf("mask paint %x\n", group); + cairo_matrix_t mat; + cairo_get_matrix(cairo, &mat); + cairo_set_matrix(maskCtx, &mat); +#if 0 + cairo_set_source(maskCtx, group); + cairo_paint(maskCtx); +#endif + cairo_get_matrix(maskCtx, &mat); + printMatrix(&mat); + printf("convert to alpha\n"); + cairo_surface_t *pats; +#if 0 + cairo_pattern_get_matrix(group, &mat); + printMatrix(&mat); +#endif + cairo_pattern_get_surface(group, &pats); +#if 0 + printf("w h %d %d\n", width, height); + width = cairo_image_surface_get_width(pats); + height = cairo_image_surface_get_height(pats); + printf("w h %d %d\n", width, height); +#endif + /* get stride in units of 32 bits */ + + //cairo_matrix_t i; + //cairo_matrix_init_identity(&i); + //cairo_pattern_set_matrix(group, &i); + //cairo_set_matrix(maskCtx, &i); + + //cairo_set_source_rgb(maskCtx, 1,1,1); + //cairo_paint(maskCtx); + + //cairo_set_source(maskCtx, group); + //cairo_surface_set_device_offset(pats, 0, 0); + double x_offset, y_offset; + cairo_surface_get_device_offset(pats, &x_offset, &y_offset); + cairo_surface_set_device_offset(source, x_offset, y_offset); + //cairo_set_source_surface(maskCtx, pats, 0, 0); + cairo_set_source(maskCtx, group); + cairo_paint(maskCtx); + + uint32_t *source_data = (uint32_t*)cairo_image_surface_get_data(source); + //uint32_t *source_data = (uint32_t*)cairo_image_surface_get_data(pats); + /* get stride in units of 32 bits */ + int stride = cairo_image_surface_get_stride(source)/4; + for (int y=0; y %x\n",x,y, source_data[y*stride + x], luminocity(source_data[y*stride + x])); +#endif + source_data[y*stride + x] = luminocity(source_data[y*stride + x]); + //source_data[y*stride + x] = 0xff000000; + +#if 0 + here is how splash deals with the transferfunction + if (transferFunc) { + transferFunc->transform(&lum, &lum2); + } else { + lum2 = lum; + } + p[x] = (int)(lum2 * 255.0 + 0.5); +#endif + + } + } + mask = cairo_pattern_create_for_surface(source); + cairo_matrix_t patMatrix; + cairo_pattern_get_matrix(group, &patMatrix); + cairo_pattern_set_matrix(mask, &patMatrix); + //mask = group; + //cairo_surface_destroy(source); + } else { + //cairo_set_source (cairo, group); + mask = group; + } +#if 0 + // this looks obsolete + //cairo_paint (cairo); +#endif +} + +void CairoOutputDev::clearSoftMask(GfxState * /*state*/) { + printf("clear soft mask\n"); + //mask = NULL; +} void CairoOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, Index: poppler/CairoOutputDev.h =================================================================== RCS file: /cvs/poppler/poppler/poppler/CairoOutputDev.h,v retrieving revision 1.18 diff -u -r1.18 CairoOutputDev.h --- poppler/CairoOutputDev.h 21 May 2007 21:35:10 -0000 1.18 +++ poppler/CairoOutputDev.h 29 Jul 2007 20:59:20 -0000 @@ -158,10 +158,21 @@ GBool maskInvert); + //----- transparency groups and soft masks + virtual void beginTransparencyGroup(GfxState * /*state*/, double * /*bbox*/, + GfxColorSpace * /*blendingColorSpace*/, + GBool /*isolated*/, GBool /*knockout*/, + GBool /*forSoftMask*/); + virtual void endTransparencyGroup(GfxState * /*state*/); + virtual void paintTransparencyGroup(GfxState * /*state*/, double * /*bbox*/); + virtual void setSoftMask(GfxState * /*state*/, double * /*bbox*/, GBool /*alpha*/, + Function * /*transferFunc*/, GfxColor * /*backdropColor*/); + virtual void clearSoftMask(GfxState * /*state*/); + //----- Type 3 font operators virtual void type3D0(GfxState *state, double wx, double wy); virtual void type3D1(GfxState *state, double wx, double wy, - double llx, double lly, double urx, double ury); + double llx, double lly, double urx, double ury); //----- special access