Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Bitmap-Read-a-PPM-file/C/bitmap-read-a-ppm-file-1.c
Normal file
1
Task/Bitmap-Read-a-PPM-file/C/bitmap-read-a-ppm-file-1.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
image get_ppm(FILE *pf);
|
||||
38
Task/Bitmap-Read-a-PPM-file/C/bitmap-read-a-ppm-file-2.c
Normal file
38
Task/Bitmap-Read-a-PPM-file/C/bitmap-read-a-ppm-file-2.c
Normal 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;
|
||||
}
|
||||
}
|
||||
16
Task/Bitmap-Read-a-PPM-file/C/bitmap-read-a-ppm-file-3.c
Normal file
16
Task/Bitmap-Read-a-PPM-file/C/bitmap-read-a-ppm-file-3.c
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue