Bitmap

cs_lapal Messages postés 3 Date d'inscription lundi 1 septembre 2003 Statut Membre Dernière intervention 6 septembre 2003 - 5 sept. 2003 à 15:41
sami_zrafi Messages postés 1 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 12 avril 2005 - 12 avril 2005 à 17:51
salut

j'aimerais lire une image bitmap en noir et blanc mais je ne sais pas comment faire. pouvez vous m'aider?
merci

3 réponses

cs_Kaid Messages postés 949 Date d'inscription mardi 2 octobre 2001 Statut Membre Dernière intervention 8 juillet 2006 1
5 sept. 2003 à 19:06
Soit plus explicite, que veux tu faire ensuite avec cette image, l'afficher, la convertir, la traiter, ..., ? Sous quelle plateforme et avec quel compilateur ?

Kaid - kaid.fr.st
0
cs_lapal Messages postés 3 Date d'inscription lundi 1 septembre 2003 Statut Membre Dernière intervention 6 septembre 2003
6 sept. 2003 à 12:08
je travaille sous window

en fait, j'ai deja une fonction qui lit les image bmp en couleur mais je ne sais pas comment la modifier pour pouvoir lire les bmp en noir et blanc.

voici la fonction :
Code:
int LoadBMP(char *filename)
{
int i, j=0;
FILE *l_file;
unsigned char *l_texture; //The pointer to the memory zone in which we will load the texture
GLuint num_texture = -1;

// windows.h gives us these types to work with the Bitmap files
BITMAPFILEHEADER fileheader;
BITMAPINFOHEADER infoheader;
RGBTRIPLE rgb;

num_texture++; // The counter of the current texture is increased

if( (l_file = fopen(filename, "rb"))==NULL) return (-1); // Open the file for reading

fread(&fileheader, sizeof(fileheader), 1, l_file); // Read the fileheader

fseek(l_file, sizeof(fileheader), SEEK_SET); // Jump the fileheader
fread(&infoheader, sizeof(infoheader), 1, l_file); // and read the infoheader

// Now we need to allocate the memory for our image (width * height * color deep)
l_texture = (unsigned char *) malloc(infoheader.biWidth * infoheader.biHeight * 4);
// And fill it with zeros
memset(l_texture, 0, infoheader.biWidth * infoheader.biHeight * 4);

// At this point we can read every pixel of the image
for (i=0; i < infoheader.biWidth*infoheader.biHeight; i++)
{
// We load an RGB value from the file
fread(&rgb, sizeof(rgb), 1, l_file);

// And store it
l_texture[j+0] = rgb.rgbtRed; // Red component
l_texture[j+1] = rgb.rgbtGreen; // Green component
l_texture[j+2] = rgb.rgbtBlue; // Blue component
l_texture[j+3] = 255; // Alpha value
j += 4; // Go to the next position
}

width = infoheader.biWidth;
height = infoheader.biHeight;

fclose(l_file); // Closes the file stream


free(l_texture); // Free the memory we used to load the texture

}
0
sami_zrafi Messages postés 1 Date d'inscription mercredi 6 avril 2005 Statut Membre Dernière intervention 12 avril 2005
12 avril 2005 à 17:51
Salut,

C'est très facile.
Tu laisses la meme structure (RGB) mais tu fais une boucle qui parcourt le tableau RGB est tu décides :
BW[i][j]=255 RGB[i][j] > 127
BW[i][j]=0 sinon

Ceci pour les images 256 couleurs.
S'il te plait,est ce que tu peux me filer le code complet de load_bmp (surtout le header) car j'en ai très très besoin sur cet e-mail : semi_zrafi@yahoo.fr
Merci.
0
Rejoignez-nous