fork download
  1. /* sobel operatorで輝度のみ */
  2.  
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. char *sobel_mask(char *src, int width, int height, int pitch)
  7. {
  8. const int sobel_h[] = {1, 0, -1, 2, 0, -2, 1, 0, -1};
  9. const int sobel_v[] = {1, 2, 1, 0, 0, 0, -1, -2, -1};
  10.  
  11. char *dst = calloc(width * height, 1);
  12. if (!dst) {
  13. return NULL;
  14. }
  15.  
  16. char *srcp = src;
  17. char *dstp = dst;
  18. /* 画像端の処理は省略 */
  19. for (int y = 1; y < width - 1; y++) {
  20. char *top = srcp;
  21. srcp += pitch;
  22. char *bottom = srcp + pitch;
  23. dstp += width;
  24. for (int x = 1; x < width -1; x++) {
  25. char array[] = {
  26. top[x - 1], top[x], top[x + 1],
  27. srcp[x - 1], srcp[x], srcp[x + 1],
  28. bottom[x - 1], bottom[x], bottom[x + 1]
  29. }
  30. int val_h = 0;
  31. int val_v = 0;
  32. for (int i = 0; i < 9; i++) {
  33. val_h += array[i] * sobel_h[i];
  34. val_v += array[i] * sobel_v[i];
  35. }
  36. dstp[x] = (char)(sqrt((double)(val_h * val_h + val_v * val_v)) / 8);
  37. }
  38. }
  39.  
  40. return dst;
  41. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘sobel_mask’:
prog.c:30: error: expected ‘,’ or ‘;’ before ‘int’
prog.c:33: error: ‘val_h’ undeclared (first use in this function)
prog.c:33: error: (Each undeclared identifier is reported only once
prog.c:33: error: for each function it appears in.)
stdout
Standard output is empty