pour info : toujours mettre les images dans un tableau !! ( je l'ai deja indiqué sur le forum
toujours essayer de mettre les Startdrawing()--stopdrawing() en dehors des boucles !! ....c'est tres important pour la vitesse
voila bonne Vacances ...
( pour moi il fait toutes les tranches !!ma modif a peut etre arrangé le probleme
j'ai mis un tableau de 2000x2000 ce qui limite les images a ce format ....
Code : Tout sélectionner
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Button_0
#Button_1
#ScrollArea_1
#Progressbar_0
#Progressbar_1
#Progressbar_2
#TextGadget_0
#TextGadget_1
#StringGadget_0
#StringGadget_1
; #Image_1
#Image_2
; #Image_3
; #Image_4
EndEnumeration
;}
;{ Images
; Enumeration
; #Image_Image_2
; EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Global x.f, y.f, z.f
Global rho.f, theta.f, phi.f, theta_offset.f
Global in, out, in_width, in_height
global Dim Tableau(2000, 2000) ; ajouté par Dobro
;UseJPEG2000ImageDecoder
;UseJPEG2000ImageEncoder
UseJPEGImageDecoder()
UseJPEGImageEncoder()
UsePNGImageDecoder()
UsePNGImageEncoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
Procedure spherical_to_cartesian( rrho.f, ttheta.f, pphi.f )
x= rrho*Cos(ttheta)*Sin(pphi)
y= rrho*Sin(ttheta)*Sin(pphi)
z= rrho*Cos(pphi)
EndProcedure
Procedure cartesian_to_spherical( xx.f, yy.f, zz.f )
rho= Sqr(xx*xx+yy*yy+zz*zz)
theta= ATan2(xx,yy)
phi= ACos(zz/rho)
EndProcedure
Procedure getcolour (xx.f, yy.f, zz.f)
Protected rrrho.f,tttheta.f,ppphi.f
Protected u,v
rrrho= Sqr(xx*xx+yy*yy+zz*zz)
tttheta= ATan2(xx,yy)
ppphi= ACos(zz/rrrho)
;cartesian_to_spherical( xx, yy, zz );my ($rho, $theta, $phi) = ;
tttheta + theta_offset;
u = Int ( ( tttheta / ( 2 * #PI ) ) * in_width );
v = Int ( in_height - ( ( ppphi / #PI ) * in_height ) );
;;;;;;; StartDrawing(ImageOutput(in)) ; enlevé par Dobro , plus besoin on a un tableau ,
colour = tableau(u,v) ; enlev par Dobro Point(u, v);my $colour = $in->Get( "pixel[$u,$v]" );
;StopDrawing()
;Debug colour
ProcedureReturn colour
EndProcedure
Procedure tranche(nbre_de_panel, circonference, image$ )
;<number of panels> <circumference> <filename> exemple $0 16 1000 input.jpg
Protected n,out_size,out_filetype$,out_height,out_width,rho_out.f, phi_out.f
Protected y_out, x_out, junk_out, z_out
;Dim image_out(12)
n = nbre_de_panel
SetGadgetAttribute(#ProgressBar_0, #PB_ProgressBar_Maximum, n)
SetGadgetAttribute(#ProgressBar_1, #PB_ProgressBar_Maximum, out_width)
SetGadgetAttribute(#ProgressBar_2, #PB_ProgressBar_Maximum, out_height)
out_size = circonference; output circumference
out_filetype$ = "png"; can be changed to tif, gif, jpg or whatever..
out_height = Int ( out_size / 2 );
out_width = Int ( ( out_size / #PI ) * Tan( #PI / n ) );
rho_out = out_height / #PI; output radius
in = LoadImage(#PB_Any, image$);
in_width = ImageWidth(in)
in_height = ImageHeight(in)
Debug "Input image is " + Str(in_width) + " x " + Str(in_height)
SetWindowTitle(#Window_0,"Input image is " + Str(in_width) + " x " + Str(in_height))
; ************** ajout Dobro ****************
StartDrawing(ImageOutput(in)) ; on met l'image en tableau pour mettre le Turbo
for y1=0 to in_height -1
for x1=0 to in_width -1
tableau(x1,y1)=point(x1,y1)
next x1
next y1
StopDrawing();
; *************************************************
out = CreateImage(#PB_Any, out_width*n, out_height)
StartDrawing(ImageOutput(out))
Box(0,0,out_width*n, out_height,$ffffff);
StopDrawing();
SetGadgetState(#ProgressBar_0, 0)
StartDrawing(ImageOutput(out))
For panel = 0 To n-1
SetGadgetState(#ProgressBar_0, panel)
Debug panel
theta_offset = ( #PI / n ) * ( panel + 0.5 ) * 2;
;Debug theta_offset
SetGadgetState(#ProgressBar_1, 0)
For u = 0 To out_width - 1
;Debug "u " + Str(u)
SetGadgetState(#ProgressBar_1, u)
;SetGadgetState(#ProgressBar_2, 0)
For v = 0 To out_height - 1;
;SetGadgetState(#ProgressBar_2, v)
;Debug "v " + Str(v)
y_out = u - ( out_width / 2 );
phi_out = ( ( v / out_height ) * #PI ); # phi is inclination
;Debug phi_out
spherical_to_cartesian( rho_out, 0, phi_out );
x_out=x
junk-out=y
z_out=z
If x_out >= 0
If ATan(y_out/x_out) =< (#PI/n)
If ( 0 - ATan(y_out/x_out)) =< (#PI/n)
colour = getcolour( x_out,y_out,-z_out )
Plot(u+out_width*panel,v,colour)
EndIf
EndIf
EndIf
Next v
Next u
Next panel
StopDrawing()
Debug "ok"
SetGadgetState(#Image_2,ImageID(out))
;}
EndProcedure
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 3, 2, 1020, 760, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
ButtonGadget(#Button_0, 20, 15, 135, 30, "Ouvrir image")
ButtonGadget(#Button_1, 170, 15, 135, 30, "Enregistrer image")
ProgressBarGadget(#ProgressBar_0, 320, 3, 300, 15, 0, 100 )
ProgressBarGadget(#ProgressBar_1, 320, 21, 300, 15, 0, 100 )
ProgressBarGadget(#ProgressBar_2, 320, 39, 300, 15, 0, 100 )
TextGadget(#TextGadget_0, 650, 7, 60, 28, "Tranches")
TextGadget(#TextGadget_1, 650, 35, 60, 28, "Diamètre")
StringGadget(#StringGadget_0, 720, 3, 50, 24, "12")
StringGadget(#StringGadget_1, 720, 30, 50, 24, "2048")
ScrollAreaGadget(#ScrollArea_1, 5, 60, 1000, 650, 3000, 1000, 100, #PB_ScrollArea_Single)
ImageGadget(#Image_2, 10, 10, 565, 450, 0, #PB_Image_Border)
CloseGadgetList()
EndIf
EndProcedure
Procedure.s openimage()
FichierParDefaut$ = ""
Filtre$ = "Images (*.jpg)|*.jpg;*.bmp|Tous les fichiers (*.*)|*.*"
Filtre = 0 ; utiliser par défaut le premier des trois filtres possibles
image$ = OpenFileRequester("Choisissez un fichier à charger", FichierParDefaut$, Filtre$, Filtre)
ProcedureReturn image$
EndProcedure
OpenWindow_Window_0()
;{- Event loop
Repeat
Event = WaitWindowEvent()
Select Event
; ///////////////////
Case #PB_Event_Gadget
EventGadget = EventGadget()
EventType = EventType()
If EventGadget = #Button_0
image$=openimage()
DisableGadget(#Button_1, 1)
If image$
;tranche(nbre_de_panel, circonference, image$ )
tranche(Val(GetGadgetText(#StringGadget_0)), Val(GetGadgetText(#StringGadget_1)), image$ )
; Else
; MessageRequester("Information", "La sélection a été annulée.", 0)
DisableGadget(#Button_1, 0)
EndIf
ElseIf EventGadget = #Button_1
outFichier$ = SaveFileRequester("Enregistrer l'image sous...", image$ + "(maquette).jpg", "*.*",0)
If outFichier$
Resultat = SaveImage(out, outFichier$ ,#PB_ImagePlugin_JPEG , 10 )
EndIf
; #PB_ImagePlugin_BMP : Enregistre l'image en BMP (défaut).
; #PB_ImagePlugin_JPEG : Enregistre l'image en JPEG (UseJPEGImageEncoder() doit être utilisé)
; #PB_ImagePlugin_JPEG2000 : Enregistre l'image en JPEG2000 (UseJPEG2000ImageEncoder() doit être utilisé)
; #PB_ImagePlugin_PNG : Enregistre l'image en PNG (UsePNGImageEncoder() doit être utilisé)
Debug "enregistré"
EndIf
; ////////////////////////
Case #PB_Event_CloseWindow
EventWindow = EventWindow()
If EventWindow = #Window_0
CloseWindow(#Window_0)
Break
EndIf
EndSelect
ForEver
;
;}
; EPB