Code: Select all
#MaxIW = 1600
#MaxIH = 1200
Structure PixelMatrixColumn
y.i[#MaxIH+1]
EndStructure
Structure PixelMatrix
x.PixelMatrixColumn[#MaxIW+1] ; colour matrix
EndStructure
Macro Pixel(strucname,x,y)
strucname\pixelmatrix\x[x]\y[y]
EndMacro
Procedure.b ImageIntoStructuredPixelArray(img.i, *st,fieldoffset.i, free.b)
If Not IsImage(img) : ProcedureReturn #False : EndIf
iw = ImageWidth(img)
ih = ImageHeight(img)
id = ImageDepth(img)
*mem = AllocateMemory(iw*ih << 2)
CopyImageToMemory(img,*mem)
If free
FreeImage(img)
EndIf
*px.LONG = *mem
*strcptr.LONG = *st + fieldoffset
*strcptr-SizeOf(INTEGER)
For x = 0 To iw-1
ycounter = x
For y = 0 To ih-1
*strcptr+SizeOf(INTEGER)
If y<ih And x<iw
*px = *mem + (ycounter<<2)
;*strcptr\l = RGBA(*px\l >> 16 & $FF, *px\l >> 8 & $FF, *px\l & $FF, *px\l >> 24 & $FF)
If id=32
alpha = *px\l >> 24 & $FF
Else
alpha = 255
EndIf
*strcptr\l = RGBA(*px\l >> 16 & $FF, *px\l >> 8 & $FF, *px\l & $FF, alpha)
EndIf
ycounter+iw
Next y
*strcptr+SizeOf(INTEGER)
*strcptr + ((#MaxIH-ih)*SizeOf(INTEGER))
Next x
FreeMemory(*mem)
ProcedureReturn #True
EndProcedure