/* Simple rendering test. Copyright (C) 2001 Johan Rydberg. All Rights Reserved. This file is part of Crust. 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #define IMAGE_WIDTH 800 #define IMAGE_HEIGHT 500 #define IMAGE_PITCH (IMAGE_WIDTH * 4) int main (int argc, char *argv) { GFColorSpaceRef colorspace; GFContextRef context; void *buffer; FILE *fp; buffer = malloc (IMAGE_PITCH * IMAGE_HEIGHT); if (! buffer) error (1, ENOMEM, "Could not allocate pixel buffer"); memset (buffer, 0x80, IMAGE_PITCH * IMAGE_HEIGHT); colorspace = GFColorSpaceCreateDeviceRGB (); context = GFBitmapContextCreate (buffer, IMAGE_WIDTH, IMAGE_HEIGHT, 8, IMAGE_PITCH, colorspace, kCGImageAlphaSeparateLast); if (context) { GFRect rect = GFRectMake (10, 10, IMAGE_WIDTH - 20, IMAGE_HEIGHT - 20); GFContextSaveGState (context); GFContextSetRGBFillColor (context, 0.6, 0.8, 0.8, 0.8); GFContextBeginPath (context); GFContextMoveToPoint (context, 15 * 10, 27 * 10); GFContextAddLineToPoint (context, 7.947 * 10, 5.292 * 10); GFContextAddLineToPoint (context, 26.413 * 10, 18.708 * 10); GFContextAddLineToPoint (context, 3.587 * 10, 18.708 * 10); GFContextAddLineToPoint (context, 22.053 * 10, 5.292 * 10); GFContextAddLineToPoint (context, 15 * 10, 27 * 10); GFContextDrawPath (context, kGFPathEOFill); GFContextSetRGBFillColor (context, 1.0, 0.8, 0.8, 0.8); GFContextSetRGBStrokeColor (context, 0.0, 0.0, 0.0, 1.0); GFContextSetLineWidth (context, 2.0); GFContextRotateCTM (context, (M_PI/180) * 5); GFContextDrawPath (context, kGFPathEOFillStroke); GFContextRestoreGState (context); GFContextSetRGBStrokeColor (context, 0.8, 1.0, 1.0, 0.85); GFContextBeginPath (context); GFContextMoveToPoint (context, 10.0, IMAGE_HEIGHT / 2); GFContextSetLineWidth (context, 20.0); GFContextAddCurveToPoint (context, 260, IMAGE_HEIGHT - 10, 260, IMAGE_HEIGHT - 10, IMAGE_WIDTH - 10, IMAGE_HEIGHT / 2); GFContextStrokePath (context); fp = fopen ("bitmap-test-render.rgba", "w"); if (fp) { fwrite (buffer, IMAGE_PITCH, IMAGE_HEIGHT, fp); fclose (fp); } else error (1, 0, "Could not create output file"); free (buffer); } else error (1, 0, "Could not create bitmap context"); return 0; }