Sha256: e149f3990921da9786d81478b9d6ce8329535da0fd1fc76fdf6e6908e5c9f52c

Contents?: true

Size: 1.79 KB

Versions: 22

Compression:

Stored size: 1.79 KB

Contents

#include <Gosu/Bitmap.hpp>
#include <cassert>
#include <algorithm>
#include <vector>

void Gosu::Bitmap::swap(Bitmap& other)
{
    std::swap(pixels, other.pixels);
    std::swap(w, other.w);
    std::swap(h, other.h);
}

void Gosu::Bitmap::resize(unsigned width, unsigned height, Color c)
{
    if (width == w && height == h)
        return;
    
    Bitmap temp(width, height, c);
    temp.insert(*this, 0, 0);
    swap(temp);
}

void Gosu::Bitmap::fill(Color c)
{
    std::fill(pixels.begin(), pixels.end(), c);
}

void Gosu::Bitmap::replace(Color what, Color with)
{
    std::replace(pixels.begin(), pixels.end(), what, with);
}

void Gosu::Bitmap::insert(const Bitmap& source, int x, int y)
{
    insert(source, x, y, 0, 0, source.width(), source.height());
}

void Gosu::Bitmap::insert(const Bitmap& source, int x, int y, unsigned srcX,
    unsigned srcY, unsigned srcWidth, unsigned srcHeight)
{
    if (x < 0)
    {
        unsigned clipLeft = -x;

        if (clipLeft >= srcWidth)
            return;

        srcX += clipLeft;
        srcWidth -= clipLeft;
        x = 0;
    }

    if (y < 0)
    {
        unsigned clipTop = -y;

        if (clipTop >= srcHeight)
            return;

        srcY += clipTop;
        srcHeight -= clipTop;
        y = 0;
    }

    if (x + srcWidth > w)
    {
        if (static_cast<unsigned>(x) >= w)
            return;

        srcWidth = w - x;
    }

    if (y + srcHeight > h)
    {
        if (static_cast<unsigned>(y) >= h)
            return;

        srcHeight = h - y;
    }

    for (unsigned relY = 0; relY < srcHeight; ++relY)
        for (unsigned relX = 0; relX < srcWidth; ++relX)
            setPixel(x + relX, y + relY,
                source.getPixel(srcX + relX, srcY + relY));
}

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
gosu-0.8.0.pre3 GosuImpl/Graphics/Bitmap.cpp
gosu-0.8.0.pre2 GosuImpl/Graphics/Bitmap.cpp
gosu-0.8.0.pre1 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.50 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.49 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.48 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.47.1 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.46 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.45 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.44 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.43 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.41 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.40 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.39 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.38 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.37 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.36.2 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.35 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.33 GosuImpl/Graphics/Bitmap.cpp
gosu-0.7.32 GosuImpl/Graphics/Bitmap.cpp