Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Select a certain number of horizontal seams and remove them...
- for( int vSeams = 0; vSeams < difWid; vSeams++ ){////personally I hate the spaces after control-flow statement keywords.
- ////What is the meaning of it? for(...) is very clear. Where you want the space is between it, which you do have.
- ////And again, the space between ) and {. Just why? Is it not clear you are starting a control-flow statement and that's just the syntax that's there?
- ////What you want most readable are your params.
- ////And yeah, I removed the space.
- //Create and calculate the seam values
- //Set the first row of seam values equal to the energies at those points.
- double *seamMap = new double [ (inWid-vSeams)*outHei ]; ////you space params, but not for complex index selectors?
- for( int col = 0; col < inWid-vSeams; col++ ){
- seamMap[col] = energy[col];
- } ////I also like to ONLY use curly braces. It's an extra line, but what if you want to add something later?
- ////Okay sure, your IDE makes it easy, but to me it's a lot more clear that it's
- ////this is my own personal autism and something you might not want to take to heart if you don't agree and/or employer doesn't.
- //For every subsequent row, set each pixel's seam value equal to the sum of its energy and the least of all the top neighbor's energies.
- for( int row = 1; row < outHei ; row++ ){
- for( int col = 0; col < inWid-vSeams; col++ ){
- seamMap[ row*(inWid-vSeams) + col ] = energy[ row*inWid + col ]
- + minOfThree( getArBd(row-1,col-1,inWid-vSeams,outHei,seamMap,maxEnergy*outHei),////I have never seen this space between function and opening bracket for its params shit. wtf.
- getArBd(row-1,col ,inWid-vSeams,outHei,seamMap,maxEnergy*outHei),
- getArBd(row-1,col+1,inWid-vSeams,outHei,seamMap,maxEnergy*outHei));////this is fine. Same way I'd do it...
- ////I super-fucking-question why this is a "minOfThree" function instead of one that takes n-params, though...
- }
- }
- //Store each column index for every row, starting from last and working backward. This way we can easily get each pixel of the seam.
- int *colIndicies = new int [outHei];
- //Find lowest value seam ending by looking at ending columns and finding lowest cumulative seam.
- colIndicies[outHei-1] = 0;
- double minSeam = getArBd( outHei-1, 0, inWid-vSeams, outHei, seamMap, maxEnergy*outHei );
- for( int col = 1; col < inWid-vSeams; col++ ){
- double current = getArBd( outHei-1, col, inWid-vSeams, outHei, seamMap, maxEnergy*inWid );
- if( current < minSeam ){
- minSeam = current;
- colIndicies[outHei-1] = col;
- }//// don't do that compact one line shit. It's a pain to read.
- }
- //Work from ending to recover entire least important seam.
- for( int row = outHei - 2; row >= 0; row -- ){
- double a = getArBd( row, colIndicies[row+1]-1, inWid-vSeams, outHei, seamMap, maxEnergy*outHei ),
- b = getArBd( row, colIndicies[row+1] , inWid-vSeams, outHei, seamMap, maxEnergy*outHei ),
- c = getArBd( row, colIndicies[row+1]+1, inWid-vSeams, outHei, seamMap, maxEnergy*outHei );////it's all doubles. Some will say not to do this because "muh legacy programming", though.
- double min = minOfThree( a, b, c ); ////why are there so many trailing spaces? Your IDE should handle removing those.
- //// I like to put a gap between setting variables and code that actually does something when there is no extra control-flow statement.
- colIndicies[row] =
- min == a ? colIndicies[row+1]-1 :
- min == b ? colIndicies[row+1] :
- colIndicies[row+1]+1;////i herd u liek ternary so i put a ternary in ur ternary.
- ////this does the same thing with half the characters.
- }
- //Call shift function on the seam point of each column of image and energy; get rid of that seam in the image and in energy map
- for( int row = 0; row < outHei; row ++ ){
- shift( row, colIndicies[row], inWid-vSeams, outHei, inWid, false, image );
- shift( row, colIndicies[row], inWid-vSeams, outHei, inWid, false, energy );
- }
- //Recompute the energy at the locations where the seam was removed, and at the locations exactly below that
- for( int row = 0; row < outHei; row ++ ){
- for( int dif = -2; dif <= 2; dif ++ ){
- int index = colIndicies[row] + dif;
- if( index >= 0 && index < inWid-vSeams ){ ////unnessisary brackets around inWid-vSeams that weren't elsewhere...
- energy[row*inWid + index] = computeEnergy( row, index, inWid-vSeams-1, outHei, inWid, image );
- }
- }
- }////you added curly braces here when you didn't need them, no?
- ////Another reason why I just always use them. It can make it confusing why you sometimes use them when you don't need them.
- delete [] colIndicies;
- delete [] seamMap;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement