Page 1 sur 4

Legerement MARRE de MemVideo !!

Publié : mar. 29/avr./2008 15:36
par SPH
Bon,

meme si ce n'est pas l'avis générale, je pense etre relativement intelligent, plutot logique et imaginatif. Mais là, à defaut de passer PB par la fenetre, je poste ici ceci :

Code : Tout sélectionner

InitSprite()
InitKeyboard()
InitMouse()

dw=1024
dh=768
dc=32
video=dw*dh*dc/8
If OpenScreen(dw,dh,dc,"")=0
End
EndIf


Dim p(dw,dh)

For i=0 To 30
p(i ,i) = RGB(255,255,255) ; ceci est bien une ligne diagonale ? Je ne suis pas gogole quand meme !!
Next

;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;

Repeat

StartDrawing(ScreenOutput()) 

MemVideo = DrawingBuffer() 
CopyMemory(@p(), MemVideo, video) 

StopDrawing() 
FlipBuffers()

ExamineKeyboard()

Until KeyboardPushed(#PB_Key_Escape)
Ce code est très simple, ET POURTANT, j'ai encore ce foutu bug graphique !
Rassurez moi : ce code devrait bien afficher une ligne blanche diagonale allant de 0,0 à 30,30 ??
Au lieu de ca, j'ai 4 lignes pointillées !!!! :twisted: :twisted: :twisted:

Publié : mar. 29/avr./2008 18:01
par djes
cherche dans le forum drawingbufferpitch()

Publié : mar. 29/avr./2008 19:50
par SPH
djes a écrit :cherche dans le forum drawingbufferpitch()
Oui, cela etait adapté a la copie ligne par ligne d'un tableau dans la memoire video. Mais la, je n'ai qu'un seul choix : copier mon bloc (un dim de la resolution de mon ecran ouvert) dans la memoire video.

FRANCHEMENT, qu'est ce que c'est mal foutu ce truc !!!!!!!!!

Il devrait y avoir une instruction qui copie un tableau de la taille du screenopen dans la memoire video sans se préhocuper des retour a la ligne ou je ne sais quoi...

Franchement, j'ai appris cette instruction il y a quelques années ici meme, sur ce forum, par un code de LSI je crois. Et sans l'avoir retrouvé, LSI lui non plus n'avait pas utilisé bufferpitch. Meme mes vieux code marchaient sur les ordi de tout le monde. Et la, changement de matos et pan : tout bug.

GRRRRRRRRRRRRRRRRRRRRRRR

Publié : mar. 29/avr./2008 20:26
par djes
Le problème vient de toi. Les cartes graphiques sont conçues comme ça, pb n'y est pour rien. La solution la plus simple pour toi (même si ce n'est pas la plus rapide, mais je ne vois pas bien ce que tu veux faire) est de faire un tableau qui ait la même structure que l'écran, avec le même pitch. Ca devrait fonctionner.

Publié : mar. 29/avr./2008 20:49
par Ollivier
Salut SPH,

Attention aux petites erreurs de dimensionnement de tableaux :
Pour 768 lignes et 1024 colonnes, les valeurs sw et sh seront 1023 et 767.

Après cette correction, il n'y a plus de problème de transfert. Par contre, il y en a un au niveau des ressources CPU... car ça bouffe beaucoup cette méthode.

Publié : mar. 29/avr./2008 21:18
par Ollivier
ça, c'est plus cool en ressources CPU:

Code : Tout sélectionner

Structure PITCH 
      X.L[1024] 
EndStructure 
Structure BUFFER 
      Y.PITCH[768] 
EndStructure      
InitSprite() 
InitKeyboard() 
InitMouse() 
Dim _Cos(511) 
Dim _Sin(511) 
For i = 0 To 511 
      Angle.F = i * #PI / 256.0 
      _Cos(i) = Cos(Angle) * 200.0 
      _Sin(i) = Sin(Angle) * 200.0      
Next 

Dim *Buff(1) 

OpenScreen(1024, 768, 32, "") 

      StartDrawing(ScreenOutput() ) 
            *Buff(0) = DrawingBuffer() 
      StopDrawing() 
      FlipBuffers() 
      
      StartDrawing(ScreenOutput() ) 
            *Buff(1) = DrawingBuffer() 
      StopDrawing() 
            
      CX = 512 
      CY = 384 
      Repeat 
            Delay(20) 
            ExamineMouse() 
            MDX = MouseDeltaX() 
            MDY = MouseDeltaY() 
            If MDX Or MDY Or 1 
                  CX + MDX 
                  CY + MDY 
                  ClearScreen(0) 
                  StartDrawing(ScreenOutput() ) 
                        FlipBuffer = 1 - FlipBuffer 
                        *Buffer.BUFFER = *Buff(FlipBuffer) 
                        For i = 0 To 255 
                              p = i 
                              p + n 
                              p & 511 
                              For j = 0 To 511 - 7 Step 8 
                                    k = j 
                                    k + m 
                                    X = CX + _Cos(p) 
                                    Y = CY + _Sin(p) 
                                    X + _Cos(k) >> 1                                    
                                    Y + _Sin(k) >> 1 
                                    X & 1023 ; Sécu 1 
                                    If (Y <= 767) And (Y => 0) ; Sécu 2 
                                          *Buffer\Y[Y]\X[X] = $FFFFFF ; Pif 
                                    EndIf 
                              Next 
                        Next 
                        m + 1 
                        m & 7 
                        n - 1 
                        n & 511 
                  StopDrawing()  
                  FlipBuffers()                
            EndIf 
            ExamineKeyboard() 
      Until KeyboardPushed(#PB_Key_Escape) 
CloseScreen() 

Publié : mar. 29/avr./2008 21:30
par SPH
Ollivier a écrit :ça, c'est plus cool en ressources CPU:

Code : Tout sélectionner

.........
Ca me conforte dans l'idée que personne ne sait utiliser la copie en memoire video...

Ton code me fait un decallage monstrueux. Je ne sais meme pas ce que c'est mais il y a une platrée de points blancs qui dancent en bandes diagonales...

Publié : mer. 30/avr./2008 6:26
par Backup
le prg suivant, et ses procedures
; CLS,GET,PUT,STRETCH,GRAB ;(grab is a PUT for part of image)
reprennent le principe du GFA basic et permet la copie de partie d'ecran et meme un stretch

peut etre que cela correspond a ce que tu cherche a faire.... :)

Code : Tout sélectionner

; English forum: http://purebasic.myforums.net/viewtopic.php?t=7731&highlight=
; Author: einander
; Date: 08. October 2003

;Conversion Purebasic 4.10 : Dobro

; My dreams come true: working GFA16 commands in PB!  
; CLS,GET,PUT,STRETCH,GRAB ;(grab is a PUT for part of image) 


;Binary raster operation - october 7 - 2003 - by Einander 
;Combines the bits from the selected pen with the bits in the destination bitmap. 
;(Bit-block transfer of color Data from source DC into a destination DC) 

; -********Choose your BitMap on line 39************* 
;With Debugger option Off, gets your BitMap; else, only part of debug window 

; 15 combination modes: 
;#BLACKNESS, #DSTINVERT, #MERGECOPY, #MERGEPAINT, #NOTSRCCOPY, #NOTSRCERASE ;#PATCOPY 
; #PATINVERT, #PATPAINT, #SRCAND, #SRCCOPY, #SRCERASE, #SRCINVERT, #SRCPAINT, #WHITENESS 

Declare Get(n_wind,x,y,Wi,He)    ; Get source image - returns image handle 
Declare Put(n_wind,x,y,IMG,mode) ; Draws image from IMG TO DEST (DEST = GetDC_(SrcID))  
Declare Stretch(n_wind,x,y,Wi,He,IMG,mode)  ; draws stretched image  
Declare Grab(n_wind,StartX,StartY,Wi,He,IMG,x,y,mode)  ; draws part of image 
Declare CLS(n_wind,color)   ; clear screen 

;__________________________ 
UseJPEGImageDecoder()
IMAGE$="D:\Mes_Photos\Capture_ecran\avatar2.jpg" 
#Window=0

LoadImage(1,IMAGE$) 
WIMG=100 : HIMG=100 
ResizeImage(1,WIMG,HIMG)  ; STARTING  WITH 100 X 100 PIXS 

id=OpenWindow(#Window,0,0,WIMG,HIMG,"",#PB_Window_BorderLess )    
StartDrawing(WindowOutput(#Window)) 
DrawImage(ImageID(1),0,0) 
IMG=Get(#Window,0,0,WIMG,HIMG) 
StopDrawing() 
CloseWindow(0) 

_X=GetSystemMetrics_(#SM_CXSCREEN) : _Y=GetSystemMetrics_(#SM_CYSCREEN) 
hwnd=OpenWindow(#Window,0,0,_X,_Y,"",#WS_OVERLAPPEDWINDOW | #WS_MAXIMIZE) 
CLS(#Window,#Black)      



;Testing some modes 

Put(#Window,220,100,IMG,#SRCCOPY) 
Put(#Window,350,100,IMG,#SRCPAINT) 

Stretch(#Window,20,200,200,200,IMG,#NOTSRCCOPY) 
x=0 : y=_Y-150 

Repeat 
        Grab(#Window,0,0,50,50,IMG,20+i,y,#SRCPAINT) 
        i+50 
       Grab(#Window,50,50,50,50,IMG,20+i,y,#SRCPAINT) 
        y-50 
Until  y<50 

Repeat 
Until WaitWindowEvent()= #PB_Event_CloseWindow  

End  



Procedure Get(n_wind,x,y,Wi,He)    ; Get source image - returns image handle 
  SRC=GetDC_(WindowID(n_wind)) 
  DEST = CreateCompatibleDC_(SRC) 
  SelectObject_(DEST,CreateImage(0,Wi,He))  
  BitBlt_(DEST,0,0,Wi,He,SRC,x,y,#SRCCOPY) 
  ProcedureReturn DEST 
EndProcedure 

Procedure Put(n_wind,x,y,IMG,mode) ; Draws image from IMG TO DEST (DEST = GetDC_(SrcID))  
  BitBlt_(GetDC_(WindowID(n_wind)),x,y,ImageWidth(n_wind),ImageHeight(n_wind),IMG,0,0,mode) 
EndProcedure 

Procedure Stretch(n_wind,x,y,Wi,He,IMG,mode)  ; draws stretched image  
  StretchBlt_(GetDC_(WindowID(n_wind)),x,y,Wi,He,IMG,0,0,ImageWidth(n_wind),ImageHeight(n_wind),mode) 
EndProcedure 

Procedure Grab(n_wind,StartX,StartY,Wi,He,IMG,x,y,mode)  ; draws part of image 
  BitBlt_(GetDC_(WindowID(n_wind)),x,y,Wi,He,IMG,StartX,StartY,mode) 
EndProcedure 

Procedure CLS(n_wind,color)   ; clear screen 
  StartDrawing(WindowOutput(n_wind)) 
  Box(0,0,WindowWidth(n_wind),WindowHeight(n_wind),color) 
  StopDrawing() 
EndProcedure 



; ExecutableFormat=Windows
; EnableXP
; DisableDebugger
; EOF

Value Description
#BLACKNESS Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.)
#DSTINVERT Inverts the destination rectangle.
#MERGECOPY Merges the colors of the source rectangle with the specified pattern by using the Boolean AND operator.
#MERGEPAINT Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator.
#NOTSRCCOPY Copies the inverted source rectangle to the destination.
#NOTSRCERASE Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color.
#PATCOPY Copies the specified pattern into the destination bitmap.
#PATINVERT Combines the colors of the specified pattern with the colors of the destination rectangle by using the Boolean XOR operator.
#PATPAINT Combines the colors of the pattern with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator.
#SRCAND Combines the colors of the source and destination rectangles by using the Boolean AND operator.
#SRCCOPY Copies the source rectangle directly to the destination rectangle.
#SRCERASE Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator.
#SRCINVERT Combines the colors of the source and destination rectangles by using the Boolean XOR operator.
#SRCPAINT Combines the colors of the source and destination rectangles by using the Boolean OR operator.
#WHITENESS Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.)

Publié : mer. 30/avr./2008 6:59
par Ollivier
Précise-moi ce que tu vois à l'écran quand tu exécute mon code stp.

ça fera avancer le shmilblick.

Publié : mer. 30/avr./2008 7:05
par poshu
ce qui est bien, c'est que j'étais venu avec l'envie d'aider et une petite partie des compétences pour y arriver, et après avoir lu comme SPH est doué et que toute le reste de la communauté est débile, je m'en vais.

Publié : mer. 30/avr./2008 10:05
par case
poshu a écrit :ce qui est bien, c'est que j'étais venu avec l'envie d'aider et une petite partie des compétences pour y arriver, et après avoir lu comme SPH est doué et que toute le reste de la communauté est débile, je m'en vais.
oO

je ne pense pas que cela soit constructif de dire ce genre de choses,
le terme débile ne s'applique pas ici. peut etre simplement qu'ils on mal compris le but de SPH.

si toi tu as la solution au lieu d'insulter la communauté montres nous que tu n'es pas toi même un débile juste bon a passer sur le forum pour poster des trucs encore plus stupides.

ceci dit en passant, SPH
Franchement, j'ai appris cette instruction il y a quelques années ici meme, sur ce forum, par un code de LSI je crois. Et sans l'avoir retrouvé, LSI lui non plus n'avait pas utilisé bufferpitch. Meme mes vieux code marchaient sur les ordi de tout le monde. Et la, changement de matos et pan : tout bug.
comme tu le dis toi même la faute n'en reviens pas a pure basic mais au code original qui ne se préoccupais justement pas des bufferpitch ce qui est une erreur quand on accède directement a la mémoire vidéo. alors au lieu de blâmer pure basic, blâme ton code qui est fautif et corrige cette grossière erreur.

ce n'est pas la première foi que tu rencontre ce genre de soucis avec les buffers et la mémoire video http://www.purebasic.fr/french/viewtopi ... ght=#76313

ça serais pas mal qu'au lieu de râler tu adapte ton code pour tenir compte des contrainte liées a ce genre de pratique.

cordialement

case :)

Publié : mer. 30/avr./2008 11:31
par SPH
Ollivier a écrit :Précise-moi ce que tu vois à l'écran quand tu exécute mon code stp.

ça fera avancer le shmilblick.
Je te l'ai photographié :
http://www.servimg.com/image_preview.php?i=7&u=11124714

Publié : mer. 30/avr./2008 11:51
par cha0s
note aussi que certainne carte graphique (qui a dit les ATI :p) sont très bugué, je m'en suis rendue compte en manipulant DreamMotion et directX en bas niveau.

Publié : mer. 30/avr./2008 20:35
par Ollivier
@SPH

D'après l'image que tu as, la pronfondeur des couleurs ne semble pas altérée.

Quelle valeur te retourne ton débogueur avec ce code ci-dessous?

Code : Tout sélectionner

openscreen(1024,768,32,"")

  startdrawing(screenoutput() )

    debug drawingbufferpitch()

  stopdrawing()

closescreen()

Publié : mer. 30/avr./2008 20:56
par Ollivier
@SPH

Avec ma carte Video, je crois que j'avais 4096 (1024 * 4). Tu as peut-être une carte Video qui va te donner 8192 (2048 * 4).

Récupère la valeur obtenue, divise-la par 4 et remplace le nombre 1024 en ligne 2 (dans la structure PITCH) par le résultat obtenu (sûrement 2048).

ça devrait aller mieux pour toi après!

@Poshu

Le principal n'est pas tant le ton que sous-entend SPH. Sa requête est un peu «brutale» mais elle éveille sur les différentes formes d'accès à la mémoire écran. Chose sur laquelle je ne m'étais jamais bien interrogée.

Par exemple, si l'on fait un sacrifice sur la quantité de nuances de couleurs à afficher, je découvre que l'on peut utiliser les sprites. Dans ce cas, ma méthode ci-dessus est obsolète.

@Dobro

Merci pour ton code, ça permet quelques simplifications de programmation.