The R Project SVN R

Rev

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

Rev 29746 Rev 29948
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1999, 2001  Guido Masarotto and the R Development Core Team
3
 *  Copyright (C) 1999, 2001, 2004  Guido Masarotto and the R Development Core Team
4
 *
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
8
 *  (at your option) any later version.
Line 77... Line 77...
77
  warning("libpng: %s",(char *) msg);
77
  warning("libpng: %s",(char *) msg);
78
}
78
}
79
 
79
 
80
int R_SaveAsPng(void  *d, int width, int height, 
80
int R_SaveAsPng(void  *d, int width, int height, 
81
		unsigned long (*gp)(void *, int, int),
81
		unsigned long (*gp)(void *, int, int),
82
		int bgr, FILE *fp, unsigned int transparent) 
82
		int bgr, FILE *fp, unsigned int transparent, int res) 
83
{
83
{
84
  png_structp png_ptr;
84
  png_structp png_ptr;
85
  png_infop info_ptr;
85
  png_infop info_ptr;
86
  unsigned long  col, palette[256];
86
  unsigned long  col, palette[256];
87
  png_color pngpalette[256];
87
  png_color pngpalette[256];
Line 192... Line 192...
192
	  trans_values[0].green = GETGREEN(transparent);
192
	  trans_values[0].green = GETGREEN(transparent);
193
      }
193
      }
194
      png_set_tRNS(png_ptr, info_ptr, trans, ncols, trans_values);
194
      png_set_tRNS(png_ptr, info_ptr, trans, ncols, trans_values);
195
  }
195
  }
196
 
196
 
-
 
197
  if(res > 0) 
-
 
198
      png_set_pHYs(png_ptr, info_ptr, res/0.0254, res/0.0254,
-
 
199
		   PNG_RESOLUTION_METER);
-
 
200
 
197
  /* Write the file header information.  REQUIRED */
201
  /* Write the file header information.  REQUIRED */
198
  png_write_info(png_ptr, info_ptr);
202
  png_write_info(png_ptr, info_ptr);
199
 
203
 
200
  /* 
204
  /* 
201
   * Now, write the pixels
205
   * Now, write the pixels
Line 293... Line 297...
293
 
297
 
294
 
298
 
295
 
299
 
296
int R_SaveAsJpeg(void  *d, int width, int height, 
300
int R_SaveAsJpeg(void  *d, int width, int height, 
297
		unsigned long (*gp)(void *, int, int),
301
		unsigned long (*gp)(void *, int, int),
298
		int bgr, int quality, FILE *outfile) 
302
		int bgr, int quality, FILE *outfile, int res) 
299
{
303
{
300
  struct jpeg_compress_struct cinfo;
304
  struct jpeg_compress_struct cinfo;
301
  struct my_error_mgr jerr;
305
  struct my_error_mgr jerr;
302
  /* More stuff */
306
  /* More stuff */
303
  JSAMPLE *pscanline, *scanline = calloc(3*width,sizeof(JSAMPLE));
307
  JSAMPLE *pscanline, *scanline = calloc(3*width,sizeof(JSAMPLE));
Line 341... Line 345...
341
  cinfo.image_width = width; 	/* image width and height, in pixels */
345
  cinfo.image_width = width; 	/* image width and height, in pixels */
342
  cinfo.image_height = height;
346
  cinfo.image_height = height;
343
  cinfo.input_components = 3;		/* # of color components per pixel */
347
  cinfo.input_components = 3;		/* # of color components per pixel */
344
  cinfo.in_color_space = JCS_RGB; 	/* colorspace of input image */
348
  cinfo.in_color_space = JCS_RGB; 	/* colorspace of input image */
345
  jpeg_set_defaults(&cinfo);
349
  jpeg_set_defaults(&cinfo);
-
 
350
  if(res > 0) {
-
 
351
      cinfo.density_unit = 1;  /* pixels per inch */
-
 
352
      cinfo.X_density = res;
-
 
353
      cinfo.Y_density = res;
-
 
354
  }
346
  jpeg_set_quality(&cinfo, quality, TRUE);
355
  jpeg_set_quality(&cinfo, quality, TRUE);
347
  /* Step 4: Start compressor */
356
  /* Step 4: Start compressor */
348
  jpeg_start_compress(&cinfo, TRUE);
357
  jpeg_start_compress(&cinfo, TRUE);
349
 
358
 
350
  /* Step 5: while (scan lines remain to be written) */
359
  /* Step 5: while (scan lines remain to be written) */