Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #define STB_IMAGE_IMPLEMENTATION
- #include "stb/stb_image.h"
- #define STB_IMAGE_WRITE_IMPLEMENTATION
- #include "stb/stb_image_write.h"
- int filter[] = {1,2,1,
- 2,4,2,
- 1,2,1
- };
- using namespace std;
- unsigned char* makeStuff(unsigned char *img, int width,int height, int channel)
- {
- size_t s = (width-2)*(height-2)*channel;
- unsigned char *res = (unsigned char *)malloc(s);
- for(int i =1; i<width-1; i++)
- {
- for(int j =1; j<height-1; j++)
- {
- for(int z =0; z<channel; z++)
- {
- //upper
- res[((i - 1) + height * (j - 1)) * z] = (unsigned char)(img[((i - 1) + height * (j - 1)) * z] * filter[0] );
- res[(i + height * (j - 1) )* z] = (unsigned char)(img[(i + height * (j - 1) )* z] * filter[1] );
- res[((i + 1) + height * (j - 1) )* z] = (unsigned char)(img[((i + 1) + height * (j - 1) )* z] * filter[2] );
- //center
- res[((i - 1) + (height * j) )* z] = (unsigned char)(img[((i - 1) + (height * j) )* z] * filter[3] );
- res[(i + height * j )* z] = (unsigned char)(img[(i + height * j )* z] * filter[4] );
- res[((i + 1) + height * j )* z] = (unsigned char)(img[((i + 1) + height * j )* z] * filter[5] );
- //lower
- res[((i - 1) + height * (j + 1)) * z] = (unsigned char)(img[((i - 1) + height * (j + 1)) * z] * filter[6] );
- res[(i + height * (j + 1)) * z] = (unsigned char)(img[(i + height * (j + 1)) * z] * filter[7] );
- res[((i + 1) + height * (j + 1)) * z] = (unsigned char)(img[((i + 1) + height * (j + 1)) * z] * filter[8] );
- }
- }
- }
- return res;
- }
- int main()
- {
- string path = "t.jpg";
- int w,h,ch;
- unsigned char *image = stbi_load(path.c_str(),&w,&h,&ch,0);
- cout<<ch;
- unsigned char *im = makeStuff(image,w,h,ch);
- cout<<sizeof(image)/sizeof(char);
- stbi_write_jpg("t2.jpg",w,h,ch,im,100);
- //cout<<w<<" "<<h<<" "<<ch<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement