Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Select a certain number of horizontal seams and remove them...
  2.         for( int vSeams = 0; vSeams < difWid; vSeams++ ){////personally I hate the spaces after control-flow statement keywords.
  3.             ////What is the meaning of it?  for(...) is very clear.  Where you want the space is between it, which you do have.
  4.             ////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?
  5.             ////What you want most readable are your params.
  6.             ////And yeah, I removed the space.
  7.             //Create and calculate the seam values
  8.             //Set the first row of seam values equal to the energies at those points.
  9.             double *seamMap = new double [ (inWid-vSeams)*outHei ]; ////you space params, but not for complex index selectors?
  10.             for( int col = 0; col < inWid-vSeams; col++ ){
  11.                 seamMap[col] = energy[col];
  12.             } ////I also like to ONLY use curly braces. It's an extra line, but what if you want to add something later?
  13.             ////Okay sure, your IDE makes it easy, but to me it's a lot more clear that it's
  14.             ////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.
  15.  
  16.             //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.
  17.             for( int row = 1; row < outHei ; row++ ){
  18.                 for( int col = 0; col < inWid-vSeams; col++ ){
  19.                     seamMap[ row*(inWid-vSeams) + col ] = energy[ row*inWid + col ]
  20.                                                       + 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.
  21.                                                                      getArBd(row-1,col  ,inWid-vSeams,outHei,seamMap,maxEnergy*outHei),
  22.                                                                      getArBd(row-1,col+1,inWid-vSeams,outHei,seamMap,maxEnergy*outHei));////this is fine. Same way I'd do it...
  23.                                                       ////I super-fucking-question why this is a "minOfThree" function instead of one that takes n-params, though...
  24.                 }
  25.             }
  26.  
  27.             //Store each column index for every row, starting from last and working backward. This way we can easily get each pixel of the seam.
  28.             int *colIndicies = new int [outHei];
  29.  
  30.             //Find lowest value seam ending by looking at ending columns and finding lowest cumulative seam.
  31.             colIndicies[outHei-1] = 0;
  32.             double minSeam = getArBd( outHei-1, 0, inWid-vSeams, outHei, seamMap, maxEnergy*outHei );
  33.             for( int col = 1; col < inWid-vSeams; col++ ){
  34.                 double current = getArBd( outHei-1, col, inWid-vSeams, outHei, seamMap, maxEnergy*inWid );
  35.                 if( current < minSeam ){
  36.                     minSeam = current;
  37.                     colIndicies[outHei-1] = col;
  38.                 }//// don't do that compact one line shit. It's a pain to read.
  39.             }
  40.            
  41.             //Work from ending to recover entire least important seam.
  42.             for( int row = outHei - 2; row >= 0; row -- ){
  43.                 double a = getArBd( row, colIndicies[row+1]-1, inWid-vSeams, outHei, seamMap, maxEnergy*outHei ),
  44.                     b = getArBd( row, colIndicies[row+1]  , inWid-vSeams, outHei, seamMap, maxEnergy*outHei ),
  45.                     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.
  46.                 double min = minOfThree( a, b, c );    ////why are there so many trailing spaces? Your IDE should handle removing those.
  47.                
  48.                 //// I like to put a gap between setting variables and code that actually does something when there is no extra control-flow statement.
  49.                 colIndicies[row] =
  50.                     min == a ? colIndicies[row+1]-1 :
  51.                         min == b ? colIndicies[row+1] :
  52.                             colIndicies[row+1]+1;////i herd u liek ternary so i put a ternary in ur ternary.
  53.                             ////this does the same thing with half the characters.
  54.             }
  55.  
  56.             //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
  57.             for( int row = 0; row < outHei; row ++ ){
  58.                 shift( row, colIndicies[row], inWid-vSeams, outHei, inWid, false, image );
  59.                 shift( row, colIndicies[row], inWid-vSeams, outHei, inWid, false, energy );
  60.             }
  61.  
  62.             //Recompute the energy at the locations where the seam was removed, and at the locations exactly below that
  63.             for( int row = 0; row < outHei; row ++ ){
  64.                 for( int dif = -2; dif <= 2; dif ++ ){
  65.                     int index = colIndicies[row] + dif;
  66.                     if( index >= 0 && index < inWid-vSeams ){ ////unnessisary brackets around inWid-vSeams that weren't elsewhere...
  67.                         energy[row*inWid + index] = computeEnergy( row, index, inWid-vSeams-1, outHei, inWid, image );
  68.                     }
  69.                 }
  70.             }////you added curly braces here when you didn't need them, no?
  71.             ////Another reason why I just always use them. It can make it confusing why you sometimes use them when you don't need them.
  72.             delete [] colIndicies;
  73.             delete [] seamMap;
  74.         }
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement