Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void readInput(const char * fileName, image *img) {
- FILE *in;
- in = fopen(fileName, "rb");
- char type[2];
- fscanf(in, "%s\n", type);
- if (strcmp(type, "P5\n")) {
- img->type = 5;
- }
- else {
- img->type = 6;
- }
- fscanf(in, "%d %d\n", &(*img).height, &(*img).width);
- fscanf(in, "%d\n", &(*img).maxval);
- unsigned char** image;
- if (img->type == 5) {
- //P5
- image = malloc(img->height * sizeof(char*));
- for (int i = 0; i < img->height; i++) {
- image[i] = malloc(img->width * sizeof(char));
- fread(image[i], 1, img->width, in);
- }
- }
- else {
- //P6
- image = malloc(img->height * sizeof(char*));
- for (int i = 0; i < img->height; i++) {
- image[i] = malloc(3 * img->width * sizeof(char));
- fread(image[i], 3, img->width, in);
- }
- }
- img->image = image;
- fclose(in);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement