Advertisement
Aveneid

Untitled

Oct 12th, 2020
2,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #define STB_IMAGE_IMPLEMENTATION
  4. #include "stb/stb_image.h"
  5.  
  6. #define STB_IMAGE_WRITE_IMPLEMENTATION
  7. #include "stb/stb_image_write.h"
  8.  
  9.  
  10. int filter[] = {1,2,1,
  11.                 2,4,2,
  12.                 1,2,1
  13.                };
  14.  
  15.  
  16.  
  17. using namespace std;
  18. unsigned char* makeStuff(unsigned char *img, int width,int height, int channel)
  19. {
  20.     size_t s = (width-2)*(height-2)*channel;
  21.     unsigned char *res = (unsigned char *)malloc(s);
  22.     for(int i =1; i<width-1; i++)
  23.     {
  24.         for(int j =1; j<height-1; j++)
  25.         {
  26.             for(int z =0; z<channel; z++)
  27.             {
  28.                 //upper
  29.                 res[((i - 1) + height * (j - 1)) * z] = (unsigned char)(img[((i - 1) + height * (j - 1)) * z] * filter[0] );
  30.                 res[(i + height * (j - 1) )* z] =    (unsigned char)(img[(i + height * (j - 1) )* z] * filter[1] );
  31.                 res[((i + 1) + height * (j - 1) )* z] = (unsigned char)(img[((i + 1) + height * (j - 1) )* z] * filter[2] );
  32.  
  33.                 //center
  34.                 res[((i - 1) + (height * j) )* z] = (unsigned char)(img[((i - 1) + (height * j) )* z] * filter[3] );
  35.                 res[(i + height * j )* z] =     (unsigned char)(img[(i + height * j )* z] * filter[4] );
  36.                 res[((i + 1) + height * j )* z] = (unsigned char)(img[((i + 1) + height * j )* z] * filter[5] );
  37.  
  38.                 //lower
  39.                 res[((i - 1) + height * (j + 1)) * z] = (unsigned char)(img[((i - 1) + height * (j + 1)) * z] * filter[6] );
  40.                 res[(i + height * (j + 1)) * z] =     (unsigned char)(img[(i + height * (j + 1)) * z] * filter[7] );
  41.                 res[((i + 1) + height * (j + 1)) * z] = (unsigned char)(img[((i + 1) + height * (j + 1)) * z] * filter[8] );
  42.             }
  43.         }
  44.     }
  45.  
  46.  
  47.     return res;
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. int main()
  55. {
  56.     string path = "t.jpg";
  57.     int w,h,ch;
  58.     unsigned char *image = stbi_load(path.c_str(),&w,&h,&ch,0);
  59.     cout<<ch;
  60.     unsigned char *im = makeStuff(image,w,h,ch);
  61.  
  62.     cout<<sizeof(image)/sizeof(char);
  63.  
  64.     stbi_write_jpg("t2.jpg",w,h,ch,im,100);
  65.  
  66. //cout<<w<<" "<<h<<" "<<ch<<endl;
  67.     return 0;
  68. }
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement