Hello!
I need your help for a problem. I have to save an image file - it is a bmp 24-bit file.
I wrote some code but when I try to execute I get the message
"12 [main] bmpengine 2532 _gygtls:handle_exceptions: Error while dumping state (probably corrupted stack) Segmentation fault (core dumped)"
Notes:
1) "bmpengine" is my executable
2) the structures are:
my "save" code is:Code:typedef struct image { BITMAP_FILE_HEADER file_info; BITMAP_INFO_HEADER bitmap_info; byte *data; } IMAGE; and // BMP File header typedef struct bitmap_file_header { byte bfType[2]; dword bfSize; word bfReserved1; word bfReserved2; dword bfOffBits; } BITMAP_FILE_HEADER; // BMP Image header typedef struct bitmap_info_header { dword biSize; dword biWidth; dword biHeight; word biPlanes; word biBitCount; dword biCompression; dword biSizeImage; dword biXPelsPerMeter; dword biYPelsPerMeter; dword biClrUsed; dword biClrImportant; } BITMAP_INFO_HEADER;
where i am doing wrong??? please help!Code:int save_image(IMAGE *image, char name[]) { FILE *fp; int i, rowsize; byte temp; unsigned int row, col, colour; fp=fopen(name, "wb"); if(fp==NULL) { printf("cannot open the file %s\n", name); return EXIT_FAILURE; } /* I dont know if i really need those - it does not work with or without them image->file_info.bfReserved1=0; image->file_info.bfReserved2=0; image->file_info.bfOffBits=54; image->bitmap_info.biBitCount=24; image->bitmap_info.biCompression=0; image->bitmap_info.biXPelsPerMeter=0; image->bitmap_info.biYPelsPerMeter=0; image->bitmap_info.biClrUsed=3; image->bitmap_info.biClrImportant=0; */ rowsize=4*((3*image->bitmap_info.biWidth+3)/4); image->bitmap_info.biSizeImage=image->bitmap_info.biHeight*rowsize; image->file_info.bfSize=54+image->bitmap_info.biSizeImage; // Reserving memory for image's data image->data=(byte*) malloc(sizeof(byte)*image->bitmap_info.biSizeImage); if (image->data==NULL) { printf("Insufficient memory to load new image.\n"); free(image); return EXIT_FAILURE; } if(image != NULL) { fwrite(&image->file_info, sizeof(BITMAP_FILE_HEADER),1,fp); fwrite(&image->bitmap_info, sizeof(BITMAP_INFO_HEADER),1,fp); for(row=image->bitmap_info.biHeight-1; row>=0; row--) {//for each row for(col=0;col<image->bitmap_info.biWidth;col++) //for each column for(colour=BLUE; colour>=RED; colour--) //for each color fwrite(&image->data[row*rowsize+3*col+colour],sizeof(byte),1,fp); for(i=rowsize-(3*image->bitmap_info.biWidth);i>=0;i--) //padding fwrite(&temp,sizeof(temp),1,fp); } //end_for } //end_if fclose(fp); return EXIT_SUCCESS; }
any help would be appreciated!
thanks...



LinkBack URL
About LinkBacks



