/* ppmround -- make a rawbits pixmap round DWF 3/23/95 Version 1 Copyright (C) 1995 David Flater. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. If you cannot find a copy of the GNU General Public License, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. gcc -O3 -o ppmround ppmround.c -lm */ #include #include #include void usage () { fprintf (stderr, "Usage: ppmround r g b < input > output\n"); exit (-1); } void bogus () { fprintf (stderr, "ppmround version 1 works ONLY on 8-bit rawbits pixmaps\n"); fprintf (stderr, "with maxval = 255, and ONLY on stdin and stdout.\n"); exit (-1); } int circlep (x, y, width, height) { double dx, dy; dx = 2.0 * fabs (x - (double)(width-1) / 2.0) / (double)width; dy = 2.0 * fabs (y - (double)(height-1) / 2.0) / (double)height; return ((dx*dx + dy*dy) <= 1.0); } int main (int argc, char **argv) { int width, height, maxval, x, y, r, g, b, newr, newg, newb; char magicnum[3], junk; if (argc != 4) usage (); if (sscanf (argv[1], "%d", &newr) != 1) usage (); if (sscanf (argv[2], "%d", &newg) != 1) usage (); if (sscanf (argv[3], "%d", &newb) != 1) usage (); if (fscanf (stdin, "%2s %d %d %d%c", magicnum, &width, &height, &maxval, &junk) != 5) { fprintf (stderr, "Error getting header data\n"); bogus (); } if (strcmp (magicnum, "P6")) { fprintf (stderr, "Bad magic number\n"); bogus (); } if (maxval != 255) { fprintf (stderr, "Maxval != 255\n"); bogus (); } printf ("%s\n%d %d\n%d\n", magicnum, width, height, maxval); for (y=0;y