Setup buildsystem for c apps
Added fbcp to repo Added setup-apps.sh Disable non runtable apps
This commit is contained in:
parent
9283caed3b
commit
2f16ff59b8
11
apps/c-src/CMakeLists.txt
Normal file
11
apps/c-src/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
SET(COMPILE_DEFINITIONS -Werror -Wall)
|
||||
|
||||
|
||||
set(CMAKE_C_FLAGS "-O3")
|
||||
|
||||
add_executable(fbcp fbcp.c)
|
||||
target_link_libraries(fbcp m)
|
||||
|
||||
add_executable(flicker flicker.c)
|
136
apps/c-src/fbcp.c
Normal file
136
apps/c-src/fbcp.c
Normal file
@ -0,0 +1,136 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/fb.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
volatile sig_atomic_t flag = 0;
|
||||
|
||||
void Error(const char * format, ...) {
|
||||
fprintf(stderr, "Error: ");
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
// fast and only approximate
|
||||
void DownsampleFrameBufferBGRA2RGB(uint8_t *in, int xin, int yin, uint8_t* out, int xout, int yout){
|
||||
int sx = xin/xout;
|
||||
int sy = yin/yout;
|
||||
int size = sx*sy;
|
||||
for(int y = 0; y != yout; y++){
|
||||
for(int x = 0; x != xout; x++){
|
||||
int xmin = x*xin/xout;
|
||||
int ymin = y*yin/yout;
|
||||
int xmax = xmin+sx;
|
||||
int ymax = ymin+sy;
|
||||
|
||||
int r = 0, g = 0, b = 0;
|
||||
int idx = xmin+ymin*xin;
|
||||
uint8_t *mem = in+4*idx;
|
||||
for (int yp = ymin; yp != ymax; yp++ ){
|
||||
for (int xp =xmin; xp != xmax; xp++ ){
|
||||
b += *mem++;
|
||||
g += *mem++;
|
||||
r += *mem++;
|
||||
mem++;
|
||||
}
|
||||
mem += 4*(xin-sx);
|
||||
}
|
||||
*out++ = r/size;
|
||||
*out++ = g/size;
|
||||
*out++ = b/size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SignalHandler(int sig){
|
||||
flag = 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
//DISPMANX_RESOURCE_HANDLE_T screen_resource;
|
||||
uint32_t image_prt;
|
||||
//VC_RECT_T rect1;
|
||||
int ret;
|
||||
int fbfd = 0;
|
||||
char *framebuffer_gbra = 0;
|
||||
|
||||
struct fb_var_screeninfo vinfo;
|
||||
struct fb_fix_screeninfo finfo;
|
||||
int serial;
|
||||
int x = atoi(argv[2]);
|
||||
int y = atoi(argv[3]);
|
||||
uint8_t * out_rgb = malloc(x*y*3+1);
|
||||
|
||||
signal(SIGINT, SignalHandler);
|
||||
|
||||
if (argc < 4){
|
||||
fprintf(stderr, "Wrong number of parameters, should be:\n\n");
|
||||
fprintf(stderr, " fbcp <framebuffer> <sizex> <sizey>\n\n");
|
||||
fprintf(stderr, "i.e. fbcp /dev/fb0\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
|
||||
fbfd = open(argv[1], O_RDWR);
|
||||
if (fbfd == -1) {
|
||||
Error("Unable to open display %s", argv[2]);
|
||||
goto clean1_1;
|
||||
}
|
||||
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
|
||||
Error("Unable to get display information");
|
||||
goto clean2;
|
||||
}
|
||||
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
|
||||
Error("Unable to get display information");
|
||||
goto clean2;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Display is %d x %d %dbps\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
|
||||
|
||||
if (vinfo.bits_per_pixel != 32){
|
||||
Error("Display has %i bits per pixel. This program only works for 32.", vinfo.bits_per_pixel);
|
||||
}
|
||||
|
||||
framebuffer_gbra = (char*) mmap(0, finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
|
||||
if (framebuffer_gbra <= 0) {
|
||||
Error("Unable to create framebuffer memory mapping");
|
||||
goto clean3;
|
||||
}
|
||||
|
||||
FILE *logfile = fopen("out.log", "w");
|
||||
int frame = 0;
|
||||
while(!flag) {
|
||||
|
||||
// vc_dispmanx_resource_read_data(screen_resource, &rect1, framebuffer_gbra, vinfo.xres * vinfo.bits_per_pixel / 8);
|
||||
fflush(logfile);
|
||||
uint8_t* out = out_rgb;
|
||||
*out++ = 1; // Begin of frame marker
|
||||
DownsampleFrameBufferBGRA2RGB(framebuffer_gbra, vinfo.xres, vinfo.yres, out, x, y);
|
||||
write(1, out_rgb+1, x*y*3);
|
||||
|
||||
frame++;
|
||||
}
|
||||
|
||||
clean4:
|
||||
munmap(framebuffer_gbra, finfo.smem_len);
|
||||
clean3:
|
||||
clean2:
|
||||
close(fbfd);
|
||||
clean1_1:
|
||||
clean1:
|
||||
exit:
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// Here I use a lcg RNG with a specificaly crafted period to enumerate all pixels
|
||||
// and color them by cycling a colormap in a randomish order
|
BIN
apps/flicker
Executable file
BIN
apps/flicker
Executable file
Binary file not shown.
38
config.py
38
config.py
@ -20,24 +20,26 @@ WebPort = 8000
|
||||
|
||||
# first app is always running in IDLE
|
||||
Apps = [
|
||||
{"guiname": "Colored noise", "name": "cnoise", "cmd": "apps/cnoise", "persistent": False},
|
||||
{"guiname": "Dual Moodlight", "name": "bimood", "cmd": "apps/bimood", "persistent": False},
|
||||
{"guiname": "Maze", "name": "maze", "cmd": "apps/maze", "persistent": False},
|
||||
{"guiname": "Dual Maze", "name": "dualmaze", "cmd": "apps/dualmaze", "persistent": False, "persistent": False},
|
||||
{"guiname": "Fibonacci Clock", "name": "fibonacci-clock", "cmd": "apps/fibonacci-clock.py"},
|
||||
{"guiname": "Predator & Prey", "name": "predprey", "cmd": "apps/predprey", "persistent": False},
|
||||
{"guiname": "IDLE", "name": "pixelflut", "cmd": "apps/idle.py", "persistent": False},
|
||||
{"guiname": "IDLE2", "name": "idlec", "cmd": "apps/idle2"},
|
||||
{"guiname": "Structure formation", "name": "swifthohenberg", "cmd": "apps/swifthohenberg.py", "persistent": False},
|
||||
{"guiname": "Flicker", "name": "flicker", "cmd": "apps/flicker"},
|
||||
{"guiname": "Pong", "name": "pong", "cmd": "apps/pong.py"},
|
||||
{"guiname": "YoutubeDL", "name": "youtubedl", "cmd": "apps/youtubedl.sh", "persistent": False},
|
||||
{"guiname": "Stream", "name": "stream", "cmd": "apps/stream.sh", "persistent": False},
|
||||
{"guiname": "Wget Video/Gif/Images", "name": "wget", "cmd": "apps/wget.sh", "persistent": False},
|
||||
{"guiname": "Tetris", "name": "tetris", "cmd": "apps/deckentetris/deckentetris.py", "persistent": False},
|
||||
{"guiname": "SkyScrapper", "name": "sky", "cmd": "apps/weather/main.py"},
|
||||
{"guiname": "Strobo", "name": "strobo", "cmd": "apps/strobo.py", "persistent": False},
|
||||
{"guiname": "Snake", "name": "snake", "cmd": "apps/snake.py", "persistent": False},
|
||||
{"guiname": "Show Framebuffer", "name": "fbcp", "cmd": ["apps/fbcp", "/dev/fb0"]},
|
||||
{"guiname": "Strobo", "name": "strobo", "cmd": "apps/strobo.py"},
|
||||
{"name": "pong", "cmd": "apps/pong.py"},
|
||||
{"name": "framebuffer", "cmd": ["apps/fbcp", "/dev/fb0"]},
|
||||
{"name": "gif", "cmd": "apps/gif.sh"},
|
||||
{"name": "colormap", "cmd": "apps/colormap.py"},
|
||||
|
||||
|
||||
#{"guiname": "Colored noise", "name": "cnoise", "cmd": "apps/cnoise", "persistent": False},
|
||||
#{"guiname": "Dual Moodlight", "name": "bimood", "cmd": "apps/bimood", "persistent": False},
|
||||
#{"guiname": "Maze", "name": "maze", "cmd": "apps/maze", "persistent": False},
|
||||
#{"guiname": "Dual Maze", "name": "dualmaze", "cmd": "apps/dualmaze", "persistent": False, "persistent": False},
|
||||
#{"guiname": "Fibonacci Clock", "name": "fibonacci-clock", "cmd": "apps/fibonacci-clock.py"},
|
||||
#{"guiname": "Predator & Prey", "name": "predprey", "cmd": "apps/predprey", "persistent": False},
|
||||
#{"guiname": "Stream", "name": "stream", "cmd": "apps/stream.sh", "persistent": False},
|
||||
#{"guiname": "Wget Video/Gif/Images", "name": "wget", "cmd": "apps/wget.sh", "persistent": False},
|
||||
#{"guiname": "Tetris", "name": "tetris", "cmd": "apps/deckentetris/deckentetris.py", "persistent": False},
|
||||
#{"guiname": "SkyScrapper", "name": "sky", "cmd": "apps/weather/main.py"},
|
||||
#{"guiname": "Strobo", "name": "strobo", "cmd": "apps/strobo.py", "persistent": False},
|
||||
#{"guiname": "Snake", "name": "snake", "cmd": "apps/snake.py", "persistent": False},
|
||||
#{"name": "gif", "cmd": "apps/gif.sh"},
|
||||
#{"name": "colormap", "cmd": "apps/colormap.py"},
|
||||
]
|
||||
|
18
setup-apps.sh
Executable file
18
setup-apps.sh
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
|
||||
# Set executable attributes
|
||||
chmod +x apps/pong.py
|
||||
chmod +x apps/swifthohenberg.py
|
||||
chmod +x apps/strobo.py
|
||||
chmod +x apps/youtubedl.sh
|
||||
|
||||
|
||||
# build c apps
|
||||
mkdir -p build/c
|
||||
pushd build/c
|
||||
cmake ../../apps/c-src
|
||||
make
|
||||
popd
|
||||
mv build/c/fbcp apps/
|
||||
mv build/c/flicker apps/
|
Loading…
Reference in New Issue
Block a user