Ejemplo n.º 1
0
PassOwnPtr<HBITMAP> SharedBitmap::clipBitmap(const IntRect& rect, bool useAlpha, BitmapInfo& bmpInfo, void*& pixels)
{
    if (!bytes())
        return nullptr;

    int oldWidth = width();
    int oldHeight = height();
    int copyWidth = std::min<int>(rect.width(), oldWidth - rect.x());
    int copyHeight = std::min<int>(rect.height(), oldHeight - rect.y());
    if (!copyWidth || !copyHeight)
        return nullptr;

    bmpInfo = BitmapInfo::createBottomUp(IntSize(copyWidth, copyHeight), (useAlpha && is32bit()) ? BitmapInfo::BitCount32 : BitmapInfo::BitCount16);
    OwnPtr<HBITMAP> newBmp = adoptPtr(CreateDIBSection(0, &bmpInfo, DIB_RGB_COLORS, &pixels, 0, 0));

    if (!newBmp)
        return nullptr;

    OwnPtr<HDC> dcNew = adoptPtr(CreateCompatibleDC(0));
    HGDIOBJ tmpNew = SelectObject(dcNew.get(), newBmp.get());

    StretchDIBits(dcNew.get(), 0, 0, copyWidth, copyHeight, rect.x(), rect.y(), copyWidth, copyHeight,
        bytes(), &bitmapInfo(), DIB_RGB_COLORS, SRCCOPY);

    SelectObject(dcNew.get(), tmpNew);
    return newBmp.release();
}
Ejemplo n.º 2
0
PassRefPtr<SharedBitmap> SharedBitmap::clipBitmap(const IntRect& rect, bool useAlpha)
{
    int oldWidth = width();
    int oldHeight = height();
    int copyWidth = std::min<int>(rect.width(), oldWidth - rect.x());
    int copyHeight = std::min<int>(rect.height(), oldHeight - rect.y());
    if (!copyWidth || !copyHeight)
        return 0;

    RefPtr<SharedBitmap> newBmp = create(IntSize(copyWidth, copyHeight), useAlpha && is32bit() ? BitmapInfo::BitCount32 : BitmapInfo::BitCount16, false);

    if (!newBmp || !newBmp->bytes())
        return 0;

    DCHolder dcNew(newBmp.get());

    StretchDIBits(dcNew.get(), 0, 0, copyWidth, copyHeight, rect.x(), rect.y(), copyWidth, copyHeight,
        bytes(), &bitmapInfo(), DIB_RGB_COLORS, SRCCOPY);

    return newBmp;
}
Ejemplo n.º 3
0
std::unique_ptr<GraphicsContext> ShareableBitmap::createGraphicsContext()
{
    ref(); // Balanced by deref in releaseBitmapContextData.
    
    RetainPtr<CGContextRef> bitmapContext = adoptCF(CGBitmapContextCreateWithData(data(), m_size.width(), m_size.height(), m_bytesPerPixel * 8 / 4, m_size.width() * m_bytesPerPixel, colorSpace(m_flags), bitmapInfo(m_flags), releaseBitmapContextData, this));
    
    ASSERT(bitmapContext.get());

    // We want the origin to be in the top left corner so we flip the backing store context.
    CGContextTranslateCTM(bitmapContext.get(), 0, m_size.height());
    CGContextScaleCTM(bitmapContext.get(), 1, -1);

    return std::make_unique<GraphicsContext>(bitmapContext.get());
}
Ejemplo n.º 4
0
RetainPtr<CGImageRef> ShareableBitmap::createCGImage(CGDataProviderRef dataProvider) const
{
    ASSERT_ARG(dataProvider, dataProvider);
    RetainPtr<CGImageRef> image = adoptCF(CGImageCreate(m_size.width(), m_size.height(), m_bytesPerPixel * 8 / 4, m_bytesPerPixel * 8, m_size.width() * m_bytesPerPixel, colorSpace(m_flags), bitmapInfo(m_flags), dataProvider, 0, false, kCGRenderingIntentDefault));
    return image;
}