Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int offset = 0;
- for (int i = 0; i < height_of_L_n; i++){
- for (int j = 0; j < width_of_L_n; j++){
- //********* This part will differ in the later version I provided below
- //
- int xSrcInt = (int)(ratio * j);
- float xDiff = ratio * j - xSrcInt;
- int ySrcInt = (int)(ratio * i);
- float yDiff = ratio * i - ySrcInt;
- // The above code will differ in the later version I provided below
- index = (ySrcInt * width_of_L_n_minus_1 + xSrcInt);
- //Get the 4 pixel values to interpolate
- a = L_n_minus_1[index];
- b = L_n_minus_1[index + 1];
- c = L_n_minus_1[index + width_of_L_n_minus_1];
- d = L_n_minus_1[index + width_of_L_n_minus_1 + 1];
- //Calculate the co-efficients for interpolation
- float c0 = (1 - x_diff)*(1 - y_diff);
- float c1 = (x_diff)*(1 - y_diff);
- float c2 = (y_diff)*(1 - x_diff);
- float c3 = (x_diff*y_diff);
- //half is added for rounding the pixel intensity.
- int intensity = (a*c0) + (b*c1) + (c*c2) + (d*c3) + 0.5;
- if (intensity > 255)
- intensity = 255;
- L_n[offset++] = intensity;
- }
- }
- int offset = 0;
- for (int i = 0; i < height_of_L_n; i++){
- for (int j = 0; j < width_of_L_n; j++){
- // Here the code differs from the first piece of code
- // Assume pixel centers start from (0.5,0.5). The top left pixel has co-ordinate (0.5,0.5)
- // 0.5 is added to go to the co-ordinates where top left pixel has co-ordinate (0.5,0.5)
- // 0.5 is subtracted to go to the generally used co-ordinates where top left pixel has co-ordinate (0,0)
- // or in other words map the new co-ordinates to array indices
- int xSrcInt = int((ratio * (j + 0.5)) - 0.5);
- float xDiff = (ratio * (j + 0.5)) - 0.5 - xSrcInt;
- int ySrcInt = int((ratio * (i + 0.5)) - 0.5);
- float yDiff = (ratio * (i + 0.5)) - 0.5 - ySrcInt;
- // Difference with previous code ends here
- index = (ySrcInt * width_of_L_n_minus_1 + xSrcInt);
- //Get the 4 pixel values to interpolate
- a = L_n_minus_1[index];
- b = L_n_minus_1[index + 1];
- c = L_n_minus_1[index + width_of_L_n_minus_1];
- d = L_n_minus_1[index + width_of_L_n_minus_1 + 1];
- //Calculate the co-efficients for interpolation
- float c0 = (1 - x_diff)*(1 - y_diff);
- float c1 = (x_diff)*(1 - y_diff);
- float c2 = (y_diff)*(1 - x_diff);
- float c3 = (x_diff*y_diff);
- //half is added for rounding the pixel intensity.
- int intensity = (a*c0) + (b*c1) + (c*c2) + (d*c3) + 0.5;
- if (intensity > 255)
- intensity = 255;
- L_n[offset++] = intensity;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement