[comp.sys.apple2] 4096 painting

johnmac@fawlty.towers.oz (John MacLean) (08/15/90)

Before anyone asks this is roughly how such a paint program should plot
a pixel at XCOORD, YCOORD with color NEWRGB:

* store your entire graphic as RGB tripples.

* extract old RGB from graphic (not from screen)

	LDA	OLDRGB
	ASL
	TAY
	LDA	[FREQ_FOR_THIS_LINE],Y
	DEC
	STA	[FREQ_FOR_THIS_LINE],Y
	BNE	SKIPDEC
	DEC	COLORS_IN_THIS_PALETTE	;one less color in this palette
SKIPDEC	EQU	*
	
* put new RGB value into this graphic (not onto screen)

	LDA	NEWRGB
	ASL
	TAY
	LDA	[FREQ_FOR_THIS_LINE],Y
	BNE	SKIPINC
	INC	COLORS_IN_THIS_PALETTE	;one more color in this palette
SKIPINC EQU	*
	INC
	STA	[FREQ_FOR_THIS_LINE],Y
	
* if there are now more than 16 colors in the palette then you need to
* select a new palette and re-map your pixels in every scanline using this
* palette on the screen.

It is this last step that can be slow - the most frequent colors DO NOT
make the best palette - you could have 18 blues that occur frequently and
1 red that appears in 1 or two pixels - unless you have a red in your
palette you are in big trouble.

You need to work out a good algorithm to keep info around about your last
palette optimization so that the incremental cost of updating the palette
is very small.
I have tried a couple - but never put them into a fully operational
paint program.
I have also only done it with 16 palettes - not 200.

John MacLean.
-- 
This net: johnmac@fawlty.towers.oz.au                   Phone: +61 2 427 2999
That net: uunet!fawlty.towers.oz.au!johnmac             Fax:   +61 2 427 7072
Snail:    Tower Technology, Unit D 31-33 Sirius Rd,     Home:  +61 2 960 1453
          Lane Cove, NSW 2066, Australia.