The R Project SVN R

Rev

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

Rev 29441 Rev 29909
Line 169... Line 169...
169
    int fast; /* Use fast fixed-width lines? */
169
    int fast; /* Use fast fixed-width lines? */
170
    unsigned int pngtrans; /* what PNG_TRANS get mapped to */
170
    unsigned int pngtrans; /* what PNG_TRANS get mapped to */
171
    Rboolean buffered;
171
    Rboolean buffered;
172
    int timeafter, timesince;
172
    int timeafter, timesince;
173
    SEXP psenv;
173
    SEXP psenv;
-
 
174
    double res_dpi;
174
} gadesc;
175
} gadesc;
175
 
176
 
176
rect getregion(gadesc *xd)
177
rect getregion(gadesc *xd)
177
{
178
{
178
    rect r = getrect(xd->bm);
179
    rect r = getrect(xd->bm);
Line 281... Line 282...
281
static int Load_Rbitmap_Dll();
282
static int Load_Rbitmap_Dll();
282
void UnLoad_Rbitmap_Dll();
283
void UnLoad_Rbitmap_Dll();
283
static void SaveAsPng(NewDevDesc *dd, char *fn);
284
static void SaveAsPng(NewDevDesc *dd, char *fn);
284
static void SaveAsJpeg(NewDevDesc *dd, int quality, char *fn);
285
static void SaveAsJpeg(NewDevDesc *dd, int quality, char *fn);
285
static void SaveAsBmp(NewDevDesc *dd, char *fn);
286
static void SaveAsBmp(NewDevDesc *dd, char *fn);
286
static void SaveAsBitmap(NewDevDesc *dd);
287
static void SaveAsBitmap(NewDevDesc *dd, int res);
287
 
288
 
288
static void PrivateCopyDevice(NewDevDesc *dd, NewDevDesc *ndd, char *name)
289
static void PrivateCopyDevice(NewDevDesc *dd, NewDevDesc *ndd, char *name)
289
{
290
{
290
    GEDevDesc* gdd;
291
    GEDevDesc* gdd;
291
    int saveDev = curDevice();
292
    int saveDev = curDevice();
Line 1522... Line 1523...
1522
	xd->kind = PRINTER;
1523
	xd->kind = PRINTER;
1523
	xd->gawin = newprinter(MM_PER_INCH * w, MM_PER_INCH * h, &dsp[10]);
1524
	xd->gawin = newprinter(MM_PER_INCH * w, MM_PER_INCH * h, &dsp[10]);
1524
	if (!xd->gawin)
1525
	if (!xd->gawin)
1525
	    return FALSE;
1526
	    return FALSE;
1526
    } else if (!strncmp(dsp, "png:", 4) || !strncmp(dsp,"bmp:", 4)) {
1527
    } else if (!strncmp(dsp, "png:", 4) || !strncmp(dsp,"bmp:", 4)) {
-
 
1528
	xd->res_dpi = (xpos == NA_INTEGER) ? 0 : xpos;
1527
	if(R_OPAQUE(canvascolor))
1529
	if(R_OPAQUE(canvascolor))
1528
	    xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1530
	    xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1529
	else
1531
	else
1530
	    xd->bg = dd->startfill = canvascolor;
1532
	    xd->bg = dd->startfill = canvascolor;
1531
	/* was R_RGB(255, 255, 255); white */
1533
	/* was R_RGB(255, 255, 255); white */
Line 1552... Line 1554...
1552
	    warning("Unable to open file `%s' for writing", buf);
1554
	    warning("Unable to open file `%s' for writing", buf);
1553
	    return FALSE;
1555
	    return FALSE;
1554
	}
1556
	}
1555
    } else if (!strncmp(dsp, "jpeg:", 5)) {
1557
    } else if (!strncmp(dsp, "jpeg:", 5)) {
1556
        char *p = strchr(&dsp[5], ':');
1558
        char *p = strchr(&dsp[5], ':');
-
 
1559
	xd->res_dpi = (xpos == NA_INTEGER) ? 0 : xpos;
1557
	xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1560
	xd->bg = dd->startfill = GArgb(canvascolor, 1.0);
1558
        xd->kind = JPEG;
1561
        xd->kind = JPEG;
1559
	if (!p) return FALSE;
1562
	if (!p) return FALSE;
1560
	if (!Load_Rbitmap_Dll()) {
1563
	if (!Load_Rbitmap_Dll()) {
1561
	    warning("Unable to load Rbitmap.dll");
1564
	    warning("Unable to load Rbitmap.dll");
Line 1837... Line 1840...
1837
	}
1840
	}
1838
    }
1841
    }
1839
    if ((xd->kind == PNG || xd->kind == JPEG || xd->kind == BMP)
1842
    if ((xd->kind == PNG || xd->kind == JPEG || xd->kind == BMP)
1840
	&& xd->needsave) {
1843
	&& xd->needsave) {
1841
	char buf[600];
1844
	char buf[600];
1842
	SaveAsBitmap(dd);
1845
	SaveAsBitmap(dd, xd->res_dpi);
1843
	snprintf(buf, 600, xd->filename, xd->npage);
1846
	snprintf(buf, 600, xd->filename, xd->npage);
1844
	if ((xd->fp = fopen(buf, "wb")) == NULL)
1847
	if ((xd->fp = fopen(buf, "wb")) == NULL)
1845
	    error("Unable to open file `%s' for writing", buf);
1848
	    error("Unable to open file `%s' for writing", buf);
1846
    }
1849
    }
1847
    if (xd->kind == SCREEN) {
1850
    if (xd->kind == SCREEN) {
Line 1895... Line 1898...
1895
	}
1898
	}
1896
	hide(xd->gawin);
1899
	hide(xd->gawin);
1897
	del(xd->bm);
1900
	del(xd->bm);
1898
	if (xd == GA_xd) GA_xd = NULL;
1901
	if (xd == GA_xd) GA_xd = NULL;
1899
    } else if ((xd->kind == PNG) || (xd->kind == JPEG) || (xd->kind == BMP)) {
1902
    } else if ((xd->kind == PNG) || (xd->kind == JPEG) || (xd->kind == BMP)) {
1900
      SaveAsBitmap(dd);
1903
      SaveAsBitmap(dd, xd->res_dpi);
1901
    }
1904
    }
1902
    del(xd->font);
1905
    del(xd->font);
1903
    del(xd->gawin);
1906
    del(xd->gawin);
1904
/*
1907
/*
1905
 * this is needed since the GraphApp delayed clean-up
1908
 * this is needed since the GraphApp delayed clean-up
Line 2545... Line 2548...
2545
    c = ((rgb *)d)[i*png_rows + j];
2548
    c = ((rgb *)d)[i*png_rows + j];
2546
    return c;
2549
    return c;
2547
}
2550
}
2548
 
2551
 
2549
/* This is the device version */
2552
/* This is the device version */
2550
static void SaveAsBitmap(NewDevDesc *dd)
2553
static void SaveAsBitmap(NewDevDesc *dd, int res)
2551
{
2554
{
2552
    rect r, r2;
2555
    rect r, r2;
2553
    gadesc *xd = (gadesc *) dd->deviceSpecific;
2556
    gadesc *xd = (gadesc *) dd->deviceSpecific;
2554
    unsigned char *data;
2557
    unsigned char *data;
2555
 
2558
 
Line 2560... Line 2563...
2560
	if(data) {
2563
	if(data) {
2561
	    png_rows = r2.width;
2564
	    png_rows = r2.width;
2562
	    if (xd->kind == PNG)
2565
	    if (xd->kind == PNG)
2563
		R_SaveAsPng(data, xd->windowWidth, xd->windowHeight,
2566
		R_SaveAsPng(data, xd->windowWidth, xd->windowHeight,
2564
			    privategetpixel2, 0, xd->fp,
2567
			    privategetpixel2, 0, xd->fp,
2565
			    R_OPAQUE(xd->bg) ? 0 : xd->pngtrans) ;
2568
			    R_OPAQUE(xd->bg) ? 0 : xd->pngtrans, res) ;
2566
	    else if (xd->kind == JPEG)
2569
	    else if (xd->kind == JPEG)
2567
		R_SaveAsJpeg(data, xd->windowWidth, xd->windowHeight,
2570
		R_SaveAsJpeg(data, xd->windowWidth, xd->windowHeight,
2568
			     privategetpixel2, 0, xd->quality, xd->fp) ;
2571
			     privategetpixel2, 0, xd->quality, xd->fp, res) ;
2569
	    else
2572
	    else
2570
		R_SaveAsBmp(data, xd->windowWidth, xd->windowHeight,
2573
		R_SaveAsBmp(data, xd->windowWidth, xd->windowHeight,
2571
			    privategetpixel2, 0, xd->fp);
2574
			    privategetpixel2, 0, xd->fp, res);
2572
	    free(data);
2575
	    free(data);
2573
	} else
2576
	} else
2574
	    warning("processing of the plot ran out of memory");
2577
	    warning("processing of the plot ran out of memory");
2575
	fclose(xd->fp);
2578
	fclose(xd->fp);
2576
    }
2579
    }
Line 2602... Line 2605...
2602
    gsetcliprect(xd->bm, r2 = getrect(xd->bm));
2605
    gsetcliprect(xd->bm, r2 = getrect(xd->bm));
2603
    getbitmapdata2(xd->bm, &data);
2606
    getbitmapdata2(xd->bm, &data);
2604
    if(data) {
2607
    if(data) {
2605
	png_rows = r2.width;
2608
	png_rows = r2.width;
2606
	R_SaveAsPng(data, xd->windowWidth, xd->windowHeight,
2609
	R_SaveAsPng(data, xd->windowWidth, xd->windowHeight,
2607
		    privategetpixel2, 0, fp, 0) ;
2610
		    privategetpixel2, 0, fp, 0, 0) ;
2608
	free(data);
2611
	free(data);
2609
    } else
2612
    } else
2610
	warning("processing of the plot ran out of memory");
2613
	warning("processing of the plot ran out of memory");
2611
    /* R_OPAQUE(xd->bg) ? 0 : xd->canvascolor) ; */
2614
    /* R_OPAQUE(xd->bg) ? 0 : xd->canvascolor) ; */
2612
    gsetcliprect(xd->bm, r);
2615
    gsetcliprect(xd->bm, r);
Line 2635... Line 2638...
2635
    gsetcliprect(xd->bm, r2 = getrect(xd->bm));
2638
    gsetcliprect(xd->bm, r2 = getrect(xd->bm));
2636
    getbitmapdata2(xd->bm, &data);
2639
    getbitmapdata2(xd->bm, &data);
2637
    if(data) {
2640
    if(data) {
2638
	png_rows = r2.width;
2641
	png_rows = r2.width;
2639
	R_SaveAsJpeg(data,xd->windowWidth, xd->windowHeight,
2642
	R_SaveAsJpeg(data,xd->windowWidth, xd->windowHeight,
2640
		     privategetpixel2, 0, quality, fp) ;
2643
		     privategetpixel2, 0, quality, fp, 0) ;
2641
	free(data);
2644
	free(data);
2642
    } else
2645
    } else
2643
	warning("processing of the plot ran out of memory");
2646
	warning("processing of the plot ran out of memory");
2644
    gsetcliprect(xd->bm, r);
2647
    gsetcliprect(xd->bm, r);
2645
    fclose(fp);
2648
    fclose(fp);
Line 2670... Line 2673...
2670
 
2673
 
2671
    getbitmapdata2(xd->bm, &data);
2674
    getbitmapdata2(xd->bm, &data);
2672
    if(data) {
2675
    if(data) {
2673
	png_rows = r2.width;
2676
	png_rows = r2.width;
2674
	R_SaveAsBmp(data, xd->windowWidth, xd->windowHeight,
2677
	R_SaveAsBmp(data, xd->windowWidth, xd->windowHeight,
2675
		    privategetpixel2, 0, fp) ;
2678
		    privategetpixel2, 0, fp, 0) ;
2676
	free(data);
2679
	free(data);
2677
    } else
2680
    } else
2678
	warning("processing of the plot ran out of memory");
2681
	warning("processing of the plot ran out of memory");
2679
    gsetcliprect(xd->bm, r);
2682
    gsetcliprect(xd->bm, r);
2680
    fclose(fp);
2683
    fclose(fp);