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