Read/Write pixel data

BlitzMax Forums/BlitzMax Programming/Read/Write pixel data

Do you guys know how to translate the value that comes from the "readPixel" command into and R,G,and B values and then convert back again so it can be used in "writePixel"? My intent is to be able to manipulate the values then write them back out to the pix map, but I'm not sure what that format is.

This should help.

If you want something simple for pre-/post- processing of pixmaps here’s a ‘template’ function that you might find useful:

SuperStrict

Graphics 800, 600

Local pm:TPixmap = CreatePixmap(256, 256, PF_RGBA8888)

ProcessPixmap(pm)

Local img:TImage = LoadImage(pm)

SetBlend AlphaBlend
SetAlpha 1.0

While Not KeyHit(KEY_ESCAPE)

	Cls
	
	DrawImage img, 0, 0
	
	Flip

Wend

End


' ---------------------------------------------------------

Rem
	'Process Pixmap TEMPLATE - modify as necessary
	'Suitable only for pre/post-processing of pixmaps
EndRem

Function ProcessPixmap(pm:TPixmap Var)

	If Not pm Then Return
	
	Local pm_format:Int = PixmapFormat(pm)
	
	If (pm_format <> PF_RGBA8888) Then pm = ConvertPixmap(pm, PF_RGBA8888)
		
	For Local x:Int = 0 To (pm.width - 1)
		For Local z:Int = 0 To (pm.height - 1)
		
			Local px:Int = ReadPixel(pm, x, z)
			Local a:Byte = px Shr 24
			Local b:Byte = px Shr 16
			Local g:Byte = px Shr 8
			Local r:Byte = px
		
			' ***		
			' ***	
			' *** Process pixels HERE
			r = Rand(128, 255)
			g = 0
			b = 0
			a = Rand(96, 255)
			' ***
			' ***
			' ***
			
			WritePixel(pm, x, z, Int(a Shl 24 | r Shl 16 | g Shl 8 | b))
			
		Next
	Next	
	
	If (pm_format <> PF_RGBA8888) Then pm = ConvertPixmap(pm, pm_format)
	
EndFunction