Read the four bytes together as DWORD, or unsigned int as you prefer, dimension your image arrays as same var type and you're done ;)
#include <stdio.h>
#define WID 200
#define DEP 600
typedef struct {
int left;
int top;
int right;
int bot;
} rect;
DWORD image1[WID*DEP];
DWORD image2[WID*DEP];
int inrect (int x, int y, rect r) {
if (x<r.left x="">r.right || y<r.top y="">r.bot)
return 0;
return 1;
}
int compareimages (DWORD *im1, DWORD *im2, int wid, int dep, rect *rarr, int rects)
{
int x, y, n, ignore;
DWORD k; for (y=0; y<dep; y++)
for (x=0; x<wid; x++) {
int read_bytes = fread(&k, 4, 1, image1); ignore = 0;
for (n=0; n<rects; n++)
ignore |= inrect (x, y, rarr[n]);
if (!ignore)
if (k != im2[y*wid+x]) return 0;
}
return 1;
}
int main(void) {
rect rectarr[2] = { {10, 10, 50, 50}, { 40, 40, 90, 90 }};
image1[20*WID+20] = 1;
if (compareimages (image1, image2, WID, DEP, rectarr, 2))
printf ("Same\n");
else
printf ("Different\n");
image1[0] = 1;
if (compareimages (image1, image2, WID, DEP, rectarr, 2))
printf ("Same\n");
else
printf ("Different\n");
return 0;
}