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

Last change on this file since 124 was 124, checked in by Sam Hocevar, 14 years ago
  • Get rid of ugly tabs and trailing spaces everywhere.
File size: 2.5 KB
Line 
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
12#include <stdio.h>
13#include <stdlib.h>
14
15#include "lbmread.hpp"
16#include "system.h"
17
18image *read_lbm(char *filename, palette *&pal)
19{
20  FILE *fp=fopen("/cam/amur/set/city/city1.lbm","rb");
21  char type[4];
22  image *im=NULL;
23  fread(type,1,4,fp);
24  if (memcmp(type,"FORM",4))
25  {
26    set_error(imNOT_SUPPORTED);
27    fclose(fp);
28    return NULL;
29  }
30  else
31  {
32    int32_t size=read_other_uint32(fp);
33    fread(type,1,4,fp);
34    if (memcmp(type,"PBM ",4))
35    {
36      set_error(imNOT_SUPPORTED);
37      fclose(fp);
38      return NULL;
39    }
40    else
41    {
42      int32_t ssize;
43      char stype[4];
44      int16_t w=0,h=0,x,y,tcolor,pagew,pageh;
45      char planes,masking,compr=0,padl,xa,ya;
46
47      while (ftell(fp)+4<size)
48      {
49    fread(stype,1,4,fp);
50    ssize=read_other_uint32(fp);
51        if (ssize &1) ssize++;            // specs say all chunks are padded by 2
52    if (!memcmp(stype,"BMHD",4))
53    {
54      w=read_other_uint16(fp);
55      h=read_other_uint16(fp);
56      x=read_other_uint16(fp);
57      y=read_other_uint16(fp);
58      planes=fgetc(fp);
59      masking=fgetc(fp);
60      compr=fgetc(fp);
61      padl=fgetc(fp);
62      tcolor=read_other_uint16(fp);
63      xa=fgetc(fp);
64      ya=fgetc(fp);
65      pagew=read_other_uint16(fp);
66      pageh=read_other_uint16(fp);
67    } else if (!memcmp(stype,"CMAP",4))
68    {
69      pal=new palette(256);
70      fread(pal->addr(),1,768,fp);
71    } else if (!memcmp(stype,"BODY",4) && w && h)  // make sure we read a BHMD before
72    {
73      if (im) delete im;  // shouldn't be two BODY's butjust in case...
74      im=new image(w,h);
75      int y;
76      if (!compr)
77      {
78        for (y=0;y<h;h++)
79          fread(im->scan_line(y),1,w,fp);
80      } else
81      {
82        for (y=0;y<h;y++)   
83        {
84          int c,i,n=0;
85          unsigned char *sl=im->scan_line(y);
86          do
87          {
88        c=fgetc(fp)&0xff;
89        if (c&0x80)
90        {
91          if (c!=0x80)
92          {
93            i=((~c)&0xff)+2;
94            c=fgetc(fp);
95            while (i--) sl[n++]=c;
96          }
97        }
98        else
99        {
100          i=c+1;
101          while (i--) sl[n++]=fgetc(fp);
102        }
103          } while (n<w);
104        }
105      }   
106    }
107    else
108      fseek(fp,ssize,SEEK_CUR);
109      }
110    }
111  }
112  fclose(fp);
113  if (!im) set_error(imFILE_CORRUPTED);
114  return im;
115}
116
117
Note: See TracBrowser for help on using the repository browser.