Commit 59019698 authored by Robert Sprowson's avatar Robert Sprowson

Fix for prevalent 'Outside file' errors

With small image files ChangeFSI would often report 'Outside file' as its detection code tried to read from around offset 512 within the file - often longer than the image itself. The extent is now checked before attempting to look for signatures that far in.
Other minor changes:
* Removed the need to pass a block of scratch memory to PROCcachesize
* Command line use is in 'CmdBasUse' not 'FSIinfo' within the docs
* Moved flag 666 image parser up into numerical order
* Don't pass an argument to SWI Hourglass_On
* Inline FNfits
* Make the uniform palette function more general rather than hardwired for 256 entries
Tested briefly, still works.

Version 1.42. Tagged as 'ChangeFSI-1_42'
parent 37d93803
/* (1.41)
/* (1.42)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.41
#define Module_MajorVersion_CMHG 1.42
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 12 Dec 2013
#define Module_Date_CMHG 08 Jan 2014
#define Module_MajorVersion "1.41"
#define Module_Version 141
#define Module_MajorVersion "1.42"
#define Module_Version 142
#define Module_MinorVersion ""
#define Module_Date "12 Dec 2013"
#define Module_Date "08 Jan 2014"
#define Module_ApplicationDate "12-Dec-13"
#define Module_ApplicationDate "08-Jan-14"
#define Module_ComponentName "ChangeFSI"
#define Module_ComponentPath "mixed/RiscOS/Sources/Apps/ChangeFSI"
#define Module_FullVersion "1.41"
#define Module_HelpVersion "1.41 (12 Dec 2013)"
#define Module_LibraryVersionInfo "1:41"
#define Module_FullVersion "1.42"
#define Module_HelpVersion "1.42 (08 Jan 2014)"
#define Module_LibraryVersionInfo "1:42"
......@@ -1513,7 +1513,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
lock%= FALSE
rwt=.299 : gwt=.587 : bwt=.114 : REM CIE Y weightings for R, G, B
IF ARG%<3 THEN
PRINT "ChangeFSI interactive input (read FSIinfo for command line details)"
PRINT "ChangeFSI interactive input (read CmdBasUse for command line details)"
INPUT "Source file: "s$,"Destination file: "f$,"Output mode: "m$
INPUT "X Scale (eg. 2:1): "xs$
INPUT "Y Scale (eg. 2:1): "ys$
......@@ -1792,7 +1792,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
IF MID$(S$,7,4)="JFIF" OR LEFT$(S$,3)=CHR$&FF+CHR$&D8+CHR$&FF OR ftype=&C85 THEN
REM Read the cache size variable
jpegblk%=FNdim(20)
PROCcachesize(jpegblk%)
PROCcachesize
A%=0
IF cache%>=EXT#c% THEN
REM Pre load the high speed reader
......@@ -1852,7 +1852,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
info$="BTPC file converted to "
ENDIF
ENDIF
IF flag=-1 THEN
IF flag=-1 AND EXT#c%>&19 THEN
PTR#c%=&10
S$=""
FOR I%=1 TO 9
......@@ -1860,7 +1860,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
NEXT
IF S$="MILLIPEDE" flag=200
ENDIF
IF flag=-1 THEN
IF flag=-1 AND EXT#c%>&49 THEN
PTR#c%=&41
S$=""
FOR I%=1 TO 8
......@@ -1868,16 +1868,16 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
NEXT
IF LEFT$(S$,4)="PNTG" flag=1800:st%=&280
ENDIF
IF flag=-1 THEN
PTR#c%=196
IF flag=-1 AND EXT#c%>&CC THEN
PTR#c%=&C4
S$=""
FOR I%=1 TO 8
S$+=CHR$BGET#c%
NEXT
IF LEFT$(S$,4)="PNTG" flag=1800:st%=&2e2
ENDIF
IF flag=-1 THEN
PTR#c%=522
IF flag=-1 AND EXT#c%>&212 THEN
PTR#c%=&20A
S$=""
FOR I%=1 TO 8
S$+=CHR$BGET#c%
......@@ -1922,10 +1922,8 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
striprows%=-1
cachebytes%= FALSE
IF xdiv%=0 AND ydiv%=0 scale%= FALSE
DIM r%(colourindex)
REM monochrome colour map
DIM g%(colourindex),b%(colourindex)
REM colour maps: in 0-colourindex out 0-1 fixed point
REM Colour maps (or just r%() for monochrome), in 0-colourindex => out 0-1 fixed point
DIM r%(colourindex),g%(colourindex),b%(colourindex)
CASE flag OF
WHEN 0
REM Archimedes Sprite file
......@@ -2267,6 +2265,32 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
r$="FN8"
cache%= TRUE
info$=".PIC image, "+ STR$sx%+" by "+ STR$sy%+" pixels, 8 bits per pixel"
WHEN 666
REM the number of the beast
REM uncompressed Eidos type reader
REM PTR#c%=0:st%=0:sx%=160:sy%=EXT#c%/160/2:input=16:cache%=TRUE:rowbytes%=2*sx%
REM step24=2:r$="FN16":DIM rpal%(255),gpal%(255)
REM FORC%=0TO255
REM gpal%(C%)=((C%AND15)<<16) OR (C%AND&C0)<<2
REM rpal%(C%)=(C%>>4) OR ((C%AND3)<<10)
REM NEXT
REM FORC%=0TO15:r%(C%)=C%/15*F:NEXT:g%()=r%():b%()=r%()
REM info$="The number of the beast, 160 by "+STR$sy%+" pixels, 12 bits per pixel"
REM 8 bit Y format reader
st%=0
PTR#c%=0
sx%=160
sy%=128
input=8
cache%= TRUE
rowbytes%=sx%
FOR C%=0 TO 255
r%(C%)=C%/255*F
NEXT
g%()=r%()
b%()=r%()
r$="FN8"
info$="The number of the beast, 160 by "+ STR$sy%+" pixels, 8 bits per pixel"
WHEN 700
REM MTV ".pic" image
quant%=8
......@@ -2546,7 +2570,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
r$="FN8"
rowbytes%=sx%
cache%= TRUE
info$="satellite image, 128 by 256 pixels, 8 bits per pixel"
info$="Satellite image, 128 by 256 pixels, 8 bits per pixel"
WHEN 1301
REM "colour" unknown TimeStep satellite format
input=24
......@@ -3504,7 +3528,10 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
REM FITS telescope format
PTR#c%=0
REPEAT
s$=FNfits
s$=""
FOR Z%=1 TO 80
s$+=CHR$BGET#c%
NEXT
CASE LEFT$(s$,8) OF
WHEN "SIMPLE "
IF MID$(s$,30,1)<>"T" ERROR 42,"ChangeFSI can only read Simple FITS format"
......@@ -4032,35 +4059,9 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
gbo%=2
bbo%=4
info$="Ronald Alpiar format, "+ STR$sx%+" by "+ STR$sy%+" pixels, 48 bits per pixel"
WHEN 666
REM the number of the beast
REM uncompressed Eidos type reader
REM PTR#c%=0:st%=0:sx%=160:sy%=EXT#c%/160/2:input=16:cache%=TRUE:rowbytes%=2*sx%
REM step24=2:r$="FN16":DIM rpal%(255),gpal%(255)
REM FORC%=0TO255
REM gpal%(C%)=((C%AND15)<<16) OR (C%AND&C0)<<2
REM rpal%(C%)=(C%>>4) OR ((C%AND3)<<10)
REM NEXT
REM FORC%=0TO15:r%(C%)=C%/15*F:NEXT:g%()=r%():b%()=r%()
REM info$="The number of the beast, 160 by "+STR$sy%+" pixels, 12 bits per pixel"
REM 8 bit Y format reader
st%=0
PTR#c%=0
sx%=160
sy%=128
input=8
cache%= TRUE
rowbytes%=sx%
FOR C%=0 TO 255
r%(C%)=C%/255*F
NEXT
g%()=r%()
b%()=r%()
r$="FN8"
info$="The number of the beast, 160 by "+ STR$sy%+" pixels, 8 bits per pixel"
ENDCASE
IF info% PRINT info$
SYS "Hourglass_On",1
SYS "Hourglass_On"
hour%=&406c4
IF m=-9 OR m=-10 THEN
REM Mono or colour JPEG output
......@@ -4225,7 +4226,7 @@ DEF FNChangeFSI(A$,spritearea%,workspace%,worklimit%,oksave%,okinfo%,RETURN ram%
code%=FNdim(8192)
SP=13
IF cache% THEN
PROCcachesize(code%)
PROCcachesize
IF cachebytes% THEN
filesize%=EXT#c%-PTR#c%
IF cache%>filesize% cache%=filesize%
......@@ -9559,15 +9560,21 @@ DEF PROCnewropal(D%)
ENDPROC
:
REM
DEF PROCnopal
FOR C%=0 TO 255
r%(C%)=C%/255*F
DEF PROCflatpal(E%)
E%=E%-1
FOR C%=0 TO E%
r%(C%)=C%/E%*F
NEXT
g%()=r%()
b%()=r%()
ENDPROC
:
REM
DEF PROCnopal
PROCflatpal(256)
ENDPROC
:
REM
DEF PROCcol(A%,B%)
B%=B%<<8 OR B%<<4 OR &10
pal%!(A%*8)=B%
......@@ -9579,14 +9586,6 @@ DEF FNbits(A%)
IF A%=1 THEN ="1 bit per pixel" ELSE = STR$A%+" bits per pixel"
:
REM
DEF FNfits
LOCAL Z%,s$
FOR Z%=1 TO 80
s$+=CHR$BGET#c%
NEXT
=s$
:
REM
DEF FNuc(a$)
LOCAL Z%,z$,b$
FOR Z%=1 TO LEN a$
......@@ -9885,13 +9884,14 @@ DEF PROCadjustpalette(mul,sub)
ENDPROC
:
REM
DEF PROCcachesize(A%)
SYS &20023,"ChangeFSI$Cache",A%,-1 TO ,,Z
IF Z<>0 THEN
SYS &23,"ChangeFSI$Cache",A%,20 TO ,,Z
A%?Z=13
cache%=VAL $A%
IF INSTR($A%,"K") OR INSTR($A%,"k") cache%=cache%*1024
DEF PROCcachesize
LOCAL size%,str$
SYS &20023,"ChangeFSI$Cache",0,-1 TO ,,size%
IF size%<>0 THEN
SYS &23,"ChangeFSI$Cache",STRING$(32,CHR$13),32 TO ,str$
cache%=VAL str$
IF INSTR(str$,"K") OR INSTR(str$,"k") cache%=cache%*1024
IF cache%<4096 THEN cache%=4096:REM Sensible floor
ELSE
cache%=128*1024
ENDIF
......@@ -10460,8 +10460,8 @@ DEF PROCrewind
buff%=datacache%
IF cachebytes% !incacheptr=datacache%:!numlefttogo=cache%
IF input=24 OR input=48 IF rbo%>=0 rb%=buff%+rbo%:gb%=buff%+gbo%:bb%=buff%+bbo%
IF flag=1500 IF compression=5 rowstogo%=striprows%
ENDIF
IF flag=1500 IF compression=5 rowstogo%=striprows%
ENDPROC
:
REM
......
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