Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. #define MAX_HEIGHT 600
  6. #define MAX_WIDTH 400
  7.  
  8. int main(int argc, char ** argv){
  9.  
  10. FILE *file = fopen("", "r");
  11.  
  12. if(file == NULL){
  13. fprintf(stderr, "File is not valid");
  14. return 0;
  15. }
  16. else {
  17. struct PPM *newPPM = getPPM(file);
  18. return 0;
  19. }
  20. }
  21.  
  22. struct PPM {
  23. char format[2]; //PPM format code
  24. int height, width; //image pixel height and width
  25. int max; //max rgb colour value
  26.  
  27. };
  28.  
  29. struct PPM_Pixel {
  30. //Create variables to hold the rgb pixel values
  31. int red, green, blue;
  32. };
  33.  
  34. struct PPM * getPPM(FILE * fd){
  35.  
  36. struct PPM *image;
  37. char format[16];
  38. int c;
  39. fd = fopen(fd, "r");
  40.  
  41. //checks if the file being opened is valid/the correct file
  42. if(fd == NULL){
  43. return NULL;
  44. }
  45.  
  46. if(!fgets(format, sizeOf(format), fd)){
  47. exit(1);
  48. }
  49.  
  50. //checks the format of the ppm file is correct
  51. if(format[0] != 'P' || format[1] != '3'){
  52. fprintf(stderr, "Invalid image format! \n");
  53. exit(1);
  54. }
  55.  
  56. //allocate memory for the image
  57. image = ((PPM *)malloc(sizeof(PPM)));
  58. if(!image){
  59. fprintf(stderr, "Cannot allocate memory");
  60. exit(1);
  61. }
  62.  
  63. //checks whether the next character is a comment and store it in a linked list
  64. c = getc(fd);
  65. while(c == '#'){
  66. while(getc(fd) != '\n'){
  67. c = getc(fd);
  68. }
  69. }
  70.  
  71. if(fscaf(fd, "%d %d", &image->height, &image->width)!= 2){
  72. fprintf(stderr, "Size of image is invalid");
  73. exit(1);
  74. }
  75.  
  76. fclose(fd);
  77. return image;
  78. };
  79.  
  80. showPPM(struct PPM * image){
  81.  
  82. //two-dimensional array to show the rows and columns of pixels.
  83.  
  84.  
  85.  
  86. };
  87.  
  88. char * decode(struct ppm * image1, struct PPM * image2){
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement