Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- int main(int argc, char **argv) {
- if (argc <= 5) {
- fprintf(
- stderr,
- "usage: %s orig.raw compose1.raw compose2 ... out.raw\n",
- argv[0]);
- return EXIT_FAILURE;
- }
- FILE *in[argc - 2];
- for (int i = 0; i < argc - 2; i++)
- in[i] = fopen(argv[i + 1], "rb");
- FILE *out = fopen(argv[argc - 1], "wb");
- while (true) {
- char *r[argc - 2];
- bool eof = false;
- for (int i = 0; i < argc - 2; i++) {
- if ((fscanf(in[i], "%c", r[i])) == EOF) {
- eof = true;
- break;
- }
- }
- if (eof) break;
- double sum = 0.;
- for (int i = 0; argc - 2; i++) {
- sum += *r[i];
- }
- fprintf(out, "%c", (char) (255 * *r[0] / sum));
- }
- for (int i = 0; i < argc - 2; i++)
- fclose(in[i]);
- fclose(out);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement