GTIA Pixel Averaging (Pixel Scanner)
- Type
- Graphics
- Category
- Image-processing demo (GTIA GRAPHICS 9)
- Author
- Lyn Buchanan
- Published in
- Antic, June 1985 (Vol. 4, No. 2)
- Year
- 1985
- Language
- Atari BASIC
- Requirements
- GTIA chip (any XL/XE, or a 400/800 built from 1982 on), any memory size, Atari BASIC; disk or cassette
- Tags
- antic, gtia, graphics-9, image-processing, smoothing, locate, tutorial, 1985
About the program
Lyn Buchanan, a civilian programmer and systems-analysis instructor at Fort Meade, Maryland, wrote this short demonstration for Antic's June 1985 graphics issue. It introduces pixel averaging, a simple form of image processing. Each pixel is replaced by the average of itself and its eight neighbours. That smooths hard edges and gives a flat drawing "depth and fullness". Buchanan compared it to the enhancement NASA used on satellite photographs, and showed how to turn the same routine round to exaggerate differences instead.
The demo uses GRAPHICS 9, the GTIA mode with 16 shades of one colour, so each pixel's "value" is simply its brightness. It draws a stick-figure bird in the top half of the screen with PLOT and DRAWTO, then builds the enhanced copy underneath it, pixel by pixel.
Typing it in
Only lines 301 and 310 contain special characters (inverse-video text): {inv} … {/inv} means press the Atari (inverse) key before and after. Antic printed TYPO II checksums beside each line of the magazine listing. They are not part of the program. All the REM lines can be left out.
How to use it
RUN it, read the introduction and press START. The bird appears quickly. The averaged version then builds up below it, and that is slow. The program itself warns that it takes about 12 minutes, so an emulator's warp/turbo mode helps. When it's done the program holds the GRAPHICS 9 screen and gives a tone. Press BREAK and then RESET to leave.
How it works
- Lines 112–151 scan the area from x = 1–77 and y = 1–88. For each pixel, nine
LOCATEstatements (lines 121–129) read the brightness of the pixel and its eight neighbours into A–I. - Line 131 takes the integer average. Line 133 turns black (0) into a mid-grey (8), to lighten the background of the copy.
- Line 141 plots the result 95 lines lower, so the original isn't disturbed as it is being read. That matters: averaging in place would feed already-smoothed pixels into the next calculation.
POKE 77,0on every pixel stops the attract mode from scrambling the colours during the long run.
Variations to try
Buchanan's suggestions:
- Sharpen instead of blur. Change
COLOR Kin line 141 toCOLOR K*4(keeping the result within 0–15) to widen the differences between pixels. - Sample only some of the neighbours, for example just left and right, for directional effects.
- Change
GRAPHICS 9in line 201 toGRAPHICS 11(16 colours of equal brightness) for "beautiful blends of colors". - Replace lines 200–270 with your own picture.
Listing
10 REM GTIA PIXEL AVERAGING
20 REM BY LYN BUCHANAN
30 REM (c) 1985, ANTIC PUBLISHING
40 GOTO 300
100 REM PIXEL AVERAGING ROUTINE
110 REM SET AREA TO BE ENHANCED
111 REM Y-COORDINATE RANGE
112 FOR Y=1 TO 88
113 REM X-COORDINATE RANGE
114 FOR X=1 TO 77
115 REM STOP ATTRACT MODE
116 POKE 77,0
120 REM LOCATE EACH PIXEL AND ASSIGN ITS VALUE TO A VARIABLE
121 LOCATE X-1,Y-1,A
122 LOCATE X-1,Y,B
123 LOCATE X-1,Y+1,C
124 LOCATE X,Y-1,D
125 LOCATE X,Y,E
126 LOCATE X,Y+1,F
127 LOCATE X+1,Y-1,G
128 LOCATE X+1,Y,H
129 LOCATE X+1,Y+1,I
130 REM AVERAGE ALL PIXEL VALUES
131 K=INT((A+B+C+D+E+F+G+H+I)/9)
132 REM LIGHTEN THE BACKGROUND
133 IF K=0 THEN K=8
140 REM REPLOT PIXEL IN NEW COLOR
141 COLOR K:PLOT X,Y+95
150 REM RETURN FOR THE NEXT PIXEL
151 NEXT X:NEXT Y
160 REM LOCK SCREEN IN GR.9 MODE
161 POKE 77,0:SOUND 0,65,14,14:GOTO 161
199 REM
200 REM DRAW STICK FIGURE BIRD
201 GRAPHICS 9:POKE 712,144
210 REM DRAW TAIL
211 FOR X=1 TO 15:COLOR X:PLOT 15+X,75:DRAWTO 3+X/4,71-X/2:NEXT X
220 REM DRAW BODY
221 FOR X=16 TO 4 STEP -1:COLOR X:PLOT 15+X/0.6,74-X:DRAWTO 60-X/1.8,74-X
222 PLOT 15+X/0.6,66+X:DRAWTO 60-X/1.8,66+X:NEXT X
230 REM DRAW WINGS
231 FOR X=1 TO 16:COLOR X:PLOT 4,63:DRAWTO 18+X,10-X/2:DRAWTO X*2+20,66-X/4:DRAWTO X*2+24,66-X/4
232 DRAWTO 46+X,20-X/2:DRAWTO 75,45:NEXT X
240 REM DRAW HEAD
241 COLOR 11:FOR X=1 TO 22:PLOT 48+X/2,60-X/2:DRAWTO 68-X/6,60-X/2:NEXT X
250 REM DRAW BEAK
251 COLOR 15:FOR X=1 TO 5:PLOT 73,67:DRAWTO 48+X,67-X:NEXT X:FOR X=1 TO 15:PLOT 49+X/2,67:DRAWTO 75,55:NEXT X
260 REM DRAW EYE
261 COLOR 0:FOR Y=54 TO 56:PLOT 60,Y:DRAWTO 62,Y:NEXT Y
270 GOTO 100
299 REM
300 GRAPHICS 0:POKE 710,28:POKE 712,28:POKE 709,2
301 ? :? :? ,"{inv}GTIA PIXEL AVERAGING{/inv}":? ," by Lyn Buchanan":?
302 ? "This demo program draws a stick-figurebird using normal PLOT and DRAWTO"
303 ? "commands. Then the program 'computer enhances' the image by sampling the"
304 ? "color value of each pixel, and":? "averaging it with the values of the surrounding pixels.":?
305 ? "The BASIC routine is slow (takes about12 minutes), but the results are worththe wait.":?
310 POKE 752,1:POSITION 12,22:? "READY? PRESS {inv} START {/inv}":POKE 53279,8
320 IF PEEK(53279)<>6 THEN 320
330 POKE 53279,8:GOTO 200
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: BIRD.BAS.
Credits
- Program listing: GTIA Pixel Averaging (Pixel Scanner) — program listing (Antic, June 1985 (Vol. 4, No. 2)) — Lyn Buchanan
- Picture: The original drawing (top) and the pixel-averaged version (bottom) after the full run. — Lyn Buchanan (program); screenshot by the site
- Antic, June 1985 - Vol. 4 No. 2: scan of the printed magazine, PDF page 14 (article) — Internet Archive, 1985
- Antic disk, June 1985 - Vol. 4 No. 2: BIRD.BAS (detokenized listing) — Lyn Buchanan, 1985
