void init_color(void) { #define CLRBUFSZ 256 char clr_parse_buff[CLRBUFSZ]; char clr_parse_buff_temp[CLRBUFSZ]; char temp_name[128], temp_chap_dir[128]; char chap_tree[64]; char chap_dir[64]; char *result_ptr; float temp; int length, i; int plate_name_input; int temp_plate; int screen_found_flag; int plate_zero_stored = 0; int endflag = 0; int parent_flag = 0; memset((char *)&plate_nm[0].name[0], 0, sizeof(struct plate_name) * 33); clear_vlist(); /* clear list of reverses */ clear_color_list(); /* clear the non-standard colors */ strcpy(clr_parse_buff, SubDirName); if ((result_ptr = strrchr(clr_parse_buff, '.')) != NULL) *result_ptr = '\0'; colorfd = p_get_table1(TreeName, clr_parse_buff, ColorTableName, default_color_name); if (colorfd <= 0) { /* parent */ if(lc_parent(TreeName, SubDirName, temp_name)) { parent_flag++; p_parent_path(TreeName, clr_parse_buff, temp_name, chap_tree, chap_dir); strcpy(temp_chap_dir, chap_dir); if ((result_ptr = strrchr(temp_chap_dir, '.')) != NULL) *result_ptr = '\0'; colorfd = p_get_table1(chap_tree, temp_chap_dir, ColorTableName, default_color_name); } } if (colorfd <= 0) /* Tree/tables and .default/tables */ colorfd = p_get_table2(TreeName, clr_parse_buff, ColorTableName, default_color_name); if ( (colorfd <= 0) && strcmp(ColorTableName, "colortable") ) { /* try using colortable.ct */ strcpy (clr_parse_buff_temp, "colortable"); colorfd = p_get_table1(TreeName, clr_parse_buff, clr_parse_buff_temp, default_color_name); if (colorfd <= 0) { if ( parent_flag) colorfd = p_get_table1(chap_tree, temp_chap_dir, clr_parse_buff_temp, default_color_name); } if (colorfd <= 0) /* Tree/tables and .default/tables */ colorfd = p_get_table2(TreeName, clr_parse_buff, clr_parse_buff_temp, default_color_name); if (colorfd > 0) p_info(PI_WLOG, "Color table %s does not exist, using colortable.ct\n", ColorTableName); } if ( colorfd <= 0 ) { /* no colortable, use black and white */ colorfd = 0; store_white_and_black(); sprintf(default_color_name, "Penta/%s/%s/???.ct", DEFAULT_DIR, TABLES_DIR); p_info(PI_WLOG, "No color table exists, only colors 0 (white) and 1 (black) are valid.\n"); return; } spot_pass = 1; /* 1st pass */ cur_color_id = -1; while ( !endflag ) { memset(clr_parse_buff, 0, CLRBUFSZ); if ( p_fgets(clr_parse_buff, CLRBUFSZ, colorfd) != clr_parse_buff) endflag++; /* out of data */ if ( (length = strlen (clr_parse_buff)) < 5 ) continue; /* not long enough for a valid string */ /* OTOH, err if line fills buff completely: */ if ( length >= (CLRBUFSZ-1) ) { p_info(PI_WLOG, "WARNING: Color table '%s' line too long, ignored after %d:\n '%s'\n", ColorTableName, CLRBUFSZ, clr_parse_buff); do { /* Flush until EOL: */ *clr_parse_buff_temp = 0; if (p_fgets(clr_parse_buff_temp, CLRBUFSZ, colorfd) != clr_parse_buff_temp) endflag++; /* out of data */ } while (strlen(clr_parse_buff_temp) >= (CLRBUFSZ-1)); } if ( (clr_parse_buff[0] == '%') || (clr_parse_buff[0] == '!') || (clr_parse_buff[0] == '#') ) continue; /* skip command lines */ strcpy (clr_parse_buff_temp, clr_parse_buff); if ( !strncmp(clr_parse_buff, "AI_Sep", 6) ) continue; /* ignore Separation Key Words */ if ( !strncmp(clr_parse_buff, "CD_Sep", 6) ) continue; /* ignore Separation Key Words */ if ( !strncmp(clr_parse_buff, "G_FG_Color", 10) ) continue; /* ignore default graphic color Key Words */ if ( !strncmp(clr_parse_buff, "G_BG_Color", 10) ) continue; /* ignore default graphic color Key Words */ if ( !strncmp(clr_parse_buff, "G_BW_Overprint", 14) ) continue; /* ignore default graphic color Key Words */ if ( !strncmp(clr_parse_buff, "Plate_Name", 10) ) { /* Save Plate Name */ plate_name_input = atoi((char *)&clr_parse_buff[11]); if ( (plate_name_input < 0) || (plate_name_input > 32)) continue; /* no number */ memset((char *)&plate_nm[plate_name_input].name[0], 0, sizeof(struct plate_name)); /* p=(strstr((char *)&clr_parse_buff[11],"-")); p++; strncpy((char *)&plate_nm[plate_name_input], p, 30); */ strncpy((char *)&plate_nm[plate_name_input], (char *)&clr_parse_buff[11], 30); plate_nm[plate_name_input].name[30] = 0; if ( (result_ptr = strrchr((char *)&plate_nm[plate_name_input], '\n') ) ) *result_ptr = 0; /* null out the new line */ continue; } msg_parse(clr_parse_buff_temp, length, CLR_KEYWORD_COUNT, clr_msg); for (i=0; i<CLR_KEYWORD_COUNT; i++) { if ( clr_msg[i].answer[0] && (i != 72)) break; /* got an answer */ } if (i >= 11) continue; /* no valid message */ if (i == 0) { /* got a color id */ if ( (cur_color_id > 0) && !plate_zero_stored) { cur_plate = 0; store_color(0); /* store plate zero for prev color */ } plate_zero_stored = 0; cur_plate = -1; cur_screen = 72; cur_pct = 100; cur_tint = 100; strcpy(cur_shape, "dot"); cur_angle = 45.; cur_reverse = 0; cur_cmyk_flag = 0; strcpy(cur_op, "false"); strcpy(cur_color_name,""); strcpy(cur_type,"process"); for (i=0; i<4; i++) cur_cmyk[i] = 0.0; cur_color_id = atoi(clr_msg[0].answer); if (cur_color_id < 0) { cur_color_id = 0; p_info(PI_ELOG, "ERROR - Negative color '%s' is invalid.\n", clr_msg[0].answer); continue; } for (i=7; i<11; i++) { /* look for CMYK values */ if ( clr_msg[i].answer[0]) { temp = atof(clr_msg[i].answer); if ( (temp < 0.0 ) || (temp > 1.0) ) p_info(PI_ELOG, "ERROR - CMYK value on line '%s' does not lie between 0 and 1.0\n",clr_parse_buff); else { #if LPMfloat if(LPMK[LPM_ColorMaster]) #else if((LPMK & LPM_ColorMaster)) #endif { cur_cmyk[i-7] = temp; cur_cmyk_flag = 1; } } } } /* end for(i=7;i<11;i++) */ if ( clr_msg[6].answer[0]) { /* got a Tint */ cur_tint = atoi(clr_msg[6].answer); if ( (cur_tint <= 0) || (cur_tint > 100) ) { cur_tint = 100; p_info(PI_ELOG, "ERROR - color Tint must be above 0, below 100;\n"); p_info(PI_ELOG, " '%s' is not valid. \n",clr_msg[6].answer); } } if ( clr_msg[45].answer[0]) /* got Overprint */ { strncpy(cur_op, clr_msg[45].answer, 5); *(cur_op+5) = 0; if ( strcmp(cur_op, "true") && strcmp(cur_op, "false")) { p_info(PI_ELOG, "ERROR - color op '%s' must be true or false, will use true.\n", cur_op); strcpy(cur_op, "true"); } } else strcpy(cur_op,"false"); if ( clr_msg[46].answer[0]) { strcpy(cur_type,(clr_msg[46].answer)); } else strcpy(cur_type,"process"); if ( clr_msg[47].answer[0]) { if (strlen(clr_msg[47].answer) > 31) { p_info(PI_ELOG, "ERROR - color name '%s' exceeds 31 characters.\n", clr_msg[47].answer); continue; } strcpy (cur_color_name,(clr_msg[47].answer)); } else strcpy(cur_color_name,""); continue; } /* end got a color id */ if ( cur_color_id < 0) { p_info(PI_ELOG, "ERROR - color id missing before line '%s' \n",clr_parse_buff); continue; } if (i == 1) { /* Plate being defined */ cur_plate = atoi(clr_msg[1].answer); if ( (cur_plate < 0) || (cur_plate >= MAX_CLRS) ) { p_info(PI_ELOG, "ERROR - Color '%d', Plate '%d' less than 0 or greater than 31 \n",cur_color_id,cur_plate); p_info(PI_ELOG, " Line in error reads '%s'\n",clr_parse_buff); cur_plate = -1; continue; } continue; } /* end define Plate */ if ( cur_plate < 0) { p_info(PI_ELOG, "ERROR - color Plate is missing before line '%s' \n", clr_parse_buff); continue; } screen_found_flag = 0; switch (i) { case 2: /* Shape */ if ( clr_msg[2].answer[0]) strcpy(cur_shape, clr_msg[2].answer); else { p_info(PI_ELOG, "ERROR - Shape '%s' is not supported.\n", clr_msg[2].answer); strcpy(cur_shape, "dot"); } case 3: /* Angle */ if ( clr_msg[3].answer[0]) cur_angle = atof(clr_msg[3].answer); /* got an Angle */ case 4: /* Screen */ if ( clr_msg[4].answer[0]) { /* got a Screen */ cur_screen = atoi(clr_msg[4].answer); if (cur_screen < 0) cur_screen = 6; } case 5: /* Percent */ if ( clr_msg[5].answer[0]) { /* got a Percent */ cur_pct = atof(clr_msg[5].answer); if ( (cur_pct < 0.0) || (cur_pct > 100.) ) { cur_pct = 0.0; p_info(PI_ELOG, "ERROR - color Percent must be between 0 and 100\n"); p_info(PI_ELOG, " '%s' is not valid. \n",clr_msg[5].answer); } } screen_found_flag++; /* set if any case 2 thru 6 found */ break; default: continue; } /* end switch (i) */ if (cur_plate && !plate_zero_stored && screen_found_flag) { /* store Plate 0 first */ temp_plate = cur_plate; cur_plate = 0; store_color(0); cur_plate = temp_plate; } if (screen_found_flag) { store_color(1); plate_zero_stored++; } } /* end while( !endflag ) */ p_close(colorfd); store_white_and_black(); cur_cmyk_flag = 0; cur_tint = 100; } /* end of init_color */
void generate( int polygons ) { double knob_value; vary_node *knobs; vary_node vn; char frame_name[128]; if (first_pass()) { knobs = second_pass(); } else { num_frames = 1; } // Default values char color_type = PNG_RGB, shading = GOROUD; int width = 1000, height = 1000, segments = 20; screen s = make_screen(width, height); vertex_list vlist = new_vlist(100); face_list flist = new_flist(100); edge_list elist = new_elist(100); stack coord_systems = new_stack(5); vector center = new_vector(0, 0, 0); vector eye = new_vector(0, 0, 200); double distance = 200; vertex text0, text1; text0.x = -100; text0.y = 0; text0.z = 0; text1.x = 100; text1.y = 0; text1.z = 0; text0.nx = text1.x - text0.x; text0.ny = text1.y - text0.y; text0.nz = text1.z - text0.z; text1.nx = text0.nx * text0.nx + text0.ny * text0.ny + text0.nz * text0.nz; text0.color = rgb(255, 255, 255); text0.shine = 3; text1.color = rgb(255, 0, 255); text1.shine = 3; uint32_t amb_color = rgb(255, 255, 255), light_color = rgb(0, 255, 255), wire_color = rgb(255, 255, 255); vector light_source = new_vector(0, 100, 200); double amb_ref_constant = 0.1, diff_ref_constant = 1, spec_ref_constant = 1; int frame, i, j; double temp; for (frame = 0; frame < num_frames; frame++) { if (num_frames > 1) { for (vn = knobs[frame]; vn != NULL; vn = vn->next) { set_value(lookup_symbol(vn->name), vn->value); } } for (i = 0; i < lastop; i++) { switch (op[i].opcode) { case TEXTURE: text0.x = op[lastop].op.texture.d0[0]; text0.y = op[lastop].op.texture.d0[1]; text0.z = op[lastop].op.texture.d0[2]; text1.x = op[lastop].op.texture.d1[0]; text1.y = op[lastop].op.texture.d1[1]; text1.z = op[lastop].op.texture.d1[2]; text0.nx = text1.x - text0.x; text0.ny = text1.y - text0.y; text0.nz = text1.z - text0.z; text1.nx = text0.nx * text0.nx + text0.ny * text0.ny + text0.nz * text0.nz; text0.color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d2[2])) ); text0.shine = op[lastop].op.texture.d2[3]; text1.color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.texture.d3[2])) ); text1.shine = op[lastop].op.texture.d3[3]; break; case CAMERA: eye.x = op[lastop].op.camera.eye[0]; eye.y = op[lastop].op.camera.eye[1]; eye.z = op[lastop].op.camera.eye[2]; center.x = eye.x + op[lastop].op.camera.aim[0]; center.y = eye.y + op[lastop].op.camera.aim[1]; center.z = eye.z + op[lastop].op.camera.aim[2]; break; case FOCAL: distance = op[lastop].op.focal.value; break; case AMBIENT: amb_color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.ambient.c[2])) ); break; case LIGHT: light_color = rgb( (uint8_t) max(0, min(0xFF, op[lastop].op.light.c[0])), (uint8_t) max(0, min(0xFF, op[lastop].op.light.c[1])), (uint8_t) max(0, min(0xFF, op[lastop].op.light.c[2])) ); light_source = new_vector( op[lastop].op.light.l[0], op[lastop].op.light.l[1], op[lastop].op.light.l[2] ); break; case SHADING: if (strcmp(op[i].op.shading.p->name, "GOROUD") == 0) { shading = GOROUD; } else { shading = WIRE; } break; case SPHERE: add_sphere( vlist, elist, flist, op[i].op.sphere.d[0], op[i].op.sphere.d[1], op[i].op.sphere.d[2], op[i].op.sphere.r, segments, text0, text1 ); transform(vlist, peek(coord_systems)); if (shading == GOROUD) { draw_faces( s, vlist, flist, center, eye, distance, amb_color, light_color, light_source, amb_ref_constant, diff_ref_constant, spec_ref_constant ); } else { draw_edges( s, vlist, elist, center, eye, distance, wire_color ); } clear_vlist(vlist); clear_elist(elist); clear_flist(flist); break; case BOX: add_box( vlist, elist, flist, op[i].op.box.d0[0], op[i].op.box.d0[1], op[i].op.box.d0[2], op[i].op.box.d1[0], op[i].op.box.d1[1], op[i].op.box.d1[2], text0, text1 ); transform(vlist, peek(coord_systems)); if (shading == GOROUD) { draw_faces( s, vlist, flist, center, eye, distance, amb_color, light_color, light_source, amb_ref_constant, diff_ref_constant, spec_ref_constant ); } else { draw_edges( s, vlist, elist, center, eye, distance, wire_color ); } clear_vlist(vlist); clear_elist(elist); clear_flist(flist); break; case LINE: add_line( vlist, elist, op[i].op.line.p0[0], op[i].op.line.p0[1], op[i].op.line.p0[2], op[i].op.line.p1[0], op[i].op.line.p1[1], op[i].op.line.p1[2], text0, text1 ); transform(vlist, peek(coord_systems)); draw_edges(s, vlist, elist, center, eye, distance, wire_color); clear_vlist(vlist); clear_elist(elist); break; case MOVE: if (op[i].op.move.p == NULL){ knob_value = 1; } else { knob_value = op[i].op.move.p->s.value; } translate( op[i].op.move.d[0] * knob_value, op[i].op.move.d[1] * knob_value, op[i].op.move.d[2] * knob_value, peek(coord_systems) ); break; case SCALE: if (op[i].op.scale.p == NULL){ knob_value = 1; } else { knob_value = op[i].op.scale.p->s.value; } scale( op[i].op.scale.d[0] * knob_value, op[i].op.scale.d[1] * knob_value, op[i].op.scale.d[2] * knob_value, peek(coord_systems) ); break; case ROTATE: if (op[i].op.rotate.p == NULL){ knob_value = 1; } else { knob_value = op[i].op.rotate.p->s.value; } temp = op[i].op.rotate.axis; if (temp == 0) { rotate_x( op[i].op.rotate.degrees * knob_value, peek(coord_systems) ); } else if (temp == 1) { rotate_y( op[i].op.rotate.degrees * knob_value, peek(coord_systems) ); } else { rotate_z( op[i].op.rotate.degrees * knob_value, peek(coord_systems) ); } break; case SET: set_value( lookup_symbol(op[i].op.set.p->name), op[i].op.set.val ); break; case SETKNOBS: for (j = 0; j < lastsym; j++) { set_value(&symtab[j], op[j].op.setknobs.value); } break; case PUSH: push(coord_systems); break; case POP: pop(coord_systems); break; case SAVE: make_png(op[i].op.save.p->name, s, color_type); break; case DISPLAY: display_png(s, color_type); break; } } if (num_frames > 1){ sprintf(frame_name, "anim/%s%03d.png", name, frame); make_png(frame_name, s, color_type); clear_screen(s); clear_stack(coord_systems); } } free_screen(s); free_vlist(vlist); free_flist(flist); free_elist(elist); free(coord_systems); }