Image warp challenge:
Write a program to rotate an image by an amount of degrees as given on the command line:
rotate [image.ppm] [degrees]
I suggest using the program brighten.c as a stub and modifying it. You will need a second image array to store the output that you write to a file:
unsigned char *output;
output=(unsigned char *)calloc(ROWS*COLS,1);
Pixel rotation is accomplished using these formulas:
x2=cos(radians)*(x1-x0)-sin(radians)*(y1-y0)+x0;
y2=sin(radians)*(x1-x0)+cos(radians)*(y1-y0)+y0;
where x0,y0 is the center width,height of the image,
x2,y2 is the input image c,r coordinate,
and x1,y1 is the output image c,r coordinate
Suggested approach:
Loop over output coordinates x1,y1 calculating a tentative input coordinate x2,y2 for each. If x2,y2 is within the image bounds (ROWS x COLS) then copy the input image at x2,y2 to the output image at x1,y1.
Note: The C trig functions use radians instead of degrees. The conversion is:
radians=degrees*M_PI/180.0