Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void negativeFilter(unsigned char* image, unsigned int width, unsigned int height, unsigned int channels)
- {
- for (unsigned int y = 0; y < height; y++)
- {
- for (unsigned int x = 0; x < width; x++)
- {
- for (unsigned int c = 0; c < channels; c++)
- {
- // Invert the pixel value
- image[(y * width + x) * channels + c] = 255 - image[(y * width + x) * channels + c];
- }
- }
- }
- }
- // Load the input image
- std::vector<unsigned char> image;
- unsigned int width, height;
- unsigned error = lodepng::decode(image, width, height, "input.png");
- if (error)
- {
- std::cerr << "Error decoding PNG: " << lodepng_error_text(error) << std::endl;
- return;
- }
- // Apply the negative filter
- negativeFilter(image.data(), width, height, 4);
- // Save the output image
- error = lodepng::encode("output.png", image, width, height);
- if (error)
- {
- std::cerr << "Error encoding PNG: " << lodepng_error_text(error) << std::endl;
- return;
- }
- std::cout << "Image processed successfully!" << std::endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement