blind-premultiply.c - blind - suckless command-line video editing utility
 (HTM) git clone git://git.suckless.org/blind
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       blind-premultiply.c (1406B)
       ---
            1 /* See LICENSE file for copyright and license details. */
            2 #ifndef TYPE
            3 #include "common.h"
            4 
            5 USAGE("[-xyz]")
            6 
            7 static int skip_x = 0;
            8 static int skip_y = 0;
            9 static int skip_z = 0;
           10 
           11 #define FILE "blind-premultiply.c"
           12 #include "define-functions.h"
           13 
           14 int
           15 main(int argc, char *argv[])
           16 {
           17         struct stream stream;
           18         void (*process)(struct stream *stream);
           19 
           20         ARGBEGIN {
           21         case 'x':
           22                 skip_x = 1;
           23                 break;
           24         case 'y':
           25                 skip_y = 1;
           26                 break;
           27         case 'z':
           28                 skip_z = 1;
           29                 break;
           30         default:
           31                 usage();
           32         } ARGEND;
           33 
           34         if (argc)
           35                 usage();
           36 
           37         eopen_stream(&stream, NULL);
           38 
           39         SELECT_PROCESS_FUNCTION(&stream);
           40         CHECK_CHANS(&stream, == 3, == stream.luma_chan);
           41         CHECK_N_CHAN(&stream, 4, 4);
           42 
           43         fprint_stream_head(stdout, &stream);
           44         efflush(stdout, "<stdout>");
           45         process(&stream);
           46         return 0;
           47 }
           48 
           49 #else
           50 
           51 static void
           52 PROCESS(struct stream *stream)
           53 {
           54         size_t i, n;
           55         TYPE a;
           56         do {
           57                 n = stream->ptr / stream->pixel_size;
           58                 for (i = 0; i < n; i++) {
           59                         a = ((TYPE *)(stream->buf))[4 * i + 3];
           60                         if (!skip_x)
           61                                 ((TYPE *)(stream->buf))[4 * i + 0] *= a;
           62                         if (!skip_y)
           63                                 ((TYPE *)(stream->buf))[4 * i + 1] *= a;
           64                         if (!skip_z)
           65                                 ((TYPE *)(stream->buf))[4 * i + 2] *= a;
           66                 }
           67                 n *= stream->pixel_size;
           68                 ewriteall(STDOUT_FILENO, stream->buf, n, "<stdout>");
           69                 memmove(stream->buf, stream->buf + n, stream->ptr -= n);
           70         } while (eread_stream(stream, SIZE_MAX));
           71         if (stream->ptr)
           72                 eprintf("%s: incomplete frame\n", stream->file);
           73 }
           74 
           75 #endif