Create PackedPixel structure.

This commit is contained in:
Fabien Freling 2014-07-06 23:47:21 +02:00
parent 049228b377
commit a6ef15ea62

View file

@ -39,6 +39,24 @@ std::basic_ostream<Elem, Traits>& operator << (std::basic_ostream<Elem, Traits>&
return o; return o;
} }
struct PackedPixel {
uint32_t r;
uint32_t g;
uint32_t b;
PackedPixel()
: r(0)
, g(0)
, b(0)
{}
};
uint8_t interpolate_packed(uint32_t pack, double x, double x_inv, double y, double y_inv)
{
return (((pack >> 24) & 0x000f) * x_inv + ((pack >> 16) & 0x000f) * x) * y_inv
+ (((pack >> 8) & 0x000f) * x_inv + (pack & 0x000f) * x) * y;
}
// //
@ -311,6 +329,31 @@ struct TiledImage : public Image {
return tile + tile_j * tile_width + (tile_i * 3); return tile + tile_j * tile_width + (tile_i * 3);
} }
PackedPixel
get_packed_pixels(unsigned int x, unsigned int y) const
{
PackedPixel pack;
this->insert_pixel(pack, x, y);
pack.r = pack.r << 8;
pack.g = pack.g << 8;
pack.b = pack.b << 8;
this->insert_pixel(pack, x + 1, y);
pack.r = pack.r << 8;
pack.g = pack.g << 8;
pack.b = pack.b << 8;
this->insert_pixel(pack, x, y + 1);
pack.r = pack.r << 8;
pack.g = pack.g << 8;
pack.b = pack.b << 8;
this->insert_pixel(pack, x + 1, y + 1);
return pack;
}
void void
print_tile(unsigned int index) const print_tile(unsigned int index) const
{ {
@ -334,6 +377,21 @@ struct TiledImage : public Image {
protected: protected:
void insert_pixel(PackedPixel& pack, unsigned int x, unsigned int y) const
{
unsigned int const tile_width = tile_w * 3;
unsigned int const tile_index = (y / tile_h) * nb_col_tile + (x / tile_w);
if (tile_index >= nb_col_tile * nb_row_tile)
return;
uint8_t const* tile = tiles[tile_index];
unsigned int const tile_j = y % tile_h;
unsigned int const tile_i = x % tile_w;
unsigned int index = tile_j * tile_width + (tile_i * 3);
pack.r += tile[index];
pack.g += tile[index + 1] + 1;
pack.b += tile[index + 2] + 1;
}
void allocate_memory(unsigned int w, unsigned int h) void allocate_memory(unsigned int w, unsigned int h)
{ {
width = w; width = w;