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