Guest User

Untitled

a guest
Jun 15th, 2020
30
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void blur(int height, int width, RGBTRIPLE image[height][width])
  2. {
  3. int red;
  4. int blue;
  5. int green;
  6. int counter = 0;
  7. RGBTRIPLE copy[height][width];
  8. for(int i =0;i<height;i++)
  9. {
  10. for(int j = 0;j<width;j++)
  11. {
  12. copy[i][j]=image[i][j];
  13. }
  14. }
  15. for(int i =0;i<height;i++)
  16. {
  17. for(int j = 0;j<width;j++)
  18. {
  19. red = image[i][j].rgbtRed;
  20. green = image[i][j].rgbtGreen;
  21. blue = image[i][j].rgbtBlue;
  22. counter++;
  23. //height
  24. if(i==0)
  25. {
  26. red = round(((float)red*counter+image[i+1][j].rgbtRed)/(counter+1));
  27. green = round(((float)green*counter+image[i+1][j].rgbtGreen)/(counter+1));
  28. blue = round(((float)blue*counter+image[i+1][j].rgbtBlue)/(counter+1));
  29. counter++;
  30. }else if(i==height-1)
  31. {
  32. red = round(((float)red*counter+image[i-1][j].rgbtRed)/(counter+1));
  33. blue=round(((float)blue*counter+image[i-1][j].rgbtBlue)/(counter+1));
  34. green=round(((float)green*counter+image[i-1][j].rgbtGreen)/(counter+1));
  35. counter++;
  36. }else
  37. {
  38. red = round(((float)red*counter+image[i-1][j].rgbtRed+image[i+1][j].rgbtRed)/(counter+2));
  39. blue=round(((float)blue*counter+image[i-1][j].rgbtBlue+image[i+1][j].rgbtBlue)/(counter+2));
  40. green = round(((float)green*counter+image[i-1][j].rgbtGreen+image[i+1][j].rgbtBlue)/(counter+2));
  41. counter+=2;
  42. }
  43. //width
  44. if(j==0)
  45. {
  46. red = round(((float)red*counter+image[i][j+1].rgbtRed)/(counter+1));
  47. green = round(((float)green*counter+image[i][j+1].rgbtGreen)/(counter+1));
  48. blue = round(((float)blue*counter+image[i][j+1].rgbtBlue)/(counter+1));
  49. counter++;
  50. }else if(j==width-1)
  51. {
  52. red = round(((float)red*counter+image[i][j-1].rgbtRed)/(counter+1));
  53. green = round(((float)green*counter+image[i][j-1].rgbtGreen)/(counter+1));
  54. blue = round(((float)blue*counter+image[i][j-1].rgbtBlue)/(counter+1));
  55. counter++;
  56. }else
  57. {
  58. red = round(((float)red*counter+image[i][j-1].rgbtRed+image[i][j+1].rgbtRed)/(counter+2));
  59. blue = round(((float)blue*counter+image[i][j-1].rgbtBlue+image[i][j+1].rgbtBlue)/(counter+2));
  60. green = round(((float)green*counter+image[i][j-1].rgbtGreen+image[i][j+1].rgbtGreen)/(counter+2));
  61. counter+=2;
  62. }
  63. //edge case
  64. if(i==0&&j==0)
  65. {
  66. red = round(((float)red*counter+image[i+1][j+1].rgbtRed)/(counter+1));
  67. blue = round(((float)blue*counter+image[i+1][j+1].rgbtBlue)/(counter+1));
  68. green = round(((float)green*counter+image[i+1][j+1].rgbtBlue)/(counter+1));
  69. counter++;
  70. }else if(i==height-1&&j==width-1)
  71. {
  72. red = round(((float)red*counter+image[i-1][j-1].rgbtRed)/(counter+1));
  73. blue = round(((float)blue*counter+image[i-1][j-1].rgbtBlue)/(counter+1));
  74. green = round(((float)green*counter+image[i-1][j-1].rgbtGreen)/(counter+1));
  75. counter++;
  76. }else if(i==height-1&&j==0)
  77. {
  78. red = round(((float)red*counter+image[i-1][j+1].rgbtRed)/(counter+1));
  79. blue = round(((float)blue*counter+image[i-1][j+1].rgbtBlue)/(counter+1));
  80. green = round(((float)green*counter+image[i-1][j+1].rgbtGreen)/(counter+1));
  81. counter++;
  82. }else if(i==0&&j==width-1)
  83. {
  84. red = round(((float)red*counter+image[i+1][j-1].rgbtRed)/(counter+1));
  85. blue = round(((float)blue*counter+image[i+1][j-1].rgbtBlue)/(counter+1));
  86. green = round(((float)green*counter+image[i+1][j-1].rgbtBlue)/(counter+1));
  87. counter++;
  88. }else if(i==0)
  89. {
  90. red = round(((float)red*counter+image[i+1][j-1].rgbtRed+image[i+1][j-1].rgbtBlue)/(counter+2));
  91. blue = round(((float)blue*counter+image[i+1][j-1].rgbtBlue+image[i+1][j-1].rgbtBlue)/(counter+2));
  92. green = round(((float)green*counter+image[i+1][j-1].rgbtGreen+image[i+1][j-1].rgbtGreen)/(counter+2));
  93. counter+=2;
  94. }else if(i==height-1)
  95. {
  96. red = round(((float)red*counter+image[i-1][j-1].rgbtRed+image[i-1][j+1].rgbtRed)/(counter+2));
  97. blue = round(((float)blue*counter+image[i-1][j-1].rgbtBlue+image[i-1][j+1].rgbtBlue)/(counter+2));
  98. green = round(((float)green*counter+image[i-1][j-1].rgbtGreen+image[i-1][j+1].rgbtGreen)/(counter+2));
  99. counter+=2;
  100. }else if(j==0)
  101. {
  102. red = round(((float)red*counter+image[i-1][j+1].rgbtRed+image[i+1][j+1].rgbtRed)/(counter+2));
  103. blue = round(((float)blue*counter+image[i-1][j+1].rgbtBlue+image[i+1][j+1].rgbtBlue)/(counter+2));
  104. green = round(((float)green*counter+image[i-1][j+1].rgbtGreen+image[i+1][j+1].rgbtGreen)/(counter+2));
  105. counter+=2;
  106. }else if(j==width-1)
  107. {
  108. red = round(((float)red*counter+image[i-1][j-1].rgbtRed+image[i+1][j-1].rgbtRed)/(counter+2));
  109. blue = round(((float)blue*counter+image[i-1][j-1].rgbtBlue+image[i+1][j-1].rgbtBlue)/(counter+2));
  110. green = round(((float)green*counter+image[i-1][j-1].rgbtGreen+image[i+1][j-1].rgbtGreen)/(counter+2));
  111. counter+=2;
  112. }else
  113. {
  114. red = round(((float)red*counter+image[i-1][j-1].rgbtRed+image[i+1][j+1].rgbtRed+image[i-1][j+1].rgbtRed+image[i+1][j-1].rgbtRed)/(counter+4));
  115. blue = round(((float)blue*counter+image[i-1][j-1].rgbtBlue+image[i+1][j+1].rgbtBlue+image[i-1][j+1].rgbtBlue+image[i+1][j-1].rgbtBlue)/(counter+4));
  116. green = round(((float)green*counter+image[i-1][j-1].rgbtGreen+image[i+1][j+1].rgbtGreen+image[i-1][j+1].rgbtGreen+image[i+1][j-1].rgbtGreen)/(counter+4));
  117. counter+=4;
  118. }
  119. copy[i][j].rgbtRed = (int)red;
  120. copy[i][j].rgbtBlue = (int)blue;
  121. copy[i][j].rgbtGreen = (int)green;
  122. }
  123. }
  124. for(int i =0;i<height;i++)
  125. {
  126. for(int j = 0;j<width;j++)
  127. {
  128. image[i][j] = copy[i][j];
  129. }
  130. }
  131. return;
  132. }
RAW Paste Data