mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-05 19:31:04 +00:00
Extract bitmap class
This commit is contained in:
parent
f2eb5e7a93
commit
e835673c5e
2 changed files with 95 additions and 44 deletions
|
@ -4,54 +4,12 @@
|
|||
|
||||
#include "imagefilters.h"
|
||||
#include "util/numeric.h"
|
||||
#include "util/bitmap.h"
|
||||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <IVideoDriver.h>
|
||||
|
||||
// Simple 2D bitmap class with just the functionality needed here
|
||||
class Bitmap {
|
||||
u32 linesize, lines;
|
||||
std::vector<u8> data;
|
||||
|
||||
static inline u32 bytepos(u32 index) { return index >> 3; }
|
||||
static inline u8 bitpos(u32 index) { return index & 7; }
|
||||
|
||||
public:
|
||||
Bitmap(u32 width, u32 height) : linesize(width), lines(height),
|
||||
data(bytepos(width * height) + 1) {}
|
||||
|
||||
inline bool get(u32 x, u32 y) const {
|
||||
u32 index = y * linesize + x;
|
||||
return data[bytepos(index)] & (1 << bitpos(index));
|
||||
}
|
||||
|
||||
inline void set(u32 x, u32 y) {
|
||||
u32 index = y * linesize + x;
|
||||
data[bytepos(index)] |= 1 << bitpos(index);
|
||||
}
|
||||
|
||||
inline bool all() const {
|
||||
for (u32 i = 0; i < data.size() - 1; i++) {
|
||||
if (data[i] != 0xff)
|
||||
return false;
|
||||
}
|
||||
// last byte not entirely filled
|
||||
for (u8 i = 0; i < bitpos(linesize * lines); i++) {
|
||||
bool value_of_bit = data.back() & (1 << i);
|
||||
if (!value_of_bit)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void copy(Bitmap &to) const {
|
||||
assert(to.linesize == linesize && to.lines == lines);
|
||||
to.data = data;
|
||||
}
|
||||
};
|
||||
|
||||
template <bool IS_A8R8G8B8>
|
||||
static void imageCleanTransparentWithInlining(video::IImage *src, u32 threshold)
|
||||
{
|
||||
|
@ -143,7 +101,7 @@ static void imageCleanTransparentWithInlining(video::IImage *src, u32 threshold)
|
|||
|
||||
// Apply changes to bitmap for next run. This is done so we don't introduce
|
||||
// a bias in color propagation in the direction pixels are processed.
|
||||
newmap.copy(bitmap);
|
||||
bitmap = newmap;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue