first commit
This commit is contained in:
33
CS4451/proj3/readppm.c
Normal file
33
CS4451/proj3/readppm.c
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct _rgb {
|
||||
unsigned char r,g,b;
|
||||
} rgb;
|
||||
|
||||
typedef
|
||||
struct _ppmimage {
|
||||
int sizex,sizey;
|
||||
rgb *color;
|
||||
} ppmimage;
|
||||
|
||||
ppmimage read_ppmimage ( const char *name )
|
||||
{
|
||||
ppmimage result;
|
||||
int range;
|
||||
FILE *fp = fopen(name,"rb");
|
||||
if (!fp)
|
||||
{
|
||||
fprintf(stderr,"No file\n");
|
||||
exit(1);
|
||||
}
|
||||
assert(getc(fp)=='P');
|
||||
assert(getc(fp)=='6');
|
||||
fscanf(fp,"%d%d%d\n",&result.sizex,&result.sizey,&range);
|
||||
assert(range==255); // we'll use only rgb range 0...255 here
|
||||
result.color = (rgb*)malloc(result.sizex*result.sizey*sizeof(rgb));
|
||||
fread(result.color,sizeof(rgb),result.sizex*result.sizey,fp);
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user