diff options
author | Juha Vehviläinen <jusu@users.sourceforge.net> | 2002-07-06 17:50:18 +0000 |
---|---|---|
committer | Juha Vehviläinen <jusu@users.sourceforge.net> | 2002-07-06 17:50:18 +0000 |
commit | 4d64e4cd434426234a5c313c151cd79b6afc299e (patch) | |
tree | 5c23dd6acc65b869741d3bb9d33912d74bb7407d /Plugins/pixels.h |
*** empty log message ***svn2git-root
svn path=/trunk/Framestein/; revision=27
Diffstat (limited to 'Plugins/pixels.h')
-rw-r--r-- | Plugins/pixels.h | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/Plugins/pixels.h b/Plugins/pixels.h new file mode 100644 index 0000000..4dd1264 --- /dev/null +++ b/Plugins/pixels.h @@ -0,0 +1,117 @@ +// Easy iteration thru pixels, see green.cpp and tile.cpp for examples +// NOTE: using this class could be a bit slower than manipulating the bits directly.. +// +// changes to 0.20 +// - pixelformat-aware functions red() green() blue() and putrgb() +// - dot16() dot24() and dot32() added +// - get/put dot() removed, use above + +#include "plugin.h" + +#ifndef _PIXELSH +#define _PIXELSH + +class pixels +{ +private: + _frame m_f; + pixel8 *p8; // pointer to a row of 8-bit pixels + pixel16 *p16; + pixel24 *p24; + pixel32 *p32; + + __inline void updaterowp(); +public: + int x, y; + + pixels(const _frame &f) + { + m_f = f; + x = -1; + y = 0; + p8 = 0; + next(); + } + + __inline pixel8 dot8() { return p8[x]; } + __inline pixel16 dot16() { return p16[x]; } + __inline pixel24 dot24() { return p24[x]; } + __inline pixel32 dot32() { return p32[x]; } + + __inline void dot8(pixel8 c) { p8[x] = c; } + __inline void dot16(pixel16 c) { p16[x] = c; } + __inline void dot24(pixel24 c) { p24[x] = c; } + __inline void dot32(pixel32 c) { p32[x] = c; } + + __inline byte red(); + __inline byte green(); + __inline byte blue(); + + __inline void putrgb(byte r, byte g, byte b); + + __inline void moveto(int tox, int toy) + { if(tox<m_f.width) x=tox; if(toy<m_f.height) { y=toy; updaterowp(); } } + + __inline int eof() { return y==m_f.height ? 1 : 0; } + void next(); +}; + +byte pixels::red() +{ + switch(m_f.pixelformat) + { + case 16: return r16(p16[x]); + case 24: return r24(p24[x]); + case 32: return r32(p32[x]); + default: return 0; + } +} + +byte pixels::green() +{ + switch(m_f.pixelformat) + { + case 16: return g16(p16[x]); + case 24: return g24(p24[x]); + case 32: return g32(p32[x]); + default: return 0; + } +} + +byte pixels::blue() +{ + switch(m_f.pixelformat) + { + case 16: return b16(p16[x]); + case 24: return b24(p24[x]); + case 32: return b32(p32[x]); + default: return 0; + } +} + +void pixels::putrgb(byte r, byte g, byte b) +{ + switch(m_f.pixelformat) + { + case 16: p16[x] = rgbtocolor16(r, g, b); break; + case 24: p24[x] = rgbtocolor24(r, g, b); break; + case 32: p32[x] = rgbtocolor32(r, g, b); break; + } +} + +void pixels::next() +{ + x++; + if(x==m_f.width) { y++; x=0; p8=0; } + if(!p8) updaterowp(); +} + +void pixels::updaterowp() +{ + p8 = scanline(m_f, y); + p16 = (pixel16 *)p8; + p24 = (pixel24 *)p8; + p32 = (pixel32 *)p8; +} + +#endif // #ifndef _PIXELSH |