Probleme avec une fonction de rotation

SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013 - 24 sept. 2005 à 15:52
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013 - 25 sept. 2005 à 10:58
voila ma fonction



HBITMAP rotate90(HBITMAP hbmp)

{



BITMAP bm;

GetObject((HBITMAP)hbmp, sizeof(bm), &bm);



BITMAPINFO bi,biNew;

biNew.bmiHeader.biSize bi.bmiHeader.biSize sizeof(BITMAPINFOHEADER);

biNew.bmiHeader.biHeight bi.bmiHeader.biWidth bm.bmWidth;

biNew.bmiHeader.biWidth bi.bmiHeader.biHeight bm.bmHeight;

biNew.bmiHeader.biPlanes bi.bmiHeader.biPlanes bm.bmPlanes;

biNew.bmiHeader.biBitCount bi.bmiHeader.biBitCount 24;

biNew.bmiHeader.biCompression bi.bmiHeader.biCompression BI_RGB;



DWORD dwWidthBytes = 4*((3*bm.bmWidth+3)/4);

DWORD dwWidthBytesNew = 4*((3*bm.bmHeight+3)/4);



LPBYTE lpBits = new BYTE[dwWidthBytes*bm.bmHeight];

LPBYTE lpBitsNew = new BYTE[dwWidthBytesNew*bm.bmWidth];





HDC hdc = GetDC(NULL);

if (hdc == NULL) { return 0; }



GetDIBits(hdc, (HBITMAP)hbmp, 0, bm.bmHeight, lpBits, &bi, DIB_RGB_COLORS);

GetDIBits(hdc, (HBITMAP)hbmp, 0, bm.bmWidth, lpBitsNew, &biNew, DIB_RGB_COLORS);



int tmp;

int tmp2;



LPDWORD lpSrc,lpDst;



for (int y = 0; y < bm.bmHeight; y++)

{

for (int x = 0; x < bm.bmWidth; x++)

{

tmp = (bm.bmHeight-y-1)*dwWidthBytes+3*x;

tmp2 = (bm.bmWidth-x-1)*dwWidthBytesNew+3*y;



lpSrc = (LPDWORD)&lpBits[tmp];

lpDst =(LPDWORD)&lpBitsNew[tmp2];

*lpDst = *lpSrc;



}

}



HBITMAP hBmpDst=CreateDIBitmap(hdc,&biNew.bmiHeader,CBM_INIT,lpBitsNew,&biNew,DIB_RGB_COLORS);

ReleaseDC(NULL, hdc);

delete lpBits;

delete lpBitsNew;



return hBmpDst;



}



Elle marche nickel sur des resolution de 33*5 ou 33*22 mais ne marche
plus sur 48*16 ou 49*16 j'ai une erreur du type "debug error" et si je
clique sur ignorer mon prog continu avec un bug d'affichage.



Un moyen de la faire marcher est de faire LPBYTE lpBitsNew = new
BYTE[dwWidthBytesNew*bm.bmWidth+4]; mais je me retrouve toujours
avec le bug d'affichage.



J'ai essayé avec plusieurs resolutions (multiple de 16 de 32) et je
n'arrive meme pas a trouver un point commun logique entre celle qui
marchent et celles qui marchent pas !

Quelqu'un voit un truc anormal ?

4 réponses

SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
24 sept. 2005 à 15:53
ha oui le probleme est sur delete lpBitsNew;
0
vecchio56 Messages postés 6535 Date d'inscription lundi 16 décembre 2002 Statut Membre Dernière intervention 22 août 2010 14
24 sept. 2005 à 17:24
Un tableau se détruit avec delete[], pas delete, qui ne supprimera que le premier element du tableau
J'ai l'impression que dans ta boucle, tmp2 peut devenir trop grand, tu devrais réserver
(bm.bmWidth-min(x)-1)*dwWidthBytesNew+3*max(y)
= (bm.bmWidth-1)*dwWidthBytesNew+3*(bm.bmHeight-1)
pour lpBitsNew
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
24 sept. 2005 à 18:01
J'ai corigé pour le delete mais par contre le probleme viens d'un decalage !!

Au debut j'ai bien cru ke tmp2 devenais trop gros(d'ailleur quand j
augmente la taille du tableau il n'y plus de probleme) mais en tracant
le max = 2301 pour un tableau de 2304.



En augmentant la taille du tableau il n'y a plus le bug mais le coté
droit a une bande de pixel noir et le coté gauche une bande de la
mauvaise couleur.
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
25 sept. 2005 à 10:58
par contre ca marche en faisant

lpBitsNew[tmp2] = lpBits[tmp];

lpBitsNew[tmp2+1] = lpBits[tmp+1];

lpBitsNew[tmp2+2] = lpBits[tmp+2];

a la place de

// lpSrc = (LPDWORD)&lpBits[tmp];

// lpDst =(LPDWORD)&lpBitsNew[tmp2];

// *lpDst = *lpSrc;



Ou me suis-je planté ???
0
Rejoignez-nous