home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Party 1994: Try This At Home
/
disk_image.bin
/
source
/
gallery
/
subdirs.exe
/
TEXTURE
/
GPIX2BIN.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-07-21
|
3KB
|
139 lines
{$N+,G+}
uses dos;
{$IFOPT N+} type real = single; {$ENDIF}
const TexRes = 128;
Type
PIX = array[0..199,0..319] of byte;
BIN = array[0..TexRes-1,0..TexRes-1] of byte;
hue = (red, green, blue);
rgb = array[hue] of byte;
Palette = array[0..255] of rgb;
{ Fits palette taking into account human eye sensitivity: }
const { 1, 4.59, 0.061 }
hueFac : array[hue] of real = (1, 1, 1);
procedure SetRGBblock ( first : byte; number : word; var RGB ); assembler;
asm
push ds
lds si, RGB { ds:si -> palette }
mov ax, number
mov cx, ax { cx = count }
shl cx, 1
add cx, ax { cx = count*3 (total RGB bytes) }
mov al, first
mov dx, $3c8
out dx, al
inc dx
rep outsb
pop ds
end;
var I, O : File;
N : string;
SrcPal, DestPal : Palette;
Xlate : array[0..255] of byte;
c : byte;
B : BIN;
P : ^PIX;
k,j : integer;
ImWidth, ImHeight : integer;
procedure fitpalette;
var bestcol : byte;
besterr, err : real;
i,j : byte;
h : hue;
r : rgb;
begin
for j := 0 to 255 do begin
r := SrcPal[j];
bestcol := 0;
besterr := sqr(64)*3+1;
for i := 0 to 255 do if ((i mod 16)<>0) or (i=0) then begin
err := 0;
for h := red to blue do
err := err + sqr( integer(r[h])-DestPal[i,h] )*hueFac[h];
if err < besterr then begin
besterr := err;
bestcol := i
end;
end;
Xlate[j] := bestcol;
SetRGBblock( j, 1, DestPal[bestcol] );
end;
end;
procedure value( var w : integer; s : string );
var v,i : integer;
begin
val(s, v, i);
if i=0 then w := v;
end;
begin
writeln('PIX2BIN converter (for BINOBJ.EXE) // A.R-M. 7/93.');
writeln;
GetMem( P, SizeOf(PIX) );
if ParamCount<1 then begin
write ('.PIX file name: '); readln( N );
writeln;
end else N := ParamStr(1);
ImWidth := 320;
ImHeight := 200;
if ParamCount>=2 then Value(ImWidth, ParamStr(2));
if ParamCount>=3 then Value(ImHeight, ParamStr(3));
assign(I,N+'.PAL'); reset(I,1);
blockread( I, SrcPal, SizeOf(SrcPal) );
close(I);
assign(I,'PIX2BIN.PAL'); reset(I,1);
blockread( I, DestPal, SizeOf(DestPal) );
close(I);
assign(I, N+'.PIX'); reset(I,1);
blockread( I, P^, SizeOf(P^) );
close(I);
asm
mov ax,$13
int $10
end;
Move( P^, ptr($a000,0000)^, 320*200 );
SetRGBblock( 0,255,SrcPal );
FitPalette;
for j := 0 to TexRes-1 do begin
for k := 0 to TexRes-1 do begin
c := P^[ round(k/(TexRes-1)*(ImHeight-1)), round(j/(TexRes-1)*(ImWidth-1)) ];
B[j,k] := Xlate[c];
end;
end;
assign( O, N+'.BIN'); rewrite(O,1);
blockwrite( O, B, SizeOf(B) );
close(O);
FreeMem( P, SizeOf(P^) );
end.