I am able to consider padding in any other function but that one. That because, I am using a fast way of color replacing, which requires incrementing the index with +3 which causes the inability of treating padding on regular ways. However.. I am almost certain that the conditional algorithm to consider padding, works! Well.. it clearly doesn't, because it causes this:
Code:
union
{
unsigned long ulColor;
unsigned char byteColor[4];
} oldColor;
union
{
unsigned long ulColor;
unsigned char byteColor[4];
} newColor;
typedef unsigned char BYTE;
typedef unsigned short int WORD;
typedef unsigned long int DWORD;
typedef unsigned longl ong int DDWORD;
DDWORD
bitfox_color_replace_data
(BYTE *buff, BYTE old_r, BYTE old_g, BYTE old_b, BYTE new_r, BYTE new_g, BYTE new_b)
{
#define OFFSET_OF_SIZE 0x2
#define OFFSET_OF_PIXELS 0xA
#define OFFSET_OF_WIDTH 0x12
#define OFFSET_OF_HEIGHT 0x16
DWORD* buffSize =(DWORD*)&buff[OFFSET_OF_SIZE];
DWORD* buffPixels =(DWORD*)&buff[OFFSET_OF_PIXELS];
DWORD* buffWidth =(DWORD*)&buff[OFFSET_OF_WIDTH];
DWORD buffHeight =0;
BYTE pad =0;
DDWORD pixels_replaced =0;
DDWORD i;
oldColor.byteColor[0]= old_b; newColor.byteColor[0]= new_b;
oldColor.byteColor[1]= old_g; newColor.byteColor[1]= new_g;
oldColor.byteColor[2]= old_r; newColor.byteColor[2]= new_r;
for(i =(*buffPixels); i <(*buffSize); i +=3)
{
if( i ==((*buffPixels)+(((*buffWidth)*3)+ pad)*(buffHeight +1)))
{
pad =((*buffWidth)%4);
buffHeight++;
i += pad;
}
if(!memcmp(buff + i, oldColor.byteColor,3))
{
memcpy(buff + i, newColor.byteColor,3);
pixels_replaced++;
}
}
return pixels_replaced;
}