Skip to content

Instantly share code, notes, and snippets.

@NeoCat
Created October 20, 2012 16:32
Show Gist options
  • Save NeoCat/3923865 to your computer and use it in GitHub Desktop.
Save NeoCat/3923865 to your computer and use it in GitHub Desktop.
Kobo Screen captute via HTTP
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
struct __attribute__((packed)) bitmapFileHeader {
unsigned char bfType[2];
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
};
struct __attribute__((packed)) bitmapInfoHeader {
unsigned int biSize;
unsigned int biWidth;
unsigned int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
unsigned int biXPixPerMeter;
unsigned int biYPixPerMeter;
unsigned int biClrUsed;
unsigned int biCirImportant;
};
static unsigned short pix565[600][800];
int main(void)
{
unsigned int w = 600, h = 800, x, y;
int fhsize = sizeof(struct bitmapFileHeader);
int ihsize = sizeof(struct bitmapInfoHeader);
struct bitmapFileHeader fileHeader =
{"BM", fhsize+ihsize+w*h*3, 0, 0, fhsize+ihsize};
struct bitmapInfoHeader infoHeader =
{ihsize, w, h, 1, 24, 0, w*h*3, 0, 0, 0, 0};
int fd, ret;
fd = open("/dev/fb0", O_RDONLY);
ret = read(fd, pix565, sizeof(pix565));
if (ret < 0) {
perror("read error");
exit(0);
}
puts("HTTP/1.0 200 OK");
puts("Content-Type: image/bmp");
puts("");
fwrite(&fileHeader, sizeof(fileHeader), 1, stdout);
fwrite(&infoHeader, sizeof(infoHeader), 1, stdout);
for (y = 0; y < h; y++) for (x = 0; x < w; x++) {
unsigned short val = pix565[w-x-1][h-y-1]; // rotated
unsigned short r5 = (val>>11) & 0x1F; // 5 bits
unsigned short g6 = (val>> 5) & 0x3F; // 6 bits
unsigned short b5 = (val ) & 0x1F; // 5 bits
printf("%c%c%c",
(b5<<3)+(b5>>2), (g6<<2)+(g6>>4), (r5<<3)+(r5>>2));
}
return 0;
}
# <service_name> <sock_type> <proto> <flags> <user> <server_path> <args>
21 stream tcp nowait root /bin/busybox ftpd -w -S /
23 stream tcp nowait root /bin/busybox telnetd -i
80 stream tcp nowait root /usr/bin/fb2bmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment