Blame view

build5/epsilon-master/kandinsky/src/framebuffer.cpp 1.61 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  #include <kandinsky/framebuffer.h>
  #include <string.h>
  
  KDFrameBuffer::KDFrameBuffer(KDColor * pixels, KDSize size) :
    m_pixels(pixels),
    m_size(size)
  {
  }
  
  KDRect KDFrameBuffer::bounds() {
    return KDRect(KDPointZero, m_size);
  }
  
  KDColor * KDFrameBuffer::pixelAddress(KDPoint p) const {
      return m_pixels + p.x() + p.y()*m_size.width();
  }
  
  void KDFrameBuffer::pushRect(KDRect rect, const KDColor * pixels) {
    const KDColor * line = pixels;
    for (KDCoordinate j=0; j<rect.height(); j++) {
      KDPoint lineOffset = KDPoint(0, j);
      memcpy(pixelAddress(rect.origin().translatedBy(lineOffset)),
          line,
          rect.width()*sizeof(KDColor));
      line += rect.width();
    }
  }
  
  void KDFrameBuffer::pushRectUniform(KDRect rect, KDColor color) {
    // Caution: this code is used very frequently
    // It's worth optimizing!
    KDColor * pixel = pixelAddress(rect.origin());
    int lineDelta = m_size.width() - rect.width();
    for (KDCoordinate j=0; j<rect.height(); j++) {
      //KDColor * topLeftPixelAddress = pixelAddress(rect.origin().translatedBy(KDPoint(0,j)));
      //*pixelAddress(rect.origin().translatedBy(KDPoint(i,j))) = color;
      for (KDCoordinate i=0; i<rect.width(); i++) {
        *pixel++ = color;
        //*pixelAddress(rect.origin().translatedBy(KDPoint(i,j))) = color;
      }
      pixel += lineDelta;
    }
  }
  
  void KDFrameBuffer::pullRect(KDRect rect, KDColor * pixels) {
    KDColor * line = pixels;
    for (KDCoordinate j=0; j<rect.height(); j++) {
      KDPoint lineOffset = KDPoint(0, j);
      memcpy(line,
          pixelAddress(rect.origin().translatedBy(lineOffset)),
          rect.width()*sizeof(KDColor));
      line += rect.width();
    }
  }