static void store_white_and_black() { int i; struct clr_lst *clr; strcpy(cur_shape, "dot"); cur_angle = 45.; cur_cmyk_flag = 0; cur_plate = 0; cur_tint = 100; cur_screen = 72; strcpy(cur_op, "false"); strcpy(cur_color_name,""); strcpy(cur_type,"process"); for (i=0; i<4; i++) cur_cmyk[i] = 0.0; if ( !(clr = find_color(0, 0)) ) /* look for white in plate 0*/ { cur_pct = 0.; cur_color_id = 0; store_color(0); /* white not defined, define it */ } if ( !(clr = find_color(1, 0)) ) /* look for black in plate 0 */ { /* black not defined, define it */ cur_pct = 100.; cur_color_id = 1; store_color(0); } } /* end function */
int color_check(int color, int def) { /* color - got it? def - use if not */ int i; uint32 plate; uint32 loop_temp; struct clr_lst *tp = 0; if (color < 0) { #ifdef TRACE if (color_trace) p_info(PI_TRACE, "color_check color %d unspecified ret(%d).\n",color,def); #endif return(def); } if ( !KeyOutputType) tp = find_color(color, 0); /* plate zero for composite */ else { /* look for plate if not composite */ for (i=0; i<MAX_CLRS-1; i++) { plate = (loop_temp= ( 1 << i )) & cc_mask; if (plate) { tp = find_color(color, i + 1); if (tp) break; } if(loop_temp >= cc_mask) break; } /* end for (i=1; i<MAX_CLRS-1; i++) */ } /* end else not composite */ if(tp == 0) /* can't find it? */ { #ifdef TRACE if (color_trace) p_info(PI_TRACE, "color_check color %d unspecified ret(%d).\n",color,def); #endif return(def); /* use second choice */ } else { #ifdef TRACE if (color_trace) p_info(PI_TRACE, "color_check found color %d @ %x.\n",color,(unsigned)tp); #endif } return(color); /* ok, use it */ }
int calculate_pixel(t_pov *pov, t_pixel *pixel, t_object *objects, t_coordinate *lightsource) { t_coordinate rayvector; int i; int color; t_intersect intersect; t_intersect intersectsaved; intersectsaved.k = 0.0; i = 0; calculate_vector(pov, pixel, &rayvector); color = 0x00000000; while (i < OBJECTS_NB) { intersect = calculate_intersection(pov, &rayvector, &objects[i]); if ((intersect.k < intersectsaved.k && intersect.k > 0) || (intersect.k > 0 && intersectsaved.k == 0)) intersectsaved = intersect; i++; } if (intersectsaved.k != 0) color = find_color(&intersectsaved, pov, &rayvector, lightsource, objects); return (color); }
void init_palmap() { int i; memset(pal_use,0,sizeof(pal_use)); // nuluj pristupy k barvam for(i=0;i<256;i++) color_map[i]=find_color(hipal[i]); //redukuj paletu; max_colors=256; // pocet barev zatim 256; }
/* Look up colors. */ int raw_color(const security_context_t raw, char **color_str) { #define CHARS_PER_COLOR 16 context_t con; uint32_t i, j, mask = 0; const secolor_t *items[N_COLOR]; char *result, *components[N_COLOR]; char buf[CHARS_PER_COLOR + 1]; size_t result_size = (N_COLOR * CHARS_PER_COLOR) + 1; int rc = -1; if (!color_str || *color_str) { return -1; } /* parse context and allocate memory */ con = context_new(raw); if (!con) return -1; if (parse_components(con, components) < 0) goto out; result = malloc(result_size); if (!result) goto out; result[0] = '\0'; /* find colors for which we have a match */ for (i = 0; i < N_COLOR; i++) { items[i] = find_color(i, components[i], raw); if (items[i]) mask |= (1 << i); } if (mask == 0) { items[0] = &default_color; mask = 1; } /* propagate colors according to the precedence rules */ for (i = 0; i < N_COLOR; i++) if (!(mask & (1 << i))) for (j = 0; j < N_COLOR - 1; j++) if (mask & (1 << precedence[i][j])) { items[i] = items[precedence[i][j]]; break; } /* print results into a big long string */ for (i = 0; i < N_COLOR; i++) { snprintf(buf, sizeof(buf), "#%06x #%06x ", items[i]->fg, items[i]->bg); strncat(result, buf, result_size-1); } *color_str = result; rc = 0; out: context_free(con); return rc; }
void draw_next_y(t_datas *datas, t_line *line, t_mlx *mlx) { t_line *next_y; t_alt alt; next_y = find_next_y(&datas, line->x, line->y + 1); if (line->color == find_color("0xffffff")) { alt.col_n = GET_COLOR(find_color(modify_colors(line, mlx))); alt.col_p = GET_COLOR(find_color(modify_colors(next_y, mlx))); } else { alt.col_n = GET_COLOR(line->color); alt.col_p = GET_COLOR(next_y->color); } mlx_draw_line_2(line, next_y, mlx, alt); }
void parse_color_def(struct high_color **color_list, unsigned char *p, unsigned char *name, int line) { unsigned char bf[256]; if (!parse_tows(&p, bf)) { struct high_color *color, *gcolor; /* Find color */ color = find_color(*color_list, bf, name); /* If it doesn't exist, create it */ if (!color) { color = joe_malloc(sizeof(struct high_color)); color->name = zdup(bf); color->color = 0; color->next = *color_list; *color_list = color; } else { i_printf_2((char *)joe_gettext(_("%s %d: Class already defined\n")), name, line); } /* Find it in global list */ if (color_list != &global_colors && (gcolor = find_color(global_colors, bf, name))) { color->color = gcolor->color; } else { /* Parse color definition */ while (parse_ws(&p, '#'), !parse_ident(&p, bf, sizeof(bf))) { color->color |= meta_color(bf); } } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing class name\n")), name, line); } }
static void compute(pixel *pal) { pixel r,g,b; for (r = 0; r < VALUES; r++) for (g = 0; g < VALUES; g++) for (b = 0; b < VALUES; b++) Table[r*VALUES*VALUES + g*VALUES + b] = find_color(pal, r*STEP, g*STEP, b*STEP); }
void drawWndPoint(KWWnd_t *wp, KWColor_t color, int x, int y) { KWDrawPointReq_t *req = NULL; req = AllocReq(wp, DrawPoint); req->color = find_color(TRUECOLOR_0888, color); req->x = x; req->y = y; }
int rgb_to_color(int r, int g, int b) { int color = find_color(r, g, b); if (color != -1) return color; fprintf(stderr, "color #%02x%02x%02x not declared\n", r, g, b); exit(EXIT_FAILURE); }
static gboolean parse_color (const char *spec, XPMColor *colorPtr) { if (spec[0] == '#') { char fmt[16]; int i, red, green, blue; if ((i = strlen (spec + 1)) % 3) { return FALSE; } i /= 3; g_snprintf (fmt, 16, "%%%dx%%%dx%%%dx", i, i, i); if (sscanf (spec + 1, fmt, &red, &green, &blue) != 3) { return FALSE; } if (i == 4) { colorPtr->red = red; colorPtr->green = green; colorPtr->blue = blue; } else if (i == 1) { colorPtr->red = (red * 0xFFFF) / 0xF; colorPtr->green = (green * 0xFFFF) / 0xF; colorPtr->blue = (blue * 0xFFFF) / 0xF; } else if (i == 2) { colorPtr->red = (red * 0xFFFF) / 0xFF; colorPtr->green = (green * 0xFFFF) / 0xFF; colorPtr->blue = (blue * 0xFFFF) / 0xFF; } else /* if (i == 3) */ { colorPtr->red = (red * 0xFFFF) / 0xFFF; colorPtr->green = (green * 0xFFFF) / 0xFFF; colorPtr->blue = (blue * 0xFFFF) / 0xFFF; } } else { if (!find_color(spec, colorPtr)) { return FALSE; } } return TRUE; }
static void update_action_color(struct syntax *syn, struct action *a) { const char *name = a->emit_name; const char *def; char full[64]; if (!name) name = a->destination->emit_name; snprintf(full, sizeof(full), "%s.%s", syn->name, name); a->emit_color = find_color(full); if (a->emit_color) return; def = find_default_color(syn, name); if (!def) return; snprintf(full, sizeof(full), "%s.%s", syn->name, def); a->emit_color = find_color(full); }
void fillWndRect(KWWnd_t *wp, KWColor_t color, int x, int y, int width, int height, bool dotted) { KWFillRectReq_t *req = NULL; req = AllocReq(wp, FillRect); req->color = find_color(TRUECOLOR_0888, color); req->x = x; req->y = y; req->width = width; req->height = height; req->dotted = dotted; }
void drawWndLine(KWWnd_t *wp, KWColor_t color, int x1, int y1, int x2, int y2, bool dotted) { KWDrawLineReq_t *req = NULL; req = AllocReq(wp, DrawLine); req->color = find_color(TRUECOLOR_0888, color); req->x1 = x1; req->y1 = y1; req->x2 = x2; req->y2 = y2; req->dotted = dotted; }
t_point *new_point(int x, int y, char *z) { t_point *point; if (!(point = (t_point *)malloc(sizeof(*point)))) str_exit(-1, "new.c : Error line 19"); point->x = x; point->y = y; point->z = ft_atoi(z); point->color = find_color(z); point->savecolor = point->color; free(z); return (point); }
int declare_color(int r, int g, int b) { int color = find_color(r, g, b); if (color != -1) return color; color = numcolors++; colors = realloc(colors, sizeof(*colors) * (numcolors)); colors[color].r = r; colors[color].g = g; colors[color].b = b; return color; }
static gboolean parse_color (const char *spec, XPMColor *colorPtr) { if (spec[0] == '#') { int i, red, green, blue; if ((i = strlen (spec + 1)) % 3) { return FALSE; } i /= 3; if (i == 4) { if (sscanf (spec + 1, "%4x%4x%4x", &red, &green, &blue) != 3) return FALSE; colorPtr->red = red; colorPtr->green = green; colorPtr->blue = blue; } else if (i == 1) { if (sscanf (spec + 1, "%1x%1x%1x", &red, &green, &blue) != 3) return FALSE; colorPtr->red = (red * 65535) / 15; colorPtr->green = (green * 65535) / 15; colorPtr->blue = (blue * 65535) / 15; } else if (i == 2) { if (sscanf (spec + 1, "%2x%2x%2x", &red, &green, &blue) != 3) return FALSE; colorPtr->red = (red * 65535) / 255; colorPtr->green = (green * 65535) / 255; colorPtr->blue = (blue * 65535) / 255; } else /* if (i == 3) */ { if (sscanf (spec + 1, "%3x%3x%3x", &red, &green, &blue) != 3) return FALSE; colorPtr->red = (red * 65535) / 4095; colorPtr->green = (green * 65535) / 4095; colorPtr->blue = (blue * 65535) / 4095; } } else { if (!find_color(spec, colorPtr)) return FALSE; } return TRUE; }
void calc_image(t_img *img) { int x; int y; int color; // img->scene.ray.orig.x = 0; // img->scene.ray.orig.y = 0; // img->scene.ray.orig.z = -10; y = 0; while (y < WIN_HGT) { x = 0; while (x < WIN_WIDTH) { // calc_dir(&img->scene.ray, x, y); img->scene.ray = prim_ray(&img->scene.cam, x, y); color = find_color(img); fill(img, x, y, color); x++; } y++; } }
//map sprites to screen location: void PianoRenderCache::Piano_load_sprite_map(const wxString& filename) //, int BufferWi, int BufferHt) //, bool clip) { debug_function(10); debug(1, "load sprite map file %s", (const char*)filename.c_str()); wxTextFile f; int numbad = 0; if (!CachedMapFilename.CmpNoCase(filename)) { debug_more(2, ", no change"); return; } //no change if (!wxFileExists(filename)) return; if (!f.Open(filename.c_str())) return; Piano_flush_map(); //invalidate cached data debug(3, "read file"); for (wxString linebuf = f.GetFirstLine(); !f.Eof(); linebuf = f.GetNextLine()) { std::string::size_type ofs; if ((ofs = linebuf.find("#")) != std::string::npos) linebuf.erase(ofs); //remove comments while (!linebuf.empty() && (linebuf.Last() == '\\')) //line continuation { linebuf.RemoveLast(); //remove trailing "\" /*std::*/wxString morebuf = f.GetNextLine(); if (f.Eof()) break; linebuf += morebuf; } while (!linebuf.empty() && isspace(linebuf.Last())) linebuf.RemoveLast(); //trim trailing spaces if (linebuf.empty()) continue; //skip blank lines //#Sprite-name Xon Yon Xoff Yoff W H DestX DestY DestZ debug(20, "got line '%s'", (const char*)linebuf.c_str()); linebuf += "\teol"; //end-of-line check for missing params wxStringTokenizer tkz(linebuf, "\t"); Sprite spr; spr.name = tkz.GetNextToken(); //first column = sprite name if (spr.name.find(".") == -1) spr.name += ".000"; //kludge: change name to match Audacity Polyphonic nodes int srcx_on = wxAtoi(tkz.GetNextToken()); //x coordinate for "on" state int srcy_on = wxAtoi(tkz.GetNextToken()); //y coordinate for "on" state int srcx_off = wxAtoi(tkz.GetNextToken()); //x coordinate for "off" state int srcy_off = wxAtoi(tkz.GetNextToken()); //y coordinate for "off" state spr.wh.x = wxAtoi(tkz.GetNextToken()); //sprite width spr.wh.y = wxAtoi(tkz.GetNextToken()); //spriate height spr.destxy.x = wxAtoi(tkz.GetNextToken()); //destination x coordinate spr.destxy.y = wxAtoi(tkz.GetNextToken()); //destination y coordinate spr.destz = wxAtoi(tkz.GetNextToken()); //destination layer // if (spr.destz > 10) spr.destz = 10; //limit to 10 layers wxString junk = tkz.GetNextToken(); if (/* !junk.empty()*/ junk.Cmp("eol")) { debug_more(20, ", junk at end '%s'", (const char*)junk.c_str()); continue; } //TODO: show error messages? debug_more(10, " => srcx/y on %d/%d, off %d/%d, sprite w/h %d/%d, dest x/y/z %d/%d/%d, junk? '%s'", srcx_on, srcy_on, srcx_off, srcy_off, spr.wh.x, spr.wh.y, spr.destxy.x, spr.destxy.y, spr.destz, (const char*)junk.c_str()); // if (!clip) { spr.destxy.x %= BufferWi; spr.destxy.y %= BufferWi; } //wrap // else if ((spr.destxy.x >= BufferWi) || (spr.destxy.y >= BufferHi) || (spr.destxy.x + keyw < 0) || (spr.destxy.y + keyh < 0)) continue; //outside of visible rect if ((srcx_off != srcx_on) || (srcy_off != srcy_on)) //need to draw when off also { if ((srcx_off < 0) || (srcx_off + spr.wh.x > Shapes.GetWidth()) || (srcy_off < 0) || (srcy_off + spr.wh.y > Shapes.GetHeight())) { debug_more(10, ": NO1"); ++numbad; continue; } //ignore invalid sprites spr.xy.push_back(wxPoint(srcx_off, srcy_off)); //state 0 == key off/up spr.off = find_color(Shapes, ColorMap, spr.xy.back(), spr.wh, "off"); } if ((srcx_on < 0) || (srcx_on + spr.wh.x > Shapes.GetWidth()) || (srcy_on < 0) || (srcy_on + spr.wh.y > Shapes.GetHeight())) { debug_more(10, ": NO2"); ++numbad; continue; } //ignore invalid sprites spr.xy.push_back(wxPoint(srcx_on, srcy_on)); //state 1 == key on/down spr.on = find_color(Shapes, ColorMap, spr.xy.back(), spr.wh, "on"); spr.ani_state = 0; //inactive // spr.repeat = 0; AllSprites[spr.name.ToStdString()] = spr; // if (spr.destz >= ByLayer.size()) ByLayer.resize(spr.destz + 1); //add new layer // ByLayer[spr.destz].push_back(&AllSprites[spr.name.ToStdString()]); debug_more(10, ", added '%s' ok? %d", spr.name.ToStdString().c_str(), AllSprites.find(spr.name.ToStdString()) != AllSprites.end()); } debug(1, "%d shapes loaded, %d invalid", AllSprites.size(), numbad); //, ByLayer.size()); CachedMapFilename = filename; //don't load same file again }
/* Load level and prepare for new game */ void load_level (struct LevelFile *lev) { SDL_Surface *collmap; int x, y, p, r; int freepix, otherpix; SDL_Color *tmpcol, defaultwater; Uint8 *bits; int basebufsize; defaultwater.r = 0; defaultwater.g = 0; defaultwater.b = 255; /* Load level artwork */ lev_level.terrain = load_level_art (lev); lev_level.width = lev_level.terrain->w; lev_level.height = lev_level.terrain->h; /* Load level collisionmap */ collmap = load_level_coll (lev); if (!collmap) { printf ("An error occured while loading collisionmap\n"); exit (1); } if (collmap->w != lev_level.width || collmap->h != lev_level.height) { printf ("Error Collision map image \"%s\" has incorrect size (%dx%d), should be %dx%d!\n", lev->settings->mainblock.collmap, collmap->w, collmap->h, lev_level.width, lev_level.height); exit (1); } /* Get palette entries */ /* Get water colour */ tmpcol = &defaultwater; find_color(TER_WATER,lev->settings->palette.entries, collmap->format->palette,&tmpcol); lev_watercol = map_rgba(tmpcol->r, tmpcol->g, tmpcol->b,0xff); /* Calculate underwater clay colour */ col_clay_uw = map_rgba((tmpcol->r+255)/2, (tmpcol->r+200)/2, (tmpcol->r+128)/2, 0xff); /* Get snow colour */ tmpcol = NULL; find_color(TER_SNOW,lev->settings->palette.entries, collmap->format->palette,&tmpcol); if (tmpcol) { col_snow = map_rgba(tmpcol->r, tmpcol->g, tmpcol->b,0xff); } /* Prepare base regeneration array */ if(game_settings.base_regen) { basebufsize=512; /* Some arbitary size */ lev_level.base = malloc(sizeof(RegenCoord)*basebufsize); } else { basebufsize=0; lev_level.base = NULL; } /* Load data map */ lev_level.base_area = 0; lev_level.regen_area = 0; lev_level.solid = malloc (sizeof (char *) * lev_level.width); freepix = 0; otherpix = 0; for (x = 0; x < lev_level.width; x++) { bits = ((Uint8 *) collmap->pixels)+x; lev_level.solid[x] = malloc (lev_level.height); for (y = 0; y < lev_level.height; y++,bits+=collmap->pitch) { lev_level.solid[x][y] = lev->settings->palette.entries[*bits]; if (lev_level.solid[x][y] == TER_FREE || lev_level.solid[x][y] == TER_WATER) freepix++; else { otherpix++; if (lev_level.solid[x][y] == TER_BASE) { if(lev_level.base) { Uint8 r,g,b; lev_level.base[lev_level.base_area].x=x; lev_level.base[lev_level.base_area].y=y; SDL_GetRGB(getpixel(lev_level.terrain,x,y), screen->format, &r, &g, &b); lev_level.base[lev_level.base_area].c= map_rgba(r, g, b, 0xff); if(lev_level.base_area==basebufsize-1) { basebufsize+=512; lev_level.base=realloc(lev_level.base, sizeof(RegenCoord)*basebufsize); } } lev_level.base_area++; } } } } SDL_FreeSurface (collmap); /* Finalize the base regeneration buffer */ if(lev_level.base) { lev_level.regen_timer = 0; lev_level.regen_area = lev_level.base_area; if(lev_level.base_area<basebufsize) { basebufsize=lev_level.base_area; lev_level.base=realloc(lev_level.base, sizeof(RegenCoord)*basebufsize); } qsort(lev_level.base,lev_level.base_area,sizeof(RegenCoord),sort_regen); } /* Position players */ if (game_settings.playmode == OutsideShip || game_settings.playmode == OutsideShip1) y = 2; else y = 1; for (p = 0; p < 4; p++) if (players[p].state != INACTIVE) { for (x = 0; x < y; x++) { r = 0; do { lev_level.player_def_x[x][p] = rand () % lev_level.width; lev_level.player_def_y[x][p] = rand () % lev_level.height; r++; if (r > 100000) { fprintf(stderr, "Warning: while searching for player %d startup position, loop counter reached 100000!\n", p); fprintf(stderr, "Number of free space (including water) pixels: %d, number of other pixels: %d\n", freepix, otherpix); fprintf (stderr, "%0.3f%% of the surface area is available\n", ((double) freepix / (double) otherpix) * 100); exit (0); } } while (lev_level. solid[lev_level.player_def_x[x][p]][lev_level. player_def_y[x] [p]] != TER_FREE); } } }
/************************************************************************* ** VID_COLOR - do setup of gray (& whatever) for a color by index ** ** MUST BE WRAPPED IN GS/GR PAIR BY CALLER ** *************************************************************************/ void vid_color(int color, int shade, uint32 plate_number) { float temp_dens[4]; struct clr_lst *clr; int ii; #ifdef TRACE if (color_trace) p_info(PI_TRACE, "start vid_color(%d, %d, %lo), Black= %lo, cc_mask= %lo\n", color, shade, plate_number, BlackPaint_cc_mask, cc_mask); #endif if (color < 0) { BlackPaint_cc_mask &= ~(1 << (plate_number-1)); /* turn off a plate */ #ifdef TRACE if (color_trace) p_info(PI_TRACE, "new BlackPaint_cc_mask= %lo\n", BlackPaint_cc_mask); #endif return; } if ( !KeyOutputType) clr = find_color(color, 0); /* use color from plate 0 for composite */ else /* normal color */ clr = find_color(color, plate_number); /* find the color structure */ if(clr == 0) { #ifdef TRACE if (color_trace) p_info(PI_TRACE, "color %d on plate= %lo not defined\n", color, plate_number); #endif BlackPaint_cc_mask &= ~(1 << (plate_number-1)); /* turn off a plate */ #ifdef TRACE if (color_trace) p_info(PI_TRACE, "new BlackPaint_cc_mask= %lo\n", BlackPaint_cc_mask); #endif return; /* not defined */ } #ifdef TRACE if (color_trace) { p_info(PI_TRACE, "color= %d, reverse= %d, freq= %d, cmyk_flag= %d\n", clr->color, clr->reverse,clr->freq,clr->cmyk_flag); p_info(PI_TRACE, " c= %f, m= %f, y= %f, k= %f, dens= %f, angle= %f, func= %s op=%s\n", clr->cmyk[0],clr->cmyk[1],clr->cmyk[2],clr->cmyk[3], clr->density,clr->angle,clr->func,clr->op); } #endif /* if( (clr->density != 1.0) && */ /* need screen if not white or black */ /* (clr->density != 0.0) ) */ /* always put out screen 7/20/92 -Enhancement 33P from Dee */ #ifdef TRACE if (color_trace) { p_info(PI_TRACE, "%s setoverprint\n",clr->op); p_info(PI_TRACE, "%d %f %s setscreen (note - density= %f)\n", clr->freq, clr->angle + (double)Orient, clr->func, clr->density); p_info(PI_TRACE, "%d %f %s %s\n", old_freq, old_angle, old_func, old_op); } #endif /* setoverprint for composites only */ if ( !strcmp(clr->op,"false") && (!KeyOutputType) ) m_fprintf("false setoverprint\n"); else if ( !strcmp(clr->op,"true") && (!KeyOutputType) ) m_fprintf("true setoverprint\n"); if ( IncludeScreens ) { /* Use PP Keyword LPI for color frequency */ /* If LPI = 0, use colortable frequency */ if (LPI != 0) clr->freq = LPI; if ( (old_freq != clr->freq) || (old_angle != clr->angle) || (strcmp(old_func, clr->func)) || firstscreen || (strcmp(old_op, clr->op)) ) { m_fprintf("%d %5.2f {%s} setscreen \n", clr->freq, clr->angle + (double)Orient, clr->func); /* set screen from structure */ firstscreen = 0; } old_freq = clr->freq; old_angle = clr->angle; strcpy(old_func, clr->func); strcpy(old_op, clr->op); } if ( !CMYK_Allowed) { /* enhancement 59P - 7/28/92 */ temp_dens[0] = 1.0 - (((1.0 - clr->density) * shade) / 100.); digi_print(temp_dens[0]); /* set density */ m_fprintf("setgray\n"); if ( temp_dens[0] == 1.0) BlackPaint_cc_mask &= ~(1 << (plate_number-1)); /* white */ else BlackPaint_cc_mask |= (1 << (plate_number-1)); /* black */ #ifdef TRACE if (color_trace) { p_info(PI_TRACE, "CMYK_Allowed=0, %6.3f setgray (to .tp file)\n", temp_dens[0]); p_info(PI_TRACE, "new BlackPaint_cc_mask= %lo\n", BlackPaint_cc_mask); } #endif } if (clr -> cmyk_flag && !KeyOutputType && CMYK_Allowed) { /* set the specified color */ if ( !strcmp(clr->type, "process")) { /* Add in tint and then shade for process color only */ for (ii=0; ii<4; ii++) clr->out_cmyk[ii] = ((clr->cmyk[ii] * clr->tint) / 100.); for (ii=0; ii<4; ii++) clr->out_cmyk[ii] = ((clr->cmyk[ii] * shade) / 100.); } else { for (ii=0; ii<4; ii++) clr->out_cmyk[ii] = clr->cmyk[ii]; } temp_dens[0] = clr->out_cmyk[0]; digi_print(temp_dens[0]); /* set C */ temp_dens[1] = clr->out_cmyk[1]; digi_print(temp_dens[1]); /* set M */ temp_dens[2] = clr->out_cmyk[2]; digi_print(temp_dens[2]); /* set Y */ temp_dens[3] = clr->out_cmyk[3]; digi_print(temp_dens[3]); /* set K */ if ( !strcmp(clr->type, "process")) { /* Add used colors to color list */ if (temp_dens[0] != 0) colorsused[0]=1; /* Has Cyan */ if (temp_dens[1] != 0) colorsused[1]=1; /* Has Magenta */ if (temp_dens[2] != 0) colorsused[2]=1; /* Has Yellow */ if (temp_dens[3] != 0) colorsused[3]=1; /* Has Black */ m_fprintf(" setcmykcolor\n"); } else { for (ii=0; ii< 48; ii++) { if (strcmp(customused[ii],clr->color_name) == 0) break; /* Already Loaded */ if (customused[ii][0] == '\0') { strcpy(customused[ii],clr->color_name); /* Found Blank Spot for new entry */ sprintf(cmykcustomused[ii],"%.2f %.2f %.2f %.2f",temp_dens[0], temp_dens[1], temp_dens[2], temp_dens[3]); break; } } m_fprintf("%s %.2f pentacustomcolor\n",clr->color_name, ( (100 - clr->tint) + (100 - shade) ) / 100); } if ( (temp_dens[0] == 0.0) && (temp_dens[1] == 0.0) && (temp_dens[2] == 0.0) && (temp_dens[3] == 0.0)) BlackPaint_cc_mask &= ~(1 << (plate_number-1)); /* white */ else BlackPaint_cc_mask |= (1 << (plate_number-1)); /* black */ #ifdef TRACE if (color_trace) p_info(PI_TRACE, "%f %f %f %f set CMYK, Black= %lo\n", temp_dens[0], temp_dens[1], temp_dens[2], temp_dens[3], BlackPaint_cc_mask); #endif } else if (!clr -> cmyk_flag && CMYK_Allowed) { /* default to black */ digi_print(0.0); /* set C */ digi_print(0.0); /* set M */ digi_print(0.0); /* set Y */ temp_dens[0] = shade / 100.; if( clr->density != 1.0) { digi_print(temp_dens[0]); /* set K - black */ BlackPaint_cc_mask = 1; /* black */ } else { digi_print(0.0); /* set K - white */ BlackPaint_cc_mask = 0; /* white */ temp_dens[0] = 0.0; } /* Add used colors to color list */ if (temp_dens[0] != 0) colorsused[3]=1; /* Has Black */ m_fprintf(" setcmykcolor\n"); #ifdef TRACE if (color_trace) p_info(PI_TRACE, "0 0 0 %f set CMYK(black), Black= %lo\n", temp_dens[0], BlackPaint_cc_mask); #endif } } /* end VID_TINT */
/* * Extract the foreground, background and highlight values from an attribute * represented as a string in one of two forms: * * "(foreground,background,highlight)" " "xxxx_color" */ static int str_to_attr(char *str, int *fg, int *bg, int *hl) { int i = 0, get_fg = 1; unsigned j; char tempstr[MAX_LEN + 1], *part; if (str[0] != '(' || lastch(str) != ')') { if ((i = find_color(str)) >= 0) { *fg = dlg_color_table[i].fg; *bg = dlg_color_table[i].bg; *hl = dlg_color_table[i].hilite; return 0; } return -1; /* invalid representation */ } /* remove the parenthesis */ strcpy(tempstr, str + 1); lastch(tempstr) = '\0'; /* get foreground and background */ while (1) { /* skip white space before fg/bg string */ i = skip_whitespace(tempstr, i); if (tempstr[i] == '\0') return -1; /* invalid representation */ part = tempstr + i; /* set 'part' to start of fg/bg string */ /* find end of fg/bg string */ while (!whitespace(tempstr[i]) && tempstr[i] != ',' && tempstr[i] != '\0') i++; if (tempstr[i] == '\0') return -1; /* invalid representation */ else if (whitespace(tempstr[i])) { /* not yet ',' */ tempstr[i++] = '\0'; /* skip white space before ',' */ i = skip_whitespace(tempstr, i); if (tempstr[i] != ',') return -1; /* invalid representation */ } tempstr[i++] = '\0'; /* skip the ',' */ for (j = 0; j < COLOR_COUNT && dlg_strcmp(part, color_names[j].name); j++) ; if (j == COLOR_COUNT) /* invalid color name */ return -1; if (get_fg) { *fg = color_names[j].value; get_fg = 0; /* next we have to get the background */ } else { *bg = color_names[j].value; break; } } /* got foreground and background */ /* get highlight */ /* skip white space before highlight string */ i = skip_whitespace(tempstr, i); if (tempstr[i] == '\0') return -1; /* invalid representation */ part = tempstr + i; /* set 'part' to start of highlight string */ /* trim trailing white space from highlight string */ i = (int) strlen(part) - 1; while (whitespace(part[i]) && i > 0) i--; part[i + 1] = '\0'; if (!dlg_strcmp(part, "ON")) *hl = TRUE; else if (!dlg_strcmp(part, "OFF")) *hl = FALSE; else return -1; /* invalid highlight value */ return 0; }
/* * Parse the configuration file and set up variables */ int dlg_parse_rc(void) { int i; int l = 1; PARSE_LINE parse; char str[MAX_LEN + 1]; char *var; char *value; char *tempptr; int result = 0; FILE *rc_file = 0; char *params; /* * At startup, dialog determines the settings to use as follows: * * a) if the environment variable $DIALOGRC is set, its value determines * the name of the configuration file. * * b) if the file in (a) can't be found, use the file $HOME/.dialogrc * as the configuration file. * * c) if the file in (b) can't be found, try using the GLOBALRC file. * Usually this will be /etc/dialogrc. * * d) if the file in (c) cannot be found, use the compiled-in defaults. */ /* try step (a) */ if ((tempptr = getenv("DIALOGRC")) != NULL) rc_file = fopen(tempptr, "rt"); if (rc_file == NULL) { /* step (a) failed? */ /* try step (b) */ if ((tempptr = getenv("HOME")) != NULL && strlen(tempptr) < MAX_LEN - (sizeof(DIALOGRC) + 3)) { if (tempptr[0] == '\0' || lastch(tempptr) == '/') sprintf(str, "%s%s", tempptr, DIALOGRC); else sprintf(str, "%s/%s", tempptr, DIALOGRC); rc_file = fopen(tempptr = str, "rt"); } } if (rc_file == NULL) { /* step (b) failed? */ /* try step (c) */ strcpy(str, GLOBALRC); if ((rc_file = fopen(tempptr = str, "rt")) == NULL) return 0; /* step (c) failed, use default values */ } DLG_TRACE(("opened rc file \"%s\"\n", tempptr)); /* Scan each line and set variables */ while ((result == 0) && (fgets(str, MAX_LEN, rc_file) != NULL)) { DLG_TRACE(("rc:%s", str)); if (*str == '\0' || lastch(str) != '\n') { /* ignore rest of file if line too long */ fprintf(stderr, "\nParse error: line %d of configuration" " file too long.\n", l); result = -1; /* parse aborted */ break; } lastch(str) = '\0'; if (begins_with(str, "bindkey", ¶ms)) { if (!dlg_parse_bindkey(params)) { fprintf(stderr, "\nParse error: line %d of configuration\n", l); result = -1; } continue; } parse = parse_line(str, &var, &value); /* parse current line */ switch (parse) { case LINE_EMPTY: /* ignore blank lines and comments */ break; case LINE_EQUALS: /* search table for matching config variable name */ if ((i = find_vars(var)) >= 0) { switch (vars[i].type) { case VAL_INT: *((int *) vars[i].var) = atoi(value); break; case VAL_STR: if (!isquote(value[0]) || !isquote(lastch(value)) || strlen(value) < 2) { fprintf(stderr, "\nParse error: string value " "expected at line %d of configuration " "file.\n", l); result = -1; /* parse aborted */ } else { /* remove the (") quotes */ value++; lastch(value) = '\0'; strcpy((char *) vars[i].var, value); } break; case VAL_BOOL: if (!dlg_strcmp(value, "ON")) *((bool *) vars[i].var) = TRUE; else if (!dlg_strcmp(value, "OFF")) *((bool *) vars[i].var) = FALSE; else { fprintf(stderr, "\nParse error: boolean value " "expected at line %d of configuration " "file (found %s).\n", l, value); result = -1; /* parse aborted */ } break; } #ifdef HAVE_COLOR } else if ((i = find_color(var)) >= 0) { int fg = 0; int bg = 0; int hl = 0; if (str_to_attr(value, &fg, &bg, &hl) == -1) { fprintf(stderr, "\nParse error: attribute " "value expected at line %d of configuration " "file.\n", l); result = -1; /* parse aborted */ } else { dlg_color_table[i].fg = fg; dlg_color_table[i].bg = bg; dlg_color_table[i].hilite = hl; } } else { #endif /* HAVE_COLOR */ fprintf(stderr, "\nParse error: unknown variable " "at line %d of configuration file:\n\t%s\n", l, var); result = -1; /* parse aborted */ } break; case LINE_ERROR: fprintf(stderr, "\nParse error: syntax error at line %d of " "configuration file.\n", l); result = -1; /* parse aborted */ break; } l++; /* next line */ } (void) fclose(rc_file); return result; }