8-Bit Software Online Conversion
JPEG Reader - Listing
5MODE7
10REM Read a JPEG header to extract t
he
20REM useful information
30:
40INPUT"JPEG file to read: "f$
50F=OPENINf$
60DIMmarkerSOF(15)
70FORloop=0TO15:markerSOF(loop)=&C0+l
oop:NEXT:REM Array of command codes
80markerSOF(4)=255:REM Evil people,th
is one doesn't fit the pattern
90markerSOI=&D8:REM Start of image
100markerEOI=&D9:REM End of image
110markerSOS=&DA:REM Start of stream
120markerCOM=&FE:REM Comment
130IFBGET#F<>255 ORBGET#F<>markerSOI T
HENPRINT"Not a JPEG file":CLOSE#F:END
140:
150REPEAT
160M%=FNgetmarker
170FORloop=0TO15
180 IFmarkerSOF(loop)=M% THENPROCdecod
emark(M%):M%=0:loop=16
190NEXT
200IFmarkerSOS=M% ORmarkerEOI=M% THENM
%=TRUE
210IFmarkerCOM=M% THENPROCshowcomment:
M%=0
220IFM%<>TRUE ANDM%<>0 THENM%=FNskipun
known
230UNTILM%=TRUE
240CLOSE#F
250END
260:
270DEFFNtwobyte
280LOCALbyte%:byte%=(BGET#F*256):=byte
%+BGET#F
290:
300DEFPROCshowcomment
310LOCALloop%
320length%=FNtwobyte:FORloop%=1TO(leng
th%-2):VDU BGET#F:NEXT
330PRINT
340ENDPROC
350:
360DEFPROCdecodemark(M%)
370LOCALloop%,flag%
380length%=FNtwobyte
390precision%=BGET#F
400height%=FNtwobyte
410width%=FNtwobyte
420components%=BGET#F
430PRINT"Compression method: ";
440IFM%=markerSOF(0) THENPRINT"Baselin
e":flag%=TRUE
450IFM%=markerSOF(1) THENPRINT"Extende
d sequential":flag%=TRUE
460IFM%=markerSOF(2) THENPRINT"Progres
sive":flag%=TRUE
470IFM%=markerSOF(3) THENPRINT"Lossles
s";:flag%=TRUE
480IFM%=markerSOF(5) THENPRINT"Differe
ntial sequential":flag%=TRUE
490IFM%=markerSOF(6) THENPRINT"Differe
ntial progressive":flag%=TRUE
500IFM%=markerSOF(7) THENPRINT"Differe
ntial lossless":flag%=TRUE
510IFM%=markerSOF(8) THENPRINT"Extende
d sequential, arithmetic coding":flag%=T
RUE
520IFM%=markerSOF(10) THENPRINT"Progre
ssive, arithmetic coding":flag%=TRUE
530IFM%=markerSOF(11) THENPRINT"Lossle
ss, arithmetic coding":flag%=TRUE
540IFM%=markerSOF(13) THENPRINT"Differ
ential sequential, arithmetic coding":fl
ag%=TRUE
550IFM%=markerSOF(14) THENPRINT"Differ
ential progressive, arithmetic coding":f
lag%=TRUE
560IFM%=markerSOF(15) THENPRINT"Differ
ential lossless, arithmetic coding":flag
%=TRUE
570IFflag%=FALSE THENPRINT"Unknown"
580PRINT"Size: ";width%" x ";height%
590IFlength%<>(8+(components%*3)) THEN
PRINT"Bad SOF marker":CLOSE#F:END
600FORloop%=1TOcomponents%
610 dummy=BGET#F:REM Component ID code
620 dummy=BGET#F:REM H, V sampling fac
tors
630 dummy=BGET#F:REM Quantization tabl
e number
640NEXT
650ENDPROC
660:
670DEFFNgetmarker
680LOCALbyte%,length%:length%=TRUE
690REPEAT:byte%=BGET#F:length%=length%
+1:UNTILbyte%=&FF
700REPEAT:byte%=BGET#F:UNTILbyte%<>&FF
710IFlength%<>0 THENPRINT"Too many byt
es found in JPEG header":=TRUE
720=byte%
730:
740DEFFNskipunknown
750LOCALbyte%
760byte%=FNtwobyte:IFbyte%<2 THENPRINT
"Bad pointer length in JPEG header":=TRU
E
770PTR#F=PTR#F+(byte%-2)
780=FALSE