blind-double-sine-wave.c (1482B)
1 /* See LICENSE file for copyright and license details. */ 2 #ifndef TYPE 3 #include "common.h" 4 5 USAGE("[-e]") 6 7 static int equal = 0; 8 9 #define FILE "blind-double-sine-wave.c" 10 #include "define-functions.h" 11 12 int 13 main(int argc, char *argv[]) 14 { 15 struct stream stream; 16 void (*process)(struct stream *stream); 17 18 ARGBEGIN { 19 case 'e': 20 equal = 1; 21 break; 22 default: 23 usage(); 24 } ARGEND; 25 26 if (argc) 27 usage(); 28 29 eopen_stream(&stream, NULL); 30 31 SELECT_PROCESS_FUNCTION(&stream); 32 fprint_stream_head(stdout, &stream); 33 efflush(stdout, "<stdout>"); 34 process(&stream); 35 return 0; 36 } 37 38 #else 39 40 static void 41 PROCESS(struct stream *stream) 42 { 43 size_t i, j, n; 44 TYPE v, *p; 45 do { 46 if (equal) { 47 n = stream->ptr / stream->pixel_size; 48 for (i = 0; i < n; i++) { 49 p = (TYPE *)(stream->buf) + i * stream->n_chan; 50 v = posmod(*p, (TYPE)2); 51 v = v > 1 ? 2 - v : v; 52 v = 1 - (sin(v * (2 * (TYPE)M_PI)) + 1) / 2; 53 for (j = 0; j < stream->n_chan; j++) 54 p[j] = v; 55 } 56 n *= stream->pixel_size; 57 } else { 58 n = stream->ptr / stream->chan_size; 59 for (i = 0; i < n; i++) { 60 p = (TYPE *)(stream->buf) + i; 61 v = posmod(*p, (TYPE)2); 62 v = v > 1 ? 2 - v : v; 63 *p = 1 - (sin(v * (2 * (TYPE)M_PI)) + 1) / 2; 64 } 65 n *= stream->chan_size; 66 } 67 ewriteall(STDOUT_FILENO, stream->buf, n, "<stdout>"); 68 memmove(stream->buf, stream->buf + n, stream->ptr -= n); 69 } while (eread_stream(stream, SIZE_MAX)); 70 if (stream->ptr) 71 eprintf("%s: incomplete frame\n", stream->file); 72 } 73 74 #endif