Exemple #1
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);
}
Exemple #2
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();
}
//----------------------------------------------------------------------------------
// 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();
	}
}
Exemple #4
0
bool nativeImageHasAlpha(const NativeImagePtr& image)
{
    return !image || cairo_surface_get_content(image.get()) != CAIRO_CONTENT_COLOR;
}
Exemple #5
0
IntSize nativeImageSize(const NativeImagePtr& image)
{
    return image ? cairoSurfaceSize(image.get()) : IntSize();
}