Feature #5: RGB pixel, get and print functions

To facilitate access to pixels of the data array, we propose to define a structure and a function to access to specific pixel at position x,y.

Feature description

To facilitate access to pixels of the data array, we propose to define a structure and a function to access to specific pixel at position x,y.

Parameters value
name print_pixel
Command -c print_pixel <X> <Y>
arguments X: x coordinate of the pixel
Y: y coordinate of the pixel
Input an image
output print_pixel (x, y): R, G, B (with R, G, B the component values of pixel at (x,y))

Usage

freud.exe -f ./images/input/image.jpeg -c print_pixel 45 500

Output

print_pixel (45, 500): 160, 190, 200

First, you have to define a structure for a RGB pixel in utils.h. Complete the given struct in utils.h with the pixelRGB attributes: R, G, and B unsigned char.

Second you have to define the prototype of get_pixel function in utils.h. We propose the following prototype for this function:

pixelRGB * get_pixel( unsigned char* data, const unsigned int width, const unsigned int height, const unsigned int n, const unsigned int x, const unsigned int y );
Parameters value
data the data array containing R, G, and B components of each pixels
width image width
height image height
n channel count
x position x of the pixel we want to return
y position y of the pixel we want to return

With data the array resulting from the function read_image_data from <estia-image.h>. Same for width, height, and n.

int read_image_data(const char *filename, unsigned char **data, int *width, int *height, int *channel_count);

Then, you have to implement the get_pixel function in utils.c.

  • The function returns NULL if x or y are beyond range.
  • The function returns NULL if data is NULL
  • If these preconditions are verified, then the function returns the address of the requested RGBpixel :
  return (pixelRGB *) &data[ /* TO COMPLETE */] ;

Repeat these steps to define and implement print_pixel. This function prints on the command line RGB values of the corresponding pixel.

void print_pixel( char *filename, int x, int y );

Describe tips for implementing feature

Read the page about how images are stored and the estia-image documentation.