Sha256: 3d1b6a23207463991f8e20d41ff746b38c01c601203b21077dba2a521fb40345

Contents?: true

Size: 1.88 KB

Versions: 21

Compression:

Stored size: 1.88 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)
{
    // TODO: This should use memcpy if possible (x == 0 && srcWidth == this->width())
    
    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

21 entries across 21 versions & 1 rubygems

Version Path
gosu-0.9.2 src/Bitmap/Bitmap.cpp
gosu-0.9.2.pre1 src/Bitmap/Bitmap.cpp
gosu-0.9.1 src/Bitmap/Bitmap.cpp
gosu-0.9.0 src/Bitmap/Bitmap.cpp
gosu-0.9.0.pre1 src/Bitmap/Bitmap.cpp
gosu-0.8.7.2 src/Bitmap/Bitmap.cpp
gosu-0.8.7.1 src/Bitmap/Bitmap.cpp
gosu-0.8.7 src/Bitmap/Bitmap.cpp
gosu-0.8.6 src/Bitmap/Bitmap.cpp
gosu-0.8.6.pre1 src/Bitmap/Bitmap.cpp
gosu-0.8.5 src/Bitmap/Bitmap.cpp
gosu-0.8.5.pre1 src/Bitmap/Bitmap.cpp
gosu-0.8.4 src/Bitmap/Bitmap.cpp
gosu-0.8.3 src/Bitmap/Bitmap.cpp
gosu-0.8.2 src/Bitmap/Bitmap.cpp
gosu-0.8.1 src/Bitmap/Bitmap.cpp
gosu-0.8.0 src/Bitmap/Bitmap.cpp
gosu-0.8.0.pre7 src/Bitmap/Bitmap.cpp
gosu-0.8.0.pre6 src/Bitmap/Bitmap.cpp
gosu-0.8.0.pre5 src/Bitmap/Bitmap.cpp