libtthimage/Lib/sobel4.c

66 lines
1.6 KiB
C
Raw Normal View History

2022-06-26 20:06:35 +11:00
/*
* Sobel4 new 26 avril 2007 - Fonsegrives
* ====== ===============================
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
2022-06-27 09:48:18 +11:00
#include "../tthimage.h"
2022-06-26 20:06:35 +11:00
/*::------------------------------------------------------------------::*/
2024-08-11 20:21:23 +11:00
int Image_filtre_Sobel_4(Image_Desc *src, Image_Desc *dst, int rotation)
2022-06-26 20:06:35 +11:00
{
static int Sobel[] =
{
1, 2, 1,
0, 0, 0,
-1, -2, -1,
1, 128
};
int filtre[11], foo;
Image_Desc *tmp[4];
int x, y, r, g, b;
2024-08-11 20:21:23 +11:00
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst,rotation);
2022-06-26 20:06:35 +11:00
memcpy(filtre, Sobel, 11*sizeof(int));
2022-07-07 21:52:00 +11:00
for (foo=0; foo<4; foo++) {
2022-06-26 20:06:35 +11:00
fprintf(stderr, "sobel4: pass %d\n", foo);
2022-07-07 21:52:00 +11:00
if (NULL == (tmp[foo] = Image_clone(src, 0))) {
2022-06-26 20:06:35 +11:00
fprintf(stderr,"Sobel 4: no memory, aborting\n");
abort();
}
Image_convolueur_2(src, tmp[foo], filtre, "rgb");
Image_rotate_filtre(filtre);
Image_rotate_filtre(filtre);
}
2022-07-07 21:52:00 +11:00
for (x=0; x<src->width; x++) {
for (y=0; y<src->height; y++) {
2022-06-26 20:06:35 +11:00
r = ( tmp[0]->Rpix[y][x] + tmp[1]->Rpix[y][x] +
tmp[2]->Rpix[y][x] + tmp[3]->Rpix[y][x]) / 4;
g = ( tmp[0]->Gpix[y][x] + tmp[1]->Gpix[y][x] +
tmp[2]->Gpix[y][x] + tmp[3]->Gpix[y][x]) / 4;
b = ( tmp[0]->Bpix[y][x] + tmp[1]->Bpix[y][x] +
tmp[2]->Bpix[y][x] + tmp[3]->Bpix[y][x]) / 4;
dst->Rpix[y][x] = r;
dst->Gpix[y][x] = g;
dst->Bpix[y][x] = b;
}
}
dst->modified = 1;
2022-07-07 21:52:00 +11:00
for (foo=0; foo<4; foo++) {
2022-06-26 20:06:35 +11:00
#if DEBUG_LEVEL > 1
fprintf(stderr, "%s: freeing %d\n", __func__, foo);
#endif
Image_DeAllocate(tmp[foo]); free(tmp[foo]);
}
return FUNC_NOT_FINISH;
}
/*::------------------------------------------------------------------::*/