Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. int offset = 0;
  2.  
  3. for (int i = 0; i < height_of_L_n; i++){
  4.  
  5. for (int j = 0; j < width_of_L_n; j++){
  6.  
  7.  
  8.  
  9. //********* This part will differ in the later version I provided below
  10. //
  11. int xSrcInt = (int)(ratio * j);
  12. float xDiff = ratio * j - xSrcInt;
  13.  
  14. int ySrcInt = (int)(ratio * i);
  15. float yDiff = ratio * i - ySrcInt;
  16.  
  17. // The above code will differ in the later version I provided below
  18.  
  19.  
  20.  
  21. index = (ySrcInt * width_of_L_n_minus_1 + xSrcInt);
  22.  
  23. //Get the 4 pixel values to interpolate
  24. a = L_n_minus_1[index];
  25. b = L_n_minus_1[index + 1];
  26. c = L_n_minus_1[index + width_of_L_n_minus_1];
  27. d = L_n_minus_1[index + width_of_L_n_minus_1 + 1];
  28.  
  29. //Calculate the co-efficients for interpolation
  30. float c0 = (1 - x_diff)*(1 - y_diff);
  31. float c1 = (x_diff)*(1 - y_diff);
  32. float c2 = (y_diff)*(1 - x_diff);
  33. float c3 = (x_diff*y_diff);
  34.  
  35. //half is added for rounding the pixel intensity.
  36. int intensity = (a*c0) + (b*c1) + (c*c2) + (d*c3) + 0.5;
  37.  
  38. if (intensity > 255)
  39. intensity = 255;
  40.  
  41. L_n[offset++] = intensity;
  42.  
  43. }
  44.  
  45. }
  46.  
  47. int offset = 0;
  48.  
  49. for (int i = 0; i < height_of_L_n; i++){
  50.  
  51. for (int j = 0; j < width_of_L_n; j++){
  52.  
  53.  
  54. // Here the code differs from the first piece of code
  55. // Assume pixel centers start from (0.5,0.5). The top left pixel has co-ordinate (0.5,0.5)
  56. // 0.5 is added to go to the co-ordinates where top left pixel has co-ordinate (0.5,0.5)
  57. // 0.5 is subtracted to go to the generally used co-ordinates where top left pixel has co-ordinate (0,0)
  58. // or in other words map the new co-ordinates to array indices
  59.  
  60. int xSrcInt = int((ratio * (j + 0.5)) - 0.5);
  61. float xDiff = (ratio * (j + 0.5)) - 0.5 - xSrcInt;
  62.  
  63. int ySrcInt = int((ratio * (i + 0.5)) - 0.5);
  64. float yDiff = (ratio * (i + 0.5)) - 0.5 - ySrcInt;
  65.  
  66. // Difference with previous code ends here
  67.  
  68.  
  69.  
  70. index = (ySrcInt * width_of_L_n_minus_1 + xSrcInt);
  71.  
  72.  
  73. //Get the 4 pixel values to interpolate
  74. a = L_n_minus_1[index];
  75. b = L_n_minus_1[index + 1];
  76. c = L_n_minus_1[index + width_of_L_n_minus_1];
  77. d = L_n_minus_1[index + width_of_L_n_minus_1 + 1];
  78.  
  79.  
  80. //Calculate the co-efficients for interpolation
  81. float c0 = (1 - x_diff)*(1 - y_diff);
  82. float c1 = (x_diff)*(1 - y_diff);
  83. float c2 = (y_diff)*(1 - x_diff);
  84. float c3 = (x_diff*y_diff);
  85.  
  86. //half is added for rounding the pixel intensity.
  87. int intensity = (a*c0) + (b*c1) + (c*c2) + (d*c3) + 0.5;
  88.  
  89. if (intensity > 255)
  90. intensity = 255;
  91.  
  92. L_n[offset++] = intensity;
  93.  
  94. }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement