Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_HEIGHT 600
- #define MAX_WIDTH 400
- int main(int argc, char ** argv){
- FILE *file = fopen("", "r");
- if(file == NULL){
- fprintf(stderr, "File is not valid");
- return 0;
- }
- else {
- struct PPM *newPPM = getPPM(file);
- return 0;
- }
- }
- struct PPM {
- char format[2]; //PPM format code
- int height, width; //image pixel height and width
- int max; //max rgb colour value
- };
- struct PPM_Pixel {
- //Create variables to hold the rgb pixel values
- int red, green, blue;
- };
- struct PPM * getPPM(FILE * fd){
- struct PPM *image;
- char format[16];
- int c;
- fd = fopen(fd, "r");
- //checks if the file being opened is valid/the correct file
- if(fd == NULL){
- return NULL;
- }
- if(!fgets(format, sizeOf(format), fd)){
- exit(1);
- }
- //checks the format of the ppm file is correct
- if(format[0] != 'P' || format[1] != '3'){
- fprintf(stderr, "Invalid image format! \n");
- exit(1);
- }
- //allocate memory for the image
- image = ((PPM *)malloc(sizeof(PPM)));
- if(!image){
- fprintf(stderr, "Cannot allocate memory");
- exit(1);
- }
- //checks whether the next character is a comment and store it in a linked list
- c = getc(fd);
- while(c == '#'){
- while(getc(fd) != '\n'){
- c = getc(fd);
- }
- }
- if(fscaf(fd, "%d %d", &image->height, &image->width)!= 2){
- fprintf(stderr, "Size of image is invalid");
- exit(1);
- }
- fclose(fd);
- return image;
- };
- showPPM(struct PPM * image){
- //two-dimensional array to show the rows and columns of pixels.
- };
- char * decode(struct ppm * image1, struct PPM * image2){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement