Or please replace Procedure.i ImageToGrayScaleBuffer(Img.i) with:
Code: Select all
Procedure.i ImageToGrayScaleBuffer(Img.i)
Structure rgba
b.a
g.a
r.a
alpha.a
EndStructure
Protected.i ImgWidth, ImgHeight, PixelBytes, LinePadBytes, X, Y
Protected *Buffer, *BufferPos.Ascii, *ImgPos.rgba
If IsImage(Img)
If StartDrawing(ImageOutput(Img))
ImgWidth = ImageWidth(Img)
ImgHeight = ImageHeight(Img)
*Buffer = AllocateMemory(ImgWidth * ImgHeight, #PB_Memory_NoClear)
If *Buffer
PixelBytes = 3
*ImgPos = DrawingBuffer()
If DrawingBufferPixelFormat() & #PB_PixelFormat_32Bits_RGB : PixelBytes = 4 : EndIf
If DrawingBufferPixelFormat() & #PB_PixelFormat_32Bits_BGR : PixelBytes = 4 : EndIf
LinePadBytes = DrawingBufferPitch() - (ImgWidth * PixelBytes)
Debug "PixelBytes: " + Str(PixelBytes)
ImgWidth - 1
ImgHeight - 1
*BufferPos = *Buffer
For Y = 0 To ImgHeight
For X = 0 To ImgWidth
;Debug Hex(*ImgPos\a) + " " + Hex(*ImgPos\r) + " " + Hex(*ImgPos\g) + " " + Hex(*ImgPos\b)
If PixelBytes = 3
*BufferPos\a = (*ImgPos\r + *ImgPos\g + *ImgPos\b) / 3
Else
If *ImgPos\alpha > 127
*BufferPos\a = (*ImgPos\r + *ImgPos\g + *ImgPos\b) / 3
Else
*BufferPos\a = $FF
EndIf
EndIf
;*BufferPos\a = 0.2990 * *ImgPos\r + 0.5870 * *ImgPos\g + 0.1140 * *ImgPos\b ; TV
;*BufferPos\a = 0.2126 * *ImgPos\r + 0.7152 * *ImgPos\g + 0.0722 * *ImgPos\b ; ITU-R BT.709 HDTV and CIE 1931 sRGB
;*BufferPos\a = 0.2627 * *ImgPos\r + 0.6780 * *ImgPos\g + 0.0593 * *ImgPos\b ; ITU-R BT.2100 HDR
*BufferPos + 1
*ImgPos + PixelBytes
Next X
*ImgPos + LinePadBytes
Next Y
EndIf
StopDrawing()
EndIf
EndIf
ProcedureReturn *Buffer
EndProcedure
This image is strange. It uses only black color (0 0 0) and it only sets the transparency.