Hello and Merry Christmas ! I've made a program that overwrites all the colors from a 24bit bitmap (except for white) with a given one (it is said that the background is white) . The problem is that i can't remove the padding . I've read bunch of tutorials and questions and still can't manage to solve the problem . I'm asked to overwrite the padding with 0 (I don't know why , in my opinion it will make the padding black) but i'm getting in the upper-right corner always a black row of one third the size of the width..
This is the input image
http://i.stack.imgur.com/jAsW6.png[
^]
This is the desired output
http://i.stack.imgur.com/aAgix.png[
^]
And this is my result
http://i.stack.imgur.com/yNvqq.png[
^]
Now i've seen that not even the color is right..
And here is the code :
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "bmp_header.h"
int main(void)
{
FILE *f;
f = fopen("captcha.bmp","rb");
fread(&BMP_header,sizeof(BMP_header),1,f);
fread(&BMP_info_header,sizeof(BMP_info_header),1,f);
fseek(f,BMP_header.imageDataOffset,SEEK_SET);
int rowSize = (BMP_info_header.bitPix * BMP_info_header.width + 31 ) /32 * 4 ;
unsigned char *PixelArray = (unsigned char *)malloc(rowSize * abs(BMP_info_header.height));
fread(PixelArray,sizeof(char),BMP_info_header.biSizeImage,f);
int i,j,k,addPadding;
int padding = 4-((BMP_info_header.width*3)%4);
for( i = 0; i<abs(BMP_info_header.height); i++)
{
for(j = 0 ; j<rowSize-padding; j+= 3)
{
int offset = i * (rowSize-padding) + j;
if((PixelArray[offset] != 255 ) && (PixelArray[offset+1] != 255) && (PixelArray[offset+2] != 255))
{ PixelArray[offset] = 69;
PixelArray[offset+1] = 106;
PixelArray[offset+2] = 671;
}
}
for (addPadding = 0 ; addPadding < padding ; addPadding ++)
PixelArray[ i * (rowSize+padding) + j ] = 255;
}
f = fopen("result.bmp","wb");
fwrite(&BMP_header,sizeof(BMP_header),1,f);
fwrite(&BMP_info_header,sizeof(BMP_info_header),1,f);
fwrite(PixelArray,rowSize * abs(BMP_info_header.height),1,f);
fclose(f);
free(PixelArray);
return 0;
}
Here is "bmp_header.h" 's content :
#pragma pack(1)
struct bmp_fileheader
{
unsigned char fileMarker1;
unsigned char fileMarker2;
unsigned int bfSize;
unsigned short unused1;
unsigned short unused2;
unsigned int imageDataOffset;
}BMP_header,BMP_header_out;
struct bmp_infoheader
{
unsigned int biSize;
signed int width;
signed int height;
unsigned short planes;
unsigned short bitPix;
unsigned int biCompression;
unsigned int biSizeImage;
int biXPelsPerMeter;
int biYPelsPerMeter;
unsigned int biClrUsed;
unsigned int biClrImportant;
}BMP_info_header,BMP_info_header_out;
#pragma pack()
Any help would be very much appreciated :)