Beispiel #1
0
wxBitmap* gdiplusResize(wxBitmap* bitmap, const FloatSize& size)
{
    IntSize intSize = IntSize(ceilf(size.width()), ceilf(size.height()));
    if (intSize.width() == bitmap->GetWidth() && intSize.height() == bitmap->GetHeight())
        return new wxBitmap(*bitmap); // just return a copy if the asked for the same size

    wxBitmap* newBitmap = new wxBitmap(intSize.width(), intSize.height(), 32);
    newBitmap->UseAlpha();

    wxMemoryDC memdc(*newBitmap);
    wxGraphicsContext* gc = wxGraphicsContext::Create(memdc);
    wxGraphicsBitmap gcbitmap(gc->CreateBitmap(*bitmap));

    Graphics* graphics = (Graphics*)gc->GetNativeContext();
    graphics->Clear(Gdiplus::Color(0, 0, 0, 0));

    // Only use HighQualityBicubic when downsampling.
    InterpolationMode mode;
    if (size.width() < (int)bitmap->GetWidth() && size.height() < (int)bitmap->GetHeight())
        mode = InterpolationModeHighQualityBicubic;
    else
        mode = InterpolationModeBicubic;

    graphics->SetInterpolationMode(mode);
    graphics->DrawImage((Bitmap*)gcbitmap.GetNativeBitmap(), 0.0, 0.0, size.width(), size.height());
    
    premultiplyAlpha(*newBitmap);

    delete gc;

    return newBitmap;
}
Beispiel #2
0
void TestPlugin::drawPrimitive()
{
    DCHECK_EQ(m_scene.primitive, PrimitiveTriangle);
    DCHECK(m_scene.vbo);
    DCHECK(m_scene.program);

    m_context->useProgram(m_scene.program);

    // Bind primitive color.
    float color[4];
    premultiplyAlpha(m_scene.primitiveColor, m_scene.opacity, color);
    m_context->uniform4f(m_scene.colorLocation, color[0], color[1], color[2], color[3]);

    // Bind primitive vertices.
    m_context->bindBuffer(GL_ARRAY_BUFFER, m_scene.vbo);
    m_context->enableVertexAttribArray(m_scene.positionLocation);
    m_context->vertexAttribPointer(m_scene.positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
    m_context->drawArrays(GL_TRIANGLES, 0, 3);
}
Beispiel #3
0
bool TestPlugin::initScene()
{
    float color[4];
    premultiplyAlpha(m_scene.backgroundColor, m_scene.opacity, color);

    m_colorTexture = m_context->createTexture();
    m_framebuffer = m_context->createFramebuffer();

    m_context->viewport(0, 0, m_rect.width, m_rect.height);
    m_context->disable(GL_DEPTH_TEST);
    m_context->disable(GL_SCISSOR_TEST);

    m_context->clearColor(color[0], color[1], color[2], color[3]);

    m_context->enable(GL_BLEND);
    m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

    return m_scene.primitive != PrimitiveNone ? initProgram() && initPrimitive() : true;
}