Traitement d'image

Résolu
abdobergach Messages postés 26 Date d'inscription jeudi 25 mars 2010 Statut Membre Dernière intervention 7 juin 2011 - 6 mai 2011 à 15:20
cs_Lucky92 Messages postés 180 Date d'inscription mercredi 22 décembre 2004 Statut Membre Dernière intervention 16 août 2012 - 6 mai 2011 à 19:25
bonjour

j'ai trouvé ce code dans une application de chargement d'une image bmp en C
mais le problem j'arrive pas à comprendre ca sert à qoi le bourrage ici
qlq peut m'explique en détail merci infiniment


/*---------------------------------*/
//Enregistre un fichier bmp24 bits
/*---------------------------------*/
BOOL SaveBmp24(char *path,PIXEL *data,int width,int height)
{
BITMAPFILEHEADER	fileheader;
BITMAPINFOHEADER	infoheader;
HANDLE				fichier;
DWORD				dummy;
int					size;
int					bourrage = 0;
int					i,j,k;
char				*ima = NULL;

fichier = CreateFile(path,
 GENERIC_WRITE,
 FILE_SHARE_READ,
 NULL,
 CREATE_ALWAYS,
 FILE_ATTRIBUTE_NORMAL,
 NULL);
if (fichier == INVALID_HANDLE_VALUE)
return FALSE;

fileheader.bfType = 0x4D42;	//"bm"
fileheader.bfSize = 54 + width*height*3;
fileheader.bfReserved2 = 0;
fileheader.bfReserved1 = 0;
fileheader.bfOffBits = 54;

infoheader.biSize = sizeof(BITMAPINFOHEADER);
infoheader.biWidth = width;
infoheader.biHeight = height;
infoheader.biPlanes = 1;
infoheader.biBitCount = 24;
infoheader.biCompression = 0;
infoheader.biSizeImage = width*height;
infoheader.biXPelsPerMeter = 0;
infoheader.biYPelsPerMeter = 0;
infoheader.biClrImportant = 0;
infoheader.biClrUsed = 0;

while ((3*width+bourrage) % 4 !0)	//calcul du nb de bits de bourrage (3 car 24bits 3octs)
bourrage++;

size = width*height;

ima = new char[size*3+bourrage*height];
if (ima == NULL)
{
CloseHandle(fichier);
return FALSE;
}

for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
ima[i*(3*width+bourrage)+3*j]		= data[(height-i-1)*width+j].b;
ima[i*(3*width+bourrage)+3*j+1]	= data[(height-i-1)*width+j].g;
ima[i*(3*width+bourrage)+3*j+2]	= data[(height-i-1)*width+j].r;
}
for(k=1;k<bourrage;k++)
ima[i*(3*width+bourrage)+3*j+k] = 0;
}

1 réponse

cs_Lucky92 Messages postés 180 Date d'inscription mercredi 22 décembre 2004 Statut Membre Dernière intervention 16 août 2012 2
6 mai 2011 à 19:25
Salut,

Tu trouves l'explication dans la définition du format.

Il faut 3 octets par pixel, mais il faut que le nombre d'octets par ligne soit un multiple de 4 ; "bourrage" correspond au nombre de 0 qu'il faut ajouter à chaque fin de ligne pour satisfaire cette condition.

Good luck:)
3
Rejoignez-nous