@spock : je comprends l'idée, puisque c'est ce que je pensais faire ^^. Maintenant, il faut que je mette ça en pratique
pour le moment, c'est ce que je pensais aussi ^^.
Pour la baguette magique, j'ai trouvé un algo de remplissage de Comtois qui fonctionne super bien, il manque juste la tolérance (des pixels plus ou moins proches du pixel sélectionné), mais sinon, ça me semble une bonne technique pour la baguette magique :
Mais par contre, je ne sais encore comment je vais convertir ça en couche alpha.
Code : Tout sélectionner
; Alpha selection
; by blendman jully 2015
Global w, h
w = 1024
h = 768
Enumeration ; sprite
#Sp_Layer
#Sp_LayerTempo
#Sp_Checker
#Sp_Selection
EndEnumeration
Enumeration ;Image
#Img_Layer
#Img_LayerTempo
#Img_AlphaSel
EndEnumeration
CreateImage(#Img_Layer,w,h,32,#PB_Image_Transparent)
CreateImage(#Img_LayerTempo,w,h,32,#PB_Image_Transparent)
CreateImage(#Img_AlphaSel,w,h,32,#PB_Image_Transparent)
;{ procedure
Procedure cb(x,y,top,bottom)
; by wilbert
If (x!y) & 8; checkerboard pattern
ProcedureReturn top
Else
ProcedureReturn bottom
EndIf
EndProcedure
Procedure Filtre_MaskAlpha(x, y, CouleurSource, CouleurDestination)
ProcedureReturn (CouleurSource & $00FFFFFF) | (Alpha(CouleurSource)*Alpha(CouleurDestination)/255)<<24
EndProcedure
Procedure CanvasUpdate()
If StartDrawing(SpriteOutput(#Sp_Layer))
; Box(0, 0, w, h, RGB(160,160,160))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,w,h,RGBA(0,0,0,0))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(#Img_Layer),0,0)
DrawAlphaImage(ImageID(#Img_AlphaSel),0,0)
; draw the painting
DrawingMode(#PB_2DDrawing_CustomFilter)
CustomFilterCallback(@Filtre_MaskAlpha())
DrawAlphaImage(ImageID(#Img_LayerTempo),0,0)
StopDrawing()
EndIf
ClearScreen(RGB(160,160,160))
DisplayTransparentSprite(#Sp_Checker,0,0)
DisplayTransparentSprite(#Sp_Layer,0,0)
DisplayTransparentSprite(#Sp_Selection,0,0)
FlipBuffers()
EndProcedure
;}
InitSprite()
OpenWindow(0, 0, 0, w, h, "Selection and alpha", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
screenwidth = 1024
screenheight = 768
If OpenWindowedScreen(WindowID(0),0,0,w, h)=0
MessageRequester("Error", "Can't Open Screen!", 0)
End
EndIf
; the image
If StartDrawing(ImageOutput(#Img_Layer))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,w,h,RGBA(0,0,0,0))
StopDrawing()
EndIf
If StartDrawing(ImageOutput(#Img_LayerTempo))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,w,h,RGBA(0,0,0,0))
StopDrawing()
EndIf
If StartDrawing(ImageOutput(#Img_AlphaSel))
DrawingMode(#PB_2DDrawing_AlphaChannel)
; create the mask
Circle(450,350,100,RGBA(0,0,0,255))
Circle(305,240,145,RGBA(0,0,0,120))
StopDrawing()
EndIf
; the sprite (for the preview)
CreateSprite(#Sp_Layer,w,h,#PB_Sprite_AlphaBlending)
CreateSprite(#Sp_LayerTempo,w,h,#PB_Sprite_AlphaBlending)
CreateSprite(#Sp_Selection,w,h,#PB_Sprite_AlphaBlending)
CreateSprite(#Sp_Checker,w,h,#PB_Sprite_AlphaBlending) ; the checker
If StartDrawing(SpriteOutput(#Sp_Checker))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0,0,w,h,RGBA(200,200,200,255))
DrawingMode(#PB_2DDrawing_CustomFilter)
CustomFilterCallback(@cb())
Box(0,0,w,h,RGBA(160,160,160,255))
StopDrawing()
EndIf
If StartDrawing(SpriteOutput(#Sp_Selection))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,w,h,RGBA(0,0,0,0))
;DrawingMode(#PB_2DDrawing_Outlined) ; <------------- here, I would like to find a way to see a selection border
; based on the alpha of the shape (the two icrcle, in this exemple),
; which could work With image( it's ok if I use only box(), circle()....
;DrawAlphaImage(ImageID(#Img_AlphaSel),0,0)
StopDrawing()
EndIf
CanvasUpdate()
Repeat
Repeat
Event = WaitWindowEvent(1)
Select Event
Case #PB_Event_CloseWindow
End
Case #WM_LBUTTONDOWN ; left buton down
paint = 1
Case #PB_Event_LeftClick ; left buton up
paint = 0
EndSelect
Until event = 0
If paint = 1
If StartDrawing(ImageOutput(#Img_LayerTempo))
DrawingMode(#PB_2DDrawing_AlphaBlend)
x = WindowMouseX(0)
y = WindowMouseY(0)
Circle(x, y, 50, RGBA(255,120,120,255))
StopDrawing()
EndIf
CanvasUpdate()
EndIf
ForEver