N
Moin,
also erstmal vielen Dank für eure Hilfe, hab mir aber jetzt doch was selbst gebaut. Nun aber zu meinem Problem:
Ich habe folgende Funktion geschrieben:
void load_bitmap_file(char *filename, image* bmppic)
{
FILE *filePtr; //our file pointer
BMPFILEHEAD bitmapFileHeader; //the bitmap file header
BMPINFOHEAD bitmapInfoHeader; //the bitmap info header
unsigned char *bitmapImage; //store image data
int imageIdx=0; //image index counter
unsigned char tempRGB; //our swap variable
bmppic->no_of_cols = 0;
bmppic->no_of_rows = 0;
//open filename in read binary mode
filePtr = fopen(filename,"rb");
if (filePtr == NULL)
{
}
//read the bitmap file header
fread(&bitmapFileHeader.bfType, 14,1,filePtr);
//verify that this is a bmp file by check bitmap id
if (bitmapFileHeader.bfType !=0x4D42)
{
fclose(filePtr);
}
//read the bitmap info header
fread(&bitmapInfoHeader, sizeof(BMPINFOHEAD),1,filePtr);
// calculate offset to picturedata
int pointer_mover = 14+40; // Size of FILEHEADER and INFORMATIONHEADER
if (bitmapInfoHeader.biCompression == 3)
{
pointer_mover = pointer_mover + 3*4; // 3 DWORDS FOR BITMASKS
}
if (bitmapInfoHeader.biClrUsed == 0)
{
if ( (bitmapInfoHeader.biBitCount == 1) || (bitmapInfoHeader.biBitCount == 4) || (bitmapInfoHeader.biBitCount == 8) )
{
pointer_mover = pointer_mover + 4*pow(2,bitmapInfoHeader.biBitCount); // 2^bitmapInfoHeader.biBitCount entries in colourmap (each colormap = 4 Bytes)
}
}
else
{
pointer_mover = pointer_mover + 4*bitmapInfoHeader.biClrUsed; // bitmapInfoHeader.biClrUsed entries in colourmap (each colormap = 4 Bytes)
}
//move file pointer to the begging of bitmap data
fseek(filePtr, pointer_mover, SEEK_SET);
//allocate enough memory for the bitmap image data
bitmapImage = (unsigned char*)malloc(bitmapInfoHeader.biSizeImage*sizeof(unsigned char));
bitmapImage[0] = '1';
//read in the bitmap image data
fread(bitmapImage,bitmapInfoHeader.biSizeImage,1,filePtr);
//make sure bitmap image data was read
if (bitmapImage == NULL)
{
fclose(filePtr);
}
//close file and return bitmap iamge data
fclose(filePtr);
// Write Image Struct
bmppic->no_of_cols = bitmapInfoHeader.biWidth;
bmppic->no_of_rows = bitmapInfoHeader.biHeight;
bmppic->image_data = (int*) malloc (bitmapInfoHeader.biSizeImage*sizeof(int));
// Sort picturedata to image struct
int i=0, k=0, j=0;
if (bitmapInfoHeader.biHeight >= 0) // BOTTOM-UP-STRUCTURE IN BITMAP-FILE
{
for (k=0; k<=bmppic->no_of_cols; k++)
{
for (j=1; j<=bmppic->no_of_rows; j++)
{
bmppic->image_data[i] = bitmapImage[((bmppic->no_of_rows-j)*bmppic->no_of_cols)+k];
i++;
}
}
}
else // UP-DOWN-STRUCTURE IN BITMAP-FILE
{
for (k=0; k<=bmppic->no_of_cols; k++)
{
for (j=0; j<=bmppic->no_of_rows; j++)
{
bmppic->image_data[i] = bitmapImage[((j*bmppic->no_of_cols)+k)];
i++;
}
}
}
free(bitmapImage);
}
Diese Funktion soll mir ein BMP-File einlesen und es in eine von mir definierte Struktur schreiben, dafür übergebe ich Ihr den Dateinamen und einen Zeiger auf meine Struktur. Das Problem besteht nun darin, dass die Funktion beim ersten mal durchlaufen wird und einwandfrei funktioniert. Beim zweiten Mal erhalte ich bei der Definition des unsigned char Arrays folgende Fehlermeldung:
Nicht abgefangene Ausnahme in xyz.exe (NTDLL.DLL): 0xC0000005: Access Violation.
Dieser Fehler wiederholt sich dann beim allozieren des Speichers und beim Versuch in eine Stelle des Char-Arrays zu schreiben bricht das Programm vollständig ab. (NUR beim 2. Durchlauf der Funktion)... Hat da jemand eine Idee woran es liegen könnte???
mfg
NablA