Advertisement
cd62131

Raw Image (RGB) Compositor

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