3
* p_ndx_cell, p_rgb_cell for Mac OS X.
5
* Copyright (c) 1999. See accompanying LEGAL file for details.
10
static void m_cell(p_win *w, unsigned char *ndxs, unsigned char *rgbs,
11
int ncols, int nrows, int x0, int y0, int x1, int y1);
12
static void m_release_data(void *info, const void *data, size_t size);
16
p_ndx_cell(p_win *w, unsigned char *ndxs, int ncols, int nrows,
17
int x0, int y0, int x1, int y1)
19
m_cell(w, ndxs, 0, ncols, nrows, x0, y0, x1, y1);
23
p_rgb_cell(p_win *w, unsigned char *rgbs, int ncols, int nrows,
24
int x0, int y0, int x1, int y1)
26
m_cell(w, 0, rgbs, ncols, nrows, x0, y0, x1, y1);
30
p_rgb_read(p_win *w, unsigned char *rgbs,
31
int x0, int y0, int x1, int y1)
33
printf ("p_rgb_read\n");
34
/* This function is needed for g_rgb_read, which is never called. */
38
m_cell(p_win *w, unsigned char *ndxs, unsigned char *rgbs,
39
int ncols, int nrows, int x0, int y0, int x1, int y1)
47
CGContextRef cr = w->cr;
48
const size_t nComponents = 3; /* red, green, blue */
49
const size_t bytesPerComponent = 1;
50
const size_t bitsPerComponent = 8 * bytesPerComponent;
51
const size_t bitsPerPixel = bitsPerComponent * nComponents;
52
const size_t bytesPerRow = nComponents * bytesPerComponent * ncols;
53
const size_t size = bytesPerRow * nrows;
54
unsigned char* data = (unsigned char*)malloc(size*sizeof(unsigned char));
57
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
60
unsigned char* index = ndxs;
61
for (ii = 0; ii < nrows; ii++) {
63
for (jj = 0; jj < ncols; jj++, index++) {
64
float* color = w->pixels[*index];
65
data[3*(kk+jj)] = 256 * color[0];
66
data[3*(kk+jj)+1] = 256 * color[1];
67
data[3*(kk+jj)+2] = 256 * color[2];
72
for (ii = 0; ii < size; ii+=bytesPerRow) {
74
for (jj = 0; jj < bytesPerRow; jj++) {
75
data[kk+jj] = rgbs[ii+jj];
79
CGDataProviderRef provider = CGDataProviderCreateWithData (NULL,
83
CGImageRef bitmap = CGImageCreate (ncols,
93
kCGRenderingIntentDefault);
94
CGColorSpaceRelease(colorspace);
97
{ CGContextDrawImage(cr, CGRectMake(x0,y0,x1-x0,y1-y0), bitmap);
98
CGImageRelease(bitmap);
100
CGDataProviderRelease(provider);
106
m_release_data(void *info, const void *data, size_t size)
107
{ unsigned char* p = (unsigned char*) data;