blind-matrix-transpose.c (1553B)
1 /* See LICENSE file for copyright and license details. */ 2 #ifndef TYPE 3 #include "common.h" 4 5 USAGE("[-c]") 6 7 static int per_channel = 0; 8 9 #define FILE "blind-matrix-transpose.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 'c': 20 per_channel = 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 CHECK_CHANS(&stream, == 3, == 1); 33 34 if (stream.width != 1 || stream.height != 1) 35 eprintf("<stdin>: each frame must contain exactly 1 pixels\n"); 36 37 stream.width = 3; 38 stream.height = 3; 39 fprint_stream_head(stdout, &stream); 40 efflush(stdout, "<stdout>"); 41 42 process(&stream); 43 return 0; 44 } 45 46 #else 47 48 static void 49 PROCESS(struct stream *stream) 50 { 51 typedef TYPE pixel_t[4]; 52 pixel_t matrix[9]; 53 pixel_t buf; 54 size_t i; 55 56 for (i = 0; i < stream->n_chan; i++) { 57 matrix[0][i] = 1, matrix[1][i] = 0, matrix[2][i] = 0; 58 matrix[3][i] = 0, matrix[4][i] = 1, matrix[5][i] = 0; 59 matrix[6][i] = 0, matrix[7][i] = 0, matrix[8][i] = 1; 60 } 61 62 while (eread_frame(stream, buf)) { 63 if (per_channel) { 64 for (i = 0; i < stream->n_chan; i++) { 65 matrix[3][i] = matrix[1][i] = buf[i]; 66 matrix[4][i] = matrix[0][i] = 1 - buf[i]; 67 } 68 } else { 69 buf[1] *= buf[3]; 70 for (i = 0; i < stream->n_chan; i++) { 71 matrix[3][i] = matrix[1][i] = buf[1]; 72 matrix[4][i] = matrix[0][i] = 1 - matrix[3][i]; 73 } 74 } 75 ewriteall(STDOUT_FILENO, matrix, sizeof(matrix), "<stdout>"); 76 } 77 } 78 79 #endif