Improve put/get_pixel_fast() functions to avoid virtual function call

This commit is contained in:
David Capello 2013-11-10 14:49:06 -03:00
parent 48864b440b
commit 5b8d000171
2 changed files with 7 additions and 6 deletions

View File

@ -37,10 +37,6 @@ namespace raster {
address_t m_bits;
address_t* m_rows;
inline address_t address(int x, int y) const {
return (address_t)(m_rows[y] + x / (Traits::pixels_per_byte == 0 ? 1 : Traits::pixels_per_byte));
}
inline address_t getBitsAddress() {
return m_bits;
}
@ -60,6 +56,10 @@ namespace raster {
}
public:
inline address_t address(int x, int y) const {
return (address_t)(m_rows[y] + x / (Traits::pixels_per_byte == 0 ? 1 : Traits::pixels_per_byte));
}
ImageImpl(int width, int height,
const ImageBufferPtr& buffer)
: Image(static_cast<PixelFormat>(Traits::pixel_format), width, height)

View File

@ -20,6 +20,7 @@
#define RASTER_PRIMITIVES_FAST_H_INCLUDED
#include "raster/color.h"
#include "raster/image_impl.h"
namespace raster {
class Image;
@ -29,7 +30,7 @@ namespace raster {
ASSERT(x >= 0 && x < image->getWidth());
ASSERT(y >= 0 && y < image->getHeight());
return *((typename Traits::address_t)image->getPixelAddress(x, y));
return *(((ImageImpl<Traits>*)image)->address(x, y));
}
template<class Traits>
@ -37,7 +38,7 @@ namespace raster {
ASSERT(x >= 0 && x < image->getWidth());
ASSERT(y >= 0 && y < image->getHeight());
*((typename Traits::address_t)image->getPixelAddress(x, y)) = color;
*(((ImageImpl<Traits>*)image)->address(x, y)) = color;
}
//////////////////////////////////////////////////////////////////////