static void bmp_get_row_data_for_8(bmpfile_t *bmp, unsigned char *buf, size_t buf_len, uint32_t row) { int i; if (bmp->dib.width > buf_len) return; for (i = 0; i < bmp->dib.width; ++i) buf[i] = find_closest_color(bmp, bmp->pixels[i][row]); }
union tree *get_layer(struct db_tree_state *tsp, const struct db_full_path *pathp, union tree *UNUSED(curtree), void *UNUSED(client_data)) { char *layer_name; int color_num; layer_name = db_path_to_string(pathp); color_num = find_closest_color(tsp->ts_mater.ma_color); fprintf(fp, "0\nLAYER\n2\n%s\n62\n%d\n", layer_name, color_num); bu_free(layer_name, "layer name"); return (union tree *)NULL; }
void bmp_to_array(int* pixels, bmpfile_t* bmp_read, int width, int height ){ int i, j; #pragma omp parallel for private(j) for( i = 0; i < width; ++i){ for( j= 0; j < height; ++j){ //printf("Thread %i : i is %i j is %i \n", omp_get_thread_num(), i, j); rgb_pixel_t *pixel = bmp_get_pixel(bmp_read, i, j); pixels[i*height + j] = find_closest_color( bmp_read, *pixel); } } //printf("hello\n"); }
static void bmp_get_row_data_for_4(bmpfile_t *bmp, unsigned char *buf, size_t buf_len, uint32_t row) { uint8_t pos_weights[2] = {16, 1}; uint32_t i = 0, j, k = 0; uint32_t index; if (bmp->dib.width > 2 * buf_len) return; while (i < bmp->dib.width) { for (j = 0, index = 0; j < 2 && i < bmp->dib.width; ++i, ++j) index += pos_weights[j] * find_closest_color(bmp, bmp->pixels[i][row]); buf[k++] = index & 0xff; } }
static void build_shading_tables16( struct rgb_color *colors, short color_count, pixel16 *shading_tables, byte *remapping_table) { short i; short start, count, level; memset(shading_tables, iBLACK, PIXEL8_MAXIMUM_COLORS*sizeof(pixel8)); start= 0, count= 0; while (get_next_color_run(colors, color_count, &start, &count)) { for (i= 0; i<count; ++i) { for (level= 0; level<number_of_shading_tables; ++level) { struct rgb_color *color= colors + start + i; RGBColor result; short result_index; result.red= (color->red*level)/(number_of_shading_tables-1); result.green= (color->green*level)/(number_of_shading_tables-1); result.blue= (color->blue*level)/(number_of_shading_tables-1); result_index= find_closest_color(&result, colors, color_count); shading_tables[PIXEL8_MAXIMUM_COLORS*level+start+i]= RGBCOLOR_TO_PIXEL16(colors[result_index].red, colors[result_index].green, colors[result_index].blue); } } } return; }
static void nmg_to_dxf(struct nmgregion *r, const struct db_full_path *pathp, int UNUSED(region_id), int UNUSED(material_id), float color[3]) { struct model *m; struct shell *s; struct vertex *v; struct bu_ptbl verts; char *region_name; int region_polys=0; int tri_count=0; int color_num; int do_triangulate=0; NMG_CK_REGION(r); RT_CK_FULL_PATH(pathp); region_name = db_path_to_string(pathp); m = r->m_p; NMG_CK_MODEL(m); /* Count triangles */ for (BU_LIST_FOR(s, shell, &r->s_hd)) { struct faceuse *fu; NMG_CK_SHELL(s); for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) { struct loopuse *lu; int vert_count=0; NMG_CK_FACEUSE(fu); if (fu->orientation != OT_SAME) continue; for (BU_LIST_FOR(lu, loopuse, &fu->lu_hd)) { struct edgeuse *eu; if (BU_LIST_FIRST_MAGIC(&lu->down_hd) != NMG_EDGEUSE_MAGIC) continue; for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) { vert_count++; } if (vert_count > 3) { do_triangulate = 1; goto triangulate; } tri_count++; } } } triangulate: if (do_triangulate) { /* triangulate model */ nmg_triangulate_model(m, &tol); /* Count triangles */ tri_count = 0; for (BU_LIST_FOR(s, shell, &r->s_hd)) { struct faceuse *fu; for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) { struct loopuse *lu; if (fu->orientation != OT_SAME) continue; for (BU_LIST_FOR(lu, loopuse, &fu->lu_hd)) { if (BU_LIST_FIRST_MAGIC(&lu->down_hd) != NMG_EDGEUSE_MAGIC) continue; tri_count++; } } } } nmg_vertex_tabulate(&verts, &r->l.magic); color_num = find_closest_color(color); if (polyface_mesh) { size_t i; fprintf(fp, "0\nPOLYLINE\n8\n%s\n62\n%d\n70\n64\n71\n%lu\n72\n%d\n", region_name, color_num, (unsigned long)BU_PTBL_LEN(&verts), tri_count); for (i = 0; i < BU_PTBL_LEN(&verts); i++) { fprintf(fp, "0\nVERTEX\n8\n%s\n", region_name); v = (struct vertex *)BU_PTBL_GET(&verts, i); NMG_CK_VERTEX(v); if (inches) { fprintf(fp, "10\n%f\n20\n%f\n30\n%f\n70\n192\n", V3ARGSIN(v->vg_p->coord)); } else { fprintf(fp, "10\n%f\n20\n%f\n30\n%f\n70\n192\n", V3ARGS(v->vg_p->coord)); } } } /* Check triangles */ for (BU_LIST_FOR(s, shell, &r->s_hd)) { struct faceuse *fu; NMG_CK_SHELL(s); for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) { struct loopuse *lu; NMG_CK_FACEUSE(fu); if (fu->orientation != OT_SAME) continue; for (BU_LIST_FOR(lu, loopuse, &fu->lu_hd)) { struct edgeuse *eu; int vert_count=0; NMG_CK_LOOPUSE(lu); if (BU_LIST_FIRST_MAGIC(&lu->down_hd) != NMG_EDGEUSE_MAGIC) continue; if (polyface_mesh) { fprintf(fp, "0\nVERTEX\n8\n%s\n70\n128\n10\n0.0\n20\n0.0\n30\n0.0\n", region_name); } else { fprintf(fp, "0\n3DFACE\n8\n%s\n62\n%d\n", region_name, color_num); } /* check vertex numbers for each triangle */ for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) { NMG_CK_EDGEUSE(eu); vert_count++; v = eu->vu_p->v_p; NMG_CK_VERTEX(v); if (polyface_mesh) { fprintf(fp, "%d\n%d\n", vert_count+70, bu_ptbl_locate(&verts, (long *)v) + 1); } else { if (inches) { fprintf(fp, "%d\n%f\n%d\n%f\n%d\n%f\n", 10 + vert_count - 1, v->vg_p->coord[X] / 25.4, 20 + vert_count - 1, v->vg_p->coord[Y] / 25.4, 30 + vert_count -1, v->vg_p->coord[Z] / 25.4); } else { fprintf(fp, "%d\n%f\n%d\n%f\n%d\n%f\n", 10 + vert_count - 1, v->vg_p->coord[X], 20 + vert_count - 1, v->vg_p->coord[Y], 30 + vert_count -1, v->vg_p->coord[Z]); } } } if (vert_count > 3) { bu_free(region_name, "region name"); bu_log("lu %p has %d vertices!\n", (void *)lu, vert_count); bu_exit(1, "ERROR: LU is not a triangle\n"); } else if (vert_count < 3) { continue; } else { /* repeat the last vertex for the benefit of codes * that interpret the dxf specification for * 3DFACES as requiring a fourth vertex even when * only three are input. */ if (!polyface_mesh) { vert_count++; if (inches) { fprintf(fp, "%d\n%f\n%d\n%f\n%d\n%f\n", 10 + vert_count - 1, v->vg_p->coord[X] / 25.4, 20 + vert_count - 1, v->vg_p->coord[Y] / 25.4, 30 + vert_count -1, v->vg_p->coord[Z] / 25.4); } else { fprintf(fp, "%d\n%f\n%d\n%f\n%d\n%f\n", 10 + vert_count - 1, v->vg_p->coord[X], 20 + vert_count - 1, v->vg_p->coord[Y], 30 + vert_count -1, v->vg_p->coord[Z]); } } } tot_polygons++; region_polys++; } } } bu_ptbl_free(&verts); bu_free(region_name, "region name"); if (polyface_mesh) { fprintf(fp, "0\nSEQEND\n"); } }