示例#1
0
文件: colors.c 项目: Vladimir84/rcc
SEXP do_col2RGB(SEXP call, SEXP op, SEXP args, SEXP env)
{
/* colorname, "#rrggbb" or "col.number" to (r,g,b) conversion */
    SEXP colors, ans, names, dmns;
    unsigned int col;
    int n, i, i4;

    checkArity(op, args);

    PROTECT(colors = coerceVector(CAR(args),STRSXP));
    n = LENGTH(colors);
    PROTECT(ans = allocMatrix(INTSXP, 4, n));
    PROTECT(dmns = allocVector(VECSXP, 2));

    PROTECT(names = allocVector(STRSXP, 4));
    SET_STRING_ELT(names, 0, mkChar("red"));
    SET_STRING_ELT(names, 1, mkChar("green"));
    SET_STRING_ELT(names, 2, mkChar("blue"));
    SET_STRING_ELT(names, 3, mkChar("alpha"));
    SET_VECTOR_ELT(dmns, 0, names);
    UNPROTECT(1);/*names*/
    if ((names = getAttrib(colors, R_NamesSymbol)) != R_NilValue)
	SET_VECTOR_ELT(dmns, 1, names);
    setAttrib(ans, R_DimNamesSymbol, dmns);
    for(i = i4 = 0; i < n; i++, i4 += 4) {
	col = str2col(CHAR(STRING_ELT(colors, i)));
	INTEGER(ans)[i4 +0] = R_RED(col);
	INTEGER(ans)[i4 +1] = R_GREEN(col);
	INTEGER(ans)[i4 +2] = R_BLUE(col);
	INTEGER(ans)[i4 +3] = R_ALPHA(col);
    }
    UNPROTECT(3);
    return ans;
}
示例#2
0
static void SWF_SetLineStyle(SWFShape shape, const pGEcontext plotParams, 
	swfDevDesc *swfInfo ){
	
	byte red = R_RED(plotParams->col);
	byte green = R_GREEN(plotParams->col);
	byte blue = R_BLUE(plotParams->col);
	byte alpha =  R_ALPHA(plotParams->col);
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,"\tLineStyle: Red=%d, ",red);
		fprintf(swfInfo->logFile,"Green=%d, ",green);
		fprintf(swfInfo->logFile,"Blue=%d, ",blue);
		fprintf(swfInfo->logFile,"Alpha=%d\n",alpha);
		fflush(swfInfo->logFile);
	}
	
	//FIXME: Honor all the line parameters such as 
	//lty, lend, ljoin 
	SWFShape_setLine(shape,
		(unsigned short) plotParams->lwd,
		red, green, blue, alpha);
		
	/* does not play nicely with setRightFill
	SWFShape_setLine2Filled(shape,
		(unsigned short) plotParams->lwd,
		newSWFSolidFillStyle( red, green, blue, alpha ),
		SWF_LINESTYLE_CAP_ROUND,
		plotParams->lmitre);
	*/
		
		
}
示例#3
0
static Rboolean SWF_Open( pDevDesc deviceInfo ){

	/* 
	 * Shortcut pointers to variables of interest. 
	 * It seems like there HAS to be a more elegent way of accesing
	 * these...
	*/
	swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific;

	//Debug log
	if( swfInfo->debug == TRUE ){
		if( !( swfInfo->logFile = 
			fopen(R_ExpandFileName(swfInfo->logFileName), "w") ) )
			return FALSE;
			
		fprintf(swfInfo->logFile,
			"SWF_Open: Begin swf output\n");	
		fprintf(swfInfo->logFile,
			"SWF_Open: Setting dimensions %6.1f by %6.1f\n",
			deviceInfo->right, deviceInfo->top);	
		fprintf(swfInfo->logFile,
			"SWF_Open: Setting background %3d, %3d, %3d\n",
			R_RED(deviceInfo->startfill), 
			R_GREEN(deviceInfo->startfill), 
			R_BLUE(deviceInfo->startfill));
			
		fflush(swfInfo->logFile);
		//Rprintf("%s",dashTo);
	}

	// Set the background color for the movie
	SWFMovie_setBackground(swfInfo->m, 
		R_RED(deviceInfo->startfill), 
		R_GREEN(deviceInfo->startfill), 
		R_BLUE(deviceInfo->startfill));
		
	SWFMovie_setDimension(swfInfo->m, deviceInfo->right, deviceInfo->top);

	// Set the frame rate for the movie
	SWFMovie_setRate(swfInfo->m, swfInfo->frameRate);
	
	// Set the total number of frames in the movie to 1
	SWFMovie_setNumberOfFrames(swfInfo->m, 1);

	return TRUE;

}
示例#4
0
/* set the r, g, b, and pixel values of gcol to color */
static void SetColor(wxColour *gcol, int color)
{
    int red, green, blue;

    red = R_RED(color);
    green = R_GREEN(color);
    blue = R_BLUE(color);

    gcol->Set(red, green, blue);
}
示例#5
0
static void Quartz_SetFill(int fill, double gamma, NewDevDesc *dd)
{
    QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
    xd->fill = fill;
    CGContextSetRGBFillColor( GetContext(xd), 
			      (float)R_RED(fill)/255.0, 
			      (float)R_GREEN(fill)/255.0, 
			      (float)R_BLUE(fill)/255.0, 
			      (float)R_ALPHA(fill)/255.0);
}
示例#6
0
static void Quartz_SetStroke(int color, double gamma, NewDevDesc *dd)
{
    QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
    xd->color = color;
    CGContextSetRGBStrokeColor( GetContext(xd), 
				(float)R_RED(color)/255.0, 
				(float)R_GREEN(color)/255.0, 
				(float)R_BLUE(color)/255.0, 
				(float)R_ALPHA(color)/255.0);
}
示例#7
0
/* R uses gc->col for text color, but actually we need to "fill" the outlines */
void swfSetTextColor(SWFShape shape, const pGEcontext gc, pswfDesc swfInfo)
{
    SWFFillStyle fill;
    fill = newSWFSolidFillStyle(R_RED(gc->col),
                                R_GREEN(gc->col),
                                R_BLUE(gc->col),
                                R_ALPHA(gc->col));
    SWFShape_setRightFillStyle(shape, fill);
    
    SWFArray_append(swfInfo->array, (SWFObject) fill);
}
示例#8
0
void write_attr_col(FILE* f, const char* attr, unsigned int col) {
    int alpha = R_ALPHA(col);

    if (col == NA_INTEGER || alpha == 0) {
        fprintf(f, " %s='none'", attr);
        return;
    } else {
        fprintf(f, " %s='#%02X%02X%02X'", attr, R_RED(col), R_GREEN(col), R_BLUE(col));
        if (alpha != 255)
            fprintf(f, " %s-opacity='%0.2f'", attr, alpha / 255.0);
    }
}
示例#9
0
文件: devGTK.c 项目: cran/gtkDevice
/* set the r, g, b, and pixel values of gcol to color */
static void SetColor(GdkColor *gcol, int color)
{
    int red, green, blue;

    red = R_RED(color);
    green = R_GREEN(color);
    blue = R_BLUE(color);
    gcol->red = 0;
    gcol->green = 0;
    gcol->blue = 0;
    gcol->pixel = gdk_rgb_xpixel_from_rgb((red << 16)|(green << 8)|(blue));
}
示例#10
0
    /*
     * device_Text should have the side-effect that the
     * given text is drawn at the given location.
     * The text should be rotated according to rot (degrees)
     *
     * R_GE_gcontext parameters that should be honoured (if possible):
     *   font, cex, ps, col, gamma
     */
static void SWF_Text( double x, double y, const char *str,
		double rot, double hadj, const pGEcontext plotParams, 
		pDevDesc deviceInfo)
{
	/* Shortcut pointers to variables of interest. */
	swfDevDesc *swfInfo = (swfDevDesc *) deviceInfo->deviceSpecific;
	
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,
			"SWF_Text: Writing Text \"%s\"\n", str);
		fflush(swfInfo->logFile);
	}
	
	/* It is possible that this will be very expensive and storing 
	 * a single text object in swfInfo may be better.
	 */
	SWFText text_object = newSWFText();
	SWFDisplayItem text_display;
	/*Ming (0,0) is the top left, convert to R (0,0) at bottom left*/
	y = deviceInfo->top - y;
	
	//found = !strcmp(name, fontlist->family->fxname);
	
	// Tell the text object to use the font previously loaded
	SWFText_setFont(text_object, 
		selectFont(plotParams->fontface, plotParams->fontfamily, swfInfo));
	
	// Set the height of the text
	SWFText_setHeight(text_object, plotParams->ps * plotParams->cex);
	
	// Set the color of the text
	byte red = R_RED(plotParams->col);
	byte green = R_GREEN(plotParams->col);
	byte blue = R_BLUE(plotParams->col);
	byte alpha =  R_ALPHA(plotParams->col);
	SWFText_setColor(text_object, red, green, blue, alpha);
	
	// Add a string to the text object
	SWFText_addString(text_object, str, NULL);
	
	// Add the text object to the movie (at 0,0)
	text_display = SWFMovie_add(swfInfo->m, (SWFBlock) text_object);
	
	addToDisplayList( text_display );
	
	// Move to correct coordinate and rotate
	SWFDisplayItem_moveTo(text_display, x, y);
	SWFDisplayItem_rotate(text_display, rot);
	
			
}
示例#11
0
static void SWF_SetFill(SWFShape shape, const pGEcontext plotParams, 
	swfDevDesc *swfInfo  ){
	
	/*
	 *	Some Notes on Color
	 *
	 *	R uses a 24-bit color model.  Colors are specified in 32-bit
	 *	integers which are partitioned into 4 bytes as follows.
	 *
	 *		<-- most sig	    least sig -->
	 *		+-------------------------------+
	 *		|   0	| blue	| green |  red	|
	 *		+-------------------------------+
	 *
	 *	The red, green and blue bytes can be extracted as follows.
	 *
	 *		red   = ((color	     ) & 255)
	 *		green = ((color >>  8) & 255)
	 *		blue  = ((color >> 16) & 255)
	 */
	
	byte red = R_RED(plotParams->fill);
	byte green = R_GREEN(plotParams->fill);
	byte blue = R_BLUE(plotParams->fill);
	
	//Top 8 bits: 255 = opaque, 0 = transparent
	byte alpha = R_ALPHA(plotParams->fill);
	
	if( swfInfo->debug == TRUE ){
		fprintf(swfInfo->logFile,"\tFill: Red=%d, ",red);
		fprintf(swfInfo->logFile,"Green=%d, ",green);
		fprintf(swfInfo->logFile,"Blue=%d, ",blue);
		fprintf(swfInfo->logFile,"Alpha=%d\n",alpha);
		fflush(swfInfo->logFile);
	}
		
		
		
	
	SWFFillStyle fill_style;
	fill_style = newSWFSolidFillStyle( red, green, blue, alpha );
	if(fill_style == NULL)
		error("Failed to allocate memory for fill object!");
	SWFShape_setRightFillStyle(shape, fill_style);
}
示例#12
0
/**********************************
 * Below are supporting functions *
 **********************************/
void swfSetLineStyle(SWFShape shape, const pGEcontext gc, pswfDesc swfInfo)
{
    int cap = SWF_LINESTYLE_CAP_ROUND;
    int endcap = SWF_LINESTYLE_FLAG_ENDCAP_ROUND;
    int join = SWF_LINESTYLE_JOIN_ROUND;
    switch(gc->lend)
    {
        case GE_ROUND_CAP:
            cap = SWF_LINESTYLE_CAP_ROUND;
            endcap = SWF_LINESTYLE_FLAG_ENDCAP_ROUND;
            break;
        case GE_BUTT_CAP:
            cap = SWF_LINESTYLE_CAP_NONE;
            endcap = SWF_LINESTYLE_FLAG_ENDCAP_NONE;
            break;
        case GE_SQUARE_CAP:
            cap = SWF_LINESTYLE_CAP_SQUARE;
            endcap = SWF_LINESTYLE_FLAG_ENDCAP_SQUARE;
            break;
    }
    switch(gc->ljoin)
    {
        case GE_ROUND_JOIN:
            join = SWF_LINESTYLE_JOIN_ROUND;
            break;
        case GE_MITRE_JOIN:
            join = SWF_LINESTYLE_JOIN_MITER;
            break;
        case GE_BEVEL_JOIN:
            join = SWF_LINESTYLE_JOIN_BEVEL;
            break;
    }
    SWFShape_setLine2(shape, (unsigned short) gc->lwd,
                             R_RED(gc->col),
                             R_GREEN(gc->col),
                             R_BLUE(gc->col),
                             R_ALPHA(gc->col),
                             cap | endcap | join,
                             (float) gc->lmitre);
}
示例#13
0
文件: colors.c 项目: SensePlatform/R
SEXP attribute_hidden do_col2RGB(SEXP call, SEXP op, SEXP args, SEXP env)
{
/* colorname, "#rrggbb" or "col.number" to (r,g,b) conversion */

    SEXP colors, ans, names, dmns;
    double col, bg;
    unsigned int icol;
    int n, i, i4;

    checkArity(op, args);
    colors = CAR(args);
    if(isString(colors)) PROTECT(colors);
    else {
	PROTECT(colors = coerceVector(colors, INTSXP));
	if (TYPEOF(colors) != INTSXP)
	    error(_("invalid '%s' value"), "col");
    }
    n = LENGTH(colors);

    /* First set up the output matrix */
    PROTECT(ans = allocMatrix(INTSXP, 4, n));
    PROTECT(dmns = allocVector(VECSXP, 2));
    PROTECT(names = allocVector(STRSXP, 4));
    SET_STRING_ELT(names, 0, mkChar("red"));
    SET_STRING_ELT(names, 1, mkChar("green"));
    SET_STRING_ELT(names, 2, mkChar("blue"));
    SET_STRING_ELT(names, 3, mkChar("alpha"));
    SET_VECTOR_ELT(dmns, 0, names);
    UNPROTECT(1); /*names*/
    if ((names = getAttrib(colors, R_NamesSymbol)) != R_NilValue)
	SET_VECTOR_ELT(dmns, 1, names);
    setAttrib(ans, R_DimNamesSymbol, dmns);

    /* avoid looking up the background unless we will need it;
       this may avoid opening a new window.  Unfortunately, there is no
       unavailable colour, so we work with doubles and convert at the 
       last minute */

#define BG_NEEDED -1.0

    bg = BG_NEEDED;

    if(isString(colors)) {
	for(i = i4 = 0; i < n; i++, i4 += 4) {
	    col = str2col(CHAR(STRING_ELT(colors, i)), bg);
	    if (col == BG_NEEDED)
	    	col = bg = dpptr(GEcurrentDevice())->bg;
	    icol = (unsigned int)col;
	    INTEGER(ans)[i4 +0] = R_RED(icol);
	    INTEGER(ans)[i4 +1] = R_GREEN(icol);
	    INTEGER(ans)[i4 +2] = R_BLUE(icol);
	    INTEGER(ans)[i4 +3] = R_ALPHA(icol);
	}
    } else {
	for(i = i4 = 0; i < n; i++, i4 += 4) {
	    col = INTEGER(colors)[i];
	    if      (col == NA_INTEGER) col = R_TRANWHITE;
	    else if (col == 0)          col = bg;
	    else 		        col = R_ColorTable[(unsigned int)(col-1) % R_ColorTableSize];
	    if (col == BG_NEEDED)
	    	col = bg = dpptr(GEcurrentDevice())->bg;
	    icol = (unsigned int)col;
	    INTEGER(ans)[i4 +0] = R_RED(icol);
	    INTEGER(ans)[i4 +1] = R_GREEN(icol);
	    INTEGER(ans)[i4 +2] = R_BLUE(icol);
	    INTEGER(ans)[i4 +3] = R_ALPHA(icol);
	}
    }
    UNPROTECT(3);
    return ans;
}