c++ - Stack cookie instrumentation code detected a stack-based buffer overrun - Fixed -
so having few issues programme used pixelate image. 1 issue "stack around variable 'pixarray' corrupted" , then, when click go on after breaking gives error in title.
i'm not sure if acceptable utilize pastebin, i'll utilize sake of having "short" post.
the code
the image beingness used
also, when runs through, of pixelated squares 1 pixel short on left , top of squares. using original info when writes outfile. if seek figure out why happening, bonus points.
finally, averages don't seem averaging correctly, can see squares around right-most side of image after running program.
any help of these problems appreciated. in advance!
edit: sorted through code, commenting out sections utilize pixarray
, , section that, when commented out, fixes problem @ bottom of function, getaveragesforrgb
start = 0;//reset start number for(int row = 0; row < squaresize; row++) { if(row != 0) start = ((square * maxrows) / (maxcols / squaresize)) + 1; stop = (((square + 1) * maxrows) / (maxcols / squaresize)); (int col = start; col < stop; col++) { //write each average each piece of array pixarray[row][col].red = redavg; pixarray[row][col].green = greenavg; pixarray[row][col].blue = blueavg; } }
edit 2: got running smoothly now. in case ever runs exact problem whatever reason, here new getaveragesforrgb
of problems were.
void getaveragesforrgb(pixel pixarray[][maxcols], int squaresize, int square, int numsquaresperstripe) { //initialize variables needed function int start, stop; int redavg, greenavg, blueavg; //reset averages current square's usage redavg = 0; greenavg = 0; blueavg = 0; start = 0; //reset start number (int row=0; row < squaresize; row++) { if (row != 0) start = ((square * maxrows) / (maxcols / squaresize)) - 1; //starting point loop on columns stop = start + squaresize;//stopping point ^^^ (int col = start; col < stop - 1; col++) { //add each rgb value sum divided later redavg += pixarray[row][col].red; greenavg += pixarray[row][col].green; blueavg += pixarray[row][col].blue; } } //divide number of pixels in square average redavg /= (squaresize * squaresize); greenavg /= (squaresize * squaresize); blueavg /= (squaresize * squaresize); start = 0;//reset start number (int row = 0; row < squaresize; row++) { if (row != 0) start = ((square * maxrows) / (maxcols / squaresize)) - 1; //starting point loop on columns stop = (((square + 1) * maxrows) / (maxcols / squaresize)); //stopping point ^^^ (int col = start; col < stop - 1; col++) { //write each average each piece of array pixarray[row][col].red = redavg; pixarray[row][col].green = greenavg; pixarray[row][col].blue = blueavg; } } }
c++ image-processing buffer-overrun pixelate stack-based
No comments:
Post a Comment