PGM on the Atari 8-bit

Jpeg Viewers    PGM Viewer    Sample BASIC program    Home

horizontal bar

a8jdpeg and JpegView can both convert JPEGs to PGM (Portable Greymap) format. PGM files can easily be read on the Atari 8-bit (and many other machines too), and converted to whatever format suits you.

Now there's a PGM viewer available for the Atari 8-bit. This uses the same interface as JpegView, but only needs 48K of RAM. This means that you can now view images in HIP and other flicker modes on a 48K machine:

PgmView 0.1 (17Oct03)

a PGM viewer for the Atari 8-bit.

This is also useful for frequently viewed images or if you want to view an image in several different display modes, especially if you've got a large ramdisk. It's a lot quicker to decode a PGM than a JPEG. The downside is that PGMs take up a lot more disk space than JPEGs.

PgmView also gives another way of transfering images between other computers and the Atari 8-bit. Netpbm is a freely available toolkit that allows you to convert images from many formats to PGM and back on Unix, Windows and Mac computers. So you can convert from just about any image format to PGM and then view it on your Atari 8-bit.

Converting formats

PGM is a good format to use if you want to extract the image information from a JPEG for your own use. The PGM files created by a8jdpeg 0.8 contain a header:
P5 #a8jdpeg-0.8
width height 255
Where width and height are the width and height of the image in pixels. These values are stored in ASCII. The header will be followed by the image data, with each pixel being held in 1 byte of data, with values ranging from 0 (black) to 255 (white). The total number of bytes in the file will depend on the width and height of the image, as found in the header. JpegView produces PGMs with an identical header, except that the #a8jdpeg-0.8 comment is replaced by #JpegView-0.9.

As an example of how to do this, a simple Atari BASIC program that reads the PGMs produced by a8jdpeg and JpegView is available. To try it, first create a PGM file called "PICTURE.PGM" using either a8jdpeg or JpegView, then LOAD this program into BASIC and RUN it. The program displays the PGM file as a GR.9 image. The program itself is very slow - it's provided as a simple example of how to read a PGM file, not as an example of how to draw GR.9 screens quickly (it'd be much quicker to POKE the data to the screen area rather than using COLOR and PLOT commands). You should be able to easily adapt this program to suit your own needs.

Download READPGM.BAS (1825 bytes)

NOTE: This is an Atari BASIC tokenized program, the .BIN extension is to make sure the file gets downloaded as a binary, you can get rid of the .BIN extension after you have downloaded the file. Boot into BASIC and either LOAD or RUN the file.

Here is the source to READPGM.BAS:

1 REM READ A PGM FILE CREATED BY
2 REM A8JDPEG
3 REM RAPHAEL ESPINO, 17SEP02
9 REM ---------------------------
10 WIDTH=0:HEIGHT=0:PARAM=0:DIM DAT$(1000)
20 OPEN #1,4,0,"D:PICTURE.PGM"
30 GOSUB 1000:REM READ PGM HEADER
40 REM IMAGE DIMENSIONS ARE NOW IN WIDTH AND HEIGHT VARIABLES, YOU CAN NOW READ IN IMAGE DATA AND PROCESS IT
50 WID=WIDTH:IF WID>80 THEN WID=80
55 HEI=HEIGHT:IF HEI>192 THEN HEI=192
60 ADRHI=INT(ADR(DAT$)/256):ADRLO=ADR(DAT$)-ADRHI*256:LENHI=INT(WIDTH/256):LENLO=WIDTH-LENHI*256
70 GRAPHICS 9
80 FOR Q=1 TO HEI:REM READ 1 LINE AT A TIME
90 DAT$(1)="":DAT$(1000)="":DAT$(2)=DAT$
100 POKE 852,ADRLO:POKE 853,ADRHI:POKE 856,LENLO:POKE 857,LENHI:POKE
850,7:I=USR(ADR("hhh*LVd"),16):REM The '*' and 'd' are in inverse video
109 REM NOW DRAW THE LINE ON THE SCREEN PIXEL BY PIXEL, THIS IS VERY SLOW BUT WORKS
110 FOR W=1 TO WID
120 COLOR INT(ASC(DAT$(W,W))/16):PLOT W-1,Q-1
130 NEXT W
140 NEXT Q
150 GOTO 150
200 CLOSE #1:END 
999 REM -------------------------
1000 REM READ PGM HEADER
1010 GET #1,K:IF K<>ASC("P") THEN ? "NOT A PGM FILE":END 
1020 GET #1,K:IF K<>ASC("5") THEN ? "UNSUPPORTED TYPE P";CHR$(K):END 
1040 GET #1,K
1050 IF K=ASC("#") THEN GOSUB 1200:GOTO 1040:REM SKIP COMMENTS
1060 IF KASC("9") THEN 1040
1069 REM MUST BE A NUMBER IN ASCII
1070 GOSUB 1100:IF PARAM<3 THEN 1040
1080 RETURN 
1099 REM -----------------------
1100 REM READ A NUMBER IN ASCII
1105 TOT=0
1110 TOT=TOT*10+K-48
1120 GET #1,K:IF K>=ASC("0") AND K<=ASC("9") THEN GOTO 1110
1130 PARAM=PARAM+1
1140 IF PARAM=1 THEN WIDTH=TOT:RETURN 
1150 IF PARAM=2 THEN HEIGHT=TOT:RETURN 
1160 IF PARAM=3 AND TOT<>255 THEN ? "UNSUPPORTED NUMBER OF GREYS":END 
1170 RETURN 
1199 REM ---------------------
1200 REM READ A COMMENT
1210 GET #1,K
1220 IF K=10 OR K=13 THEN RETURN 
1230 GOTO 1210


horizontal bar

Jpeg Viewers   Home