From a6ef15ea62fc1273a488b4ffe1c6ce65bc445c80 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Sun, 6 Jul 2014 23:47:21 +0200 Subject: [PATCH] Create PackedPixel structure. --- rotation.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/rotation.cpp b/rotation.cpp index e7f6a87..a46e9f7 100644 --- a/rotation.cpp +++ b/rotation.cpp @@ -39,6 +39,24 @@ std::basic_ostream& operator << (std::basic_ostream& 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); } + 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 print_tile(unsigned int index) const { @@ -334,6 +377,21 @@ struct TiledImage : public Image { 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) { width = w;