The R Project SVN R

Rev

Rev 55671 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 55671 Rev 76910
Line 100... Line 100...
100
PROTECTED
100
PROTECTED
101
int has_transparent_pixels(image img)
101
int has_transparent_pixels(image img)
102
{
102
{
103
    int i, width, height, total;
103
    int i, width, height, total;
104
    rgb *palette;
104
    rgb *palette;
105
    byte *pixel8;
105
    GAbyte *pixel8;
106
    rgb *pixel32;
106
    rgb *pixel32;
107
    rgb col;
107
    rgb col;
108
 
108
 
109
    if (! img)
109
    if (! img)
110
	return 0;
110
	return 0;
Line 151... Line 151...
151
    /* remember some facts about the image */
151
    /* remember some facts about the image */
152
    int width = getwidth(img), height = getheight(img);
152
    int width = getwidth(img), height = getheight(img);
153
    int depth = getdepth(img);
153
    int depth = getdepth(img);
154
    rgb *palette = getpalette(img);
154
    rgb *palette = getpalette(img);
155
    int palsize = getpalettesize(img);
155
    int palsize = getpalettesize(img);
156
    byte *pixel8 = getpixels(img);
156
    GAbyte *pixel8 = getpixels(img);
157
    rgb *pixel32 = (rgb *) pixel8;
157
    rgb *pixel32 = (rgb *) pixel8;
158
 
158
 
159
    /* create DIB info in memory */
159
    /* create DIB info in memory */
160
    size = sizeof(BITMAPINFOHEADER) + 4; /* Why + 4 ? */
160
    size = sizeof(BITMAPINFOHEADER) + 4; /* Why + 4 ? */
161
    size += (sizeof(RGBQUAD) * palsize);
161
    size += (sizeof(RGBQUAD) * palsize);
Line 167... Line 167...
167
 
167
 
168
    /* create the block, align on LONG boundary
168
    /* create the block, align on LONG boundary
169
       malloc will have done the alignment, which needs to 
169
       malloc will have done the alignment, which needs to 
170
       be for pointers.
170
       be for pointers.
171
    */
171
    */
172
    byte *block = array(size, byte);
172
    GAbyte *block = array(size, GAbyte);
173
    BITMAPINFO *bmi = (BITMAPINFO *) block;
173
    BITMAPINFO *bmi = (BITMAPINFO *) block;
174
	
174
	
175
 
175
 
176
    /* assign header info */
176
    /* assign header info */
177
    bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
177
    bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
Line 183... Line 183...
183
    bmi->bmiHeader.biClrUsed = palsize;
183
    bmi->bmiHeader.biClrUsed = palsize;
184
 
184
 
185
    /* assign colour table */
185
    /* assign colour table */
186
    for (int i = 0; i < palsize; i++) {
186
    for (int i = 0; i < palsize; i++) {
187
	rgb colour  = palette[i];
187
	rgb colour  = palette[i];
188
	byte *data = (byte *) (& bmi->bmiColors[i]);
188
	GAbyte *data = (GAbyte *) (& bmi->bmiColors[i]);
189
	data[0] = getblue(colour);
189
	data[0] = getblue(colour);
190
	data[1] = getgreen(colour);
190
	data[1] = getgreen(colour);
191
	data[2] = getred(colour);
191
	data[2] = getred(colour);
192
	data[3] = 0;
192
	data[3] = 0;
193
    }
193
    }
194
 
194
 
195
    /* assign the bitmap data itself */
195
    /* assign the bitmap data itself */
196
    byte *data = (byte *) (&bmi->bmiColors[palsize]);
196
    GAbyte *data = (GAbyte *) (&bmi->bmiColors[palsize]);
197
 
197
 
198
    if (depth == 8)
198
    if (depth == 8)
199
	for (unsigned y = 0; y < height; y++) {
199
	for (unsigned y = 0; y < height; y++) {
200
	    // memcpy(data + y * row_bytes, pixel8 + y * width, width);
200
	    // memcpy(data + y * row_bytes, pixel8 + y * width, width);
201
	    for (unsigned x = 0; x < width; x++)
201
	    for (unsigned x = 0; x < width; x++)
Line 323... Line 323...
323
    row_bytes = ((depth * r.width) + 7) / 8;
323
    row_bytes = ((depth * r.width) + 7) / 8;
324
    /* Each row must be a multiple of 16 bits wide. */
324
    /* Each row must be a multiple of 16 bits wide. */
325
    if (row_bytes % 2) {
325
    if (row_bytes % 2) {
326
	/* Odd number of bytes, must assign into new array. */
326
	/* Odd number of bytes, must assign into new array. */
327
	size = (row_bytes+1) * r.height;
327
	size = (row_bytes+1) * r.height;
328
	newdata = array (size, byte);
328
	newdata = array (size, GAbyte);
329
	if (! newdata)
329
	if (! newdata)
330
	    return;
330
	    return;
331
	for (y=0; y<r.height; y++) {
331
	for (y=0; y<r.height; y++) {
332
	    for (x=0; x<row_bytes; x++) {
332
	    for (x=0; x<row_bytes; x++) {
333
		newdata[y*(row_bytes+1)+x] =
333
		newdata[y*(row_bytes+1)+x] =
Line 358... Line 358...
358
    row_bytes = ((depth * r.width) + 7) / 8;
358
    row_bytes = ((depth * r.width) + 7) / 8;
359
    /* Each row must be a multiple of 16 bits wide. */
359
    /* Each row must be a multiple of 16 bits wide. */
360
    if (row_bytes % 2) {
360
    if (row_bytes % 2) {
361
	/* Odd number of bytes, must assign into new array. */
361
	/* Odd number of bytes, must assign into new array. */
362
	size = (row_bytes+1) * r.height;
362
	size = (row_bytes+1) * r.height;
363
	newdata = array (size, byte);
363
	newdata = array (size, GAbyte);
364
	if (! newdata)
364
	if (! newdata)
365
	    return;
365
	    return;
366
	GetBitmapBits((HBITMAP)obj->handle, size,
366
	GetBitmapBits((HBITMAP)obj->handle, size,
367
		      (LPSTR)newdata);
367
		      (LPSTR)newdata);
368
	for (y=0; y<r.height; y++) {
368
	for (y=0; y<r.height; y++) {