-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgfxwindow.c
87 lines (78 loc) · 2.79 KB
/
gfxwindow.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* gfxwindow.c
Simple GUI abstraction.
Part of the swftools package.
Copyright (c) 2005 Matthias Kramm <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifdef WIN32
#include "gfxwindow_win32.c"
#else
#include "gfxwindow_unix.c"
#endif
void gfxwindow_paste_image(gfxwindow_t*dest, image_t*src, int x,int y)
{
int width=src->width;
int height=src->height;
if(x+width > dest->width)
width = dest->width - x;
if(y+height > dest->height)
height = dest->height - y;
if(x<0 || y<0) {
fprintf(stderr, "negative coordinates not allowed in paste");
return;
}
if(width<=0 || height<=0) {
fprintf(stderr, "Area (%d,%d,%d,%d) is outside of (0,0,%d,%d)\n",
x, y, x+src->width, y+src->height, dest->width, dest->height);
return;
}
int startx = x;
int starty = y;
for(y=0;y<height;y++) {
unsigned char*dline = &dest->currentscr[(y+starty)*dest->width*4+startx*4];
RGBA*sline = &src->data[y*src->width];
for(x=0;x<width;x++) {
dline[x*4+0] = sline[x].r;
dline[x*4+1] = sline[x].g;
dline[x*4+2] = sline[x].b;
}
}
}
void gfxwindow_paste_bytearray(gfxwindow_t*dest, bytearray_t*src, int x,int y)
{
int width=src->width;
int height=src->height;
if(x+width > dest->width)
width = dest->width - x;
if(y+height > dest->height)
height = dest->height - y;
if(x<0 || y<0) {
fprintf(stderr, "negative coordinates not allowed in paste");
return;
}
if(width<=0 || height<=0) {
fprintf(stderr, "Area (%d,%d,%d,%d) is outside of (0,0,%d,%d)\n",
x, y, x+src->width, y+src->height, dest->width, dest->height);
return;
}
int startx = x;
int starty = y;
for(y=0;y<height;y++) {
unsigned char*dline = &dest->currentscr[(y+starty)*dest->width*4+startx*4];
unsigned char*sline = &src->data[y*src->width];
for(x=0;x<width;x++) {
dline[x*4+0] = (sline[x]<<0)&0xe0;
dline[x*4+1] = (sline[x]<<3)&0xe0;
dline[x*4+2] = (sline[x]<<6)&0xc0;
}
}
}