Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1 @@
image get_ppm(FILE *pf);

View file

@ -0,0 +1,38 @@
#include "imglib.h"
#define PPMREADBUFLEN 256
image get_ppm(FILE *pf)
{
char buf[PPMREADBUFLEN], *t;
image img;
unsigned int w, h, d;
int r;
if (pf == NULL) return NULL;
t = fgets(buf, PPMREADBUFLEN, pf);
/* the code fails if the white space following "P6" is not '\n' */
if ( (t == NULL) || ( strncmp(buf, "P6\n", 3) != 0 ) ) return NULL;
do
{ /* Px formats can have # comments after first line */
t = fgets(buf, PPMREADBUFLEN, pf);
if ( t == NULL ) return NULL;
} while ( strncmp(buf, "#", 1) == 0 );
r = sscanf(buf, "%u %u", &w, &h);
if ( r < 2 ) return NULL;
r = fscanf(pf, "%u", &d);
if ( (r < 1) || ( d != 255 ) ) return NULL;
fseek(pf, 1, SEEK_CUR); /* skip one byte, should be whitespace */
img = alloc_img(w, h);
if ( img != NULL )
{
size_t rd = fread(img->buf, sizeof(pixel), w*h, pf);
if ( rd < w*h )
{
free_img(img);
return NULL;
}
return img;
}
}

View file

@ -0,0 +1,16 @@
#include <stdio.h>
#include "imglib.h"
int main()
{
image source;
grayimage idest;
source = get_ppm(stdin);
idest = tograyscale(source);
free_img(source);
source = tocolor(idest);
output_ppm(stdout, source);
free_img(source); free_img((image)idest);
return 0;
}