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

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