// draw the scene to a file in a given format, trying to match the // view of the given DisplayDevice as closely as possible // returns TRUE if successful, FALSE if not int Scene::filedraw(FileRenderer *render, const char *filename, DisplayDevice *display) { // Copy all relevant info from the current main DisplayDevice (*((DisplayDevice *)render)) = (*display); // set up the lights for (int i=0; i<DISP_LIGHTS; i++) { if (lightState[i].on) render->do_define_light(i, lightState[i].color, lightState[i].pos); render->do_activate_light(i, lightState[i].on); } // set up the colors render->use_colors(colorData); render->set_background(color_value(background->color_id())); render->set_backgradient(color_value(backgradtop->color_id()), color_value(backgradbot->color_id())); // returns FALSE if not able to open file if (!render -> open_file(filename)) { return FALSE; } // writes the header render->prepare3D(TRUE); // draw the scene to the file root.draw(render); // write the trailer and close render->render_done(); render->update(TRUE); // rendering was successful return TRUE; }
void populateSettings(const QByteArray &xSettings) { if (xSettings.length() < 12) return; // we ignore byteorder for now char byteOrder = xSettings.at(1); Q_UNUSED(byteOrder); uint serial = *reinterpret_cast<const uint *>(xSettings.mid(4,4).constData()); serial = serial; uint number_of_settings = *reinterpret_cast<const uint *>(xSettings.mid(8,4).constData()); const char *data = xSettings.constData() + 12; size_t offset = 0; for (uint i = 0; i < number_of_settings; i++) { int local_offset = 0; XSettingsType type = static_cast<XSettingsType>(*reinterpret_cast<const quint8 *>(data + offset)); local_offset += 2; quint16 name_len = *reinterpret_cast<const quint16 *>(data + offset + local_offset); local_offset += 2; QByteArray name(data + offset + local_offset, name_len); local_offset += round_to_nearest_multiple_of_4(name_len); int last_change_serial = *reinterpret_cast<const int *>(data + offset + local_offset); Q_UNUSED(last_change_serial); local_offset += 4; QVariant value; if (type == XSettingsTypeString) { int value_length = *reinterpret_cast<const int *>(data + offset + local_offset); local_offset+=4; QByteArray value_string(data + offset + local_offset, value_length); value.setValue(value_string); local_offset += round_to_nearest_multiple_of_4(value_length); } else if (type == XSettingsTypeInteger) { int value_length = *reinterpret_cast<const int *>(data + offset + local_offset); local_offset += 4; value.setValue(value_length); } else if (type == XSettingsTypeColor) { quint16 red = *reinterpret_cast<const quint16 *>(data + offset + local_offset); local_offset += 2; quint16 green = *reinterpret_cast<const quint16 *>(data + offset + local_offset); local_offset += 2; quint16 blue = *reinterpret_cast<const quint16 *>(data + offset + local_offset); local_offset += 2; quint16 alpha= *reinterpret_cast<const quint16 *>(data + offset + local_offset); local_offset += 2; QColor color_value(red,green,blue,alpha); value.setValue(color_value); } offset += local_offset; settings[name].updateValue(screen,name,value,last_change_serial); } }
int Scene::nearest_index(float r, float g, float b) const { const float *rcol = color_value(BEGREGCLRS); // get the solid colors float lsq = r - rcol[0]; lsq *= lsq; float tmp = g - rcol[1]; lsq += tmp * tmp; tmp = b - rcol[2]; lsq += tmp * tmp; float best = lsq; int bestidx = BEGREGCLRS; for (int n= BEGREGCLRS+1; n < (BEGREGCLRS + REGCLRS); n++) { rcol = color_value(n); lsq = r - rcol[0]; lsq *= lsq; tmp = g - rcol[1]; lsq += tmp * tmp; tmp = b - rcol[2]; lsq += tmp * tmp; if (lsq < best) { best = lsq; bestidx = n; } } return bestidx; }
//--------------------------------------------------------------------------- float CalculateRules2(float hue, float saturation, float value, int color) { float ret_val,lower_sum=0; int RulesCounter=0; while (fuzzy_rules[RulesCounter].hue>=0) { /* if (do_grey_scale || (strcmp(fuzzy_rules[RulesCounter].color,"white") && strcmp(fuzzy_rules[RulesCounter].color,"light_grey") && strcmp(fuzzy_rules[RulesCounter].color,"dark_grey") && strcmp(fuzzy_rules[RulesCounter].color,"black"))) { */ if (fuzzy_rules[RulesCounter].color==color) /* calculate only rules of the same color */ { /* hue functions */ ret_val=color_value(fuzzy_rules[RulesCounter].hue,hue); if (ret_val==0) goto loop; /* saturation function */ if (fuzzy_rules[RulesCounter].saturation==SATURATION_GREY) ret_val=ret_val*grey_value(saturation); if (fuzzy_rules[RulesCounter].saturation==SATURATION_ALMOST_GREY) ret_val=ret_val*almost_grey_value(saturation); if (fuzzy_rules[RulesCounter].saturation==SATURATION_TEND_GREY) ret_val=ret_val*tend_grey_value(saturation); if (fuzzy_rules[RulesCounter].saturation==SATURATION_MEDIUM_GREY) ret_val=ret_val*medium_grey_value(saturation); if (fuzzy_rules[RulesCounter].saturation==SATURATION_TEND_CLEAR) ret_val=ret_val*tend_clear_value(saturation); if (fuzzy_rules[RulesCounter].saturation==SATURATION_CLEAR) ret_val=ret_val*clear_value(saturation); if (ret_val==0) goto loop; /* value functions */ if (fuzzy_rules[RulesCounter].value==VALUE_DARK) ret_val=ret_val*dark_value(value); if (fuzzy_rules[RulesCounter].value==VALUE_ALMOST_DARK) ret_val=ret_val*almost_dark_value(value); if (fuzzy_rules[RulesCounter].value==VALUE_TEND_DARK) ret_val=ret_val*tend_dark_value(value); if (fuzzy_rules[RulesCounter].value==VALUE_TEND_LIGHT) ret_val=ret_val*tend_light_value(value); if (fuzzy_rules[RulesCounter].value==VALUE_LIGHT) ret_val=ret_val*light_value(value); /* add the rule values */ lower_sum=lower_sum+ret_val; } loop: RulesCounter++; } return(lower_sum); }
// draws the scene to the given DisplayDevice // this is the only Scene which tells the display to do graphics commands // // XXX implementation of multi-pass rendering, accumulation buffers, // and better snapshot behavior will require modifications to this // mechanism. The current system is very simple minded, and doesn't // allow for property-based sorting of geometry, occlusion culling // algorithms, etc. This needs to be changed. // // XXX note, this method should really be a 'const' method since // it is run concurrently by several processes that share memory, but // we can't actually write it that way since the locking routines do // indeed write to lock variables. The code in draw() should be written // as though it were a const method however, at least in terms of what // state is changed in the Scene class or subclass. // void Scene::draw(DisplayDevice *display) { if (!display) return; if (!display->is_renderer_process()) // master process doesn't draw return; // check background rendering mode if (backgroundmode_changed) { display->set_background_mode(backgroundmode); } // XXX Make a Displayable for lights, as we do for background color, and // have a DispCmd for turning lights on and off. if (light_changed) { // set up the lights for (int i=0; i<DISP_LIGHTS; i++) { display->do_define_light(i, lightState[i].color, lightState[i].pos); display->do_activate_light(i, lightState[i].on); } } #if 0 // XXX advanced lights are not yet implemented by displays // XXX Make a Displayable for lights, as we do for background color, and // have a DispCmd for turning lights on and off. if (adv_light_changed) { // set up the lights for (int i=0; i<DISP_LIGHTS; i++) { display->do_define_light(i, lightState[i].color, lightState[i].pos); display->do_activate_light(i, lightState[i].on); } } #endif // update colors display->use_colors(colorData); // set the background color if any color definitions changed, or if the // the color assigned to background changed. // XXX Make a DispCmd for background color so that background color can // be handled automatically by the renderers, rather than special-cased // as we do here. This should work because the background displayable is // the first item traversed in the scene graph. if (background_color_changed) { display->set_background(color_value(background_color_id)); } // set the background gradient colors if any definitions changed, or if // the color assigned to the gradient changed. if (backgradtop_color_changed || backgradbot_color_changed) { display->set_backgradient(color_value(backgradtop->color_id()), color_value(backgradbot->color_id())); } // clear the display and set the viewport correctly display->prepare3D(TRUE); // on some machines with broken stereo implementations, we have // to draw in stereo even when VMD is set for mono mode // XXX this is all very ugly, and while this trick works for drawing // in normal mode, it doesn't fix the other single-buffer "stereo" // modes, since they don't fall into this test case. Scene doesn't have // intimate knowledge of the details of the display subclass's // stereo mode implementations, so a future rewrite will probably have // to move all of this code into the DisplayDevice class, with Scene // simply passing in a bunch of parameters so the display subclass // can deal with these problems for itself. if (display->forced_stereo_draws() && !(display->stereo_mode())) { display->left(); // this will be done as normal() since stereo is off // but we'll actually draw to GL_BACK_LEFT display->prepareOpaque(); root.draw(display); if (display->prepareTrans()) { root.draw(display); } display->right(); // this will be done as normal() since stereo is off // but we'll actually draw to GL_BACK_RIGHT display->prepareOpaque(); root.draw(display); if (display->prepareTrans()) { root.draw(display); } } else { // draw left eye first, if stereo if (display->stereo_mode()) display->left(); else display->normal(); // draw all the objects for normal, or left eye position display->prepareOpaque(); root.draw(display); if (display->prepareTrans()) { root.draw(display); } // now draw right eye, if in stereo if (display->stereo_mode()) { display->right(); display->prepareOpaque(); root.draw(display); if (display->prepareTrans()) { root.draw(display); } } } display->render_done(); // update the display display->update(TRUE); }
/* * Print a transaction. */ static void print_tx(struct PN *node, const uint8_t *tx, size_t len) { uint8_t *ins[MAX_INPUTS]; size_t inlens[MAX_INPUTS]; uint8_t *outs[MAX_OUTPUTS]; size_t outlens[MAX_OUTPUTS]; uint64_t outvals[MAX_OUTPUTS]; jmp_buf env; struct buf buf0 = {tx, 0, len, &env}; struct buf *buf = &buf0; if (setjmp(env)) { parse_error: fprintf(stderr, "error: unable to parse transaction\n"); return; } size_t num_ins, num_outs; if (!parse_tx(buf, ins, inlens, &num_ins, outs, outlens, outvals, &num_outs)) goto parse_error; // Formatting constraints: size_t lines = MAX(num_ins, num_outs); size_t in_d = lines - num_ins; size_t out_d = lines - num_outs; size_t in_s = 0 + in_d / 2; size_t in_e = lines - (in_d + 1) / 2; size_t out_s = 0 + out_d / 2; size_t out_e = lines - (out_d + 1) / 2; size_t mid = (in_s + in_e) / 2; time_t t = time(NULL); mutex_lock(&lock); putchar('\n'); num_tx++; num_tx_bytes += len; for (size_t i = 0; i < lines; i++) { if (i >= in_s && i < in_e) { size_t idx = i - in_s; uint8_t pub_key[65]; uint8_t script[520]; size_t script_len; char addr[35]; addr[0] = '\0'; if (script_is_p2pkh_input(ins[idx], inlens[idx], pub_key)) { size_t pub_key_len = (pub_key[0] == 0x04? 65: 33); make_input_addr(pub_key, pub_key_len, 0x00, addr); } else if (script_is_p2sh_input(ins[idx], inlens[idx], script, &script_len)) make_input_addr(script, script_len, 0x05, addr); if (addr[0] != '\0') { color_input(); printf("%s", addr); color_clear(); size_t len = strlen(addr); for (size_t j = 0; j < 34 - len; j++) putchar(' '); } else printf("[UNKNOWN] "); } else { for (size_t i = 0; i < 34; i++) putchar(' '); } putchar(' '); if (i >= out_s && i < out_e) { size_t idx = i - out_s; uint8_t hash160[20]; char addr[35]; uint8_t data[80]; size_t dlen; bool is_data = false; addr[0] = '\0'; if (script_is_p2pkh_output(outs[idx], outlens[idx], hash160)) make_output_addr(hash160, 0x00, addr); else if (script_is_p2sh_output(outs[idx], outlens[idx], hash160)) make_output_addr(hash160, 0x05, addr); else if (script_is_data_output(outs[idx], outlens[idx], data, &dlen)) is_data = true; if (addr[0] != '\0') { color_output(); printf("%s", addr); color_clear(); size_t len = strlen(addr); for (size_t j = 0; j < 34 - len; j++) putchar(' '); } else if (is_data) { color_output(); printf("[DATA] \""); size_t space = 26, j; for (j = 0; j < dlen && j < 22; j++) { if (isprint(data[j])) putchar(data[j]); else putchar('?'); space--; } if (j < dlen) { printf("..."); space -= 3; } putchar('\"'); space--; for (j = 0; j < space; j++) putchar(' '); color_clear(); } else printf("[UNKNOWN] "); // The following is complicated way to ensure the number fits: color_value(); double val = GET_BTC(outvals[idx]); double btc_val = (double)(unsigned)(val); char buf[32]; size_t len = snprintf(buf, sizeof(buf)-1, "%u", (unsigned)btc_val); if (len > 8) { printf("UNKNOWN\n"); color_clear(); continue; } printf(" %s", buf); double mant = val - btc_val; if (mant == 0.0) { color_clear(); putchar('\n'); continue; } size_t prec = 8 - len; switch (prec) { case 1: len = snprintf(buf, sizeof(buf)-1, "%.1f", mant); break; case 2: len = snprintf(buf, sizeof(buf)-1, "%.2f", mant); break; case 3: len = snprintf(buf, sizeof(buf)-1, "%.3f", mant); break; case 4: len = snprintf(buf, sizeof(buf)-1, "%.4f", mant); break; case 5: len = snprintf(buf, sizeof(buf)-1, "%.5f", mant); break; case 6: len = snprintf(buf, sizeof(buf)-1, "%.6f", mant); break; case 7: len = snprintf(buf, sizeof(buf)-1, "%.7f", mant); break; case 8: len = snprintf(buf, sizeof(buf)-1, "%.8f", mant); break; default: buf[1] = '\0'; len = 0; break; } while (len >= 2 && buf[len-1] == '0') { buf[len-1] = '\0'; len--; } printf("%s", buf+1); color_clear(); } putchar('\n'); } if (option_verbose) { printf("NODE : height=%u in=%u out=%u sent=%.2gMB recv=%.2gMB\n", PN_get_info(node, PN_HEIGHT), PN_get_info(node, PN_NUM_IN_PEERS), PN_get_info(node, PN_NUM_OUT_PEERS), (double)PN_get_info(node, PN_NUM_SEND_BYTES) / 1000000.0, (double)PN_get_info(node, PN_NUM_RECV_BYTES) / 1000000.0); printf("TX : hash="); hash256_t hash; PN_sha256d(tx, len, &hash); for (size_t i = 0; i < sizeof(hash); i++) printf("%.2x", hash.i8[32 - i - 1]); uint64_t tx_val = 0; for (size_t i = 0; i < num_outs; i++) tx_val += outvals[i]; total_val += tx_val; printf("\n size=%uB inputs=%u outputs=%u val=%gBTC\n", (unsigned)len, (unsigned)num_ins, (unsigned)num_outs, GET_BTC(tx_val)); printf("TOTALS: #tx=%u #block=%u size=%uB val=%gBTC\n", (unsigned)num_tx, (unsigned)num_blocks, (unsigned)num_tx_bytes, GET_BTC(total_val)); double vps, sps, txps; get_rate_info(t, tx_val, len, &vps, &sps, &txps); printf("RATES : tx/s=%.3g bytes/s=%g BTC/s=%g\n", txps, sps, GET_BTC(vps)); } prev_msg = false; mutex_unlock(&lock); }
void populateSettings(const QByteArray &xSettings) { if (xSettings.length() < 12) return; char byteOrder = xSettings.at(0); if (byteOrder != LSBFirst && byteOrder != MSBFirst) { qWarning("%s ByteOrder byte %d not 0 or 1", Q_FUNC_INFO , byteOrder); return; } #define ADJUST_BO(b, t, x) \ ((b == LSBFirst) ? \ qFromLittleEndian<t>((const uchar *)(x)) : \ qFromBigEndian<t>((const uchar *)(x))) #define VALIDATE_LENGTH(x) \ if ((size_t)xSettings.length() < (offset + local_offset + 12 + x)) { \ qWarning("%s Length %d runs past end of data", Q_FUNC_INFO , x); \ return; \ } uint number_of_settings = ADJUST_BO(byteOrder, quint32, xSettings.mid(8,4).constData()); const char *data = xSettings.constData() + 12; size_t offset = 0; for (uint i = 0; i < number_of_settings; i++) { int local_offset = 0; VALIDATE_LENGTH(2); XSettingsType type = static_cast<XSettingsType>(*reinterpret_cast<const quint8 *>(data + offset)); local_offset += 2; VALIDATE_LENGTH(2); quint16 name_len = ADJUST_BO(byteOrder, quint16, data + offset + local_offset); local_offset += 2; VALIDATE_LENGTH(name_len); QByteArray name(data + offset + local_offset, name_len); local_offset += round_to_nearest_multiple_of_4(name_len); VALIDATE_LENGTH(4); int last_change_serial = ADJUST_BO(byteOrder, qint32, data + offset + local_offset); Q_UNUSED(last_change_serial); local_offset += 4; QVariant value; if (type == XSettingsTypeString) { VALIDATE_LENGTH(4); int value_length = ADJUST_BO(byteOrder, qint32, data + offset + local_offset); local_offset+=4; VALIDATE_LENGTH(value_length); QByteArray value_string(data + offset + local_offset, value_length); value.setValue(value_string); local_offset += round_to_nearest_multiple_of_4(value_length); } else if (type == XSettingsTypeInteger) { VALIDATE_LENGTH(4); int value_length = ADJUST_BO(byteOrder, qint32, data + offset + local_offset); local_offset += 4; value.setValue(value_length); } else if (type == XSettingsTypeColor) { VALIDATE_LENGTH(2*4); quint16 red = ADJUST_BO(byteOrder, quint16, data + offset + local_offset); local_offset += 2; quint16 green = ADJUST_BO(byteOrder, quint16, data + offset + local_offset); local_offset += 2; quint16 blue = ADJUST_BO(byteOrder, quint16, data + offset + local_offset); local_offset += 2; quint16 alpha= ADJUST_BO(byteOrder, quint16, data + offset + local_offset); local_offset += 2; QColor color_value(red,green,blue,alpha); value.setValue(color_value); } offset += local_offset; settings[name].updateValue(screen,name,value,last_change_serial); } }