OpenWareLaboratory
ColourScreenPatch.cpp
Go to the documentation of this file.
1 #include <cstddef>
2 #include <string.h>
3 #include "device.h"
4 #include "ColourScreenPatch.h"
5 #include "ProgramVector.h"
6 #include "PatchProcessor.h"
7 #include "ServiceCall.h"
8 
9 PatchProcessor* getInitialisingPatchProcessor();
10 
11 static void onDrawCallback(uint8_t* pixels, uint16_t width, uint16_t height){
13  if(patch != NULL){
14  ColourScreenBuffer screen(width, height);
15  screen.setBuffer(pixels);
16  patch->processScreen(screen);
17  }
18 }
19 
21  void* drawArgs[] = {(void*)SYSTEM_FUNCTION_DRAW, (void*)&onDrawCallback};
22  getProgramVector()->serviceCall(OWL_SERVICE_REGISTER_CALLBACK, drawArgs, 2);
23 }
24 
26 
28  return 64;
29 }
31  return 64;
32 }
33 
34 template<>
35 Colour ColourScreenBuffer::getPixel(unsigned int x, unsigned int y){
36  if(x >= width || y >= height)
37  return 0;
38  return pixels[y*width+x];
39 }
40 
41 template<>
42 void ColourScreenBuffer::setPixel(unsigned int x, unsigned int y, Colour c){
43  if(x < width && y < height)
44  pixels[y*width+x] = c;
45 }
46 
47 template<>
48 void ColourScreenBuffer::invertPixel(unsigned int x, unsigned int y){
49  if(x < width && y < height)
50  pixels[y*width+x] ^= WHITE;
51 }
52 
53 template<>
54 void ColourScreenBuffer::fade(uint16_t steps){
55  for(int i=0; i<height*width; ++i)
56  pixels[i] =
57  (((pixels[i] & RED) >> steps) & RED) |
58  (((pixels[i] & GREEN) >> steps) & GREEN) |
59  (((pixels[i] & BLUE) >> steps) & BLUE);
60 }
61 
62 template<>
64  for(int i=0; i<height*width; ++i)
65  pixels[i] = c;
66 }
67 
static void onDrawCallback(uint8_t *pixels, uint16_t width, uint16_t height)
PatchProcessor * getInitialisingPatchProcessor()
uint16_t Colour
#define BLUE
#define WHITE
#define RED
#define GREEN
Abstract base class for patches that use a colour screen.
virtual void processScreen(ColourScreenBuffer &screen)=0
void setPixel(unsigned int x, unsigned int y, Colour c)
Colour getPixel(unsigned int x, unsigned int y)
void invertPixel(unsigned int x, unsigned int y)
void fade(uint16_t steps)
void fill(Colour c)
void setBuffer(uint8_t *buffer)
Definition: ScreenBuffer.h:36