1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | * |
---|
6 | * This software was released into the Public Domain. As with most public |
---|
7 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
8 | * Jonathan Clark. |
---|
9 | */ |
---|
10 | |
---|
11 | #include "config.h" |
---|
12 | |
---|
13 | #include "common.h" |
---|
14 | |
---|
15 | #include "include.h" |
---|
16 | #include "ctype.h" |
---|
17 | |
---|
18 | void write_include(image *im, palette *pal, char *filename, char *name) |
---|
19 | { |
---|
20 | char tmp_name[200]; |
---|
21 | strcpy(tmp_name,name); |
---|
22 | unsigned int j; |
---|
23 | int append=0,i; |
---|
24 | for (j=0; j<strlen(name); j++) |
---|
25 | if (toupper(tmp_name[j])<'A' || toupper(tmp_name[j])>'Z') |
---|
26 | tmp_name[j]='_'; |
---|
27 | |
---|
28 | FILE *fp=fopen(filename,"rb"); // see if the file already exsist |
---|
29 | if (fp) |
---|
30 | { |
---|
31 | fclose(fp); |
---|
32 | fp=fopen(filename,"ab"); // if so, append to the end and don't write the palette |
---|
33 | append=1; |
---|
34 | } |
---|
35 | else fp=fopen(filename,"wb"); |
---|
36 | |
---|
37 | if (!fp) |
---|
38 | set_error(imWRITE_ERROR); |
---|
39 | else |
---|
40 | { |
---|
41 | fprintf(fp,"/* File produced by Satan Paint (c) 1994 Jonathan Clark */\n\n"); |
---|
42 | if (!append) |
---|
43 | { |
---|
44 | fprintf(fp,"unsigned char %s_palette[256*3] = {\n ",tmp_name); |
---|
45 | unsigned char *p=(unsigned char *)pal->addr(); |
---|
46 | for (i=0; i<768; i++,p++) |
---|
47 | { |
---|
48 | fprintf(fp,"%d",(int)*p); |
---|
49 | if (i==767) |
---|
50 | fprintf(fp,"};\n\n"); |
---|
51 | else |
---|
52 | if (i%15==14) |
---|
53 | fprintf(fp,",\n "); |
---|
54 | else fprintf(fp,", "); |
---|
55 | } |
---|
56 | } |
---|
57 | vec2i size = im->Size(); |
---|
58 | fprintf(fp,"unsigned char %s[%d*%d]={\n ",tmp_name, size.x, size.y); |
---|
59 | int x,y,max=size.x*size.y-1; |
---|
60 | for (y=0,i=0; y<size.y; y++) |
---|
61 | for (x=0; x<size.x; x++,i++) |
---|
62 | { |
---|
63 | fprintf(fp,"%d",(int)im->pixel(x,y)); |
---|
64 | if (i==max) |
---|
65 | fprintf(fp,"};\n\n"); |
---|
66 | else |
---|
67 | if (i%15==14) |
---|
68 | fprintf(fp,",\n "); |
---|
69 | else fprintf(fp,", "); |
---|
70 | } |
---|
71 | } |
---|
72 | fclose(fp); |
---|
73 | } |
---|
74 | |
---|