#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
int r;
int g;
int b;
} pixel;
pixel imagem[2][2];
void filtro_negativo(pixel im[2][2], int alt, int larg, int max);
int main(void) {
imagem[0][0].r = 1; imagem[0][0].g = 1; imagem[0][0].b = 1;
imagem[0][1].r = 2; imagem[0][1].g = 2; imagem[0][1].b = 2;
imagem[1][0].r = 3; imagem[1][0].g = 3; imagem[1][0].b = 3;
imagem[1][1].r = 4; imagem[1][1].g = 4; imagem[1][1].b = 4;
int i, j;
for(i = 0; i < 2; i++) {
for(j = 0; j < 2; j++) {
printf("%d %d %d\n", imagem
[i
][j
].
r, imagem
[i
][j
].
g, imagem
[i
][j
].
b); }
}
filtro_negativo(imagem, 2, 2, 4);
for(i = 0; i < 2; i++) {
for(j = 0; j < 2; j++) {
printf("%d %d %d\n", imagem
[i
][j
].
r, imagem
[i
][j
].
g, imagem
[i
][j
].
b); }
}
printf("Depois (exibindo errado):\n"); for(i = 0; i < 2; i++) {
for(j = 0; j < 2; j++) {
printf("%d %d %d\n", 4 - imagem
[i
][j
].
r, 4 - imagem
[i
][j
].
g, 4 - imagem
[i
][j
].
b); }
}
return (EXIT_SUCCESS);
}
void filtro_negativo(pixel im[2][2], int alt, int larg, int max) {
int i, j;
for (i = 0; i < alt; i++) {
for (j = 0; j < larg; j++) {
im[i][j].r = max - im[i][j].r;
im[i][j].g = max - im[i][j].g;
im[i][j].b = max - im[i][j].b;
}
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKdHlwZWRlZiBzdHJ1Y3QgewogICAgaW50IHI7CiAgICBpbnQgZzsKICAgIGludCBiOwp9IHBpeGVsOwoKcGl4ZWwgaW1hZ2VtWzJdWzJdOwoKdm9pZCBmaWx0cm9fbmVnYXRpdm8ocGl4ZWwgaW1bMl1bMl0sIGludCBhbHQsIGludCBsYXJnLCBpbnQgbWF4KTsKCmludCBtY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