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

Last change on this file since 494 was 494, checked in by Sam Hocevar, 12 years ago

style: remove trailing spaces, fix copyright statements.

File size: 1.8 KB
RevLine 
[56]1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
[494]4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
[56]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
[481]13#include "include.h"
[2]14#include "ctype.h"
15
16void write_include(image *im, palette *pal, char *filename, char *name)
17{
18  char tmp_name[200];
19  strcpy(tmp_name,name);
[4]20  unsigned int j;
21  int append=0,i;
[494]22  for (j=0; j<strlen(name); j++)
[2]23    if (toupper(tmp_name[j])<'A' || toupper(tmp_name[j])>'Z')
24      tmp_name[j]='_';
25
26  FILE *fp=fopen(filename,"rb");  // see if the file already exsist
27  if (fp)
28  {
29    fclose(fp);
30    fp=fopen(filename,"ab");  // if so, append to the end and don't write the palette
31    append=1;
32  }
33  else fp=fopen(filename,"wb");
34
35  if (!fp)
36    set_error(imWRITE_ERROR);
37  else
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();
[494]44      for (i=0; i<768; i++,p++)
[2]45      {
[124]46    fprintf(fp,"%d",(int)*p);
47    if (i==767)
[2]48        fprintf(fp,"};\n\n");
[124]49    else
[2]50        if (i%15==14)
[124]51    fprintf(fp,",\n    ");
[2]52        else fprintf(fp,", ");
53      }
54    }
55    fprintf(fp,"unsigned char %s[%d*%d]={\n    ",tmp_name,
[124]56            im->width(),im->height());
[2]57    int x,y,max=im->width()*im->height()-1;
[494]58    for (y=0,i=0; y<im->height(); y++)
59      for (x=0; x<im->width(); x++,i++)
[2]60      {
61        fprintf(fp,"%d",(int)im->pixel(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  }
70  fclose(fp);
71}
72
Note: See TracBrowser for help on using the repository browser.