Numworks Epsilon  1.4.1
Graphing Calculator Operating System
display.cpp
Go to the documentation of this file.
1 #include <ion.h>
2 #include <kandinsky.h>
3 #include <stdlib.h>
4 #include <png.h>
5 #include "display.h"
6 
7 namespace Ion {
8 namespace Display {
9 
10 static bool sFrameBufferActive = false;
13 
14 void pushRect(KDRect r, const KDColor * pixels) {
15  if (sFrameBufferActive) {
16  sFrameBuffer.pushRect(r, pixels);
17  }
18 }
19 
21  if (sFrameBufferActive) {
22  sFrameBuffer.pushRectUniform(r, c);
23  }
24 }
25 
26 void pullRect(KDRect r, KDColor * pixels) {
27  if (sFrameBufferActive) {
28  sFrameBuffer.pullRect(r, pixels);
29  }
30 }
31 
32 void waitForVBlank() {
33 }
34 
35 }
36 }
37 
38 namespace Ion {
39 namespace Display {
40 namespace Blackbox {
41 
42 void setFrameBufferActive(bool enabled) {
43  sFrameBufferActive = enabled;
44 }
45 
46 typedef struct {
50 } pixel_t;
51 
52 void writeFrameBufferToFile(const char * filename) {
53  FILE * file = fopen(filename, "wb"); // Write in binary mode
54  //ENSURE(file != NULL, "Opening file %s", filename);
55 
56  png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
57  //ENSURE(png != NULL, "Allocating PNG write structure");
58 
59  png_infop info = png_create_info_struct(png);
60  //ENSURE(info != NULL, "Allocating info structure");
61 
62  png_init_io(png, file);
63 
64  png_set_IHDR(png, info,
66  8, // Number of bits per channel
67  PNG_COLOR_TYPE_RGB,
68  PNG_INTERLACE_NONE,
69  PNG_COMPRESSION_TYPE_DEFAULT,
70  PNG_FILTER_TYPE_DEFAULT);
71 
72  png_write_info(png, info);
73 
74  static_assert(sizeof(pixel_t) == 3, "pixel_t shall be 3 bytes long (RGB888 format)");
76  for (int j=0;j<Ion::Display::Height;j++) {
77  for (int i=0; i<Ion::Display::Width; i++) {
78  KDColor c = sPixels[i+Ion::Display::Width*j];
79  row[i].red = c.red();
80  row[i].green = c.green();
81  row[i].blue = c.blue();
82  }
83  png_write_row(png, (png_bytep)row);
84  }
85  free(row);
86 
87  png_write_end(png, NULL);
88 
89  png_free_data(png, info, PNG_FREE_ALL, -1); // -1 = all items
90  png_destroy_write_struct(&png, (png_infopp)NULL);
91  fclose(file);
92 }
93 
94 }
95 }
96 }
void pushRectUniform(KDRect rect, KDColor color)
Definition: framebuffer.cpp:29
constexpr int Width
Definition: display.h:26
void Display(const char *input)
Definition: display.cpp:11
void pullRect(KDRect r, KDColor *pixels)
Definition: display.cpp:26
LIBA_BEGIN_DECLS void free(void *ptr)
Definition: malloc.c:33
void pushRect(KDRect r, const KDColor *pixels)
Definition: display.cpp:14
unsigned char uint8_t
Definition: stdint.h:4
Definition: size.h:6
c(generic_all_nodes)
#define NULL
Definition: stddef.h:4
void pushRect(KDRect rect, const KDColor *pixels)
Definition: framebuffer.cpp:18
void pullRect(KDRect rect, KDColor *pixels)
Definition: framebuffer.cpp:45
void setFrameBufferActive(bool enabled)
Definition: display.cpp:42
void writeFrameBufferToFile(const char *filename)
Definition: display.cpp:52
void * malloc(size_t size)
Definition: malloc.c:44
Definition: rect.h:26
Definition: color.h:6
void FILE
Definition: stdio.h:8
Definition: backlight.h:6
void pushRectUniform(KDRect r, KDColor c)
Definition: display.cpp:20
constexpr int Height
Definition: display.h:27
void waitForVBlank()
Definition: display.cpp:32