Advertisement
Tark_Wight

Untitled

Apr 2nd, 2023
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. void negativeFilter(unsigned char* image, unsigned int width, unsigned int height, unsigned int channels)
  2. {
  3. for (unsigned int y = 0; y < height; y++)
  4. {
  5. for (unsigned int x = 0; x < width; x++)
  6. {
  7. for (unsigned int c = 0; c < channels; c++)
  8. {
  9. // Invert the pixel value
  10. image[(y * width + x) * channels + c] = 255 - image[(y * width + x) * channels + c];
  11. }
  12. }
  13. }
  14. }
  15.  
  16. // Load the input image
  17. std::vector<unsigned char> image;
  18. unsigned int width, height;
  19. unsigned error = lodepng::decode(image, width, height, "input.png");
  20. if (error)
  21. {
  22. std::cerr << "Error decoding PNG: " << lodepng_error_text(error) << std::endl;
  23. return;
  24. }
  25.  
  26. // Apply the negative filter
  27. negativeFilter(image.data(), width, height, 4);
  28.  
  29. // Save the output image
  30. error = lodepng::encode("output.png", image, width, height);
  31. if (error)
  32. {
  33. std::cerr << "Error encoding PNG: " << lodepng_error_text(error) << std::endl;
  34. return;
  35. }
  36.  
  37. std::cout << "Image processed successfully!" << std::endl;
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement