c - Inverting a PGM's Color Values Distorts the Image -


my goal read in pgm image , produce image inverted color values. when put in this image, this image. i'm programming in c, using eclipse , mingw gcc on windows 7 (64-bit). why image getting drastically distorted?

int complement(pgmimage *img) { int i, j;  // set new pgm copy onto pgmimage* comimg = (pgmimage*)malloc(sizeof(pgmimage)); (*comimg).width = (*img).width; (*comimg).height = (*img).height;  // invert each pixel for(i = 0; <= (*img).width; i++) {     for(j = 0; j <= (*img).height; j++) {          // set inverted value each new pixel         (*comimg).data[i][j].red = abs((*img).maxval - (*img).data[i][j].red);         (*comimg).data[i][j].green = abs((*img).maxval - (*img).data[i][j].green);         (*comimg).data[i][j].blue = abs((*img).maxval - (*img).data[i][j].blue);     } }  // save copy of complement image save("c:\\image_complement.pgm", comimg); printf("a copy of image has been saved \"c:\\image_complement.pgm\"\n\n"); void free(comimg); return 0; } 

i'm not sure, suspect outer array index of image line , inner column. expect i should run (*img).height , j (*img).width.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -