pixelbuf.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //-----------------------------------------------------------------------------
  2. // --------------------
  3. // File ....: pixelbuf.h
  4. // --------------------
  5. // Author...: Tom Hudson
  6. // Date ....: Dec. 09, 1995
  7. // Descr....: Pixel Buffer Classes
  8. // Usage....: These templated classes let you set up a buffer for pixels that
  9. // will automatically clean itself up when it goes out of scope.
  10. //
  11. // History .: Dec. 09 1995 - Started file
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef __PIXBUF_H__
  15. #define __PIXBUF_H__
  16. // Handy-dandy pixel buffer classes:
  17. template <class T> class PixelBufT {
  18. private:
  19. T *buf;
  20. int width;
  21. public:
  22. inline PixelBufT(int width) { buf = (T *)calloc(width,sizeof(T)); this->width=width; };
  23. inline ~PixelBufT() { if(buf) free(buf); };
  24. inline T* Ptr() { return buf; };
  25. inline T& operator[](int i) { return buf[i]; }
  26. int Fill(int start, int count, T color) {
  27. int ix,jx=start+count;
  28. if(jx >= width)
  29. return 0;
  30. for(ix=start; ix<jx; buf[ix++]=color);
  31. return 1;
  32. };
  33. };
  34. typedef PixelBufT<UBYTE> PixelBuf8;
  35. typedef PixelBufT<USHORT> PixelBuf16;
  36. typedef PixelBufT<BMM_Color_24> PixelBuf24;
  37. typedef PixelBufT<BMM_Color_32> PixelBuf32;
  38. typedef PixelBufT<BMM_Color_48> PixelBuf48;
  39. typedef PixelBufT<BMM_Color_64> PixelBuf64;
  40. #endif // __PIXBUF_H__