forked from jp3141/KindleThermometer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitblt.c
executable file
·66 lines (62 loc) · 2.56 KB
/
bitblt.c
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
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
//#include <inttypes.h>
#define FRAMEBUFFER_NAME "/dev/fb0"
#define fb_X_Size 600L
#define fb_Y_Size 800
/*
600
+--------------------------------------+
| ^ |
| | |
| y offset |
| | |
| v |
|<---x---->############# |
| offset ############# |
| ############# |8
| ############# |0
| ## SOURCE X## |0
| ############# |
| ############# |
| |
| |
| |
| |
| |
+--------------------------------------+
*/
char sourceLine[fb_Y_Size]; // 800 is big enough
int main (int argc, char *argv[]) {
int i=0;
long seek;
short sourceXY[2]; // written in LSB,MSB order
int X_offset, Y_offset;
if (argc < 4) {printf("Usage: %s image_file X Y\nwill write image_file to framebuffer at X, Y\nFirst 2 words of gray scale image_file are X and Y dimensions\n", argv[0]);}
printf("argc = %i\n", argc);
printf("This: %s\n", argv[i++]);
printf("Image: %s\n", argv[i++]);
printf("X pos: %s\n", argv[i++]);
printf("Y pos: %s\n", argv[i++]);
X_offset = atoi(argv[2]);
Y_offset = atoi(argv[3]);
FILE *framebuffer, *source_Image;
framebuffer=fopen(FRAMEBUFFER_NAME, "r+");
printf("short int is %i\n", sizeof(short int));
source_Image=fopen(argv[1], "r");
fread(sourceXY, sizeof(short int), 2, source_Image); // get X, Y size (assumes contiguous in memory)
//fread(& sourceXY[1], sizeof(short int), 1, source_Image); // get Y size
//printf("At %i\n", ftell(source_Image));
printf("pointer=%p\n", &source_Image);
printf("X size = %hi, Y size = %hi\n", sourceXY[0], sourceXY[1]);
for (int iLine=0; iLine < sourceXY[1]; iLine++) { // do each line
//fseek(source_Image, (long int) 4+sourceXY[0]*iLine, SEEK_SET); // not needed since reading sequentially
fread(sourceLine, (size_t) sourceXY[0], 1, source_Image); // read 1 line of X size
for (i=0; i < sourceXY[0]; i++) sourceLine[i]=~sourceLine[i];
fseek(framebuffer, (long) (X_offset + (Y_offset+iLine)*fb_X_Size), SEEK_SET);
fwrite(sourceLine, (size_t) sourceXY[0], 1, framebuffer);
}
fclose(framebuffer);
fclose(source_Image);
printf("Done\n");
}