source: abuse/trunk/src/imlib/include.cpp @ 523

Last change on this file since 523 was 523, checked in by Sam Hocevar, 11 years ago

imlib: remove dead code.

File size: 1.8 KB
Line 
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
18void 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  {
39    fprintf(fp,"/* File produced by Satan Paint (c) 1994 Jonathan Clark */\n\n");
40    if (!append)
41    {
42      fprintf(fp,"unsigned char %s_palette[256*3] = {\n    ",tmp_name);
43      unsigned char *p=(unsigned char *)pal->addr();
44      for (i=0; i<768; i++,p++)
45      {
46    fprintf(fp,"%d",(int)*p);
47    if (i==767)
48        fprintf(fp,"};\n\n");
49    else
50        if (i%15==14)
51    fprintf(fp,",\n    ");
52        else fprintf(fp,", ");
53      }
54    }
55    vec2i size = im->Size();
56    fprintf(fp,"unsigned char %s[%d*%d]={\n    ",tmp_name, size.x, size.y);
57    int x,y,max=size.x*size.y-1;
58    for (y=0,i=0; y<size.y; y++)
59      for (x=0; x<size.x; x++,i++)
60      {
61        fprintf(fp,"%d",(int)im->Pixel(vec2i(x,y)));
62        if (i==max)
63          fprintf(fp,"};\n\n");
64        else
65          if (i%15==14)
66            fprintf(fp,",\n    ");
67          else fprintf(fp,", ");
68      }
69    fclose(fp);
70  }
71}
72
Note: See TracBrowser for help on using the repository browser.