Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ReadImage (Image *I, char* FileName){
- /* Function: Reads in the image I (graylevel or color) from File
- The image header (the second of the file) might
- include a comment line, e.g. "# Created by Paint Shop Pro 7"
- Your code should be able to ignore it.
- Preconditions: None
- Postconditions: All the image pixels are read in and the image
- width and height recorded in the appropriate fields.
- If the image is a gray level one, then all the three
- color values of each pixel is set to intensity value of
- that pixel. It returns 1 for success and 0 for failure.
- ---------------------------------------------------------------------*/
- int cnt;
- int Height = 0, Width = 0, ColorCap = 0;
- char str[80];
- FILE *fp;
- fp = fopen(FileName, "r");
- fscanf(fp, "%s", str);
- if (strcmp (str, "P6") == 0) {
- fscanf (fp, "%s", str);
- if (str[0] == '#') {//Comment line
- while (getc(fp) != '\n') {};
- fscanf(fp, "%s", str);
- Width = atoi(str);
- I->Width = Width;
- fscanf(fp, "%s", str);
- Height = atoi(str);
- I->Height = Height;
- }
- else {
- Width = atoi(str);
- fscanf(fp, "%s", str);
- }
- fscanf(fp, "%s", str);
- ColorCap = atoi(str);
- cnt = 0;
- while(cnt < Height*Width*3){
- I->Value[cnt] = (unsigned int) (getc(fp));
- cnt++;
- }
- fclose(fp);
- return 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement