static int get_fig_colour(at_color this_colour, at_exception_type * exp) { int hash, i, this_ind; hash = fig_col_hash(this_colour); /* Special case: black _IS_ zero: */ if ((hash == 0) && (at_color_equal(&(fig_colour_map[0].c), &this_colour))) { return (0); } if (fig_hash[hash].colour == 0) { fig_hash[hash].colour = LAST_FIG_COLOUR; fig_colour_map[LAST_FIG_COLOUR].c.r = this_colour.r; fig_colour_map[LAST_FIG_COLOUR].c.g = this_colour.g; fig_colour_map[LAST_FIG_COLOUR].c.b = this_colour.b; LAST_FIG_COLOUR++; if (LAST_FIG_COLOUR >= MAX_FIG_COLOUR) { LOG("Output-Fig: too many colours: %d", LAST_FIG_COLOUR); at_exception_fatal(exp, "Output-Fig: too many colours"); return 0; } return (fig_hash[hash].colour); } else { i = 0; this_ind = fig_hash[hash].colour; figcolloop: /* If colour match return current colour */ if (at_color_equal(&(fig_colour_map[this_ind].c), &this_colour)) { return (this_ind); } /* If next colour zero - set it, return */ if (fig_colour_map[this_ind].alternate == 0) { fig_colour_map[this_ind].alternate = LAST_FIG_COLOUR; fig_colour_map[LAST_FIG_COLOUR].c.r = this_colour.r; fig_colour_map[LAST_FIG_COLOUR].c.g = this_colour.g; fig_colour_map[LAST_FIG_COLOUR].c.b = this_colour.b; LAST_FIG_COLOUR++; if (LAST_FIG_COLOUR >= MAX_FIG_COLOUR) { LOG("Output-Fig: too many colours: %d", LAST_FIG_COLOUR); at_exception_fatal(exp, "Output-Fig: too many colours"); return 0; } return (fig_colour_map[this_ind].alternate); } /* Else get next colour */ this_ind = fig_colour_map[this_ind].alternate; /* Sanity check ... if colour too big - abort */ if (i++ > MAX_FIG_COLOUR) { LOG("Output-Fig: too many colours (loop): %d", i); at_exception_fatal(exp, "Output-Fig: too many colours (loop)"); return 0; } /* Else loop top */ goto figcolloop; } }
gboolean at_bitmap_equal_color(const at_bitmap * bitmap, unsigned int row, unsigned int col, at_color * color) { at_color c; g_return_val_if_fail (bitmap, FALSE); g_return_val_if_fail (color, FALSE); at_bitmap_get_color(bitmap, row, col, &c); return at_color_equal(&c, color); }
static void out_splines (FILE * epd_file, spline_list_array_type shape) { unsigned this_list; spline_list_type list; at_color last_color = {0,0,0}; for (this_list = 0; this_list < SPLINE_LIST_ARRAY_LENGTH (shape); this_list++) { unsigned this_spline; spline_type first; list = SPLINE_LIST_ARRAY_ELT (shape, this_list); first = SPLINE_LIST_ELT (list, 0); if (this_list == 0 || !at_color_equal(&list.color, &last_color)) { if (this_list > 0) { OUT_LINE ((shape.centerline || list.open) ? "S" : "f"); OUT_LINE("h"); } OUT4 ("%.3f %.3f %.3f %s\n", (double) list.color.r / 255.0, (double) list.color.g / 255.0, (double) list.color.b / 255.0, (shape.centerline || list.open) ? "RG" : "rg"); last_color = list.color; } OUT_COMMAND2 (START_POINT (first).x, START_POINT (first).y, "m"); for (this_spline = 0; this_spline < SPLINE_LIST_LENGTH (list); this_spline++) { spline_type s = SPLINE_LIST_ELT (list, this_spline); if (SPLINE_DEGREE (s) == LINEARTYPE) OUT_COMMAND2 (END_POINT (s).x, END_POINT (s).y, "l"); else OUT_COMMAND6 (CONTROL1 (s).x, CONTROL1 (s).y, CONTROL2 (s).x, CONTROL2 (s).y, END_POINT (s).x, END_POINT (s).y, "c"); } } if (SPLINE_LIST_ARRAY_LENGTH(shape) > 0) OUT_LINE ((shape.centerline || list.open) ? "S" : "f"); }
static void out_splines(FILE * file, spline_list_array_type shape, int height) { unsigned this_list; spline_list_type list; at_color last_color = { 0, 0, 0 }; for (this_list = 0; this_list < SPLINE_LIST_ARRAY_LENGTH(shape); this_list++) { unsigned this_spline; spline_type first; list = SPLINE_LIST_ARRAY_ELT(shape, this_list); first = SPLINE_LIST_ELT(list, 0); if (this_list == 0 || !at_color_equal(&list.color, &last_color)) { if (this_list > 0) { if (!(shape.centerline || list.open)) fputs("z", file); fputs("\"/>\n", file); } fprintf(file, "<path style=\"%s:#%02x%02x%02x; %s:none;\" d=\"", (shape.centerline || list.open) ? "stroke" : "fill", list.color.r, list.color.g, list.color.b, (shape.centerline || list.open) ? "fill" : "stroke"); } fprintf(file, "M%g %g", START_POINT(first).x, height - START_POINT(first).y); for (this_spline = 0; this_spline < SPLINE_LIST_LENGTH(list); this_spline++) { spline_type s = SPLINE_LIST_ELT(list, this_spline); if (SPLINE_DEGREE(s) == LINEARTYPE) { fprintf(file, "L%g %g", END_POINT(s).x, height - END_POINT(s).y); } else { fprintf(file, "C%g %g %g %g %g %g", CONTROL1(s).x, height - CONTROL1(s).y, CONTROL2(s).x, height - CONTROL2(s).y, END_POINT(s).x, height - END_POINT(s).y); } last_color = list.color; } } if (!(shape.centerline || list.open)) fputs("z", file); if (SPLINE_LIST_ARRAY_LENGTH(shape) > 0) fputs("\"/>\n", file); }
/****************************************************************************** * This function outputs a complete layer table for all 255 colors. */ void output_layer(FILE *dxf_file, spline_list_array_type shape) { int i, idx; char layerlist[256]; unsigned this_list; at_color last_color = {0,0,0}; memset(layerlist, 0, sizeof(layerlist)); for (this_list = 0; this_list < SPLINE_LIST_ARRAY_LENGTH (shape); this_list++) { spline_list_type list = SPLINE_LIST_ARRAY_ELT (shape, this_list); at_color curr_color = (list.clockwise && shape.background_color != NULL) ? *(shape.background_color) : list.color; if (&this_list == 0 || !at_color_equal(&curr_color, &last_color)) { if (!(curr_color.r==0 && curr_color.g==0 && curr_color.b==0) || !color_check) { idx = GetIndexByRGBValue(curr_color.r, curr_color.g, curr_color.b); layerlist[idx-1] = 1; last_color = curr_color; } } } OUT_LINE(" 0"); OUT_LINE("SECTION"); OUT_LINE(" 2"); OUT_LINE("TABLES"); OUT_LINE(" 0"); OUT_LINE("TABLE"); OUT_LINE(" 2"); OUT_LINE("LAYER"); OUT_LINE(" 70"); OUT_LINE(" 2048"); OUT_LINE(" 0"); OUT_LINE("LAYER"); OUT_LINE(" 2"); OUT_LINE("0"); OUT_LINE(" 70"); OUT_LINE(" 0"); OUT_LINE(" 62"); OUT_LINE(" 7"); OUT_LINE(" 6"); OUT_LINE("CONTINUOUS"); for (i=1; i<256; i++) { if (layerlist[i-1]) { OUT_LINE(" 0"); OUT_LINE("LAYER"); OUT_LINE(" 2"); OUT1 ("C%d\n", i); OUT_LINE(" 70"); OUT_LINE(" 64"); OUT_LINE(" 62"); OUT1 ("%d\n", i); OUT_LINE(" 6"); OUT_LINE("CONTINUOUS"); } } OUT_LINE(" 0"); OUT_LINE("ENDTAB"); OUT_LINE (" 0"); OUT_LINE ("ENDSEC"); }
/****************************************************************************** * This function outputs the DXF code which produces the polylines */ static void out_splines (FILE * dxf_file, spline_list_array_type shape) { unsigned this_list; double startx, starty; xypnt_head_rec *vec, *res; xypnt pnt, pnt_old = {0,0}; char fin, new_layer=0, layerstr[10]; int i, first_seg = 1, idx; strcpy(layerstr, "C1"); for (this_list = 0; this_list < SPLINE_LIST_ARRAY_LENGTH (shape); this_list++) { unsigned this_spline; at_color last_color = {0,0,0}; spline_list_type list = SPLINE_LIST_ARRAY_ELT (shape, this_list); spline_type first = SPLINE_LIST_ELT (list, 0); at_color curr_color = curr_color = (list.clockwise && shape.background_color != NULL)? *(shape.background_color) : list.color; if (this_list == 0 || !at_color_equal(&curr_color, &last_color)) { if (!(curr_color.r==0 && curr_color.g==0 && curr_color.b==0) || !color_check) { idx = GetIndexByRGBValue(curr_color.r, curr_color.g, curr_color.b); sprintf(layerstr, "C%d", idx); new_layer = 1; last_color = curr_color; } } startx = START_POINT (first).x; starty = START_POINT (first).y; if (!first_seg) { if (ROUND(startx*RESOLUTION) != pnt_old.xp || ROUND(starty*RESOLUTION) != pnt_old.yp || new_layer) { /* must begin new polyline */ new_layer = 0; fprintf(dxf_file, " 0\nSEQEND\n 8\n%s\n", layerstr); fprintf(dxf_file, " 0\nPOLYLINE\n 8\n%s\n 66\n1\n 10\n%f\n 20\n%f\n", layerstr, startx, starty); fprintf(dxf_file, " 0\nVERTEX\n 8\n%s\n 10\n%f\n 20\n%f\n", layerstr, startx, starty); pnt_old.xp = ROUND(startx*RESOLUTION); pnt_old.yp = ROUND(starty*RESOLUTION); } } else { fprintf(dxf_file, " 0\nPOLYLINE\n 8\n%s\n 66\n1\n 10\n%f\n 20\n%f\n", layerstr, startx, starty); fprintf(dxf_file, " 0\nVERTEX\n 8\n%s\n 10\n%f\n 20\n%f\n", layerstr, startx, starty); pnt_old.xp = ROUND(startx*RESOLUTION); pnt_old.yp = ROUND(starty*RESOLUTION); } for (this_spline = 0; this_spline < SPLINE_LIST_LENGTH (list); this_spline++) { spline_type s = SPLINE_LIST_ELT (list, this_spline); if (SPLINE_DEGREE (s) == LINEARTYPE) { if (ROUND(startx*RESOLUTION) != pnt_old.xp || ROUND(starty*RESOLUTION) != pnt_old.yp || new_layer) { /* must begin new polyline */ new_layer = 0; fprintf(dxf_file, " 0\nSEQEND\n 8\n%s\n", layerstr); fprintf(dxf_file, " 0\nPOLYLINE\n 8\n%s\n 66\n1\n 10\n%f\n 20\n%f\n", layerstr, startx, starty); fprintf(dxf_file, " 0\nVERTEX\n 8\n%s\n 10\n%f\n 20\n%f\n", layerstr, startx, starty); } fprintf(dxf_file, " 0\nVERTEX\n 8\n%s\n 10\n%f\n 20\n%f\n", layerstr, END_POINT(s).x, END_POINT (s).y); startx = END_POINT(s).x; starty = END_POINT(s).y; pnt_old.xp = ROUND(startx*RESOLUTION); pnt_old.yp = ROUND(starty*RESOLUTION); } else { vec = (struct xypnt_head_t *)calloc(1, sizeof (struct xypnt_head_t)); pnt.xp = ROUND(startx*RESOLUTION); pnt.yp = ROUND(starty*RESOLUTION); xypnt_add_pnt(vec, pnt); pnt.xp = ROUND(CONTROL1(s).x*RESOLUTION); pnt.yp = ROUND(CONTROL1 (s).y*RESOLUTION); xypnt_add_pnt(vec, pnt); pnt.xp = ROUND(CONTROL2(s).x*RESOLUTION); pnt.yp = ROUND(CONTROL2 (s).y*RESOLUTION); xypnt_add_pnt(vec, pnt); pnt.xp = ROUND(END_POINT(s).x*RESOLUTION); pnt.yp = ROUND(END_POINT (s).y*RESOLUTION); xypnt_add_pnt(vec, pnt); res = NULL; /* Note that spline order can be max. 4 since we have only 4 spline control points */ bspline_to_lines(vec, &res, 4, 4, 10000); xypnt_first_pnt(res, &pnt, &fin); if (pnt.xp != pnt_old.xp || pnt.yp != pnt_old.yp || new_layer) { /* must begin new polyline */ new_layer = 0; fprintf(dxf_file, " 0\nSEQEND\n 8\n%s\n", layerstr); fprintf(dxf_file, " 0\nPOLYLINE\n 8\n%s\n 66\n1\n 10\n%f\n 20\n%f\n", layerstr, (double)pnt.xp/RESOLUTION, (double)pnt.yp/RESOLUTION); fprintf(dxf_file, " 0\nVERTEX\n 8\n%s\n 10\n%f\n 20\n%f\n", layerstr, (double)pnt.xp/RESOLUTION, (double)pnt.yp/RESOLUTION); } i = 0; while (!fin) { if (i) { fprintf(dxf_file, " 0\nVERTEX\n 8\n%s\n 10\n%f\n 20\n%f\n", layerstr, (double)pnt.xp/RESOLUTION, (double)pnt.yp/RESOLUTION); } xypnt_next_pnt(res, &pnt, &fin); i++; } pnt_old = pnt; xypnt_dispose_list(&vec); xypnt_dispose_list(&res); startx = END_POINT(s).x; starty = END_POINT(s).y; free(res); free(vec); } } first_seg = 0; last_color = curr_color; } fprintf(dxf_file, " 0\nSEQEND\n 8\n0\n"); }