Commit 43ad8e7b authored by Robert Sprowson's avatar Robert Sprowson

Add support for 24 (and 32) bpp PCX files

ChangeFSI's slightly lapse check of >= 8bpp header vetting for PCX meant it would try to load such files and fail with an EOF error.
* Change header parsing to correctly deduce a 24 or 32bpp PCX is being handled, select the appropriate decoder
* Add a sample 4 plane 8 bit PCX to the tests directory, created with ImageMagick
* Docs updated
Note that is seems highly unlikely from inspection of the code that 5/6/7bpp PCX files will come out the right colour since the PCX file format header only has space for 16 palette entries but ChangeFSI will continue reading off the end of the table into the start of the image data. However, no examples of 5/6/7bpp images could be found in the wild, so let sleeping dogs lie.

Version 1.53. Tagged as 'ChangeFSI-1_53'
parent 0bf6bfbd
......@@ -224,12 +224,15 @@ colours, uncompressed. Documentation part of QRT.
ZSoft .PCX files
----------------
Used by PC Paintbrush. Usually a 4 bit per pixel image (CGA, EGA, VGA), but
can be 1-8 bits per pixel.
can be 1-8 or 24 bits per pixel.
Recognised by file type 697, or &0A,&00|02|03|04|05,&01 at the start of
the file, or the file is beneath a directory named PCX, or the file's name
ends /PCX.
True colour variants exist with version 5 headers with 8 bits per component
and either 3 or 4 planes.
Intelligent check for resolution of the DACs on the PC card. Use -info to
find out what ChangeFSI thinks it is.
......@@ -729,7 +732,8 @@ TimeStep satellite image 800x800y256g [file type 7A0]
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]
ZSoft .PCX files [10,1-5,1 in file OR file type 697
OR named pcx. OR /PCX]
Degas PI1, PI2, PI3 images [file type 691]
!Translator Clear format [file type 690]
CCIR 601 4:2:2 PAL image [file type 601]
......
/* (1.52)
/* (1.53)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.52
#define Module_MajorVersion_CMHG 1.53
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 12 Oct 2014
#define Module_Date_CMHG 13 Jun 2015
#define Module_MajorVersion "1.52"
#define Module_Version 152
#define Module_MajorVersion "1.53"
#define Module_Version 153
#define Module_MinorVersion ""
#define Module_Date "12 Oct 2014"
#define Module_Date "13 Jun 2015"
#define Module_ApplicationDate "12-Oct-14"
#define Module_ApplicationDate "13-Jun-15"
#define Module_ComponentName "ChangeFSI"
#define Module_ComponentPath "mixed/RiscOS/Sources/Apps/ChangeFSI"
#define Module_FullVersion "1.52"
#define Module_HelpVersion "1.52 (12 Oct 2014)"
#define Module_LibraryVersionInfo "1:52"
#define Module_FullVersion "1.53"
#define Module_HelpVersion "1.53 (13 Jun 2015)"
#define Module_LibraryVersionInfo "1:53"
......@@ -3058,7 +3058,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
C%=BGET#c%
E%=BGET#c%
IF E%<>1 ERROR 42,"ZSoft .PCX file with unknown encoding"
E%=BGET#c%
E%=BGET#c%:REM Bits per plane
sx%=FNHW
sy%=FNHW
sx%=FNHW+1-sx%
......@@ -3069,38 +3069,52 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
planar%=planes%>1
rowbytes%=FNHW
bpp%=E%*planes%
pcxpal=16
IF bpp%>4 AND C%=5 THEN
pcxpal=16:REM Default 16 entry EGA palette is in the header
IF bpp%=8 AND C%=5 THEN
REM Might be 8bpp palettised, see if there's a palette appended
PTR#c%=EXT#c%-769
IF BGET#c%=12 pcxpal=EXT#c%-768
ENDIF
PTR#c%=pcxpal
E%=0
FOR C%=0 TO (1<<bpp%)*3-1
E%=E% OR BGET#c%
NEXT
IF info% PRINT ".PCX palette mask established at ";~E%
IF E%=0 THEN
FOR C%=0 TO (1<<bpp%)-1
r%(C%)=C%/((1<<bpp%)-1)*F
NEXT
g%()=r%()
b%()=r%()
ELSE
PTR#c%=pcxpal
FOR C%=0 TO (1<<bpp%)-1
r%(C%)=(BGET#c% AND E%)/E%*F
g%(C%)=(BGET#c% AND E%)/E%*F
b%(C%)=(BGET#c% AND E%)/E%*F
NEXT
ENDIF
CASE bpp% OF
WHEN 1,2,3,4,5,6,7,8
E%=0
FOR C%=0 TO (1<<bpp%)*3-1
E%=E% OR BGET#c%
NEXT
IF info% PRINT ".PCX palette mask established as ";~E%
IF E%=0 THEN
PROCflatpal(1<<bpp%):REM Empty palette, use default
ELSE
PTR#c%=pcxpal
FOR C%=0 TO (1<<bpp%)-1
r%(C%)=(BGET#c% AND E%)/E%*F
g%(C%)=(BGET#c% AND E%)/E%*F
b%(C%)=(BGET#c% AND E%)/E%*F
NEXT
ENDIF
WHEN 24,32
PROCnopal:REM Truecolour RGB and RGBA
OTHERWISE
ERROR 42,"ZSoft .PCX with unknown pixel depth"
ENDCASE
PROCrewind
REM cache false!
plbytes%=rowbytes%*planes%
plbuff%=FNdim(plbytes%)
cache%= TRUE
cachebytes%= TRUE
IF planar% pbuff%=FNdim(sx%) ELSE input=bpp%:bigendianbits= TRUE :r$="FN1100"
IF planar% THEN
IF bpp%>=24 THEN
input=24:step24=1:r$="FN1124"
REM Plane of R, then plane of G, then plane of B, ignore any 4th alpha plane
rbo%=0*rowbytes%:gbo%=1*rowbytes%:bbo%=2*rowbytes%
ELSE
pbuff%=FNdim(sx%):REM Line buffer to flatten out the planes
ENDIF
ELSE
REM Single plane
input=bpp%:bigendianbits=TRUE:r$="FN1100"
ENDIF
info$="ZSoft .PCX file, "+ STR$sx%+" by "+ STR$sy%+" pixels, "+FNbits(bpp%)
WHEN 2000
REM Truevision TGA
......@@ -8707,6 +8721,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
base%!(10*4)=5<<27 OR nx<<1 OR ny<<14 OR 1
base%+=base%!(8*4)
WHEN -7
REM 24bpp is an alias for 32bpp for now
REM xwords%=xsp%*3+3ANDNOT3:sz%=xwords%*ysp%:Y%=ysp%
REM A%=Y%:PROCgetoutput(sz%,64,xwords%,Y%)
REM ram%!4=0:ram%!8=16:ram%!12=16:SYS&2E,&109,ram%
......@@ -10243,13 +10258,13 @@ DEF FN1001(z%())
CALL mappix%,z%(1,0),r%(0),g%(0),b%(0),buff%
= TRUE
:
REM 1-8bpp packed RLE'd: SunRaster, CADSoft
REM 1-8bpp packed RLE'd: SunRaster, CADSoft, single plane PCX
DEF FN1100(z%())
CALL readline%,plbytes%,rep%,pix%,plbuff%
CALL mappix%,z%(1,0),r%(0),g%(0),b%(0),plbuff%
= TRUE
:
REM 24 (and 32bpp) packed RLE'd: SunRaster
REM 24 (and 32bpp) packed RLE'd: SunRaster, PCX
DEF FN1124(z%())
CALL readline%,plbytes%,rep%,pix%,plbuff%
rb%=plbuff%+rbo%
......
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