forked from aligrudi/fbpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrsnap.c
43 lines (37 loc) · 753 Bytes
/
scrsnap.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
#include <stdlib.h>
#include <string.h>
#include "draw.h"
#define NSCRS 128
static void *scrs[NSCRS];
void scr_snap(int idx)
{
int rowsz = FBM_BPP(fb_mode()) * fb_cols();
int i;
if (idx < NSCRS && !scrs[idx])
scrs[idx] = malloc(fb_rows() * rowsz);
if (idx < NSCRS && scrs[idx])
for (i = 0; i < fb_rows(); i++)
memcpy(scrs[idx] + i * rowsz, fb_mem(i), rowsz);
}
void scr_free(int idx)
{
if (idx < NSCRS) {
free(scrs[idx]);
scrs[idx] = NULL;
}
}
int scr_load(int idx)
{
int rowsz = FBM_BPP(fb_mode()) * fb_cols();
int i;
if (idx < NSCRS && scrs[idx])
for (i = 0; i < fb_rows(); i++)
memcpy(fb_mem(i), scrs[idx] + i * rowsz, rowsz);
return 0;
}
void scr_done(void)
{
int i;
for (i = 0; i < NSCRS; i++)
free(scrs[i]);
}