BitmapPtr SVG::internalRenderElement(const SVGElementPtr& pElement, const glm::vec2& renderSize, const glm::vec2& size) { glm::vec2 pos = pElement->getPos(); glm::vec2 scale(renderSize.x/size.x, renderSize.y/size.y); IntPoint boundingBox = IntPoint(renderSize) + IntPoint(int(scale.x+0.5), int(scale.y+0.5)); BitmapPtr pBmp(new Bitmap(boundingBox, B8G8R8A8)); FilterFill<Pixel32>(Pixel32(0,0,0,0)).applyInPlace(pBmp); cairo_surface_t* pSurface; cairo_t* pCairo; pSurface = cairo_image_surface_create_for_data(pBmp->getPixels(), CAIRO_FORMAT_ARGB32, boundingBox.x, boundingBox.y, pBmp->getStride()); pCairo = cairo_create(pSurface); cairo_scale(pCairo, scale.x, scale.y); cairo_translate(pCairo, -pos.x, -pos.y); rsvg_handle_render_cairo_sub(m_pRSVG, pCairo, pElement->getUnescapedID().c_str()); FilterUnmultiplyAlpha().applyInPlace(pBmp); cairo_surface_destroy(pSurface); cairo_destroy(pCairo); if (!BitmapLoader::get()->isBlueFirst()) { FilterFlipRGB().applyInPlace(pBmp); } return pBmp; }
BitmapPtr OffscreenCanvas::screenshot(bool bIgnoreAlpha) const { if (!isRunning() || !m_bIsRendered) { throw(Exception(AVG_ERR_UNSUPPORTED, "OffscreenCanvas::screenshot(): Canvas has not been rendered. No screenshot available")); } BitmapPtr pBmp = m_pFBO->getImage(0); if (bIgnoreAlpha) { pBmp->setPixelFormat(B8G8R8X8); } else { FilterUnmultiplyAlpha().applyInPlace(pBmp); } return pBmp; }