#include "font.h"
enum RasterOperations {
RO_COPY, RO_OR, RO_AND, RO_XOR
};
class RGB {
о
JM.
4. Работа с основными графическими устройствам
public:
char red;
char green;
char blue;
RGB () {}
RGB ( int r, int g, int b ) {
red = r; green = g; blue = b;
}
};
struct PixelFormat {
unsigned redMask; // bit mask for red color bits int redShift; // position of red bits in pixel
int red Bits; // # of bits for red field
unsigned greenMask; // bit mask for green color bits int greenShift; // position of green bits in pixel
int greenBits; // # of bits for green field
unsigned blueMask; // bit mask for blue color bits int blueShift; // position of blue bits in pixel
int blueBits;
int bitsPerPixel; // # of bits per pixel
int bytesPerPixel; // # of bytes per single pixel
void completeFromMasks ();
};
inline int operator == ( const PixelFormat& f1, const PixelFormat& f2 ) {
return f1.redMask == f2.redMask &&
f1 .greenMask == f2.greenMask && f1 .blueMask == f2.blueMask;
}
inline int rgbTo24Bit ( int red, int green, int blue ) {
return blue I (green « 8) | (red « 16);
}
inline int rgbTo16Bit ( int red, int green, int blue ) {
return (blue»3) I ((green»2)«5) | ((red»3)«10);
}
inline int rgbTo15Bit ( int red, int green, int blue ) {
return (blue»3) I ((green»3)«5) | ((red»3)«10);
}
inline int rgbToInt ( int red, int green, int blue, const PixelFormat& fmt ) {
Компьютерная графика. Полигональные модели
return ((blue»(8-fmt.blueBits))«fmt.blueShift) | ((green»(8-fmt.greenBits))«fmt.greenShift) |
((red»(8-fmt.redBits))«fmt.redShift);
}
class Surface : public Object {
protected: // function pointers
int (Surface::*getPixelAddr) (intx, inty); void (Surface: :*drawPixelAddr) (int x, int y, int color); void (Surface::*drawLineAddr) (int x1, int y1, int x2, tnt y2 ); void (Surface::*drawCharAddr) (int x, int y, int ch); void (Surface::*drawStringAddr)(int x, int y, const char * str); void (Surface::*drawBarAddr) (int x1, int y1, int x2, int y2 ); void (Surface::*copyAddr) (Surface& dstSurface, const Rect& srcRect,