nonipal

Filter - Sepia

Sep 21st, 2021
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. void sepia(int height, int width, RGBTRIPLE image[height][width])
  2. {
  3.     // Start loop
  4.     for (int i = 0; i <= height; i++)
  5.     {
  6.         for (int j = 0; j <= width; j++)
  7.         {
  8.             // Compute sepia RGB
  9.             float SepiaRed = 0.393 * image[i][j].rgbtRed + 0.769 * image[i][j].rgbtGreen + 0.189 * image[i][j].rgbtBlue;
  10.             float SepiaGreen = 0.349 * image[i][j].rgbtRed + 0.686 * image[i][j].rgbtGreen + 0.168 * image[i][j].rgbtBlue;
  11.             float SepiaBlue = 0.272 * image[i][j].rgbtRed + 0.534 * image[i][j].rgbtGreen + 0.131 * image[i][j].rgbtBlue;
  12.            
  13.             // Rounding off
  14.             SepiaRed = SepiaRed + 0.5;
  15.             SepiaGreen = SepiaGreen + 0.5;
  16.             SepiaBlue = SepiaBlue + 0.5;
  17.            
  18.             // Apply sepia RGB
  19.             image[i][j].rgbtRed = SepiaRed;
  20.             image[i][j].rgbtGreen = SepiaGreen;
  21.             image[i][j].rgbtBlue = SepiaBlue;
  22.            
  23.             // Cap at maximum value
  24.             if (image[i][j].rgbtRed > 255)
  25.             {
  26.                 image[i][j].rgbtRed = 255;
  27.             }
  28.             else if (image[i][j].rgbtGreen > 255)
  29.             {
  30.                 image[i][j].rgbtGreen = 255;
  31.             }
  32.             else if (image[i][j].rgbtBlue > 255)
  33.             {
  34.                 image[i][j].rgbtBlue = 255;
  35.             }
  36.            
  37.             // Apply sepia RGB
  38.             image[i][j].rgbtRed = SepiaRed;
  39.             image[i][j].rgbtGreen = SepiaGreen;
  40.             image[i][j].rgbtBlue = SepiaBlue;
  41.         }
  42.     }
  43.  
  44.     return;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment