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

Last change on this file since 124 was 124, checked in by Sam Hocevar, 11 years ago
  • Get rid of ugly tabs and trailing spaces everywhere.
File size: 3.3 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
14#include "macs.hpp"
15#include "image.hpp"
16#include "palette.hpp"
17#include "video.hpp"
18#include "system.h"
19
20image *read_glfont(char *fn)
21{
22  image *im,*sub;
23  uint16_t length,y;
24  uint8_t size,first,width,height,gsize,last;
25  FILE *fp;
26  fp=fopen(fn,"rb");
27  if (!fp) return NULL;
28  fread(&length,1,2,fp);  length=uint16_to_local(length);
29  fread(&size,1,1,fp);
30  fread(&first,1,1,fp);
31  if (size+first>255) { set_error(imFILE_CORRUPTED); fclose(fp); return NULL; }
32  fread(&width,1,1,fp);
33  fread(&height,1,1,fp);
34  fread(&gsize,1,1,fp);
35  make_block(sizeof(image));
36  im=new image(width*32,height*8);
37  make_block(sizeof(image));
38  sub=new image(width,height);
39  im->clear();  // in case all the fonts aren't in the file, clear extra area
40  last=first+size-1;
41  while (first<=last)
42  {
43    sub->lock();
44    for (y=0;(int)y<(int)height;y++)
45    {
46      fread(sub->scan_line(y),1,gsize/height,fp);
47      sub->unpack_scanline(y);
48    }
49    sub->unlock();
50    sub->put_image(im,(first%32)*width,(first/32)*height);
51    first++;
52  }
53  delete sub;
54  return im;
55}
56
57image *read_pic(char *fn, palette *&pal)
58{
59  image *im = NULL;
60  char x[4],bpp;
61  uint8_t *sl=NULL,esc,c,n,marker,vmode;
62  uint16_t w,h,len,bufsize,blocks,sn,esize,edesc;
63  int xx,yy;
64  FILE *fp;
65  fp=fopen(fn,"rb");
66
67  fread(&x[0],1,2,fp);
68  fread(&w,1,2,fp);
69  fread(&h,1,2,fp);
70  w=uint16_to_local(w);  h=uint16_to_local(h);
71  fread(x,1,4,fp);
72  fread(&bpp,1,1,fp);
73  fread(&marker,1,1,fp);
74  if (marker!=0xff)
75  { fclose(fp); set_error(imFILE_CORRUPTED); return NULL; }
76
77  im = new image(w, h);
78
79  fread(&vmode,1,1,fp);
80  fread(&edesc,1,2,fp);
81  edesc=uint16_to_local(edesc);
82  fread(&esize,1,2,fp);
83  esize=uint16_to_local(esize);
84  if (esize==768 && !pal)
85  { pal=new palette(1<<bpp);
86    fread(pal->addr(),1,(1<<bpp)*3,fp);
87    pal->shift(2);
88  }
89  else if (esize)
90    fseek(fp,esize,SEEK_CUR);
91  fread(&blocks,1,2,fp);
92  blocks=uint16_to_local(blocks);
93
94  yy=h; xx=w;
95
96  im->lock();
97
98  while (blocks-- && w>=1 && yy>=0)
99  {
100    fread(&bufsize,1,2,fp);
101    bufsize=uint16_to_local(bufsize);
102    fread(&len,1,2,fp);
103    len=uint16_to_local(len);
104    fread(&esc,1,1,fp);
105    while (yy>=0 && len)
106    {
107      fread(&c,1,1,fp);
108      if (c!=esc)
109      {
110    if (xx>=w) { yy--; xx=0; sl=im->scan_line(yy);
111    if (yy==h) printf("bufsize=%d\n",bufsize); CHECK(yy<h); }
112    sl[xx++]=c;     len--;
113      }
114      else
115      {
116    fread(&n,1,1,fp);
117    if (n!=0)
118    {
119      fread(&c,1,1,fp);
120      while (n-- && yy>=0 && len)
121      {
122        if (xx>=w) { yy--; xx=0; sl=im->scan_line(yy);
123          if (yy==h) printf("bufsize=%d\n",bufsize); CHECK(yy<h); }
124        sl[xx++]=c; len--;
125      }
126    }
127    else
128    {
129      fread(&sn,1,2,fp);
130      sn=uint16_to_local(sn);
131      fread(&c,1,1,fp);
132      while (sn-- && yy>=0 && len)
133      {
134        if (xx>=w) { yy--; xx=0; sl=im->scan_line(yy); CHECK(yy<h); }
135        sl[xx++]=c; len--;
136      }
137    }
138
139      }
140    }
141  }
142
143  im->unlock();
144
145  fclose(fp);
146  return im;
147}
148
149image *read_clp(char *fn)
150{
151  palette *pal=NULL;
152  image *im=read_pic(fn,pal);
153  if (pal) delete pal;
154  return im;
155}
156
Note: See TracBrowser for help on using the repository browser.