0

Before working on filters in problem set 4, I wanted to make sure I understood the basics. I have downloaded yard.bmp (attached here) and am trying to do simple operations (e.g. use pointers, extract file information, modify pixels). However, I am completely lost in terms of working at the pixel level. For example, how do I (a) extract the RGB value of pixel [40][50], and (b) change the colors of a 10 x 10 pixel box? I am basically stuck after the file-headers stage.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    /*Read in image file and verify readin status.*/
    FILE *inptr = fopen("yard.bmp", "r"); 
    if (inptr == NULL){
        printf("NULL\n");
    }
    else {
        printf("Not NULL\n");
    }

    /* Read in and parse header.
    See: http://www.ece.ualberta.ca/~elliott/ee552/studentAppNotes/2003_w/misc/bmp_file_format/bmp_file_format.htm
    for nice layout.*/
    unsigned char info[54]; // 14 bytes Header + 40 bytes InfoHeader
    fread(info, sizeof(unsigned char), 54, inptr);
    int width = *(int*)&info[18]; //See: https://stackoverflow.com/questions/50908563/extract-width-of-bmp-image-in-c
    int height = *(int*)&info[22];
    int size = 3 * width * abs(height);
    printf("%Width: %d pixels Height: %d pixels Size: %d\n", width, height, size);

    //return 0;
}

enter image description here

You must log in to answer this question.

Browse other questions tagged .