
Mais alors à quoi sert ReDIM

Son intérêt est d'uniquement réduire un tableau (si besoin) alors ?
Code : Tout sélectionner
; Ar-S FX Lib 1.1 - Multi Effets sur image par Ar-S // 2013
UsePNGImageDecoder()
UsePNGImageEncoder()
Enumeration 10
#IMG_ORIGINALE ; Image originale
#IMAGE_FX ; Image cible
#IMAGE_FX_90 ; pour l'image retournée qui nécessitera une taille différente de l'originale
EndEnumeration
#Image_Flip_X = 1
#Image_Flip_Y = 2
#Image_Rotate_90L = 3
#Image_Rotate_90R = 4
#Image_2colors = 5
#Image_Gray = 6
#Image_Mirror_L = 7
#Image_Mirror_R = 8
#Image_Rotate_180 = 9
#Image_MixPixel = 10
Declare StockPixelTab(IMG)
Declare MixPixel()
Declare ARS_FX(IMG, FX)
Lwin = 741 : Hwin = 480
Global Canvas_MAX_L = Lwin - 101
Global Canvas_MAX_H = Hwin
Global Dim TabPixel(1,1)
Global Dim TabMix(1,1)
Global Diff = 54
; ********Exemple**********
; ********************* PROGRAMME **********************
LoadImage(#IMG_ORIGINALE,GetCurrentDirectory()+"pb.png")
CreateImage(#IMAGE_FX, ImageWidth(#IMG_ORIGINALE), ImageHeight(#IMG_ORIGINALE))
CreateImage(#IMAGE_FX_90, ImageHeight(#IMG_ORIGINALE), ImageWidth(#IMG_ORIGINALE))
StockPixelTab(#IMG_ORIGINALE)
hwnd = OpenWindow(0, #PB_Any, #PB_Any, Lwin, Hwin, "Image FX Lib by Ar-S // 2013", #PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
StickyWindow(0,1)
Clic = 0
Clac = 0
CanvasGadget(1, 101, 1, Canvas_MAX_L, Canvas_MAX_H , #PB_Canvas_DrawFocus|#PB_Canvas_ClipMouse)
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0,0, Canvas_MAX_L, Canvas_MAX_H, $FFFFFF)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(5,5, "Vide", $0)
StopDrawing()
ButtonGadget(2,1,1,100,29,"Image originale")
ButtonGadget(3,1,30,100,29,"Niveau de Gris")
ButtonGadget(4,1,60,100,29,"2 Couleurs ")
TrackBarGadget(5, 45, 90, 20, 100, 0, 255, #PB_TrackBar_Vertical)
ButtonGadget(6,1,200,100,29,"Rotation 180° ")
ButtonGadget(7,1,230,100,29,"Sym Verticale ")
ButtonGadget(8,1,260,100,29,"Sym Horizontale ")
ButtonGadget(9,1,290,100,29,"90° gauche")
ButtonGadget(10,1,320,100,29,"Miroir Droite")
ButtonGadget(11,1,350,100,29,"Mixer les pixels")
SetGadgetState(5, Diff)
; ************ EVENT et BOUCLE **********************
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 2 ; Voir Image originale
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMG_ORIGINALE),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(5,5, "Image originale", $0)
StopDrawing()
Case 3 ; Voir Image GRIS
ARS_FX(#IMAGE_FX, #Image_Gray)
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMAGE_FX),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(5,5, "Image Gray", $0)
StopDrawing()
Case 4 ; Voir image 2 COL
start = ElapsedMilliseconds()
ARS_FX(#IMAGE_FX, #Image_2colors)
endms = ElapsedMilliseconds() - start
Debug endms
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMAGE_FX),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(5,5, "Image 2 col : Diff = "+Str(Diff), $0)
StopDrawing()
;
Case 5 ; Réglage de l'intensité (valeur de Diff) via la trackbar en mode 2 couleurs
Diff = GetGadgetState(5)
ARS_FX(#IMAGE_FX, #Image_2colors)
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMAGE_FX),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(5,5, "Image 2 col : Diff = "+Str(Diff), $0)
StopDrawing()
Case 6 ; Rotation 180 °
ARS_FX(#IMAGE_FX, #Image_Rotate_180)
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMAGE_FX),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(105,ImageHeight(#IMAGE_FX)-30, "Rotation 180°", $0)
StopDrawing()
Case 7 ; Symétrie Verticale
ARS_FX(#IMAGE_FX, #Image_Flip_Y)
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMAGE_FX),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(5,ImageHeight(#IMAGE_FX)-30, "Symétrie Verticale", $0)
StopDrawing()
Case 8 ; Symétrie Horizontale
ARS_FX(#IMAGE_FX, #Image_Flip_X)
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMAGE_FX),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(105,5, "Symétrie Horizontale", $0)
StopDrawing()
Case 9 ; Rotation 90° de l'image
If clic = 0
ARS_FX(#IMAGE_FX_90, #Image_Rotate_90L)
clic +1
SetGadgetText(9, "90° Droite")
Else
ARS_FX(#IMAGE_FX_90, #Image_Rotate_90R)
clic = 0
SetGadgetText(9, "90° Gauche")
EndIf
StartDrawing(CanvasOutput(1))
Box (0,0,GadgetWidth(1), GadgetHeight(1),$FFFFFF)
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMAGE_FX_90),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(105,5, "Rotation 90°", $0)
StopDrawing()
Case 10 ; Mirroring
If Clac = 0
ARS_FX(#IMAGE_FX, #Image_Mirror_L)
Clac +1
MirTXT.s = " Droite"
SetGadgetText(10, "Miroir Gauche")
Else
ARS_FX(#IMAGE_FX, #Image_Mirror_R)
Clac = 0
MirTXT.s = " Gauche"
SetGadgetText(10, "Miroir Droite")
EndIf
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMAGE_FX),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(105,5, "Miroir" +MirTXT, $0)
StopDrawing()
Case 11 ; Mixer les Pixels
MixPixel()
ARS_FX(#IMAGE_FX, #Image_MixPixel)
StartDrawing(CanvasOutput(1))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(#IMAGE_FX),0,0)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(5,ImageHeight(#IMAGE_FX)-30, "Mixer les pixels", $0)
StopDrawing()
EndSelect
Case #PB_Event_CloseWindow
Select EventWindow()
Case 0
quite=1
EndSelect
EndSelect
Until quite=1
For i = #IMG_ORIGINALE To #IMAGE_FX_90
If IsImage(i)
FreeImage(i)
EndIf
Next
End
; ************ PROCEDURES **********************
Procedure StockPixelTab(IMG)
Protected Couleur
DimX = ImageWidth(IMG)
DimY = ImageHeight(IMG)
Dim TabPixel(DimX, DimY)
Dim TabMix( DimX,DimY )
StartDrawing(ImageOutput(IMG))
For y = 0 To DimY-1
For x = 0 To DimX-1
TabPixel(x,y) = Point (x,y)
Next x
Next y
StopDrawing()
EndProcedure
Procedure MixPixel()
Dim TabMix (ArraySize (TabPixel(),1 ), ArraySize (TabPixel(),2) )
CopyArray(TabPixel(), TabMix())
RandomizeArray(TabMix())
EndProcedure
Procedure ARS_FX(IMG, FX)
; Effets multiples sur image.
Protected Image_Grab
If IsImage(IMG) = 0
ProcedureReturn 0
EndIf
StartDrawing(ImageOutput(IMG))
DrawImage(ImageID(IMG),0,0)
Select FX
Case #Image_2colors
For y = 0 To ImageHeight(IMG)-1
For x = 0 To ImageWidth(IMG)-1
Couleur = TabPixel(x,y)
R = Red(Couleur)
G = Green(Couleur)
B = Blue(Couleur)
Gray = (R+G+B)/3
If Gray >= Diff
Gray = 255
Else
;Gray = (R+G+B)/3 ; Blanc jusqu'à niveau de gris
Gray = 10 ; Blanc jusqu'à (presque) noire
EndIf
NewCOLOR = RGBA(Gray,Gray,Gray,255)
Plot (x, y , NewCOLOR)
Next x
Next y
Case #Image_Flip_X
For y = 0 To ImageHeight(IMG)-1
For x = ImageWidth(IMG)-1 To 0 Step -1
Plot (x, y , TabPixel(x,y))
Next x
Next y
Case #Image_Flip_Y
For y = ImageHeight(IMG)-1 To 0 Step -1
For x = 0 To ImageWidth(IMG)-1
Plot (x, y , TabPixel(x,y))
Next x
Next y
Case #Image_Gray
For y = 0 To ImageHeight(IMG)-1
For x = 0 To ImageWidth(IMG)-1
R = Red(TabPixel(x,y))
G = Green(TabPixel(x,y))
B = Blue(TabPixel(x,y))
Gray = (R+G+B) / 3
Plot (x, y , RGBA(Gray, Gray, Gray, 255))
Next x
Next y
Case #Image_Mirror_R
Image_Grab = GrabImage(#IMG_ORIGINALE, #PB_Any, 0, 0, ImageWidth(IMG) / 2, ImageHeight(IMG))
Box (0,0,ImageWidth(IMG), ImageHeight(IMG))
DrawImage(ImageID(Image_Grab),0,0)
For y = 0 To ImageHeight(IMG)-1
For x = ImageWidth(IMG)-1 To 0 Step -1
Plot (x, y , TabPixel(x,y))
Next x
Next y
DrawImage(ImageID(Image_Grab),0,0)
FreeImage(Image_Grab)
Case #Image_Mirror_L
Image_Grab = GrabImage(#IMG_ORIGINALE, #PB_Any, ImageWidth(IMG) /2, 0, ImageWidth(IMG) / 2, ImageHeight(IMG))
Box (0,0,ImageWidth(IMG), ImageHeight(IMG))
DrawImage(ImageID(Image_Grab),ImageWidth(IMG) /2 ,0)
For y = 0 To ImageHeight(IMG)-1
For x = ImageWidth(IMG)-1 To 0 Step -1
Plot (x, y , TabPixel(x,y))
Next x
Next y
DrawImage(ImageID(Image_Grab),ImageWidth(IMG) /2 ,0)
FreeImage(Image_Grab)
Case #Image_Rotate_180
For y = ImageHeight(IMG)-1 To 0 Step -1
For x = ImageWidth(IMG)-1 To 0 Step -1
Plot (x, y , TabPixel(x,y))
Next x
Next y
Case #Image_Rotate_90L
For x = 0 To ImageWidth(IMG)-1
For y = ImageHeight(IMG)-1 To 0 Step -1
Plot (x, y , TabPixel(y,x))
Next y
Next x
Case #Image_Rotate_90R
For x = ImageWidth(IMG)-1 To 0 Step -1
For y = 0 To ImageHeight(IMG)-1
Plot (x, y , TabPixel(y,x))
Next y
Next x
Case #Image_MixPixel
For y = 0 To ImageHeight(IMG)-1
For x = ImageWidth(IMG)-1 To 0 Step -1
Plot (x, y , TabMix(x,y))
Next x
Next y
FreeArray(TabMix())
Default
StopDrawing()
ProcedureReturn 0
EndSelect
StopDrawing()
ProcedureReturn 1
EndProcedure
Code : Tout sélectionner
CreateImage(#IMAGE_FX, ImageWidth(#IMG_ORIGINALE), ImageHeight(#IMG_ORIGINALE))
CreateImage(#IMAGE_FX_90, ImageHeight(#IMG_ORIGINALE), ImageWidth(#IMG_ORIGINALE))
Code : Tout sélectionner
Case #Image_Flip_X
For y = 0 To ImageHeight(IMG)-1
For x = ImageWidth(IMG)-1 To 0 Step -1
Plot (x, y , TabPixel(x,y))
Next x
Next y
Non rien qui me choque ici, vu que je vais retourner l'image à 90° il faut bien que je prépare une image ou largeur et hauteur seront inversées...Dobro a écrit :Ligne 43 , il n'y a rien qui te choque ?
là :Code : Tout sélectionner
CreateImage(#IMAGE_FX, ImageWidth(#IMG_ORIGINALE), ImageHeight(#IMG_ORIGINALE)) CreateImage(#IMAGE_FX_90, ImageHeight(#IMG_ORIGINALE), ImageWidth(#IMG_ORIGINALE))
Bah je ne vois pas non plus, vu que je prends mes pixels x de la fin vers le début pour l'effet miroir.Dobro a écrit : au fait , ici , il n'y a rien qui te choque ?Code : Tout sélectionner
Case #Image_Flip_X For y = 0 To ImageHeight(IMG)-1 For x = ImageWidth(IMG)-1 To 0 Step -1 Plot (x, y , TabPixel(x,y)) Next x Next y
![]()
tu fais quoi la ? hein ?
Ar-S a écrit :Non rien qui me choque ici, vu que je vais retourner l'image à 90°Dobro a écrit :Ligne 43 , il n'y a rien qui te choque ?
là :Code : Tout sélectionner
CreateImage(#IMAGE_FX, ImageWidth(#IMG_ORIGINALE), ImageHeight(#IMG_ORIGINALE)) CreateImage(#IMAGE_FX_90, ImageHeight(#IMG_ORIGINALE), ImageWidth(#IMG_ORIGINALE))
![]()
Bah je ne vois pas non plus, vu que je prends mes pixels x de la fin vers le début pour l'effet miroir.Dobro a écrit : au fait , ici , il n'y a rien qui te choque ?Code : Tout sélectionner
Case #Image_Flip_X For y = 0 To ImageHeight(IMG)-1 For x = ImageWidth(IMG)-1 To 0 Step -1 Plot (x, y , TabPixel(x,y)) Next x Next y
![]()
tu fais quoi la ? hein ?
Code : Tout sélectionner
Case #Image_Flip_X
For y = 0 To ImageHeight(IMG)-1
For x = 0 to ImageWidth(IMG)-1 ;ImageWidth(IMG)-1 To 0 Step -1
Plot ((ImageWidth(IMG)-1)-x, y , TabPixel(x,y))
Next x
Next y
Code : Tout sélectionner
Case #Image_Flip_Y
For y = 0 to ImageHeight(IMG)-1
For x = 0 To ImageWidth(IMG)-1
Plot (x, (ImageHeight(IMG)-1)-y , TabPixel(x,y))
Next x
Next y
Code : Tout sélectionner
For y = 0 To ImageHeight(IMG)-1
For x = ImageWidth(IMG)-1 To 0 Step -1
Plot ((ImageWidth(IMG)-1)-x, y , TabPixel(x,y))
Next x
Next y
Code : Tout sélectionner
Global maxtab = 5000
Dim tabpos(5000,5000)
;------ test
For x=1 To 5000
tabpos(x,2) = x
Next
For x=1 To 1500
tabpos(x,1) = x +15
Next
For x=1501 To 3000
tabpos(x,1) = x +22
Next
For x=3001 To 5000
tabpos(x,1) = x +11
Next
;------------fin test
I = maxtab / 2
While I > 0
t = maxtab - I
Repeat
p = 0
For n = 1 To t
tr1.l = tabpos(1,n)
tr2.l = tabpos(1,(n +I))
If tr1.l < tr2.l ; pour trier dans l'autre sens faite >
swp1.l = tabpos(1, n)
tabpos(1, n) = tabpos(1,(n) + I )
tabpos(1,(n) + I) = swp1.l
swp2.l = tabpos(2, n); pour ajouté une colonne ajoutez ce code en remplaçant les 2 par des 3 ect
tabpos(2,n) = tabpos(2,(n) + I);*************
tabpos(2,(n) + I) = swp2.l; fin pour une colonne sup
p = n
EndIf
Next
t = p - I
Until p = 0
I = I / 2
Wend
;----résultat
For y =1 To maxtab
Debug Str(tabpos(y,2)) + " " + Str(tabpos(y,1))
Next
Code : Tout sélectionner
width.l = 0
height.l = 0
Dim image.c(0)
Macro resize_image(w,h)
ReDim image( (w*4) * (h*4) )
width = w
height = h
EndMacro
Macro set_pixel(x,y,color)
PokeL(@image( ((x*4) * width + (y*4))),color)
EndMacro
Macro get_pixel(x,y)
PeekL( @image( ((x*4) * width + (y*4))) )
EndMacro
resize_image(1,1)
set_pixel(0,0, RGBA(255,128,64,32))
color = get_pixel(0,0)
Debug Red(color)
Debug Green(color)
Debug Blue(color)
Debug Alpha(color)