The R Project SVN R

Rev

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

Rev 44580 Rev 44594
Line 371... Line 371...
371
    return 1;
371
    return 1;
372
}
372
}
373
 
373
 
374
#endif /* HAVE_JPEG */
374
#endif /* HAVE_JPEG */
375
 
375
 
-
 
376
#ifdef HAVE_TIFF
-
 
377
#include <tiffio.h>
-
 
378
 
-
 
379
__declspec(dllexport)
-
 
380
int R_SaveAsTIFF(void  *d, int width, int height,
-
 
381
		unsigned int (*gp)(void *, int, int),
-
 
382
		int bgr, const char *outfile, int res, int compression)
-
 
383
{
-
 
384
    TIFF *out;
-
 
385
    int sampleperpixel;
-
 
386
    tsize_t linebytes;
-
 
387
    unsigned char *buf, *pscanline;
-
 
388
    unsigned int col, i, j;
-
 
389
    int have_alpha = 0;
-
 
390
 
-
 
391
    DECLARESHIFTS;
-
 
392
 
-
 
393
#if 0
-
 
394
    for (i = 0; i < height; i++)
-
 
395
	for (j = 0; j < width; j++) {
-
 
396
	    col = gp(d,i,j);
-
 
397
	    if (GETALPHA(col) < 255) {
-
 
398
		have_alpha = 1;
-
 
399
		break;
-
 
400
	    }
-
 
401
	}
-
 
402
#endif
-
 
403
    sampleperpixel = 3 + have_alpha;
-
 
404
    
-
 
405
    out = TIFFOpen(outfile, "w");
-
 
406
    if (!out) {
-
 
407
	warning("unable to open TIFF file '%s'", outfile);
-
 
408
	return 0;
-
 
409
    }
-
 
410
    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, width);
-
 
411
    TIFFSetField(out, TIFFTAG_IMAGELENGTH, height);
-
 
412
    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, sampleperpixel);
-
 
413
    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
-
 
414
    TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
-
 
415
    TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
-
 
416
    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
-
 
417
#if 0
-
 
418
    /* Possible compression values
-
 
419
       COMPRESSION_NONE = 1;
-
 
420
       COMPRESSION_CCITTRLE = 2;
-
 
421
       COMPRESSION_CCITTFAX3 = COMPRESSION_CCITT_T4 = 3;
-
 
422
       COMPRESSION_CCITTFAX4 = COMPRESSION_CCITT_T6 = 4;
-
 
423
       COMPRESSION_LZW = 5;
-
 
424
       COMPRESSION_JPEG = 7;
-
 
425
       COMPRESSION_DEFLATE = 32946;
-
 
426
       COMPRESSION_ADOBE_DEFLATE = 8;  
-
 
427
    */
-
 
428
    TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
-
 
429
#endif
-
 
430
    if(compression > 1)
-
 
431
	TIFFSetField(out, TIFFTAG_COMPRESSION, compression);
-
 
432
 
-
 
433
    if (res > 0) {
-
 
434
	TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
-
 
435
	TIFFSetField(out, TIFFTAG_XRESOLUTION, (float) res);
-
 
436
	TIFFSetField(out, TIFFTAG_YRESOLUTION, (float) res);
-
 
437
    }
-
 
438
 
-
 
439
    linebytes = sampleperpixel * width;
-
 
440
    if (TIFFScanlineSize(out))
-
 
441
	buf =(unsigned char *)_TIFFmalloc(linebytes);
-
 
442
    else
-
 
443
	buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
-
 
444
 
-
 
445
    for (i = 0; i < height; i++) {
-
 
446
	pscanline = buf;
-
 
447
	for(j = 0; j < width; j++) {
-
 
448
	    col = gp(d, i, j);
-
 
449
	    *pscanline++ = GETRED(col) ;
-
 
450
	    *pscanline++ = GETGREEN(col) ;
-
 
451
	    *pscanline++ = GETBLUE(col) ;
-
 
452
	    if(have_alpha) *pscanline++ = GETALPHA(col) ;
-
 
453
	}
-
 
454
	TIFFWriteScanline(out, buf, i, 0);
-
 
455
    }
-
 
456
    TIFFClose(out);
-
 
457
    _TIFFfree(buf);
-
 
458
    return 1;
-
 
459
}
-
 
460
#endif  /* HAVE_TIFF */
-
 
461
 
-
 
462
 
376
/*
463
/*
377
 * Try to save the content of the device 'd' in 'filename' as Windows BMP.
464
 * Try to save the content of the device 'd' in 'filename' as Windows BMP.
378
 * If numbers of colors is less than 256 we use a 'palette' BMP.
465
 * If numbers of colors is less than 256 we use a 'palette' BMP.
379
 * Return 1 on success, 0 on failure
466
 * Return 1 on success, 0 on failure
380
*/
467
*/