Commit 47af4441 authored by Robert Sprowson's avatar Robert Sprowson

Add support for version 1.0 RLE compressed targa images

Fix RLE decompression of 15bpp targa images

In spec 1.0 RLE compressed data was allowed to span multiple scan lines, whereas spec 2.0 said the exact opposite (so that fast lookup tables into scan lines became possible). However, ChangeFSI could only handle RLE decompression where the data exactly decompressed to one line long, otherwise getting stuck in a REPEAT UNTIL loop until overrunning the end of the line buffer.
A new PROCtarga (since it's common to all 5 possible pixel depths) loads lines, and optionally suspends decompression once one line has been fetched to allow continuation on the next line.

A truncating divide when calculating 'step24' meant that 15bpp TGA's only got allocated half the memory they needed, leading to a data abort. Now, 8/15/16/24/32bpp get the right allocation.
Docs updated.

Version 1.49. Not tagged
parent ecd55cb3
......@@ -192,9 +192,14 @@ per pixel.
Recognised by file type 69D, or the file's name ends with TGA or VDA.
Only uncompressed formats readable.
Uncompressed (types 1-3) and RLE compressed (types 9-11) are readable.
Only 8 and 16 bit per pixel formats tested.
Resolution information in the extension fields, if any, are ignored; equal
to mode 27 assumed.
Compatible with Truevision TGA specification version 1.0 and 2.0, a key
difference being that RLE compressed lines are not allowed to span rows
in the 2.0 specification whereas they could previously.
MTV 24-bit PIC images
---------------------
......@@ -712,7 +717,7 @@ ProArtisan compressed pictures 640x256y256c [file type DE2]
JPEG "JFIF" file [JFIF in file]
Kodak PhotoCD images [file type BE8 OR named /PCD]
TimeStep satellite image 800x800y256g [file type 7A0]
PC TGA images [name ends in /TGA OR /VDA]
PC TGA images [file type 69D OR named /TGA OR /VDA]
MTV 24 bit pic. images [named pic.]
QRT 24 bit .raw images [named .raw]
ZSoft .PCX files [10,1-5,1 in file OR named pcx. OR /PCX]
......
......@@ -3140,23 +3140,22 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
PROCnopal
ENDCASE
st%=PTR#c%
rep%=-1
step24=(B%+7) DIV 8 : REM 8/15/16/24/32 -> 1/2/2/3/4
rowbytes%=step24*sx%
CASE I% OF
WHEN 1,2,3
cache%= TRUE
IF B%>8 THEN
IF B%>16 THEN
input=24
r$="FN24"
bbo%=0
gbo%=1
rbo%=2
step24=B% DIV 8
r$="FN24"
rowbytes%=step24*sx%
ELSE
rowbytes%=sx%*2
DIM rpal%(255),gpal%(255)
input=16
step24=2
r$="FN16"
FOR C%=0 TO 255
gpal%(C%)=(C%>>5)<<8 OR (C% AND 31)<<16
......@@ -3174,20 +3173,18 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
ENDIF
info$="Truevision TGA image, "+ STR$sx%+" by "+ STR$sy%+" pixels, "+FNbits(B%)
WHEN 9,10,11
step24=B% DIV 8
rowbytes%=step24*sx%
buff%=FNdim(rowbytes%)
pbuff%=FNdim(4)
IF B%>8 THEN
IF B%>16 THEN
input=24
r$="FN2002"
bb%=buff%
gb%=buff%+1
rb%=buff%+2
r$="FN2002"
ELSE
DIM rpal%(255),gpal%(255)
input=16
step24=2
r$="FN2001"
FOR C%=0 TO 255
gpal%(C%)=(C%>>5)<<8 OR (C% AND 31)<<16
......@@ -9854,6 +9851,34 @@ DEF PROCnextstrip
ENDPROC
:
REM
DEF PROCtarga(step%)
X%=buff%
B%=rowbytes%
REPEAT
IF rep%<128 THEN
C%=(rep%+1)*step%
IF C%=B% THEN rep%=-1 : REM Perfect fit, so need to reload next time
IF C%>B% THEN rep%=((C%-B%)/step%)-1 : C%=B% : REM Partial read
SYS 12,4,c%,X%,C%
ELSE
C%=((rep% AND&7F)+1)*step%
IF C%=B% THEN rep%=-1 : REM Perfect fit, so need to reload next time
IF C%>B% THEN rep%=((C%-B%)/step%)-1 OR 128 : C%=B% : REM Partial RLE
FOR L%=0 TO C%-1 STEP step%
X%!L%=pix%
NEXT
ENDIF
X%+=C%
B%-=C%
IF B%<>0 THEN
REM Get more and go round again
rep%=BGET#c%
IF rep%>=128 THEN SYS 12,4,c%,pbuff%,step% : pix%=!pbuff%
ENDIF
UNTIL B%=0
ENDPROC
:
REM
DEF PROCwatford(wtsx%,RETURN rep%,RETURN wt%,X%,c%)
CALL rlexpand%,wtsx%,rep%,wt%,X%
REPEAT
......@@ -10306,64 +10331,19 @@ DEF FN1900(z%())
:
REM 1-8bpp packed RLE'd: Targa
DEF FN2000(z%())
X%=buff%
REPEAT
C%=BGET#c%
IF C%<128 THEN
C%+=1
SYS 12,4,c%,X%,C%
X%+=C%
ELSE
F%=X%
?F%=BGET#c%
FOR C%=C% TO 128 STEP -1
?X%=?F%
X%+=1
NEXT
ENDIF
UNTIL X%=buff%+rowbytes%
PROCtarga(step24)
CALL mappix%,z%(1,0),r%(0),g%(0),b%(0),buff%
= TRUE
:
REM 16bpp packed RLE'd: Targa
DEF FN2001(z%())
X%=buff%
REPEAT
C%=BGET#c%
IF C%<128 THEN
C%=(C%+1)*2
SYS 12,4,c%,X%,C%
X%+=C%
ELSE
F%=X%
SYS 12,4,c%,X%,2
FOR C%=C% TO 128 STEP -1
!X%=!F%
X%+=2
NEXT
ENDIF
UNTIL X%=buff%+rowbytes%
PROCtarga(step24)
CALL mappix%,z%(1,0),rpal%(0),gpal%(0),r%(0),g%(0),b%(0),buff%,buff%
= TRUE
:
REM 24/32bpp packed RLE'd: Targa
DEF FN2002(z%())
X%=buff%
REPEAT
C%=BGET#c%
IF C%<128 THEN
C%=(C%+1)*step24
SYS 12,4,c%,X%,C%
X%+=C%
ELSE
F%=X%
SYS 12,4,c%,X%,step24
FOR C%=C% TO 128 STEP -1
!X%=!F%
X%+=step24
NEXT
ENDIF
UNTIL X%=buff%+rowbytes%
PROCtarga(step24)
CALL mappix%,z%(1,0),r%(0),g%(0),b%(0),rb%,gb%,bb%
= TRUE
:
......@@ -10602,6 +10582,7 @@ DEF PROCrewind
rep%=-1
WHEN 2000
PTR#c%=st%
rep%=-1
WHEN 2100
PTR#c%=7
WHEN 2200
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment