bool GraphicsContext3D::ImageExtractor::extractImage(bool premultiplyAlpha, bool)
{
    if (!m_image)
        return false;

    NativeImagePtr nativeImage = m_image->nativeImageForCurrentFrame();
    if (!nativeImage)
        return false;

    m_imageWidth = nativeImage->width();
    m_imageHeight = nativeImage->height();
    if (!m_imageWidth || !m_imageHeight)
        return false;

    unsigned imageSize = m_imageWidth * m_imageHeight;
    m_imageData.resize(imageSize);
    if (!nativeImage->readPixels(m_imageData.data(), imageSize))
        return false;

    // Raw image data is premultiplied
    m_alphaOp = AlphaDoNothing;
    if (!premultiplyAlpha)
        m_alphaOp = AlphaDoUnmultiply;

    m_imagePixelData = m_imageData.data();
    m_imageSourceFormat = DataFormatBGRA8;
    m_imageSourceUnpackAlignment = 0;

    return true;
}
Exemplo n.º 2
0
void Pasteboard::writeImage(Node* node, const KURL&, const String& title)
{
    ASSERT(node);

    if (!(node->renderer() && node->renderer()->isImage()))
        return;

    RenderImage* renderer = toRenderImage(node->renderer());
    CachedImage* cachedImage = renderer->cachedImage();
    if (!cachedImage || cachedImage->errorOccurred())
        return;
    Image* image = cachedImage->imageForRenderer(renderer);
    ASSERT(image);

    NativeImagePtr bitmap = image->nativeImageForCurrentFrame();
    if (!bitmap)
        return;

    // If the image is wrapped in a link, |url| points to the target of the
    // link.  This isn't useful to us, so get the actual image URL.
    AtomicString urlString;
    if (node->hasTagName(HTMLNames::imgTag) || node->hasTagName(HTMLNames::inputTag))
        urlString = static_cast<Element*>(node)->getAttribute(HTMLNames::srcAttr);
#if ENABLE(SVG)
    else if (node->hasTagName(SVGNames::imageTag))
        urlString = static_cast<Element*>(node)->getAttribute(XLinkNames::hrefAttr);
#endif
    else if (node->hasTagName(HTMLNames::embedTag) || node->hasTagName(HTMLNames::objectTag)) {
        Element* element = static_cast<Element*>(node);
        urlString = element->getAttribute(element->imageSourceAttributeName());
    }
    KURL url = urlString.isEmpty() ? KURL() : node->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(urlString));
    WebKit::WebImage webImage = bitmap->bitmap();
    WebKit::Platform::current()->clipboard()->writeImage(webImage, WebKit::WebURL(url), WebKit::WebString(title));
}
NativeFrameBufferTexture::NativeFrameBufferTexture( NativeImagePtr nativeImage, Context& context)
  : FrameBufferTexture(nativeImage->GetWidth(),
                       nativeImage->GetHeight(),
                       nativeImage->GetPixelFormat(),
                       context),
    mNativeImage(nativeImage)
{
  DALI_LOG_INFO( Debug::Filter::gImage, Debug::General, "NativeFrameBufferTexture created 0x%x\n", &nativeImage );
}
Exemplo n.º 4
0
WebImage& WebImage::operator=(const PassRefPtr<Image>& image)
{
    NativeImagePtr p;
    if (image.get() && (p = image->nativeImageForCurrentFrame()))
        assign(p->bitmap());
    else
        reset();
    return *this;
}
Exemplo n.º 5
0
Color nativeImageSinglePixelSolidColor(const NativeImagePtr& image)
{
    if (!image || nativeImageSize(image) != IntSize(1, 1))
        return Color();

    if (cairo_surface_get_type(image.get()) != CAIRO_SURFACE_TYPE_IMAGE)
        return Color();

    RGBA32* pixel = reinterpret_cast_ptr<RGBA32*>(cairo_image_surface_get_data(image.get()));
    return colorFromPremultipliedARGB(*pixel);
}
Exemplo n.º 6
0
DragImageRef createDragImageFromImage(Image* image)
{
    if (!image || !image->nativeImageForCurrentFrame())
        return 0;

#if USE(WRATH)
    NativeImagePtr nativeImage = image->nativeImageForCurrentFrame();
    return new QPixmap(*nativeImage->getPixmap());
#else
    return new QPixmap(*image->nativeImageForCurrentFrame());
#endif
}
Exemplo n.º 7
0
void drawNativeImage(const NativeImagePtr& image, GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, const IntSize&, CompositeOperator op, BlendMode mode, const ImageOrientation& orientation)
{
    context.save();
    
    // Set the compositing operation.
    if (op == CompositeSourceOver && mode == BlendModeNormal && !nativeImageHasAlpha(image))
        context.setCompositeOperation(CompositeCopy);
    else
        context.setCompositeOperation(op, mode);
        
#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
    IntSize scaledSize = nativeImageSize(image);
    FloatRect adjustedSrcRect = adjustSourceRectForDownSampling(srcRect, scaledSize);
#else
    FloatRect adjustedSrcRect(srcRect);
#endif
        
    FloatRect adjustedDestRect = destRect;
        
    if (orientation != DefaultImageOrientation) {
        // ImageOrientation expects the origin to be at (0, 0).
        context.translate(destRect.x(), destRect.y());
        adjustedDestRect.setLocation(FloatPoint());
        context.concatCTM(orientation.transformFromDefault(adjustedDestRect.size()));
        if (orientation.usesWidthAsHeight()) {
            // The destination rectangle will have it's width and height already reversed for the orientation of
            // the image, as it was needed for page layout, so we need to reverse it back here.
            adjustedDestRect.setSize(adjustedDestRect.size().transposedSize());
        }
    }

    context.platformContext()->drawSurfaceToContext(image.get(), adjustedDestRect, adjustedSrcRect, context);
    context.restore();
}
Exemplo n.º 8
0
NativeImagePtr NativeImage::New( NativeImageInterface& resourceData )
{
  NativeImagePtr image = new NativeImage;
  image->Initialize();

  ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();

  image->mWidth  = resourceData.GetWidth();
  image->mHeight = resourceData.GetHeight();

  const ResourceTicketPtr& ticket = resourceClient.AddNativeImage( resourceData );
  DALI_ASSERT_DEBUG( dynamic_cast<ImageTicket*>( ticket.Get() ) && "Resource ticket not ImageTicket subclass for image resource.\n" );
  image->mTicket = static_cast<ImageTicket*>(ticket.Get());
  image->mTicket->AddObserver( *image );

  return image;
}
Exemplo n.º 9
0
void PlatformSupport::clipboardWriteImage(NativeImagePtr image,
                                         const KURL& sourceURL,
                                         const String& title)
{
#if WEBKIT_USING_SKIA
    WebImage webImage(image->bitmap());
#else
    WebImage webImage(image);
#endif
    webKitPlatformSupport()->clipboard()->writeImage(webImage, sourceURL, title);
}
Exemplo n.º 10
0
static GdkPixbuf* getIconPixbufSynchronously(WebKitFaviconDatabase* database, const String& pageURL, const IntSize& iconSize)
{
    ASSERT(isMainThread());

    // The exact size we pass is irrelevant to the iconDatabase code.
    // We must pass something greater than 0x0 to get a pixbuf.
    NativeImagePtr icon = iconDatabase().synchronousNativeIconForPageURL(pageURL, !iconSize.isZero() ? iconSize : IntSize(1, 1));
    if (!icon)
        return 0;

    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(cairoImageSurfaceToGdkPixbuf(icon->surface()));
    if (!pixbuf)
        return 0;

    // A size of (0, 0) means the maximum available size.
    int pixbufWidth = gdk_pixbuf_get_width(pixbuf.get());
    int pixbufHeight = gdk_pixbuf_get_height(pixbuf.get());
    if (!iconSize.isZero() && (pixbufWidth != iconSize.width() || pixbufHeight != iconSize.height()))
        pixbuf = adoptGRef(gdk_pixbuf_scale_simple(pixbuf.get(), iconSize.width(), iconSize.height(), GDK_INTERP_BILINEAR));
    return pixbuf.leakRef();
}
Exemplo n.º 11
0
static void loadBufferingImageData()
{
    static bool loaded = false;
    if (!loaded) {
        static Image* bufferingIcon = Image::loadPlatformResource("vidbuffer").leakRef();

        NativeImagePtr nativeImage = bufferingIcon->nativeImageForCurrentFrame();
        if (!nativeImage)
            return;

        loaded = true;
        s_bufferingImageWidth = bufferingIcon->width();
        s_bufferingImageHeight = bufferingIcon->height();
        int bufSize = bufferingIcon->decodedSize();
        s_bufferingImageData = static_cast<unsigned*>(malloc(bufSize));

        nativeImage->readPixels(s_bufferingImageData, s_bufferingImageWidth * s_bufferingImageHeight);

        bufferingIcon->deref();
    }
}
Exemplo n.º 12
0
void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const FloatRect& src, ColorSpace styleColorSpace, CompositeOperator op)
{
    if (dst.isEmpty() || src.isEmpty())
        return;

    NativeImagePtr image = nativeImageForCurrentFrame();
    if (!image)
        return;

    startAnimation();

    if (mayFillWithSolidColor()) {
        fillWithSolidColor(context, dst, solidColor(), styleColorSpace, op);
        return;
    }

    context->save();

    // Set the compositing operation.
    if (op == CompositeSourceOver && !frameHasAlphaAtIndex(m_currentFrame))
        context->setCompositeOperation(CompositeCopy);
    else
        context->setCompositeOperation(op);

#if ENABLE(IMAGE_DECODER_DOWN_SAMPLING)
    FloatRect srcRectLocal = adjustSourceRectForDownSampling(src, image->size());
#else
    FloatRect srcRectLocal(src);
#endif

    context->platformContext()->activePainter()->drawImage(image, dst, srcRectLocal);
    context->restore();

    if (imageObserver())
        imageObserver()->didDraw(this);
}
Exemplo n.º 13
0
//----------------------------------------------------------------------------------
// SetHostImage: Load the Host's image from the downloaded file.
//----------------------------------------------------------------------------------
void DownloadCtrl::SetHostImage(const std::string& sFile)
{
	NativeImagePtr pHostImg = GetWindow()->DecodeImage(sFile.c_str());

	if (pHostImg.get() != NULL && pHostImg->GetWidth() <= Global_HOST_AD_WIDTH_Int && pHostImg->GetWidth() > 0 &&
		pHostImg->GetHeight() <= Global_HOST_AD_HEIGHT_Int && pHostImg->GetHeight() > 0)
	{
		m_pVisitHostImageButton->SetImage(ImageButtonType_Normal, pHostImg);

		m_pVisitHostButton->SetVisible(false);
		m_pVisitHostImageButton->SetVisible(true);
		Invalidate();
	}
}
Exemplo n.º 14
0
void BitmapImage::readyWRATHWidgets(PaintedWidgetsOfWRATHHandleT<Image>& handle, ContextOfWRATH *ctx,
                                    const FloatRect& dst, const FloatRect& src,
                                    ColorSpace styleColorSpace, CompositeOperator op)
{
    BitmapImage_readyWRATHWidgets *d(BitmapImage_readyWRATHWidgets::object(this, handle));

    ContextOfWRATH::AutoPushNode autoPushRoot(ctx, d->m_root_node);

    d->m_solid_color.visible(false);
    if (d->m_image_rect_item.widget())
        d->m_image_rect_item.widget()->visible(false);

    FloatRect normalizedDst = dst.normalized();
    FloatRect normalizedSrc = src.normalized();

    startAnimation();

    if (normalizedSrc.isEmpty() || normalizedDst.isEmpty())
        return;

    NativeImagePtr nativeImage = nativeImageForCurrentFrame();
    if (!nativeImage)
        return;

    // "Hardcode" the requirement for the underlying wrath image type to WRATHImage.
    // The reason is support for setting texture coordinates, which isn't possible for WRATHCompoundImage
    WRATHImage* image = nativeImage->getWrathImage();
    if (!image)
        return;

    if (mayFillWithSolidColor()) {
        d->m_solid_color.visible(true);
        readyWRATHWidgetSolidColor(d->m_solid_color, ctx, this, normalizedDst, solidColor(), styleColorSpace, op);
        return;
    }

    // ImageRectOfWRATH methods handle changing the op with respect to composite operator
    /*
    CompositeOperator previousOperator = ctxt->compositeOperation();
    ctxt->setCompositeOperation(!image->hasAlpha() && op == CompositeSourceOver ? CompositeCopy : op);
    */
    if(!nativeImage->hasAlpha() && op == CompositeSourceOver)
      {
        op=CompositeCopy;
      }
    
    /*
      [WRATH-DANGER]: No shadows

    ContextShadow* shadow = ctxt->contextShadow();
    if (shadow->m_type != ContextShadow::NoShadow) {
        QPainter* shadowPainter = shadow->beginShadowLayer(ctxt, normalizedDst);
        if (shadowPainter) {
            shadowPainter->setOpacity(static_cast<qreal>(shadow->m_color.alpha()) / 255);
            shadowPainter->drawPixmap(normalizedDst, *image, normalizedSrc);
            shadow->endShadowLayer(ctxt);
        }
    }
    */

    /*
      [WRATH-DANGER]: Possible rounding errors from converting to IntRect
     */
    d->m_image_rect_item.update(ctx, nativeImage,
                                normalizedDst, IntRect(normalizedSrc),
                                op);
    if (d->m_image_rect_item.widget())
      d->m_image_rect_item.widget()->visible(true);

    /*
      ctxt->platformContext()->drawPixmap(normalizedDst, *image, normalizedSrc);
    */

    /*
    ctxt->setCompositeOperation(previousOperator);
    */

    if (imageObserver())
        imageObserver()->didDraw(this);
}
Exemplo n.º 15
0
bool nativeImageHasAlpha(const NativeImagePtr& image)
{
    return !image || cairo_surface_get_content(image.get()) != CAIRO_CONTENT_COLOR;
}
Exemplo n.º 16
0
IntSize nativeImageSize(const NativeImagePtr& image)
{
    return image ? cairoSurfaceSize(image.get()) : IntSize();
}