Advertisement
cd62131

Raw Image (GrayScale) Compositor

Dec 10th, 2013
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. int main(int argc, char **argv) {
  5.   if (argc <= 5) {
  6.     fprintf(
  7.       stderr,
  8.       "usage: %s orig.raw compose1.raw compose2 ... out.raw\n",
  9.       argv[0]);
  10.     return EXIT_FAILURE;
  11.   }
  12.   FILE *in[argc - 2];
  13.   for (int i = 0; i < argc - 2; i++)
  14.     in[i] = fopen(argv[i + 1], "rb");
  15.   FILE *out = fopen(argv[argc - 1], "wb");
  16.   while (true) {
  17.     char *r[argc - 2];
  18.     bool eof = false;
  19.     for (int i = 0; i < argc - 2; i++) {
  20.       if ((fscanf(in[i], "%c", r[i])) == EOF) {
  21.         eof = true;
  22.         break;
  23.       }
  24.     }
  25.     if (eof) break;
  26.     double sum = 0.;
  27.     for (int i = 0; argc - 2; i++) {
  28.       sum += *r[i];
  29.     }
  30.     fprintf(out, "%c", (char) (255 * *r[0] / sum));
  31.   }
  32.   for (int i = 0; i < argc - 2; i++)
  33.     fclose(in[i]);
  34.   fclose(out);
  35.   return EXIT_SUCCESS;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement