Numworks Epsilon  1.4.1
Graphing Calculator Operating System
framebuffer.cpp
Go to the documentation of this file.
2 #include <string.h>
3 
5  m_pixels(pixels),
6  m_size(size)
7 {
8 }
9 
11  return KDRect(KDPointZero, m_size);
12 }
13 
14 KDColor * KDFrameBuffer::pixelAddress(KDPoint p) const {
15  return m_pixels + p.x() + p.y()*m_size.width();
16 }
17 
18 void KDFrameBuffer::pushRect(KDRect rect, const KDColor * pixels) {
19  const KDColor * line = pixels;
20  for (KDCoordinate j=0; j<rect.height(); j++) {
21  KDPoint lineOffset = KDPoint(0, j);
22  memcpy(pixelAddress(rect.origin().translatedBy(lineOffset)),
23  line,
24  rect.width()*sizeof(KDColor));
25  line += rect.width();
26  }
27 }
28 
30  // Caution: this code is used very frequently
31  // It's worth optimizing!
32  KDColor * pixel = pixelAddress(rect.origin());
33  int lineDelta = m_size.width() - rect.width();
34  for (KDCoordinate j=0; j<rect.height(); j++) {
35  //KDColor * topLeftPixelAddress = pixelAddress(rect.origin().translatedBy(KDPoint(0,j)));
36  //*pixelAddress(rect.origin().translatedBy(KDPoint(i,j))) = color;
37  for (KDCoordinate i=0; i<rect.width(); i++) {
38  *pixel++ = color;
39  //*pixelAddress(rect.origin().translatedBy(KDPoint(i,j))) = color;
40  }
41  pixel += lineDelta;
42  }
43 }
44 
45 void KDFrameBuffer::pullRect(KDRect rect, KDColor * pixels) {
46  KDColor * line = pixels;
47  for (KDCoordinate j=0; j<rect.height(); j++) {
48  KDPoint lineOffset = KDPoint(0, j);
49  memcpy(line,
50  pixelAddress(rect.origin().translatedBy(lineOffset)),
51  rect.width()*sizeof(KDColor));
52  line += rect.width();
53  }
54 }
KDCoordinate y() const
Definition: point.h:11
void pushRectUniform(KDRect rect, KDColor color)
Definition: framebuffer.cpp:29
KDFrameBuffer(KDColor *pixels, KDSize size)
Definition: framebuffer.cpp:4
KDRect bounds()
Definition: framebuffer.cpp:10
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr KDCoordinate width() const
Definition: size.h:10
constexpr KDPoint KDPointZero
Definition: point.h:25
Definition: point.h:6
Definition: size.h:6
void pushRect(KDRect rect, const KDColor *pixels)
Definition: framebuffer.cpp:18
void pullRect(KDRect rect, KDColor *pixels)
Definition: framebuffer.cpp:45
Definition: rect.h:26
Definition: color.h:6
KDPoint origin() const
Definition: rect.h:38
KDCoordinate width() const
Definition: rect.h:39
KDCoordinate x() const
Definition: point.h:10
KDPoint translatedBy(KDPoint other) const
Definition: point.cpp:3
KDCoordinate height() const
Definition: rect.h:40
void * memcpy(void *dst, const void *src, size_t n)
Definition: memcpy.c:3