j’espère me lancer dans une production sur cette machine...
c'est actuellement un prototype et je rencontre un problème dont je ne comprend pas l'origine
après quelques minutes a remplir l’écran de traits de multiple couleurs
j'ai un message d'erreur ''the specified image is not initialised' ligne 522
je fais pourtant le menage apres mes allocations memoires et je met des freeimage avant de recreer de nouvelles images
afin d’être sur de ne pas avoir de memory leak
j'ai bien essayé d'ajouter un if isimage() a l'endroit ou ça bug mais dans ce cas cela apres un certain temps cela cesse d'afficher l'image tout court
le copyimage precedent semble ne pas se faire...
j'avoue je seche...
si quelqu'un a une idée de génie et trouve pourquoi ça merdoie je serai super content (et je ne m’appelle pas Jeremy)
merci a tous

Code : Tout sélectionner
InitSprite()
InitMouse()
InitKeyboard()
Global win=OpenWindow(#PB_Any,0,0,1680,1050,"",#PB_Window_BorderLess) ; CPC screen
Global can=CanvasGadget(#PB_Any,0,032,640,400)
Global cloz=CanvasGadget(#PB_Any,1024-32,0,32,32)
Global zoom=CanvasGadget(#PB_Any,640,32,400,400)
Global Dim pen_button(15),reverse
Global Dim pen(16) ; crayons
Global Dim palette(26) ; palette de l'amstrad
Global Dim palettergb(26) ; palette de l'amstrad
Global current_mode,zoomed,surface2
Global current_color=1,xm,ym
Global current_pen
Global *mem
OpenWindowedScreen(WindowID(win),-10,-10,1,1)
Global surface=CreateImage(#PB_Any,1,1,32)
StartDrawing(ImageOutput(surface))
Global rgbrg=DrawingBufferPixelFormat() % 32768
If DrawingBufferPixelFormat() > 32768 ; reverse
reverse = 1
Else ; normal
reverse = 0
EndIf
StopDrawing()
;---------------------------------------------palette en format rgb----------------------------------------------
RGB$="0000000000800000ff8000005000508000ffff0000ff0080ff00ff0080000080800080ff8080008080805050ffFF8000FF8080FF80FF00FF0000FF8000FFFF80FF0080FF8080FFFFFFFF00FFFF80FFFFFF" ; palette Amstrad
;---------------------------------------------lis la palette dans le tableau palette------------------------
For c=0 To 26 ; pour chaque couleur possible
palettergb(c)=RGB(Val("$"+Mid(RGB$,c*6+1,2)),Val("$"+Mid(RGB$,c*6+3,2)),Val("$"+Mid(RGB$,c*6+5,2))) ;RGB
Select rgbrg ; on selectionne le bon format
Case #PB_PixelFormat_32Bits_RGB ; RGB
palette(c)=RGB(Val("$"+Mid(RGB$,c*6+1,2)),Val("$"+Mid(RGB$,c*6+3,2)),Val("$"+Mid(RGB$,c*6+5,2))) ;RGB
Case #PB_PixelFormat_32Bits_BGR ;BGR
palette(c)=RGB(Val("$"+Mid(RGB$,c*6+5,2)),Val("$"+Mid(RGB$,c*6+3,2)),Val("$"+Mid(RGB$,c*6+1,2))) ;BRG
EndSelect
Next
;-----------------------------------------------------------------------------------------------------------
pen$="01242006260002081012141618220305"
For pen =0 To 15
pen(pen)=(Val(Mid(pen$,pen*2+1,2)))
Next
For p=0 To 15
pen_button(p)=CanvasGadget(#PB_Any,p*32,0,32,32)
StartDrawing(CanvasOutput(pen_button(p)))
Box(0,0,32,32,palettergb(pen(p)))
StopDrawing()
Next
Delay(20)
Enumeration
#zoomed=15
EndEnumeration
Procedure pokepixel(cpc_x,cpc_y,*mem,mode)
Select mode
Case 0
offset= (cpc_y/8)*$50+($800 * (cpc_y % 8))+cpc_x/2
Value=PeekB(*mem+128+offset) & $ff
Select cpc_x & %00000001
Case 0;-----------------------------01010101
pokepen=value & %01010101 ;-------76543210
pokepen=pokepen+ ((current_pen & %00001000) >>3)<<1
pokepen=pokepen+ ((current_pen & %00000100) >>2)<<3
pokepen=pokepen+ ((current_pen & %00000010) >>1)<<5
pokepen=pokepen+ ((current_pen & %00000001) )<<7
Case 1;-----------------------------10101010
pokepen=value & %10101010 ;-------76543210
pokepen=pokepen+ ((current_pen & %00001000) >>3)
pokepen=pokepen+ ((current_pen & %00000100) >>2)<<2
pokepen=pokepen+ ((current_pen & %00000010) >>1)<<4
pokepen=pokepen+ ((current_pen & %00000001) )<<6
EndSelect
PokeB(*mem+128+offset,pokepen )
Case 1
offset= (cpc_y/8)*$50+($800 * (cpc_y % 8))+cpc_x/4
Value=PeekB(*mem+128+offset) & $ff
Select cpc_x & %00000011
Case 0;-----------------------------01010101
pokepen=value & %01010101 ;-------76543210
pokepen=pokepen+ ((current_pen & %00001000) >>3)<<1
pokepen=pokepen+ ((current_pen & %00000100) >>2)<<3
pokepen=pokepen+ ((current_pen & %00000010) >>1)<<5
pokepen=pokepen+ ((current_pen & %00000001) )<<7
Case 1;-----------------------------10101010
pokepen=value & %10101010 ;-------76543210
pokepen=pokepen+ ((current_pen & %00001000) >>3)
pokepen=pokepen+ ((current_pen & %00000100) >>2)<<2
pokepen=pokepen+ ((current_pen & %00000010) >>1)<<4
pokepen=pokepen+ ((current_pen & %00000001) )<<6
EndSelect
PokeB(*mem+128+offset,pokepen )
Case 2
offset= (cpc_y/8)*$50+($800 * (cpc_y % 8))+cpc_x/8
Value=PeekB(*mem+128+offset) & $ff
Select cpc_x & %00000111
Case 0;-----------------------------01010101
pokepen=value & %01010101 ;-------76543210
pokepen=pokepen+ ((current_pen & %00001000) >>3)<<1
pokepen=pokepen+ ((current_pen & %00000100) >>2)<<3
pokepen=pokepen+ ((current_pen & %00000010) >>1)<<5
pokepen=pokepen+ ((current_pen & %00000001) )<<7
Case 1;-----------------------------10101010
pokepen=value & %10101010 ;-------76543210
pokepen=pokepen+ ((current_pen & %00001000) >>3)
pokepen=pokepen+ ((current_pen & %00000100) >>2)<<2
pokepen=pokepen+ ((current_pen & %00000010) >>1)<<4
pokepen=pokepen+ ((current_pen & %00000001) )<<6
EndSelect
PokeB(*mem+128+offset,pokepen )
EndSelect
EndProcedure
Procedure getmem(ID) ; copie une image dans la memoire pour y effectuer des operations avec peek et poke :)
ImageID= ImageID(id)
Hdc = CreateCompatibleDC_ ( GetDC_ ( ImageID ))
If HDC
bmi.BITMAPINFO
bm.BITMAP
GetObject_ ( ImageID , SizeOf(BITMAP), @bm.BITMAP)
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiheader\biWidth = bm\bmWidth
bmi\bmiheader\biHeight = bm\bmHeight
bmi\bmiheader\biPlanes = 1
bmi\bmiheader\biBitCount = 32
bmi\bmiheader\biCompression = #BI_RGB
HList = AllocateMemory (bm\bmWidth*bm\bmHeight*4)
GetDIBits_ (hDC, ImageID ,0,bm\bmHeight,HList,bmi, #DIB_RGB_COLORS )
ProcedureReturn HList
EndIf
EndProcedure
Procedure BresenhamLine(x0 ,y0 ,x1 ,y1,*mem,mod)
If Abs(y1 - y0) > Abs(x1 - x0);
steep =#True
Swap x0, y0
Swap x1, y1
EndIf
If x0 > x1
Swap x0, x1
Swap y0, y1
EndIf
deltax = x1 - x0
deltay = Abs(y1 - y0)
error = deltax / 2
y = y0
If y0 < y1
ystep = 1
Else
ystep = -1
EndIf
For x = x0 To x1
If steep
pokepixel(y,x,*mem,mode)
Else
pokepixel(x,y,*mem,mode)
EndIf
error - deltay
If error < 0
y + ystep
error + deltax
EndIf
Next
EndProcedure
Procedure putmem(id,mem) ;copie une zone memoire dans une image existante
ImageID= ImageID(id)
Hdc = CreateCompatibleDC_ ( GetDC_ ( ImageID ))
If HDC
bmi.BITMAPINFO
bm.BITMAP
GetObject_ ( ImageID , SizeOf(BITMAP), @bm.BITMAP)
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiheader\biWidth = bm\bmWidth
bmi\bmiheader\biHeight = bm\bmHeight
bmi\bmiheader\biPlanes = 1
bmi\bmiheader\biBitCount = 32
bmi\bmiheader\biCompression = #BI_RGB
SetDIBits_ (hDC, ImageID ,0,bm\bmHeight,mem,bmi, #DIB_RGB_COLORS )
EndIf
EndProcedure
Procedure.i decode(cpc,mode) ; cpc = adresse memoire du fichier SCR brut, mode d'affichage
current_mode=mode
Select mode
Case 0
rezpix=2 ; pixels par octets
surf=CreateImage(#PB_Any,160,200,32)
Case 1
rezpix=4 ; pixels par octets
surf=CreateImage(#PB_Any,320,200,32)
Case 2
rezpix=8 ; pixels par octets
surf=CreateImage(#PB_Any,640,200,32)
EndSelect
If IsImage(surf)
;---------------------------------------detecte le format de pixels RGB ou BRG------------------------
StartDrawing(ImageOutput(surf))
rgbrg=DrawingBufferPixelFormat() % 32768
If DrawingBufferPixelFormat() > 32768 ; reverse
reverse = 1
Else ; normal
reverse = 0
EndIf
StopDrawing()
*surf_mem=getmem(surf)
iw=ImageWidth(surf)
ih=ImageHeight(surf)
pos=128
y=0
For blocs=0 To 24
pos=128+blocs*$50
For yy=0 To 7
For x=0 To 79
o=PeekB(cpc+pos)&$ff
b$=RSet(Bin(o),8,"0")
For pix=0 To rezpix-1 ;
Select mode ; suivant le mode grraphique de l'image
Case 0 ; mode 0 160x200 16 couleurs : 2 pixels par octets ( 4 bit par pixel )
;c1=Val("%"+Mid(b$,7+pix,1)+Mid(b$,5+pix,1)+Mid(b$,3+pix,1)+Mid(b$,1+pix,1)) ; pixels courant ( interleaved)
Select pix
Case 0
c1=((o & %10000000 )>>7)+((o & %00100000 )>>4)+((o & %00001000 )>>1)+((o & %00000010 ))<<2
Case 1
c1=((o & %01000000)>>6)+((o & %00010000)>>3)+((o & %00000100))+((o & %00000001)<<3)
EndSelect
Case 1 ; mode 1 320x200 4 couleurs : 4 pixels par octets (2 bits par pixel)
Select pix
Case 0
c1=((o & %10000000)>>7+(o & %00001000)>>2)
Case 1
c1=((o & %01000000)>>6+(o & %00000100)>>1)
Case 2
c1=((o & %00100000)>>5+(o & %00000010))
Case 3
c1=(o & %00000001)<<1+(o & %00010000)>>4
EndSelect
Case 2 ; mode 2 640,200 2 couleurs : 8 pixels par octets (1 bit par pixel)
c1=(o & (128 >> pix))>>(7-pix)
EndSelect
If reverse=1
PokeL(*surf_mem+(((x*rezpix+pix)*4))+((ih-1-y)*iw*4),palette(pen(c1)))
Else
PokeL(*surf_mem+(((x*rezpix+pix)*4))+((y)*iw*4),palette(pen(c1)))
EndIf
Next
pos+1
Next
pos+$800-$50
y+1
Next
Next
putmem(surf,*surf_mem)
FreeMemory(*surf_mem)
ProcedureReturn surf
EndIf
EndProcedure
;
;
;
; les deux lignes suivantes sont inutiles mais permettent de bloquer les touches menu de windows.
;
InitKeyboard()
KeyboardMode(#PB_Keyboard_International)
;+--------------------------------------+
;| BUFFERS CLAVIER |
;+--------------------------------------+
Global *buffer=AllocateMemory(256)
Global *state=AllocateMemory(256)
;+--------------------------------------+
;| CONSTANTES DEFINITION DES TOUCHES |
;+--------------------------------------+
#AltKey_windows =91
#AltKey_Shift =16
#AltKey_LeftShift =160
#AltKey_RightShift =161
#AltKey_Alt =17
#AltKey_Left_Alt =164
#AltKey_AltGr =165
#AltKey_Esc =27
#AltKey_tilde =222
#AltKey_F1 =112
#AltKey_F2 =113
#AltKey_F3 =114
#AltKey_F4 =115
#AltKey_F5 =116
#AltKey_F6 =117
#AltKey_F7 =118
#AltKey_F8 =119
#AltKey_F9 =120
#AltKey_F10 =121
#AltKey_F11 =122
#AltKey_F12 =123
#AltKey_0 =48
#AltKey_1 =49
#AltKey_2 =50
#AltKey_3 =51
#AltKey_4 =52
#AltKey_5 =53
#AltKey_6 =54
#AltKey_7 =55
#AltKey_8 =56
#AltKey_9 =57
#AltKey_parenthese =219
#AltKey_egal =187
#AltKey_backspace =8
#AltKey_windows =91
#AltKey_Tab =9
#AltKey_A =65
#AltKey_B =66
#AltKey_C =67
#AltKey_D =68
#AltKey_E =69
#AltKey_F =70
#AltKey_G =71
#AltKey_H =72
#AltKey_I =73
#AltKey_J =74
#AltKey_K =75
#AltKey_L =76
#AltKey_M =77
#AltKey_N =78
#AltKey_O =79
#AltKey_P =80
#AltKey_Q =81
#AltKey_R =82
#AltKey_S =83
#AltKey_T =84
#AltKey_U =85
#AltKey_V =86
#AltKey_W =87
#AltKey_X =88
#AltKey_Y =89
#AltKey_Z =90
#AltKey_circ =221
#AltKey_dollar =186
#AltKey_return =13
#AltKey_caps =20
#AltKey_percent =192
#AltKey_multiply =220
#AltKey_compare =226
#AltKey_space =32
#altKey_left =37
#altKey_up =38
#altKey_right =39
#altKey_down =40
#AltKey_del =46
#AltKey_pageup =33
#altKey_pagedown =34
#altKey_fin =35
#altKey_debut =36
#AltKey_inser =45
#AltKey_prtscr =44
#AltKey_pause =19
#AltKey_mute =173
#AltKey_voldwn =174
#AltKey_volup =175
#AltKey_numlock =144
#AltKey_0num =96
#AltKey_1num =97
#AltKey_2num =98
#AltKey_3num =99
#AltKey_4num =100
#AltKey_5num =101
#AltKey_6num =102
#AltKey_7num =103
#AltKey_8num =104
#AltKey_9num =105
#Altkey_minnum =109
#Altkey_addnum =107
#altKey_leftmouse =1
#altKey_rightmouse =2
#altKey_middlemouse =5
Procedure RefreshKeyboard() ;rafraichis l'etat du clavier
CopyMemory(*buffer,*state,256) ; sauvegarde l'etat precedent pour comparaison (keyup)
GetKeyboardState_(*buffer)
EndProcedure
Procedure.s returnchar(key) ; renvoi le caractere saisi
r.s=Space(4)
ToAscii_(key,0,*buffer,@r,0)
ProcedureReturn r
EndProcedure
Procedure Keydown(key) ; teste si une touche est enfoncée (continue)
If PeekB(*buffer+key)<0
ProcedureReturn 1
EndIf
EndProcedure
Procedure keyup(key) ; teste si une touche est lachée
If PeekB(*buffer+key)>=0 And PeekB(*state+key)<0
RefreshKeyboard() ;rafraichis le clavier pour eviter un clic fantome
ProcedureReturn 1
EndIf
EndProcedure
Procedure keypushed(key) ; teste si une touche est poussée (instant)
If PeekB(*buffer+key)<0 And PeekB(*state+key)>=0
RefreshKeyboard() ;rafraichis le clavier pour eviter un clic fantome
ProcedureReturn 1
EndIf
EndProcedure
Procedure keyon(key) ; teste si une touche est 'on' ver maj, num lock etc...
ProcedureReturn PeekB(*buffer+key) &%00000001;1
EndProcedure
Procedure gestion(ev)
Static x,y
Static ox,oy
Static cpc_x,cpc_y
Static drawing
Static bd
RefreshKeyboard()
;If Keydown(#AltKey_Z)
; xg=x/2*2
; yg=y/2*2
; If xg<0:xg=0:EndIf
; If yg<0:yg=0:EndIf
; If IsImage(surface2)
; FreeImage(surface2)
; If IsImage(#zoomed)
; FreeImage(#zoomed)
; EndIf
; GrabImage(surface2,#zoomed,xg,yg,200,200)
; If IsImage(#zoomed)
; ResizeImage(#zoomed,400,400,#PB_Image_Raw)
; EndIf
; EndIf
;EndIf
Select ev
Case #PB_Event_Gadget
Select EventGadget()
Case can
x = GetGadgetAttribute(can, #PB_Canvas_MouseX)
y = GetGadgetAttribute(can, #PB_Canvas_MouseY)
xm=x
ym=y
xg=x/2*2
yg=y/2*2
If xg<0:xg=0:EndIf
If yg<0:yg=0:EndIf
If EventType() = #PB_EventType_LeftButtonDown
bd=1
EndIf
If EventType() = #PB_EventType_LeftButtonUp
bd=0
drawing=0
EndIf
If BD=1
If x<640 And y<400 And x>-1 And y>-1
Select current_mode
Case 0
cpc_x=x/4
cpc_y=y/2
Case 1
cpc_x=x/2
cpc_y=y/2
Case 2
cpc_x=x
cpc_y=y/2
EndSelect
If drawing=0
pokepixel(cpc_x,cpc_y,*mem,0)
drawing=1
Else
BresenhamLine(ox,oy,cpc_x,cpc_y,*mem,0)
EndIf
ox=cpc_x
oy=cpc_y
EndIf
EndIf
Case cloz
If EventType() = #PB_EventType_LeftButtonDown
End
EndIf
Default
For p=0 To 15
If EventGadget()= pen_button(p)
If EventType() = #PB_EventType_LeftButtonDown
current_pen=p
EndIf
EndIf
Next
EndSelect
EndSelect
EndProcedure
size=FileSize(file$)
*mem=AllocateMemory(17000)
mode=0
surface=decode(*mem,mode)
If IsImage(surface2)
FreeImage(surface2)
CopyImage(surface,surface2)
FreeImage(surface)
ResizeImage(surface2,640,400,#PB_Image_Raw)
StartDrawing(CanvasOutput(can))
DrawImage(ImageID(surface2),0,0)
StopDrawing()
EndIf
;
;
;
;
Repeat
If IsImage(surface)
FreeImage(surface)
EndIf
If IsImage(surface2)
FreeImage(surface2)
EndIf
surface=decode(*mem,mode)
If IsImage(surface)
CopyImage(surface,surface2)
FreeImage(surface)
ResizeImage(surface2,640,400,#PB_Image_Raw)
StartDrawing(CanvasOutput(can))
If IsImage(surface2)
DrawImage(ImageID(surface2),0,0)
EndIf
StopDrawing()
endif
StartDrawing(CanvasOutput(zoom))
If IsImage(#zoomed)
DrawImage(ImageID(#zoomed),0,0)
EndIf
StopDrawing()
ev=WaitWindowEvent(0)
gestion(ev)
Until ev=#PB_Event_CloseWindow
End
;
;
;
;
;
;