1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include "macs.hpp"
#include "image.hpp"
#include "palette.hpp"
#include "video.hpp"
#include "system.h"
#include <stdio.h>
image *read_glfont(char *fn)
{
image *im,*sub;
unsigned short length,y;
unsigned char size,first,width,height,gsize,last;
FILE *fp;
fp=fopen(fn,"rb");
if (!fp) return NULL;
fread(&length,1,2,fp); length=int_to_local(length);
fread(&size,1,1,fp);
fread(&first,1,1,fp);
if (size+first>255) { set_error(imFILE_CORRUPTED); fclose(fp); return NULL; }
fread(&width,1,1,fp);
fread(&height,1,1,fp);
fread(&gsize,1,1,fp);
make_block(sizeof(image));
im=new image(width*32,height*8);
make_block(sizeof(image));
sub=new image(width,height);
im->clear(); // in case all the fonts aren't in the file, clear extra area
last=first+size-1;
while (first<=last)
{
for (y=0;(int)y<(int)height;y++)
{
fread(sub->scan_line(y),1,gsize/height,fp);
sub->unpack_scanline(y);
}
sub->put_image(im,(first%32)*width,(first/32)*height);
first++;
}
delete sub;
return im;
}
image *read_pic(char *fn, palette *&pal)
{
image *im;
char x[4],bpp;
unsigned char *sl,esc,c,n,marker,vmode;
unsigned short w,h,len,bufsize,blocks,sn,esize,edesc;
int xx,yy;
FILE *fp;
im=NULL;
fp=fopen(fn,"rb");
fread(&x[0],1,2,fp);
fread(&w,1,2,fp);
fread(&h,1,2,fp);
w=int_to_local(w); h=int_to_local(h);
fread(x,1,4,fp);
fread(&bpp,1,1,fp);
fread(&marker,1,1,fp);
if (marker!=0xff)
{ fclose(fp); set_error(imFILE_CORRUPTED); return NULL; }
im=new image(w,h);
fread(&vmode,1,1,fp);
fread(&edesc,1,2,fp);
edesc=int_to_local(edesc);
fread(&esize,1,2,fp);
esize=int_to_local(esize);
if (esize==768 && !pal)
{ pal=new palette(1<<bpp);
fread(pal->addr(),1,(1<<bpp)*3,fp);
pal->shift(2);
}
else if (esize)
fseek(fp,esize,SEEK_CUR);
fread(&blocks,1,2,fp);
blocks=int_to_local(blocks);
yy=h; xx=w;
while (blocks-- && w>=1 && yy>=0)
{
fread(&bufsize,1,2,fp);
bufsize=int_to_local(bufsize);
fread(&len,1,2,fp);
len=int_to_local(len);
fread(&esc,1,1,fp);
while (yy>=0 && len)
{
fread(&c,1,1,fp);
if (c!=esc)
{
if (xx>=w) { yy--; xx=0; sl=im->scan_line(yy);
if (yy==h) printf("bufsize=%d\n",bufsize); CHECK(yy<h); }
sl[xx++]=c; len--;
}
else
{
fread(&n,1,1,fp);
if (n!=0)
{
fread(&c,1,1,fp);
while (n-- && yy>=0 && len)
{
if (xx>=w) { yy--; xx=0; sl=im->scan_line(yy);
if (yy==h) printf("bufsize=%d\n",bufsize); CHECK(yy<h); }
sl[xx++]=c; len--;
}
}
else
{
fread(&sn,1,2,fp);
sn=int_to_local(sn);
fread(&c,1,1,fp);
while (sn-- && yy>=0 && len)
{
if (xx>=w) { yy--; xx=0; sl=im->scan_line(yy); CHECK(yy<h); }
sl[xx++]=c; len--;
}
}
}
}
}
fclose(fp);
return im;
}
image *read_clp(char *fn)
{
palette *pal=NULL;
image *im=read_pic(fn,pal);
if (pal) delete pal;
return im;
}
|