Esempio n. 1
0
int main(int argc, char *argv[])
{
    char ch;
	int factor;
	FILE *inf, *outf;
	struct image img;


    while ((ch = getopt(argc, argv, "f:h")) != -1) {
        switch (ch) {
        case 'h':
            usage();
            exit(0);
            break;
        case 'f':
            factor = atoi(optarg);
            break;
        default:
            break;
        }
    }
    argc -= optind;
    argv += optind;

    if (argc != 2) {
        usage();
        exit(0);
    }

	inf = fopen(argv[0],"r");
	if (inf == NULL){
	printf("No open FIle \n");
	exit(0);
	} 

	outf = fopen(argv[1],"w");
	if (outf == NULL){
	printf("No out FIle \n");
	exit(0);
	} 
	
	imbread(inf,&img); //reads in binary file
	imbzoomwrite(outf,&img, factor); //calls the binary zoom write function which takes an output file and image and the zoom factor
	return 0 ;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    char ch;
    int r_flag = 0;

    while ((ch = getopt(argc, argv, "rh")) != -1) {
        switch (ch) {
        case 'h':
            usage();
            exit(0);
            break;
        case 'r':
            r_flag = 1;
            break;
        default:
            break;
        }
    }
    argc -= optind;
    argv += optind;

    if (argc != 2) {
        usage();
        exit(0);
    }


    // Handle opening the input file
    FILE* fp_in; 
    char *in_file = argv[0];
    if (strcmp(in_file, "-") == 0) {
        fp_in = stdin;
    } else {
        if (r_flag) {
            fp_in = fopen(in_file, "rb");
        } else {
            fp_in = fopen(in_file, "r");
        }
    }
    if (fp_in == NULL) {
        fprintf(stderr, "file not found: %s\n", in_file);
        return 0;
    }

    // Handle opening the output file
    FILE* fp_out;
    char *out_file = argv[1];
    if (strcmp(out_file, "-") == 0) {
        fp_out = stdout;
    } else {
        if (r_flag) {
            fp_out = fopen(out_file, "wb");
        } else {
            fp_out = fopen(out_file, "w");
        }
    }
    if (fp_out == NULL) {
        fprintf(stderr, "file not found: %s\n", out_file);
        return 0;
    }


    struct image img;
    if (r_flag) {
        if (imbread(fp_in, &img) != 0) {
            fprintf(stderr, "Error reading from data file\n");
            return 0;
        }

        if (imtwrite(fp_out, &img) != 0) {
            fprintf(stderr, "Error writing to text file\n");
            return 0;
        }

    } else {
        if (imtread(fp_in, &img) != 0) {
            fprintf(stderr, "Error reading from text file\n");
            return 0;
        }

        if (imbwrite(fp_out, &img) != 0) {
            fprintf(stderr, "Error writing to data file\n");
            return 0;
        }
    }


    free(img.pixbuf);
    fclose(fp_in);
    fclose(fp_out);

    return 0;
}