/*! * \brief Draw an image to Dia's _Image * \todo use maskColors to have some alpha support */ void DiaOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool interpolate, int *maskColors, GBool inlineImg) { DiaObject *obj; GdkPixbuf *pixbuf; Point pos; ObjectChange *change; double *ctm = state->getCTM(); pos.x = ctm[4] * scale; // there is some undocumented magic done with the ctm for drawImage // deduced from SplashOutputDev::drawImage() // cmt[2] and ctm[3] being negative - use that for y postion // ctm[0] and ctm[3] have width and height in device coordinates pos.y = (ctm[5] + ctm[3]) * scale; pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, maskColors ? TRUE : FALSE, 8, width, height); { // 3 channels, 8 bit ImageStream imgStr(str, width, colorMap->getNumPixelComps(), colorMap->getBits()); Guchar *line; int rowstride = gdk_pixbuf_get_rowstride (pixbuf); guchar *pixels = gdk_pixbuf_get_pixels (pixbuf); int y; imgStr.reset(); // otherwise getLine() is crashing right away line = imgStr.getLine (); for (y = 0; y < height && line; ++y) { guchar *dest = pixels + y * rowstride; colorMap->getRGBLine (line, dest, width); // ToDo: respect maskColors line = imgStr.getLine (); } } obj = create_standard_image (pos.x, pos.y, ctm[0] * scale, ctm[3] * scale, NULL); if ((change = dia_object_set_pixbuf (obj, pixbuf)) != NULL) change->free (change); /* reference transfered */ else g_object_unref (pixbuf); addObject (obj); }
/*! * \brief Draw an image to Dia's _Image * \todo use maskColors to have some alpha support */ void DiaOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, GBool interpolate, int *maskColors, GBool inlineImg) { DiaObject *obj; GdkPixbuf *pixbuf; Point pos; ObjectChange *change; double *ctm = state->getCTM(); pos.x = ctm[4] * scale; // there is some undocumented magic done with the ctm for drawImage // deduced from SplashOutputDev::drawImage() // cmt[2] and ctm[3] being negative - use that for y postion // ctm[0] and ctm[3] have width and height in device coordinates pos.y = (ctm[5] + ctm[3]) * scale; #ifdef USE_IMAGE_CACHE /* bogus: neither 'ref' nor 'str' work as unique key */ // rather than creating the image over and over again we try to cache them // via the given 'stream' object if ((pixbuf = static_cast<GdkPixbuf*>(g_hash_table_lookup (this->image_cache, str))) != NULL) { g_object_ref (pixbuf); } else { #endif pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, maskColors ? TRUE : FALSE, 8, width, height); { // 3 channels, 8 bit ImageStream imgStr(str, width, colorMap->getNumPixelComps(), colorMap->getBits()); Guchar *line; int rowstride = gdk_pixbuf_get_rowstride (pixbuf); guchar *pixels = gdk_pixbuf_get_pixels (pixbuf); int y; imgStr.reset(); // otherwise getLine() is crashing right away line = imgStr.getLine (); for (y = 0; y < height && line; ++y) { guchar *dest = pixels + y * rowstride; colorMap->getRGBLine (line, dest, width); if (maskColors) { for (int x = 0; x < width; x++) { bool is_opaque = false; for (int i = 0; i < colorMap->getNumPixelComps(); ++i) { if (line[i] < maskColors[2*i] || line[i] > maskColors[2*i+1]) { is_opaque = true; break; } } if (is_opaque) *dest |= 0xff000000; else *dest = 0; dest++; line += colorMap->getNumPixelComps(); } } line = imgStr.getLine (); } } #ifdef USE_IMAGE_CACHE // insert the new image into our cache g_hash_table_insert (this->image_cache, str, g_object_ref (pixbuf)); } #endif obj = create_standard_image (pos.x, pos.y, ctm[0] * scale, ctm[3] * scale, NULL); if ((change = dia_object_set_pixbuf (obj, pixbuf)) != NULL) { change->free (change); g_free (change); } g_object_unref (pixbuf); addObject (obj); }