#define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" #define STB_IMAGE_WRITE_IMPLEMENTATION #include "stb_image_write.h" int main(){ int width, height, channels; unsigned char *pixel_data = stbi_load("retina_slice.png", &width, &height, &channels, 3); if(!pixel_data){ printf("something is wrong with the image\n"); return 1; } size_t pixel_count = width * height; printf("pixel count: %ld\n", pixel_count); // Divy up the iterations of this loop between multiple threads for(int i = 0; i < pixel_count; i++){ // Figure out gradient // Variance over neighborhood // Are we close to an edge? if(i < width) // First row continue; if(i > width * (height - 1)) // Last row continue; if(i % width == 0) // First column continue; if(i % width == width - 1) // Last column continue; // Neighbor values unsigned char nvals[4] = { pixel_data[3 * (i - 1) + 2], // Left Neighbor pixel_data[3 * (i + 1) + 2], // Right Neighbor pixel_data[3 * (i - width) + 2], // Above Neighbor pixel_data[3 * (i + width) + 2] };// Below Neighbor unsigned char max = nvals[0]; unsigned char min = nvals[1]; for(int i = 1; i < 4; i++){ if(max < nvals[i]) max = nvals[i]; if(min > nvals[i]) min = nvals[i]; } unsigned char diff = max - min; if(diff > 30) { pixel_data[i * 3] += diff; pixel_data[i * 3 + 1] -= diff; } } stbi_write_jpg("output.jpg", width, height, 3, pixel_data, 50); return 0; }