25 |
#include <errno.h> |
#include <errno.h> |
26 |
#include <error.h> |
#include <error.h> |
27 |
#include <math.h> |
#include <math.h> |
28 |
|
#include <assert.h> |
29 |
|
|
30 |
#define IMAGE_WIDTH 800 |
#define IMAGE_WIDTH 800 |
31 |
#define IMAGE_HEIGHT 250 |
#define IMAGE_HEIGHT 250 |
32 |
#define IMAGE_PITCH (IMAGE_WIDTH * 4) |
#define IMAGE_PITCH (IMAGE_WIDTH * 4) |
33 |
|
|
34 |
|
unsigned int pattern_data [2*2] = |
35 |
|
{ |
36 |
|
0xffffffff, 0x00000000, |
37 |
|
0x00000000, 0xffffffff |
38 |
|
}; |
39 |
|
|
40 |
int |
int |
41 |
main (int argc, char *argv) |
main (int argc, char *argv) |
42 |
{ |
{ |
43 |
GFColorSpaceRef colorspace; |
GFColorSpaceRef colorspace, pattern; |
44 |
|
GFImageRef image, dst_img; |
45 |
GFContextRef context; |
GFContextRef context; |
46 |
void *buffer; |
void *buffer; |
47 |
FILE *fp; |
FILE *fp; |
48 |
|
|
49 |
buffer = malloc (IMAGE_PITCH * IMAGE_HEIGHT); |
dst_img = GFImageCreate (IMAGE_WIDTH, IMAGE_HEIGHT, 4, 8, |
50 |
if (! buffer) |
kGFImageAlphaSeparateLast); |
|
error (1, ENOMEM, "Could not allocate pixel buffer"); |
|
|
memset (buffer, 0x80, IMAGE_PITCH * IMAGE_HEIGHT); |
|
|
|
|
51 |
colorspace = GFColorSpaceCreateDeviceRGB (); |
colorspace = GFColorSpaceCreateDeviceRGB (); |
52 |
|
context = GFBitmapContextCreate (dst_img, colorspace); |
|
context = GFBitmapContextCreate (buffer, IMAGE_WIDTH, IMAGE_HEIGHT, 8, |
|
|
IMAGE_PITCH, colorspace, |
|
|
kCGImageAlphaSeparateLast); |
|
53 |
if (context) |
if (context) |
54 |
{ |
{ |
55 |
GFRect rect = GFRectMake (10, 10, IMAGE_WIDTH - 20, IMAGE_HEIGHT - 20); |
GFRect rect = GFRectMake (10, 10, IMAGE_WIDTH - 20, IMAGE_HEIGHT - 20); |
56 |
|
|
57 |
GFContextSaveGState (context); |
GFContextSaveGState (context); |
|
|
|
58 |
GFContextSetRGBFillColor (context, 0.0, 0.0, 0.0, 0.8); |
GFContextSetRGBFillColor (context, 0.0, 0.0, 0.0, 0.8); |
59 |
|
|
60 |
GFContextSelectFont (context, "Courier", "Bold", 40.0); |
GFContextSelectFont (context, "Courier", "Bold", 40.0); |
82 |
fp = fopen ("bitmap-test-render.rgba", "w"); |
fp = fopen ("bitmap-test-render.rgba", "w"); |
83 |
if (fp) |
if (fp) |
84 |
{ |
{ |
85 |
fwrite (buffer, IMAGE_PITCH, IMAGE_HEIGHT, fp); |
fwrite (dst_img->pixels, IMAGE_PITCH, IMAGE_HEIGHT, fp); |
86 |
fclose (fp); |
fclose (fp); |
87 |
} |
} |
88 |
else |
else |
89 |
error (1, 0, "Could not create output file"); |
error (1, 0, "Could not create output file"); |
90 |
free (buffer); |
free (dst_img->pixels); |
91 |
|
free (dst_img); |
92 |
} |
} |
93 |
else |
else |
94 |
error (1, 0, "Could not create bitmap context"); |
error (1, 0, "Could not create bitmap context"); |