The R Project SVN R

Rev

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

Rev 59039 Rev 59990
Line 204... Line 204...
204
		pngpalette[i].green = GETGREEN(col);
204
		pngpalette[i].green = GETGREEN(col);
205
		pngpalette[i].blue = GETBLUE(col);
205
		pngpalette[i].blue = GETBLUE(col);
206
	    } else {
206
	    } else {
207
		/* PNG needs NON-premultiplied alpha */
207
		/* PNG needs NON-premultiplied alpha */
208
		int a = GETALPHA(col);
208
		int a = GETALPHA(col);
209
		trans[i] = a;
209
		trans[i] = (png_byte) a;
210
		if(a == 255 || a == 0) {
210
		if(a == 255 || a == 0) {
211
		    pngpalette[i].red = GETRED(col);
211
		    pngpalette[i].red = GETRED(col);
212
		    pngpalette[i].green = GETGREEN(col);
212
		    pngpalette[i].green = GETGREEN(col);
213
		    pngpalette[i].blue = GETBLUE(col);
213
		    pngpalette[i].blue = GETBLUE(col);
214
		} else {
214
		} else {
215
		    pngpalette[i].red = 0.49 + 255.0*GETRED(col)/a;
215
		    pngpalette[i].red = (png_byte)(0.49 + 255.0*GETRED(col)/a);
216
		    pngpalette[i].green = 0.49 + 255.0*GETGREEN(col)/a;
216
		    pngpalette[i].green = (png_byte)(0.49 + 255.0*GETGREEN(col)/a);
217
		    pngpalette[i].blue = 0.49 + 255.0*GETBLUE(col)/a;
217
		    pngpalette[i].blue = (png_byte)(0.49 + 255.0*GETBLUE(col)/a);
218
 
218
 
219
		}
219
		}
220
	    }
220
	    }
221
	}
221
	}
222
	png_set_PLTE(png_ptr, info_ptr, pngpalette, ncols);
222
	png_set_PLTE(png_ptr, info_ptr, pngpalette, ncols);
Line 230... Line 230...
230
	trans_values[0].green = GETGREEN(transparent);
230
	trans_values[0].green = GETGREEN(transparent);
231
	png_set_tRNS(png_ptr, info_ptr, trans, ncols, trans_values);
231
	png_set_tRNS(png_ptr, info_ptr, trans, ncols, trans_values);
232
    }
232
    }
233
 
233
 
234
    if(res > 0)
234
    if(res > 0)
235
	png_set_pHYs(png_ptr, info_ptr, res/0.0254, res/0.0254,
235
	png_set_pHYs(png_ptr, info_ptr, (png_uint_32)(res/0.0254), 
236
		     PNG_RESOLUTION_METER);
236
		     (png_uint_32)(res/0.0254), PNG_RESOLUTION_METER);
237
 
237
 
238
    /* Write the file header information.  REQUIRED */
238
    /* Write the file header information.  REQUIRED */
239
    png_write_info(png_ptr, info_ptr);
239
    png_write_info(png_ptr, info_ptr);
240
 
240
 
241
    /*
241
    /*
Line 253... Line 253...
253
		    mid = (low + high)/2;
253
		    mid = (low + high)/2;
254
		    if      (col < palette[mid]) high = mid - 1;
254
		    if      (col < palette[mid]) high = mid - 1;
255
		    else if (col > palette[mid]) low  = mid + 1;
255
		    else if (col > palette[mid]) low  = mid + 1;
256
		    else break;
256
		    else break;
257
		}
257
		}
258
		*pscanline++ = mid;
258
		*pscanline++ = (png_byte) mid;
259
	    } else {
259
	    } else {
260
		if(have_alpha) {
260
		if(have_alpha) {
261
		    /* PNG needs NON-premultiplied alpha */
261
		    /* PNG needs NON-premultiplied alpha */
262
		    int a = GETALPHA(col);
262
		    int a = GETALPHA(col);
263
		    if(a == 255 || a == 0) {
263
		    if(a == 255 || a == 0) {
264
			*pscanline++ = GETRED(col) ;
264
			*pscanline++ = GETRED(col) ;
265
			*pscanline++ = GETGREEN(col) ;
265
			*pscanline++ = GETGREEN(col) ;
266
			*pscanline++ = GETBLUE(col) ;
266
			*pscanline++ = GETBLUE(col) ;
267
			*pscanline++ =  a;
267
			*pscanline++ = (png_byte) a;
268
		    } else {
268
		    } else {
269
			*pscanline++ = 0.49 + 255.0*GETRED(col)/a ;
269
			*pscanline++ = (png_byte)(0.49 + 255.0*GETRED(col)/a) ;
270
			*pscanline++ = 0.49 + 255.0*GETGREEN(col)/a ;
270
			*pscanline++ = (png_byte)(0.49 + 255.0*GETGREEN(col)/a) ;
271
			*pscanline++ = 0.49 + 255.0*GETBLUE(col)/a ;
271
			*pscanline++ = (png_byte)(0.49 + 255.0*GETBLUE(col)/a) ;
272
			*pscanline++ =  a;
272
			*pscanline++ = (png_byte) a;
273
		    }
273
		    }
274
		} else {
274
		} else {
275
		    *pscanline++ = GETRED(col) ;
275
		    *pscanline++ = GETRED(col) ;
276
		    *pscanline++ = GETGREEN(col) ;
276
		    *pscanline++ = GETGREEN(col) ;
277
		    *pscanline++ = GETBLUE(col) ;
277
		    *pscanline++ = GETBLUE(col) ;
Line 405... Line 405...
405
    cinfo.input_components = 3;		/* # of color components per pixel */
405
    cinfo.input_components = 3;		/* # of color components per pixel */
406
    cinfo.in_color_space = JCS_RGB;	/* colorspace of input image */
406
    cinfo.in_color_space = JCS_RGB;	/* colorspace of input image */
407
    jpeg_set_defaults(&cinfo);
407
    jpeg_set_defaults(&cinfo);
408
    if(res > 0) {
408
    if(res > 0) {
409
	cinfo.density_unit = 1;  /* pixels per inch */
409
	cinfo.density_unit = 1;  /* pixels per inch */
410
	cinfo.X_density = res;
410
	cinfo.X_density = (UINT16) res;
411
	cinfo.Y_density = res;
411
	cinfo.Y_density = (UINT16) res;
412
    }
412
    }
413
    jpeg_set_quality(&cinfo, quality, TRUE);
413
    jpeg_set_quality(&cinfo, quality, TRUE);
414
    /* Step 4: Start compressor */
414
    /* Step 4: Start compressor */
415
    jpeg_start_compress(&cinfo, TRUE);
415
    jpeg_start_compress(&cinfo, TRUE);
416
 
416
 
Line 642... Line 642...
642
    BMPDW(bfOffBits); /* bfOffBits */
642
    BMPDW(bfOffBits); /* bfOffBits */
643
    BMPDW(40);	/* Windows V3. size 40 bytes */
643
    BMPDW(40);	/* Windows V3. size 40 bytes */
644
    BMPDW(width); /* biWidth */
644
    BMPDW(width); /* biWidth */
645
    BMPDW(height); /* biHeight */
645
    BMPDW(height); /* biHeight */
646
    BMPW(1);	/* biPlanes - must be 1 */
646
    BMPW(1);	/* biPlanes - must be 1 */
647
    BMPW(biBitCount); /* biBitCount */
647
    BMPW((unsigned short) biBitCount); /* biBitCount */
648
    BMPDW(0); /* biCompression=BI_RGB */
648
    BMPDW(0); /* biCompression=BI_RGB */
649
    BMPDW(0); /* biSizeImage (with BI_RGB not needed)*/
649
    BMPDW(0); /* biSizeImage (with BI_RGB not needed)*/
650
    lres = (int)(0.5 + res/0.0254);
650
    lres = (int)(0.5 + res/0.0254);
651
    BMPDW(lres); /* XPels/M */
651
    BMPDW(lres); /* XPels/M */
652
    BMPDW(lres); /* XPels/M */
652
    BMPDW(lres); /* XPels/M */