RosettaCodeData/Task/Bitmap-PPM-conversion-through-a-pipe/C/bitmap-ppm-conversion-through-a-pipe-2.c
Ingy döt Net 518da4a923 B
2013-04-10 16:19:29 -07:00

17 lines
441 B
C

#define MAXCMDBUF 100
void print_jpg(image img, int qual)
{
char buf[MAXCMDBUF];
unsigned int n;
FILE *pipe;
snprintf(buf, MAXCMDBUF, "convert ppm:- -quality %d jpg:-", qual);
pipe = popen(buf, "w");
if ( pipe != NULL )
{
fprintf(pipe, "P6\n%d %d\n255\n", img->width, img->height);
n = img->width * img->height;
fwrite(img->buf, sizeof(pixel), n, pipe);
pclose(pipe);
}
}