/* Output from p2c, the Pascal-to-C translator */
/* From input file "bm2font.pas" */
/*1:*/
#include "p2c.h"
/* p2c: bm2font.pas, line 1:
* Note: Unexpected name "texfile" in program header [262] */
/* p2c: bm2font.pas, line 1:
* Note: Unexpected name "tfmfile" in program header [262] */
/* p2c: bm2font.pas, line 1:
* Note: Unexpected name "pxlfile" in program header [262] */
/* p2c: bm2font.pas, line 1:
* Note: Unexpected name "bitmap" in program header [262] */
/* p2c: bm2font.pas, line 1:
* Note: Unexpected name "tmpfil" in program header [262] */
/*logfile,*/
typedef uchar ebts;
typedef short halfk;
typedef long dynlong[52][129];
typedef unsigned short dynword[52][129];
typedef short korbyte[511];
typedef short spreadbyte[256];
/*55:*/
typedef unsigned short pxlstr;
/*:9*/
/*10:*/
Static Void korrfont()
{
uchar i, j;
i = strpos2(font, "/", 1);
while (i > 0) {
strdelete((Anyptr)font, 1, i);
i = strpos2(font, "/", 1);
}
j = strlen(font);
i = strpos2(font, ".", 1);
if (i != 0)
strdelete((Anyptr)font, i, j - i + 1);
if (strlen(font) > 7)
font[7] = '\0';
}
Local unsigned short tiftwobyte(ba, LINK)
unsigned short ba;
struct LOC_tifint *LINK;
{
if (LINK->le)
return ((unsigned short)LINK->tb[ba] + (unsigned short)LINK->tb[ba + 1] * 256);
else
return ((unsigned short)(LINK->tb[ba] * 256) +
(unsigned short)LINK->tb[ba + 1]);
}
/*22:*/
Static Void tifint()
{ /*:23*/
struct LOC_tifint V;
unsigned short i, j, l, m, tl;
long ll;
uchar tp;
boolean strips, tiffrgb;
unsigned short ttype;
long tiftemp;
ebts tiffbuf[3];
unsigned short FORLIM;
uchar FORLIM1;
unsigned short FORLIM2;
/*24:*/
strips = false;
tl = fread(V.tb, 1, sizeof(uchar) * 1199, bitmap);
V.le = (V.tb[1] == 'I');
ll = tiflong(4, &V);
if (ll > 900) {
printf("I can't digest this\n");
_Escape(0);
}
l = ll;
m = tiftwobyte(l, &V);
l += 2;
for (i = 1; i <= m; i++) {
j = tiftwobyte(l, &V);
ttype = tiftwobyte(l + 2, &V);
if (ttype == 3)
tiftemp = tifword(l + 8, &V);
else
tiftemp = tiflong(l + 8, &V);
switch (j) {
unsigned short a, g, hi, vi, vh, hr, vr;
short merk, ic, codegif, i;
ebts_ colmap, b, col, bpp;
ebts_ gpal[256][3];
unsigned short *codtab;
unsigned short folge, minhell, maxhell;
uchar *anf;
Char hexbyte[7];
short FORLIM;
/*29:*/
memcpy(V.ioff, ioff, sizeof(ilaced));
memcpy(V.ijump, ijump, sizeof(ilaced));
printf("Decoding GIF file\n");
V.logvr = 0;
V.codesav = 0;
V.lvr = 0;
minhell = 9999;
maxhell = 0;
codtab = (unsigned short *)Malloc(sizeof(tabcode));
anf = (uchar *)Malloc(sizeof(bytecod));
opentempfile();
*hexbyte = '\0';
for (i = 1; i <= 3; i++) {
sprintf(hexbyte + strlen(hexbyte), "%c", getgif(&V));
/* p2c: bm2font.pas, line 313:
* Note: Possible string truncation in assignment [145] */
}
if (strcmp(hexbyte, "GIF")) {
printf("This file is NOT a gif file!\n");
_Escape(0);
}
for (i = 1; i <= 3; i++) {
sprintf(hexbyte + strlen(hexbyte), "%c", getgif(&V));
/* p2c: bm2font.pas, line 315:
* Note: Possible string truncation in assignment [145] */
}
if (strcmp(hexbyte, "GIF87a") && strcmp(hexbyte, "GIF89a")) {
printf("The program only supports version 87a and 89a!\n");
_Escape(0);
}
b = getgif(&V);
hr = b;
b = getgif(&V);
hr += b * 256;
b = getgif(&V);
vr = b;
b = getgif(&V);
vr += b * 256;
if (hr == 640 && vr == 350) {
xratio = 3;
yratio = 4;
}
b = getgif(&V);
colmap = b & 128;
colmap >>= 7;
col = b & 112;
col >>= 4;
col++;
bitspsam = b & 7;
bitspsam++;
b = getgif(&V);
b = getgif(&V);
if (colmap == 1) { /*30:*/
g = 1;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
g *= 2;
for (i = 0; i < g; i++) {
for (j = 0; j <= 2; j++)
gpal[i][j] = getgif(&V);
if (cmyk) {
sepcols(gpal[i][0], gpal[i][1], gpal[i][2]);
if (cyan)
V.hell[i] = 255 - colcyan;
if (magenta)
V.hell[i] = 255 - colmagenta;
if (yellow)
V.hell[i] = 255 - colyellow;
if (black)
V.hell[i] = 255 - colblack;
bhell[V.hell[i]] = 255 - colblack;
} else
V.hell[i] = (long)floor(gpal[i][0] * 0.287 + gpal[i][1] * 0.589 + gpal[i]
[2] * 0.114 + 0.5);
if (V.hell[i] > maxhell)
maxhell = V.hell[i];
}
if (bitspsam > 1) {
for (i = 0; i < g; i++)
V.hell[i] = (long)floor((double)V.hell[i] / maxhell * (g - 1) + 0.5);
for (i = 0; i < g; i++)
bhell[i] = (long)floor((double)bhell[i] / maxhell * (g - 1) + 0.5);
} else {
V.hell[0] = 0;
V.hell[1] = 1;
bhell[0] = 0;
bhell[1] = 1;
}
}
b = getgif(&V);
if (b != 44) { /*31:*/
while (b != 44) { /*:31*/
b = getgif(&V);
switch (b) {
case 249:
a = getgif(&V);
for (g = 0; g <= a; g++)
b = getgif(&V);
break;
case 254:
a = getgif(&V);
while (a != 0) {
for (g = 0; g <= a; g++)
b = getgif(&V);
a = b;
if (P_eof(bitmap)) {
printf("file ended while looking for image\n");
_Escape(0);
}
}
break;
case 1:
case 255:
a = getgif(&V);
for (g = 1; g <= a; g++)
b = getgif(&V);
a = getgif(&V);
while (a != 0) {
for (g = 0; g <= a; g++)
b = getgif(&V);
a = b;
if (P_eof(bitmap)) {
printf("file ended while looking for image\n");
_Escape(0);
}
}
break;
}
b = getgif(&V);
if (P_eof(bitmap)) {
printf("file ended while looking for image\n");
_Escape(0);
}
}
}
b = getgif(&V);
hi = b;
b = getgif(&V);
hi += b * 256;
b = getgif(&V);
vi = b;
b = getgif(&V);
vi += b * 256;
b = getgif(&V);
V.hh = b;
b = getgif(&V);
V.hh += b * 256;
b = getgif(&V);
vh = b;
b = getgif(&V);
vh += b * 256;
if (V.hh != hr || vh != vr)
printf("No fragments supported!\n");
V.linebytes = (V.hh * bitspsam + (bitspsam - 1)+7) / 8;
if (V.linebytes > 3000) {
V.linebytes = 3000;
printf("Sorry, had to cut picture to a width of 3000 bytes\n");
}
b = getgif(&V);
col = b & 128;
col >>= 7;
if (col != 0) {
bitspsam = b & 7;
bitspsam++; /*30:*/
g = 1;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
g *= 2;
for (i = 0; i < g; i++) {
for (j = 0; j <= 2; j++)
gpal[i][j] = getgif(&V);
if (cmyk) {
sepcols(gpal[i][0], gpal[i][1], gpal[i][2]);
if (cyan)
V.hell[i] = 255 - colcyan;
if (magenta)
V.hell[i] = 255 - colmagenta;
if (yellow)
V.hell[i] = 255 - colyellow;
if (black)
V.hell[i] = 255 - colblack;
bhell[V.hell[i]] = 255 - colblack;
} else
V.hell[i] = (long)floor(gpal[i][0] * 0.287 + gpal[i][1] * 0.589 + gpal[i]
[2] * 0.114 + 0.5);
if (V.hell[i] > maxhell)
maxhell = V.hell[i];
}
for (i = 0; i < g; i++)
V.hell[i] = (long)floor((double)V.hell[i] / maxhell * (g - 1) + 0.5);
for (i = 0; i < g; i++) /*:30*/
bhell[i] = (long)floor((double)bhell[i] / maxhell * (g - 1) + 0.5);
}
for (pk = 0; pk <= 255; pk++)
lutsl[pk] = pk << (8 - bitspsam);
V.modus = b << 1;
V.modus >>= 7;
if (V.modus == 0)
printf("Image is loaded sequentially.\n");
else
printf("Interlaced mode, loading the image will take more time.\n");
if (V.modus != 0) {
memset((Anyptr)V.gifbuf, invbyte, 3000L);
for (i = 1; i <= vh; i++) {
_SETIO(fwrite(V.gifbuf, V.linebytes, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
FileWriteError);
fileproblem();
_Escape(0);
}
}
/* p2c: bm2font.pas, line 379:
* Note: Can't interpret size in BLOCKWRITE [174] */
V.linepos = 0;
V.logvr = 0;
fseek(tmpfil, 0L, 0);
}
/* p2c: bm2font.pas, line 378:
* Note: Can't interpret size in FILLCHAR [174] */
bpp = b << 5;
bpp >>= 5;
bpp++;
bpp = getgif(&V);
g = 1 << bpp;
ic = 1 << bpp;
V.ec = ic + 1;
V.codesample = bpp + 1;
V.maxcode = 1 << V.codesample;
for (i = 0; i <= 4095; i++)
codtab[i] = 4098;
V.ki = V.ec + 1;
a = 4098;
gbufpp = 0;
V.gifshift = 0;
V.gifinlen = getgif(&V);
/* p2c: bm2font.pas, line 387:
* Note: Can't interpret size in BLOCKREAD [174] */
fread(b1, V.gifinlen, 1, bitmap);
gbufp = 0;
if (V.gifinlen == 0)
_Escape(0);
merk = 0; /*32:*/
while (V.lvr < vh) { /*:32*/
codegif = gifcode(&V);
if (codegif == V.ec) {
printf("End of code before gif image completed!\n");
V.lvr = vh;
continue;
}
if (codegif == ic) {
for (i = 0; i <= 4095; i++)
codtab[i] = 4098;
V.ki = V.ec + 1;
V.codesample = bpp + 1;
V.maxcode = 1 << V.codesample;
a = 4098;
continue;
}
if (codegif < ic)
gifout(codegif, &V);
else {
if (codtab[codegif] == 4098) {
if (codegif != V.ki - 2) {
printf("Bytes are mangled!\n");
_Escape(0);
}
folge = a;
merk++;
while (folge > ic)
folge = codtab[folge];
b3[merk] = folge;
anf[V.ki - 2] = folge;
folge = a;
} else
folge = codegif;
while (folge > ic && folge <= 4095) {
merk++;
b3[merk] = anf[folge];
folge = codtab[folge];
}
merk++;
b3[merk] = folge;
while (merk > 0) {
gifout(b3[merk], &V);
merk--;
}
}
if (a != 4098) {
codtab[V.ki - 2] = a;
if (codegif == V.ki - 2) {
folge = a;
while (folge > ic)
folge = codtab[folge];
anf[V.ki - 2] = folge;
} else {
folge = codegif;
while (folge > ic)
folge = codtab[folge];
anf[V.ki - 2] = folge;
}
}
a = codegif;
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
if (bitspsam > 1)
greypxl = true;
mapinlen = V.linebytes;
strcpy(bitmap_NAME, "pcxtemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "r+b", bitmap);
else
bitmap = fopen(bitmap_NAME, "r+b");
if (bitmap == NULL)
_EscIO(FileNotFound);
pcxtemp = true;
if (egastretch) {
if (xratio + 1 == yratio)
picstretch();
}
posbit = 0;
mapdiv = 1.0;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
mapdiv *= 2;
mapdiv /= 16;
}
/*:43*/
/*44:*/
Local Void junkchunk(LINK)
struct LOC_iffint *LINK;
{
if (LINK->bmsize > P_maxpos(bitmap)) {
printf("File endend while reading junk\n");
_Escape(0);
}
while (LINK->bmsize > 0) {
fread(&LINK->b, 1, 1, bitmap);
LINK->bmsize--;
}
/* p2c: bm2font.pas, line 509:
* Note: Can't interpret size in BLOCKREAD [174] */
} /*:44*/
/*45:*/
Local Void checkchunk(LINK)
struct LOC_iffint *LINK;
{
short i, j, FORLIM;
if (!strcmp(LINK->bmstr, "BMHD")) {
LINK->bmsize = ifflong(LINK);
if (LINK->bmsize & 1)
LINK->bmsize++;
LINK->hh = iffword(LINK);
LINK->vh = iffword(LINK);
LINK->hi = iffword(LINK);
LINK->vi = iffword(LINK);
/* p2c: bm2font.pas, line 513:
* Note: Can't interpret size in BLOCKREAD [174] */
fread(&LINK->bps, 1, 1, bitmap);
/* p2c: bm2font.pas, line 513:
* Note: Can't interpret size in BLOCKREAD [174] */
fread(&LINK->b, 1, 1, bitmap);
/* p2c: bm2font.pas, line 514:
* Note: Can't interpret size in BLOCKREAD [174] */
fread(&LINK->b, 1, 1, bitmap);
LINK->compr = LINK->b;
for (i = 1; i <= 4; i++)
fread(&xratio, 1, 1, bitmap);
/* p2c: bm2font.pas, line 515:
* Note: Can't interpret size in BLOCKREAD [174] */
/* p2c: bm2font.pas, line 515:
* Note: Can't interpret size in BLOCKREAD [174] */
fread(&yratio, 1, 1, bitmap);
LINK->bmsize -= 16;
junkchunk(LINK);
if (LINK->bps == 1) {
LINK->col = 1;
return;
}
if (LINK->bps == 4)
LINK->col = 15;
else
LINK->col = 255;
return;
}
if (!strcmp(LINK->bmstr, "CMAP")) {
LINK->bmsize = ifflong(LINK);
LINK->col = LINK->bmsize / 3 - 1;
FORLIM = LINK->col;
for (i = 0; i <= FORLIM; i++) {
for (j = 0; j <= 2; j++) {
fread(&LINK->b, 1, 1, bitmap);
LINK->gpal[i][j] = LINK->b;
}
/* p2c: bm2font.pas, line 519:
* Note: Can't interpret size in BLOCKREAD [174] */
if (cmyk) {
colcyan = 255 - LINK->gpal[i][0];
colmagenta = 255 - LINK->gpal[i][1];
colyellow = 255 - LINK->gpal[i][2];
if (colcyan != colmagenta || colcyan != colyellow ||
colmagenta != colyellow) {
colcyan -= colmagenta / 3;
if (colcyan < 0)
colcyan = 0;
colmagenta -= colyellow / 3;
if (colmagenta < 0)
colmagenta = 0;
}
colblack = colcyan;
if (colblack > colmagenta)
colblack = colmagenta;
if (colblack > colyellow)
colblack = colyellow;
if (cyan)
LINK->hell[i] = 255 - colcyan;
if (magenta)
LINK->hell[i] = 255 - colmagenta;
if (yellow)
LINK->hell[i] = 255 - colyellow;
if (black)
LINK->hell[i] = 255 - colblack;
} else
LINK->hell[i] = (long)floor(LINK->gpal[i][0] * 0.287 + LINK->gpal[i]
[1] * 0.589 + LINK->gpal[i][2] * 0.114 + 0.5);
LINK->hell[i] = (long)(LINK->hell[i] / (256.0 / (LINK->col + 1)));
bhell[LINK->hell[i]] = (long)(255 - colblack / (256.0 / (LINK->col + 1)));
}
if (LINK->bmsize & 1)
fread(&LINK->b, 1, 1, bitmap);
/* p2c: bm2font.pas, line 534:
* Note: Can't interpret size in BLOCKREAD [174] */
return;
}
if (!strcmp(LINK->bmstr, "CRNG")) {
LINK->bmsize = ifflong(LINK);
LINK->bmoff = iffword(LINK);
LINK->bmoff = iffword(LINK);
LINK->bmoff = iffword(LINK);
/* p2c: bm2font.pas, line 536:
* Note: Can't interpret size in BLOCKREAD [174] */
fread(&LINK->b, 1, 1, bitmap);
/* p2c: bm2font.pas, line 537:
* Note: Can't interpret size in BLOCKREAD [174] */
fread(&LINK->a, 1, 1, bitmap);
if (LINK->bmsize & 1)
fread(&LINK->b, 1, 1, bitmap);
/* p2c: bm2font.pas, line 537:
* Note: Can't interpret size in BLOCKREAD [174] */
return;
}
LINK->bmsize = ifflong(LINK);
if (LINK->bmsize & 1)
LINK->bmsize++;
junkchunk(LINK);
}
/*:36*/
/*41:*/
Static Void iffint()
{ /*:45*/
struct LOC_iffint V;
unsigned short ohh;
uchar cb;
short FORLIM, FORLIM1;
/*46:*/
printf("Analysing IFF file %s\n", bmname);
opentempfile();
fread(V.bmstr, 4, 1, bitmap);
V.bmstr[4] = '\0';
if (strcmp(V.bmstr, "FORM")) {
printf("Graphic file not stored as Interchange File Format\n");
_Escape(0);
}
V.bmsize = ifflong(&V) + 8;
if (V.bmsize != P_maxpos(bitmap)) {
printf("File is incomplete, should contain %ld\n", V.bmsize);
_Escape(0);
}
fread(V.bmstr, 4, 1, bitmap);
V.bmstr[4] = '\0';
if (strcmp(V.bmstr, "ILBM"))
printf("Type of file is %s, should be ILBM\n", V.bmstr);
fread(V.bmstr, 4, 1, bitmap);
V.bmstr[4] = '\0';
while (strcmp(V.bmstr, "BODY")) {
if (P_eof(bitmap)) {
printf("No graphics information available\n");
_Escape(0);
}
checkchunk(&V);
fread(V.bmstr, 4, 1, bitmap);
V.bmstr[4] = '\0';
}
V.bmsize = ifflong(&V);
V.hh = (V.hh * V.bps + 7) / 8;
ohh = V.hh;
if (ohh & 1)
ohh++;
FORLIM = V.vh;
for (i = 1; i <= FORLIM; i++) {
if (P_eof(bitmap)) {
printf("ende\n");
_Escape(0);
}
if (V.compr == 0)
fread(b3, ohh, 1, bitmap);
else { /*47:*/
gbufp = 0;
while (gbufp < ohh) {
fread(&V.b, 1, 1, bitmap);
V.bmoff++;
if (V.b < 128) {
V.b++;
/* p2c: bm2font.pas, line 555:
* Note: Can't interpret size in BLOCKREAD [174] */
fread(&b3[gbufp], V.b, 1, bitmap);
gbufp += V.b;
continue;
}
if (V.b <= 128)
continue;
/* p2c: bm2font.pas, line 556:
* Note: Can't interpret size in BLOCKREAD [174] */
fread(&V.a, 1, 1, bitmap);
V.b = 257 - V.b;
while (V.b > 0) {
b3[gbufp] = V.a;
gbufp++;
V.b--;
}
}
/* p2c: bm2font.pas, line 554:
* Note: Can't interpret size in BLOCKREAD [174] */
} /*:47*/
/* p2c: bm2font.pas, line 553:
* Note: Can't interpret size in BLOCKREAD [174] */
if (V.bps == 4) { /*48:*/
gi = 0;
FORLIM1 = V.hh;
for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++)
b2[gbufpp] = 0;
V.a = 0;
FORLIM1 = V.hh;
for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++) {
V.b = b3[gbufpp];
for (j = 0; j <= 3; j++) {
cb = V.b & 128;
cb >>= 3 - V.a;
b2[gi] ^= cb;
V.b <<= 1;
cb = V.b & 128;
cb >>= 7 - V.a;
b2[gi] ^= cb;
V.b <<= 1;
gi++;
}
if (gi >= V.hh) {
gi = 0;
V.a++;
}
}
FORLIM1 = V.hh;
for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++)
b3[gbufpp] = b2[gbufpp];
gi = 0;
FORLIM1 = V.hh;
for (gbufpp = 0; gbufpp < FORLIM1; gbufpp++) {
b2[gi] = (V.hell[b3[gbufpp] >> 4] << 4) + V.hell[b3[gbufpp] & 15];
gi++;
} /*:48*/
} else if (V.bps == 8) {
FORLIM1 = V.hh;
for (gbufp = 0; gbufp < FORLIM1; gbufp++)
b2[gbufp] = V.hell[b3[gbufp]];
} else {
FORLIM1 = V.hh;
for (gbufp = 0; gbufp < FORLIM1; gbufp++)
b2[gbufp] = b3[gbufp];
}
/* p2c: bm2font.pas, line 568:
* Note: Can't interpret size in BLOCKWRITE [174] */
_SETIO(fwrite(b2, V.hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
FileWriteError);
fileproblem();
_Escape(0);
}
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
mapinlen = V.hh;
bitspsam = V.bps;
posbit = 0;
strcpy(bitmap_NAME, "pcxtemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
pcxtemp = true;
if (egastretch) {
if (xratio + 1 == yratio)
picstretch();
}
posbit = 0;
if (bitspsam > 1)
greypxl = true;
mapdiv = 1.0;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
mapdiv *= 2;
mapdiv /= 16;
} /*:46*/
/*49:*/
Static Void bmpint()
{
unsigned short i, k, hi, hh, hhl, vi, vh, compr, lcol;
uchar j, b, a, col, bps;
uchar gpal[256][4];
unsigned short hell[256];
Char bmstr[256];
long bmsize, bmoff;
unsigned short FORLIM;
printf("Analysing BMP file %s\n", bmname);
opentempfile();
fread(bmstr, 2, 1, bitmap);
bmstr[2] = '\0';
if (strcmp(bmstr, "BM")) {
printf("No windows bitmap %s\n", bmstr);
_Escape(0);
}
gbufp = 640;
pxlinlen = 640;
bmsize = longpcx();
for (i = 1; i <= 4; i++)
b = getpcx();
bmoff = longpcx();
bmsize = longpcx();
bmoff -= bmsize;
if (bmsize > 12) {
hi = longpcx();
vi = longpcx();
b = getpcx();
b = getpcx();
bps = wordpcx();
if (bps > 8) {
printf("only up to 256 colors supported\n");
_Escape(0);
}
hh = hi;
vh = vi;
compr = longpcx();
for (i = 1; i <= 4; i++)
b = getpcx();
xratio = longpcx();
yratio = longpcx();
lcol = longpcx();
lcol--;
if (col == 0) {
if (bps == 1)
col = 1;
else if (bps == 4)
col = 15;
else
col = 255;
}
col = longpcx();
col--;
} else {
hi = wordpcx();
vi = wordpcx();
b = getpcx();
b = getpcx();
bps = wordpcx();
if (bps > 8) {
printf("only up to 256 colors supported\n");
_Escape(0);
}
hh = hi;
vh = vi;
compr = 0;
xratio = 1;
yratio = 1;
col = 0;
}
if (lcol == 0) {
if (bps == 1)
col = 1;
else if (bps == 4)
col = 15;
else
col = 255;
}
if (bps == 1)
col = 1;
else if (bps == 4)
col = 15;
else
col = 255;
for (i = 0; i <= col; i++) {
if (bmsize > 12) {
for (j = 0; j <= 3; j++)
gpal[i][j] = getpcx();
} else {
for (j = 0; j <= 2; j++)
gpal[i][j] = getpcx();
}
if (cmyk) {
colcyan = 255 - gpal[i][2];
colmagenta = 255 - gpal[i][1];
colyellow = 255 - gpal[i][0];
if (colcyan != colmagenta || colcyan != colyellow ||
colmagenta != colyellow) {
colcyan -= colmagenta / 3;
if (colcyan < 0)
colcyan = 0;
colmagenta -= colyellow / 3;
if (colmagenta < 0)
colmagenta = 0;
}
colblack = colcyan;
if (colblack > colmagenta)
colblack = colmagenta;
if (colblack > colyellow)
colblack = colyellow;
if (cyan)
hell[i] = 255 - colcyan;
if (magenta)
hell[i] = 255 - colmagenta;
if (yellow)
hell[i] = 255 - colyellow;
if (black)
hell[i] = 255 - colblack;
hell[i] = (long)(hell[i] / (256.0 / (col + 1)));
bhell[hell[i]] = (long)((255 - colblack) / (256.0 / (col + 1)));
} else
hell[i] = (long)((gpal[i][2] * 0.287 + gpal[i][1] * 0.589 + gpal[i]
[0] * 0.114) / (256.0 / (col + 1)));
}
if (bmsize > 12)
bmoff -= (col + 1) * 4;
else
bmoff -= (col + 1) * 3;
if (compr != 0) {
printf("compression not supported yet\n");
_Escape(0);
}
hh = (hh * bps + 7) / 8;
hhl = (hh + 3) / 4 * 4 - 1;
a = 8 - ((hi * bps) & 7);
/* p2c: bm2font.pas, line 616:
* Note: Suspicious mixture of sizes in FILLCHAR [173] */
memset((Anyptr)b3, 0, hhl + 1L);
for (i = 1; i <= vh; i++) { /*$I-*/
_SETIO(fwrite(b3, hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
FileWriteError);
fileproblem();
_Escape(0);
}
}
/* p2c: bm2font.pas, line 617:
* Note: Can't interpret size in BLOCKWRITE [174] */
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
if (tmpfil != NULL)
tmpfil = freopen(tmpfil_NAME, "w+b", tmpfil);
else
tmpfil = fopen(tmpfil_NAME, "w+b");
if (tmpfil == NULL)
_EscIO(FileNotFound);
bmoff = (vh - 1) * (long)hh;
for (i = 0; i < vh; i++) {
for (k = 0; k <= hhl; k++)
b3[k] = getpcx();
if (bps == 4) {
gi = 0;
for (k = 0; k < hh; k++) {
b2[gi] = (hell[b3[k] >> 4] << 4) + hell[b3[k] & 15];
gi++;
}
} else if (bps == 8) {
for (k = 0; k < hh; k++)
b2[k] = hell[b3[k]];
} else {
for (k = 0; k < hh; k++)
b2[k] = b3[k];
}
if (a < 8) {
for (k = 0; k < a; k++)
b2[hh - 1] ^= invbit >> k;
}
fseek(tmpfil, bmoff, 0);
bmoff = bmoff - (long)hh;
/* p2c: bm2font.pas, line 629:
* Note: Can't interpret size in BLOCKWRITE [174] */
_SETIO(fwrite(b2, hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
FileWriteError);
fileproblem();
_Escape(0);
}
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
mapinlen = hh;
posbit = 0;
strcpy(bitmap_NAME, "pcxtemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
pcxtemp = true;
bitspsam = bps;
if (bitspsam > 1)
greypxl = true;
mapdiv = 1.0;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
mapdiv *= 2;
mapdiv /= 16;
}
/*50:*/
Static Void imgint()
{
unsigned short i, ki, hi, hh, bzf, imgpat;
short vh;
uchar mi, cb, j, b, a, col, bps;
unsigned short hell[16];
uchar linerep;
unsigned short FORLIM;
printf("Analysing IMG file %s\n", bmname);
invert = !invert;
if (invert) { /*51:*/
invbit = 0;
invbyte = 0;
} else {
invbit = 1;
invbyte = 255;
}
hell[0] = 0;
hell[1] = 1;
hell[2] = 6;
hell[3] = 8;
hell[4] = 3;
hell[5] = 2;
hell[6] = 7;
hell[7] = 11;
hell[8] = 4;
hell[9] = 5;
hell[10] = 12;
hell[11] = 13;
hell[12] = 10;
hell[13] = 9;
hell[14] = 14;
hell[15] = 15;
opentempfile(); /*:51*/
gbufp = 640;
pxlinlen = 640;
a = getpcx();
b = getpcx();
if (a * 256 + b != 1) { /*52:*/
printf("File does not contain GEM Image File Format\n");
_Escape(0);
}
b = getpcx();
bzf = b * 256;
b = getpcx();
bzf += b;
b = getpcx();
bps = b * 256;
b = getpcx();
bps += b;
b = getpcx();
imgpat = b * 256;
b = getpcx();
imgpat += b;
b = getpcx();
xratio = b * 256;
b = getpcx();
xratio += b;
b = getpcx();
yratio = b * 256;
b = getpcx();
yratio += b;
if (xratio != yratio) {
mapdiv = (double)yratio / xratio;
xratio = 0;
yratio = 0;
while (xratio == yratio) {
xratio++;
yratio = (long)floor(xratio * mapdiv + 0.5);
}
}
b = getpcx();
hi = b * 256;
b = getpcx();
hi += b;
b = getpcx();
vh = b * 256;
b = getpcx();
vh += b; /*:52*/
hh = (hi * bps + 7) / 8;
if (bzf > 8) {
for (i = 1; i <= (bzf - 8) * 2; i++)
b = getpcx();
}
linerep = 0;
gi = 0;
while (vh > 0) {
for (gi = 0; gi <= hh; gi++)
b3[gi] = 0;
gi = 0;
while (gi < hh) {
b = getpcx();
if (b != 0 && b != 128) {
a = b & 127;
cb = ((unsigned)(b - a)) >> 7;
if (cb == 1)
cb = 255;
for (ki = 1; ki <= a; ki++) {
b3[gi] = cb;
gi++;
}
continue;
}
if (b == 128) {
a = getpcx();
for (ki = 1; ki <= a; ki++) {
b3[gi] = getpcx();
gi++;
}
continue;
}
a = getpcx();
if (a <= 0) {
b = getpcx();
linerep = getpcx();
continue;
}
for (ki = 1; ki <= imgpat; ki++)
b2[ki] = getpcx();
for (ki = 1; ki <= a; ki++) {
for (mi = 1; mi <= imgpat; mi++) {
b = b2[mi];
b3[gi] = b;
gi++;
}
}
}
if (bps == 4) { /*48:*/
gi = 0;
for (gbufpp = 0; gbufpp < hh; gbufpp++)
b2[gbufpp] = 0;
a = 0;
for (gbufpp = 0; gbufpp < hh; gbufpp++) {
b = b3[gbufpp];
for (j = 0; j <= 3; j++) {
cb = b & 128;
cb >>= 3 - a;
b2[gi] ^= cb;
b <<= 1;
cb = b & 128;
cb >>= 7 - a;
b2[gi] ^= cb;
b <<= 1;
gi++;
}
if (gi >= hh) {
gi = 0;
a++;
}
}
for (gbufpp = 0; gbufpp < hh; gbufpp++)
b3[gbufpp] = b2[gbufpp];
gi = 0;
for (gbufpp = 0; gbufpp < hh; gbufpp++) {
b2[gi] = (hell[b3[gbufpp] >> 4] << 4) + hell[b3[gbufpp] & 15];
gi++;
} /*:48*/
} else {
for (ki = 0; ki < hh; ki++)
b2[ki] = b3[ki];
}
/* p2c: bm2font.pas, line 674:
* Note: Can't interpret size in BLOCKWRITE [174] */
_SETIO(fwrite(b2, hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
FileWriteError);
fileproblem();
_Escape(0);
}
vh--;
if (linerep <= 0)
continue;
for (i = 1; i <= linerep; i++) { /*$I-*/
_SETIO(fwrite(b2, hh, 1, tmpfil) == 1, FileWriteError);
filestat = P_ioresult;
if (filestat != 0) {
_SETIO(printf("Error occured when writing file %s!\n", tmpname) >= 0,
FileWriteError);
fileproblem();
_Escape(0);
}
}
/* p2c: bm2font.pas, line 678:
* Note: Can't interpret size in BLOCKWRITE [174] */
vh += 1 - linerep;
linerep = 0;
}
if (bitmap != NULL)
fclose(bitmap);
bitmap = NULL;
if (tmpfil != NULL)
fclose(tmpfil);
tmpfil = NULL;
if (col == 4) {
bitspsam = 4;
greypxl = true;
} else if (bps > 1) {
bitspsam = bps;
greypxl = true;
}
mapinlen = hh;
posbit = 0;
strcpy(bitmap_NAME, "pcxtemp.tmp");
if (bitmap != NULL)
bitmap = freopen(bitmap_NAME, "rb", bitmap);
else
bitmap = fopen(bitmap_NAME, "rb");
if (bitmap == NULL)
_EscIO(FileNotFound);
if (egastretch) {
if (xratio + 1 == yratio)
picstretch();
}
posbit = 0;
pcxtemp = true;
mapdiv = 1.0;
FORLIM = bitspsam;
for (i = 1; i <= FORLIM; i++)
mapdiv *= 2;
mapdiv /= 16;
}
/*54:*/
Static Void tfmhword(hword)
long hword;
{
union {
uchar b[4];
long i;
} ax;
short i;
ax.i = hword;
#ifdef INTEL
for (i = 1; i >= 0; i--)
fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
#else
for (i = 2; i <= 3; i++)
fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
#endif
}
Static Void tfmword(lword)
long lword;
{
union {
uchar b[4];
long i;
} ax;
short i;
ax.i = lword;
#ifdef INTEL
for (i = 3; i >= 0; i--)
fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
#else
for (i = 0; i <= 3; i++)
fwrite(&ax.b[i], sizeof(uchar), 1, tfmfile);
#endif
}
/*:54*/
/*57:*/
Static Void pxlmap(lword)
long lword;
{
union {
ebts b[4];
long i;
} ax;
uchar i;
ax.i = lword;
for (i = 0; i <= 3; i++) {
pxlbm[pxlbmi] = ax.b[i];
pxlbmi++;
}
} /*:57*/
i = pkwidth;
temp = true;
while (i > 0 && temp) {
if (pxlbm[row1] != pxlbm[row2])
temp = false;
row1++;
row2++;
i -= 8;
}
return temp;
}
/*:67*/
/*68:*/
Static boolean equalzo(row1, row2)
pxlstr row1;
short row2;
{
short i;
boolean temp;
i = pkwidth;
temp = true;
while (i > 0 && temp) {
if (pxlbm[row1] != (repbm[row2] & 255))
temp = false;
row1++;
row2++;
i -= 8;
}
return temp;
}
/*:68*/
/*70:*/
Static Void shipcharacte()
{ /*:87*/
pxlstr crst;
short wwid;
long compsize;
long horesc;
/*72:*/
short l;
long i, j, k;
short rowzero, onesrow, repptr, bitcounts;
ebts fillbytes, longind, mixbyte, restbyte, pkshift, dshift;
long longtab[20];
/*:72*/
/*77:*/
long count;
short test, curptr, bit, repflag;
schar pkkword;
short bitptr, bitmod32, currepeat;
pxlstr endraster; /*:77*/
/*80:*/
short dynf;
long deriv[13];
long bcompsize;
boolean firston;
short flagbyte;
/*:80*/
/*87:*/
unsigned short max2;
pxlstr predpkloc;
short bytelength;