Frame buffer demo project - strange colors and garbage on the screen

here’s the code that produced that picture:
#include <stdio.h>
#include <linux/fb.h>
#include <unistd.h>
#include <stdlib.h>

unsigned char colours[8][4] = {
{ 0x00, 0x00, 0xFF, 0xFF }, // red
{ 0x00, 0x00, 0xFF, 0xFF }, // red
{ 0x00, 0x00, 0xFF, 0xFF }, // red
{ 0x00, 0x00, 0xFF, 0xFF }, // red
{ 0x00, 0x00, 0xFF, 0xFF }, // red
{ 0x00, 0x00, 0xFF, 0xFF }, // red
{ 0x00, 0x00, 0xFF, 0xFF }, // red
{ 0x00, 0x00, 0xFF, 0xFF }, // red
};

int frames[] = {0,5,10,15,20,25,30};

int columns = 640;
int lines = 480;

#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))

int frame(int c, int l){
int i;
for(i=0; i < ARRAY_SIZE(frames); i++){
// /DEBUG/ printf(“ARRAY_SIZE returns %d\n”, ARRAY_SIZE(frames));
// /DEBUG/ printf(" sizeof(s) is %d; sizeof(a[0]) is %d.\n",
// sizeof(frames), sizeof(frames[0]));
if((c==frames[i])&&((l>=frames[i])&&l<=(lines-frames[i]))){
return 1;
}
if((c==columns-frames[i])&&((l>=frames[i])&&l<=(lines-frames[i]))){
return 1;
}
if((l==frames[i])&&((c>=frames[i])&&c<=(columns-frames[i]))){
return 1;
}
if((l==lines-frames[i])&&((c>=frames[i])&&c<=(columns-frames[i]))){
return 1;
}
}
return 0;
}

int main(int argc, char **argv)
{
unsigned char pixel[3];
int l, c;
char *filename = argv[1];
FILE *f;

if (argc != 2) {
   printf("usage: sudo hw-on-fb /dev/fb0\n");
   exit(-1);
} else {
   printf ("Device : %s\n",filename);
   f = fopen(filename,"wb");
}

if(f){
printf("Device open success \n");
    for(l=0; l<lines; l++){
        for(c=0; c < columns; c++){
            if(frame(c,l)){
                printf("frame returns nonzero\n");
                fwrite(colours[3], 1, sizeof(colours[3]), f);
            }else{
                printf("frame returns zero\n");
                int colour = c/(columns/ARRAY_SIZE(colours));
                fwrite(colours[colour], 1, sizeof(colours[colour]), f);
            }
        }
    }
    fclose(f);
}
else
   printf("Device open failed \n");

return 0;

}