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

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

ps3: make everything compile on the PS3. Of course, nothing links yet
because so much support is missing.

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
[555]7 *  domain software, no warranty is made or implied by Crack dot Com, by
8 *  Jonathan Clark, or by Sam Hocevar.
[56]9 */
10
[555]11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
[56]14
[512]15#include "common.h"
16
[481]17#include "include.h"
[2]18#include "ctype.h"
19
20void write_include(image *im, palette *pal, char *filename, char *name)
21{
22  char tmp_name[200];
23  strcpy(tmp_name,name);
[4]24  unsigned int j;
25  int append=0,i;
[494]26  for (j=0; j<strlen(name); j++)
[2]27    if (toupper(tmp_name[j])<'A' || toupper(tmp_name[j])>'Z')
28      tmp_name[j]='_';
29
30  FILE *fp=fopen(filename,"rb");  // see if the file already exsist
31  if (fp)
32  {
33    fclose(fp);
34    fp=fopen(filename,"ab");  // if so, append to the end and don't write the palette
35    append=1;
36  }
37  else fp=fopen(filename,"wb");
38
[523]39  if (fp)
[2]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();
[494]46      for (i=0; i<768; i++,p++)
[2]47      {
[124]48    fprintf(fp,"%d",(int)*p);
49    if (i==767)
[2]50        fprintf(fp,"};\n\n");
[124]51    else
[2]52        if (i%15==14)
[124]53    fprintf(fp,",\n    ");
[2]54        else fprintf(fp,", ");
55      }
56    }
[512]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++)
[2]62      {
[515]63        fprintf(fp,"%d",(int)im->Pixel(vec2i(x,y)));
[2]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      }
[523]71    fclose(fp);
[2]72  }
73}
74
Note: See TracBrowser for help on using the repository browser.