Code: Select all
Procedure RAIM(raw_img.i,bgcolour.i=#PB_Ignore,title.s="Report alpha image")
If bgcolour=#PB_Ignore
bgcolour = RGB(17,17,17)
EndIf
iw.d = ImageWidth(raw_img)
ih.d = ImageHeight(raw_img)
aimg.i = CreateImage(#PB_Any,iw,ih,32,bgcolour)
StartDrawing(ImageOutput(aimg))
DrawAlphaImage(ImageID(raw_img),0,0)
StopDrawing()
If Not title="" : title = "Report alpha image" : EndIf
win = OpenWindow(#PB_Any,0,0,iw,ih,title,#PB_Window_BorderLess|#PB_Window_ScreenCentered)
imgad = ImageGadget(#PB_Any,0,0,iw,ih,ImageID(aimg))
escapekey = 1
spacekey = 2
returnkey = 3
AddKeyboardShortcut(win,#PB_Shortcut_Escape,escapekey)
AddKeyboardShortcut(win,#PB_Shortcut_Space,spacekey)
AddKeyboardShortcut(win,#PB_Shortcut_Return,returnkey)
Repeat
we = WindowEvent()
If we
If we=#PB_Event_Menu
Break
EndIf
Else
Delay(10)
EndIf
ForEver
CloseWindow(win)
FreeImage(aimg)
EndProcedure
#FFMPEG = "P:\ffmpeg.exe" you will need to set location of ffmpeg.exe
folder.s = "P:\test4\" this will need to be a working folder
#IMAGE_WIDTH = 576
#IMAGE_HEIGHT = 432
; create a transparent 32-bit image, save it to file, discard it
img = CreateImage(#PB_Any,#IMAGE_WIDTH,#IMAGE_HEIGHT,32,#PB_Image_Transparent)
StartDrawing(ImageOutput(img))
DrawingMode(#PB_2DDrawing_AlphaBlend)
For a = 1 To 20
Box(Random(#IMAGE_WIDTH-50),Random(#IMAGE_HEIGHT-50),50,50,RGBA(Random(255),Random(255),Random(255),255))
Next a
StopDrawing()
RAIM(img)
fn.s = folder+"input.png"
UsePNGImageEncoder()
SaveImage(img,fn,#PB_ImagePlugin_PNG)
FreeImage(img)
; now try to get the image through FFMPEG...
#VIDEO_COLOR = 4
numpixels = #IMAGE_WIDTH * #IMAGE_HEIGHT
img = CreateImage(#PB_Any,#IMAGE_WIDTH,#IMAGE_HEIGHT,32,#PB_Image_Transparent)
dataSize = #IMAGE_WIDTH * #IMAGE_HEIGHT * #VIDEO_COLOR
Dim frame.a(dataSize)
param.s = "-i "+Chr(34)+fn+Chr(34)+" -c:v png -pix_fmt rgba -f image2 - -report"
prog.i = RunProgram(#FFMPEG,param,folder,#PB_Program_Open | #PB_Program_Read)
ReadProgramData(prog, @frame(0), dataSize)
CloseProgram(prog)
*pntr = @frame(0)
If StartDrawing(ImageOutput(img))
DrawingMode(#PB_2DDrawing_AlphaBlend)
For ycoord = 0 To #IMAGE_HEIGHT - 1
For x = 0 To #IMAGE_WIDTH - 1
rf.a = PeekA(*pntr)
gf.a = frame((yCoord / 2) * (#IMAGE_WIDTH / 2) + (x / 2) + numpixels)
bf.a = frame((yCoord / 2) * (#IMAGE_WIDTH / 2) + (x / 2) + numpixels + (numpixels / 4))
af.a = frame((yCoord / 2) * (#IMAGE_WIDTH / 2) + (x / 2) + numpixels + (numpixels / 4) + (numpixels / 4))
If rf > 255: rf = 255: ElseIf rf < 0: rf = 0:EndIf
If gf > 255: gf = 255: ElseIf gf < 0: gf = 0:EndIf
If bf > 255: bf = 255: ElseIf bf < 0: bf = 0:EndIf
If af > 255: af = 255: ElseIf af < 0: af = 0:EndIf
Plot (x, ycoord, RGBA(rf,gf,bf,af))
*pntr + 1
Next
Next
StopDrawing()
RAIM(img)
EndIf