Advertisement
Tark_Wight

Untitled

Apr 2nd, 2023
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <algorithm>
  2. #include <intrin.h>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6. #include <vector>
  7. #include <ctime>
  8. #include "lodepng.cpp"
  9. #include "lodepng.h"
  10.  
  11.  
  12. void negateImage(const char* in_filename, const char* out_filename) {
  13. // Загружаем изображение
  14. unsigned error;
  15. unsigned char* image;
  16. unsigned width, height;
  17.  
  18. error = lodepng_decode24_file(&image, &width, &height, in_filename);
  19. if (error) {
  20. cerr << "Failed to load image: " << lodepng_error_text(error) << endl;
  21. return;
  22. }
  23.  
  24. // Фильтр негатива
  25. for (unsigned y = 0; y < height; y++) {
  26. for (unsigned x = 0; x < width; x++) {
  27. unsigned index = (y * width + x) * 3;
  28. image[index + 0] = 255 - image[index + 0];
  29. image[index + 1] = 255 - image[index + 1];
  30. image[index + 2] = 255 - image[index + 2];
  31. }
  32. }
  33.  
  34. // Сохраняем изображение
  35. error = lodepng_encode24_file(out_filename, image, width, height);
  36. if (error) {
  37. cerr << "Failed to save image: " << lodepng_error_text(error) << endl;
  38. return;
  39. }
  40.  
  41. // Освобождаем память
  42. free(image);
  43. }
  44.  
  45.  
  46. void userConsistentNegate() {
  47. // Задаем имена входного и выходного файлов
  48. const char* in_filename = "input.png";
  49. const char* out_filename = "output.png";
  50.  
  51. // Фильтр негатива
  52. negateImage(in_filename, out_filename);
  53. }
  54.  
  55.  
  56. int main() {
  57. userConsistentNegate();
  58.  
  59. return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement