Advertisement
Guest User

Filter-less Code (Reflect & Blur)

a guest
Jun 25th, 2025
18
0
179 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.19 KB | None | 0 0
  1. void reflect(int height, int width, RGBTRIPLE image[height][width])
  2. {
  3.     int row_loop = round(width / 2);
  4.  
  5.     for (int i = 0; i < height; i++)
  6.     {
  7.         for (int j = 1; j < row_loop; j++)
  8.         {
  9.             RGBTRIPLE tmp = image[i][j];
  10.             image[i][j] = image[i][width - j];
  11.             image[i][width - j] = tmp;
  12.         }
  13.     }
  14.     return;
  15. }
  16.  
  17. void blur(int height, int width, RGBTRIPLE image[height][width])
  18. {
  19.     RGBTRIPLE copy[height][width];
  20.  
  21.     for (int i = 0; i < height; i++)
  22.     {
  23.         for (int j = 0; j < width; j++)
  24.         {
  25.             copy[i][j] = image[i][j];
  26.  
  27.             RGBTRIPLE average = blur_indiv(height, width, i, j, copy);
  28.  
  29.             image[i][j].rgbtRed = average.rgbtRed;
  30.             image[i][j].rgbtGreen = average.rgbtGreen;
  31.             image[i][j].rgbtBlue = average.rgbtBlue;
  32.         }
  33.     }
  34.     return;
  35. }
  36.  
  37. RGBTRIPLE blur_indiv(int height, int width, int h, int w, RGBTRIPLE image[h][w])
  38. {
  39.     float counter = 1;
  40.     RGBTRIPLE average;
  41.     average = image[h][w];
  42.  
  43.     if (0 < (h - 1) <= height && 0 < (w - 1) <= width)
  44.     {
  45.         average.rgbtRed += image[h - 1][w - 1].rgbtRed;
  46.         average.rgbtGreen += image[h - 1][w - 1].rgbtGreen;
  47.         average.rgbtBlue += image[h - 1][w - 1].rgbtBlue;
  48.         counter++;
  49.     }
  50.  
  51.     if (0 < (h - 1) <= height && 0 < w <= width)
  52.     {
  53.         average.rgbtRed += image[h - 1][w].rgbtRed;
  54.         average.rgbtGreen += image[h - 1][w].rgbtGreen;
  55.         average.rgbtBlue += image[h - 1][w].rgbtBlue;
  56.         counter++;
  57.     }
  58.  
  59.     if (0 < (h - 1) <= height && 0 < (w + 1) <= width)
  60.     {
  61.         average.rgbtRed += image[h - 1][w + 1].rgbtRed;
  62.         average.rgbtGreen += image[h - 1][w + 1].rgbtGreen;
  63.         average.rgbtBlue += image[h - 1][w + 1].rgbtBlue;
  64.         counter++;
  65.     }
  66.  
  67.     if (0 < h <= height && 0 < (w - 1) <= width)
  68.     {
  69.         average.rgbtRed += image[h][w - 1].rgbtRed;
  70.         average.rgbtGreen += image[h][w - 1].rgbtGreen;
  71.         average.rgbtBlue += image[h][w - 1].rgbtBlue;
  72.         counter++;
  73.     }
  74.  
  75.     if (0 < h <= height && 0 < (w + 1) <= width)
  76.     {
  77.         average.rgbtRed += image[h][w + 1].rgbtRed;
  78.         average.rgbtGreen += image[h][w + 1].rgbtGreen;
  79.         average.rgbtBlue += image[h][w + 1].rgbtBlue;
  80.         counter++;
  81.     }
  82.  
  83.     if (0 < (h + 1) <= height && 0 < (w - 1) <= width)
  84.     {
  85.         average.rgbtRed += image[h + 1][w - 1].rgbtRed;
  86.         average.rgbtGreen += image[h + 1][w - 1].rgbtGreen;
  87.         average.rgbtBlue += image[h + 1][w - 1].rgbtBlue;
  88.         counter++;
  89.     }
  90.  
  91.     if (0 < (h + 1) <= height && 0 < w <= width)
  92.     {
  93.         average.rgbtRed += image[h + 1][w].rgbtRed;
  94.         average.rgbtGreen += image[h + 1][w].rgbtGreen;
  95.         average.rgbtBlue += image[h + 1][w].rgbtBlue;
  96.         counter++;
  97.     }
  98.  
  99.     if (0 < (h + 1) <= height && 0 < (w + 1) <= width)
  100.     {
  101.         average.rgbtRed += image[h + 1][w + 1].rgbtRed;
  102.         average.rgbtGreen += image[h + 1][w + 1].rgbtGreen;
  103.         average.rgbtBlue += image[h + 1][w + 1].rgbtBlue;
  104.         counter++;
  105.     }
  106.  
  107.     average.rgbtRed /= counter;
  108.     average.rgbtGreen /= counter;
  109.     average.rgbtBlue /= counter;
  110.  
  111.     return average;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement