points to original of this index PIXEL o original rowcols col points to rotated

Points to original of this index pixel o original

This preview shows page 3 - 6 out of 7 pages.

// points to original of this index PIXEL* o = original + row*cols + col; // points to rotated image PIXEL* n = (*new) + (cols-col-1)*rows + row; // copies original to rotated image *n = *o; }
Image of page 3
} } return 0; } /* * This method horizontally flips a 24-bit, uncompressed bmp file * that has been read in using readFile(). * * THIS IS GIVEN TO YOU SOLELY TO LOOK AT AS AN EXAMPLE * TRY TO UNDERSTAND HOW IT WORKS * * original - an array containing the original PIXELs, 3 bytes per each * rows - the number of rows * cols - the number of columns * * new - the new array containing the PIXELs, allocated within */ int flip (PIXEL *original, PIXEL **new, int rows, int cols) { int row, col; if ((rows <= 0) || (cols <= 0)) return -1; *new = (PIXEL*)malloc(rows*cols*sizeof(PIXEL)); for (row=0; row < rows; row++) for (col=0; col < cols; col++) { PIXEL* o = original + row*cols + col; PIXEL* n = (*new) + row*cols + (cols-1-col); *n = *o; } return 0; } int main(int argc, char *argv[]) { //a variable that is located externally that is used to get the users value for the option extern char *optarg; //a int variable that is located externally that stores the number of mandatory operations extern int optind; // c for getopt otion and cols, r for rows, nr for new rows, nc for new cols int c, r, nr, nc; // b for original array of pixels, nb for new array of pixels PIXEL *b, *nb; // outfile name char* output_file_name; // set to null so will take stdin if no read file entered output_file_name = NULL; // infile name char* input_file_name; // set to null so will take stdout if no out file entered input_file_name = NULL; // option flags, scale, rotate, flip, outfile int sflag = 0, rflag = 0, fflag = 0, oflag = 0; // scale value, rotate degree value int vscale = 0, vrotate = 0; // usage statement static char usage[] = "usage: bmptool[-s scale | -r degree | -f][-o
Image of page 4
output_file][input_file]\n"; // while c equals one of options .... while((c = getopt(argc, argv, "s:r:fo:")) != -1) { switch(c) { case 's': // if -s entered if(sflag == 1) // if -s already used { // prints error fprintf(stderr, "Error: Duplicate '-%c' options\n", c); // and exited exit(-1); } sflag = 1; //sets flag to 1 for used
Image of page 5
Image of page 6

You've reached the end of your free preview.

Want to read all 7 pages?

  • Fall '08
  • STAFF

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture