The R Project SVN R

Rev

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

Rev 51085 Rev 51087
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-2008  Guido Masarotto and the R Development Core Team
3
 *  Copyright (C) 1999-2010  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 122... Line 122...
122
#if PNG_LIBPNG_VER < 10400
122
#if PNG_LIBPNG_VER < 10400
123
    if (setjmp(png_ptr->jmpbuf))
123
    if (setjmp(png_ptr->jmpbuf))
124
#else
124
#else
125
    if (setjmp(png_jmpbuf(png_ptr)))
125
    if (setjmp(png_jmpbuf(png_ptr)))
126
#endif
126
#endif
127
{    
127
{
128
	/* If we get here, we had a problem writing the file */
128
	/* If we get here, we had a problem writing the file */
129
	free(scanline);
129
	free(scanline);
130
	png_destroy_write_struct(&png_ptr, &info_ptr);
130
	png_destroy_write_struct(&png_ptr, &info_ptr);
131
	return 0;
131
	return 0;
132
    }
132
    }
Line 248... Line 248...
248
#endif /* HAVE_PNG */
248
#endif /* HAVE_PNG */
249
 
249
 
250
 
250
 
251
#ifdef HAVE_JPEG
251
#ifdef HAVE_JPEG
252
 
252
 
-
 
253
/* jconfig.h included by jpeglib.h may define these unconditionally */
-
 
254
#undef HAVE_STDDEF_H
-
 
255
#undef HAVE_STDLIB_H
253
#include <jpeglib.h>
256
#include <jpeglib.h>
254
 
257
 
255
/* Here's the extended error handler struct */
258
/* Here's the extended error handler struct */
256
 
259
 
257
struct my_error_mgr {
260
struct my_error_mgr {
Line 335... Line 338...
335
 
338
 
336
    /* Step 3: set parameters for compression */
339
    /* Step 3: set parameters for compression */
337
    /* First we supply a description of the input image.
340
    /* First we supply a description of the input image.
338
     * Four fields of the cinfo struct must be filled in:
341
     * Four fields of the cinfo struct must be filled in:
339
     */
342
     */
340
    cinfo.image_width = width; 	/* image width and height, in pixels */
343
    cinfo.image_width = width;	/* image width and height, in pixels */
341
    cinfo.image_height = height;
344
    cinfo.image_height = height;
342
    cinfo.input_components = 3;		/* # of color components per pixel */
345
    cinfo.input_components = 3;		/* # of color components per pixel */
343
    cinfo.in_color_space = JCS_RGB; 	/* colorspace of input image */
346
    cinfo.in_color_space = JCS_RGB;	/* colorspace of input image */
344
    jpeg_set_defaults(&cinfo);
347
    jpeg_set_defaults(&cinfo);
345
    if(res > 0) {
348
    if(res > 0) {
346
	cinfo.density_unit = 1;  /* pixels per inch */
349
	cinfo.density_unit = 1;  /* pixels per inch */
347
	cinfo.X_density = res;
350
	cinfo.X_density = res;
348
	cinfo.Y_density = res;
351
	cinfo.Y_density = res;
Line 408... Line 411...
408
		break;
411
		break;
409
	    }
412
	    }
410
	}
413
	}
411
#endif
414
#endif
412
    sampleperpixel = 3 + have_alpha;
415
    sampleperpixel = 3 + have_alpha;
413
    
416
 
414
    out = TIFFOpen(outfile, "w");
417
    out = TIFFOpen(outfile, "w");
415
    if (!out) {
418
    if (!out) {
416
	warning("unable to open TIFF file '%s'", outfile);
419
	warning("unable to open TIFF file '%s'", outfile);
417
	return 0;
420
	return 0;
418
    }
421
    }
Line 430... Line 433...
430
       COMPRESSION_CCITTFAX3 = COMPRESSION_CCITT_T4 = 3;
433
       COMPRESSION_CCITTFAX3 = COMPRESSION_CCITT_T4 = 3;
431
       COMPRESSION_CCITTFAX4 = COMPRESSION_CCITT_T6 = 4;
434
       COMPRESSION_CCITTFAX4 = COMPRESSION_CCITT_T6 = 4;
432
       COMPRESSION_LZW = 5;
435
       COMPRESSION_LZW = 5;
433
       COMPRESSION_JPEG = 7;
436
       COMPRESSION_JPEG = 7;
434
       COMPRESSION_DEFLATE = 32946;
437
       COMPRESSION_DEFLATE = 32946;
435
       COMPRESSION_ADOBE_DEFLATE = 8;  
438
       COMPRESSION_ADOBE_DEFLATE = 8;
436
    */
439
    */
437
    TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
440
    TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
438
#endif
441
#endif
439
    if(compression > 1)
442
    if(compression > 1)
440
	TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
443
	TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
Line 448... Line 451...
448
    linebytes = sampleperpixel * width;
451
    linebytes = sampleperpixel * width;
449
    if (TIFFScanlineSize(out))
452
    if (TIFFScanlineSize(out))
450
	buf =(unsigned char *)_TIFFmalloc(linebytes);
453
	buf =(unsigned char *)_TIFFmalloc(linebytes);
451
    else
454
    else
452
	buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
455
	buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
453
 
456
 
454
    for (i = 0; i < height; i++) {
457
    for (i = 0; i < height; i++) {
455
	pscanline = buf;
458
	pscanline = buf;
456
	for(j = 0; j < width; j++) {
459
	for(j = 0; j < width; j++) {
457
	    col = gp(d, i, j);
460
	    col = gp(d, i, j);
458
	    *pscanline++ = GETRED(col) ;
461
	    *pscanline++ = GETRED(col) ;
Line 535... Line 538...
535
	biBitCount = 24;
538
	biBitCount = 24;
536
	biClrUsed = 0;
539
	biClrUsed = 0;
537
    }
540
    }
538
 
541
 
539
    /* write the header */
542
    /* write the header */
540
    
543
 
541
    BMPPUTC('B');BMPPUTC('M');
544
    BMPPUTC('B');BMPPUTC('M');
542
    BMPDW(bfSize); /*bfSize*/
545
    BMPDW(bfSize); /*bfSize*/
543
    BMPW(0);BMPW(0); /* bfReserved1 and bfReserved2 must be 0*/
546
    BMPW(0);BMPW(0); /* bfReserved1 and bfReserved2 must be 0*/
544
    BMPDW(bfOffBits); /* bfOffBits */
547
    BMPDW(bfOffBits); /* bfOffBits */
545
    BMPDW(40);	/* Windows V3. size 40 bytes */
548
    BMPDW(40);	/* Windows V3. size 40 bytes */