/*+++++++++++++++++++++++++ .IDENTifer GET_SCIA_LV0_STATE_ANGLE .PURPOSE average scan angles during a number of L0 auxiliary packages .INPUT/OUTPUT call as GET_SCIA_LV0_STATE_ANGLE( num_aux, aux, &asmAngle, &esmAngle ); input: unsigned short num_aux : number of auxiliary packages struct mds0_aux *aux : L0 Auxiliary MDS records output: float *asmAngle : average azimuth scan angle float *esmAngle : average elevation scan angle .RETURNS nothing .COMMENTS none -------------------------*/ void GET_SCIA_LV0_STATE_ANGLE( unsigned short num_aux, const struct mds0_aux *aux, float *asmAngle, float *esmAngle ) { register unsigned short na, nframe, nbcp; register unsigned short numAngle = 0; register double asmSum = 0.; register double esmSum = 0.; float asmBuff[NUM_LV0_AUX_PMTC_FRAME * NUM_LV0_AUX_BCP]; float esmBuff[NUM_LV0_AUX_PMTC_FRAME * NUM_LV0_AUX_BCP]; for ( na = 0; na < num_aux; na++ ) { register unsigned short indx = 0; GET_SCIA_LV0_MDS_ANGLES( aux+na, asmBuff, esmBuff ); for ( nframe = 0; nframe < NUM_LV0_AUX_PMTC_FRAME; nframe++ ) { for ( nbcp = 0; nbcp < NUM_LV0_AUX_BCP; nbcp++ ) { if ( isnormal(asmBuff[indx]) && isnormal(esmBuff[indx]) ) { numAngle++; asmSum += asmBuff[indx]; esmSum += esmBuff[indx]; } indx++; } } } if ( numAngle > 0 ) { *asmAngle = (float)(asmSum / numAngle); *esmAngle = (float)(esmSum / numAngle); } else *asmAngle = *esmAngle = NAN; }
void gen_test (void) { union uint32_f a, b; bool c; for (int i = 0; i < 2000000 ; i++) { char aa[33],bb[33],cc[2]; a.i = rand () | rand () << 16; b.i = rand () | rand () << 16; if (fpclassify (a.f) != FP_NORMAL || fpclassify (b.f) != FP_NORMAL) continue; c = feq (a.i,b.i); for (int t = 0; t < 32;++t) { aa[31 - t] = a.i & (1 << t) ? '1' : '0'; bb[31 - t] = b.i & (1 << t) ? '1' : '0'; } aa[32] = '\0'; bb[32] = '\0'; cc[0] = c ? '1' : '0'; cc[1] = '\0'; // 非正規化数とかはやらない if (isnormal (a.f) && isnormal((b.f))) { printf ("%s\t%s\t%s\n",aa,bb,cc); } } }
int main() { double d1, _d1; d1=_d1; __VERIFIER_assume(isnormal(d1)); if(!(!isnan(d1))) __VERIFIER_error(); if(!(!isinf(d1))) __VERIFIER_error(); if(!(isfinite(d1))) __VERIFIER_error(); double d2, _d2; d2=_d2; __VERIFIER_assume(isinf(d2)); if(!(!isnormal(d2))) __VERIFIER_error(); if(!(!isnan(d2))) __VERIFIER_error(); double d3, _d3; d3=_d3; __VERIFIER_assume(isnan(d3)); if(!(!isnormal(d3))) __VERIFIER_error(); if(!(!isinf(d3))) __VERIFIER_error(); if(!(d3!=d3)) __VERIFIER_error(); double d4, _d4; d4=_d4; __VERIFIER_assume(isfinite(d4)); if(!(!isnan(d4))) __VERIFIER_error(); if(!(!isinf(d4))) __VERIFIER_error(); double d5, _d5; d5=_d5; __VERIFIER_assume(!isnan(d5) && !isinf(d5)); if(!(isfinite(d5))) __VERIFIER_error(); }
void test_isnormal() { static_assert((std::is_same<decltype(isnormal((float)0)), bool>::value), ""); static_assert((std::is_same<decltype(isnormal((double)0)), bool>::value), ""); static_assert((std::is_same<decltype(isnormal((long double)0)), bool>::value), ""); assert(isnormal(-1.0) == true); }
static int tilt_func(void *data) { wiimote_t wiimote = WIIMOTE_INIT; const char *address = config_get_s(CONFIG_WIIMOTE_ADDR); if (strlen(address) > 0) { if (wiimote_connect(&wiimote, address) < 0) log_printf("Wiimote error (%s)\n", wiimote_get_error()); else { int running = 1; wiimote.mode.bits = WIIMOTE_MODE_ACC; wiimote.led.one = 1; SDL_mutexP(mutex); state.status = running; SDL_mutexV(mutex); while (mutex && running && wiimote_is_open(&wiimote)) { if (wiimote_update(&wiimote) < 0) break; SDL_mutexP(mutex); { running = state.status; set_button(&state.A, wiimote.keys.a); set_button(&state.B, wiimote.keys.b); set_button(&state.plus, wiimote.keys.plus); set_button(&state.minus, wiimote.keys.minus); set_button(&state.home, wiimote.keys.home); set_button(&state.L, wiimote.keys.left); set_button(&state.R, wiimote.keys.right); set_button(&state.U, wiimote.keys.up); set_button(&state.D, wiimote.keys.down); if (isnormal(wiimote.tilt.y)) { state.x = (state.x * (FILTER - 1) + wiimote.tilt.y) / FILTER; } if (isnormal(wiimote.tilt.x)) { state.z = (state.z * (FILTER - 1) + wiimote.tilt.x) / FILTER; } } SDL_mutexV(mutex); } wiimote_disconnect(&wiimote); } } return 0; }
/*+++++++++++++++++++++++++ .IDENTifer GET_SCIA_LV0_STATE_OBMtemp .PURPOSE average OBM temperature during a number of L0 auxiliary packages .INPUT/OUTPUT call as GET_SCIA_LV0_STATE_OBMtemp( sost_t_obm, num_aux, aux, &obmTemp ); input: bool sost_obm : return OBM temperature according to SOST otherwise return (wrong) SDMF pre-v3.1 unsigned short num_aux : number of auxiliary packages struct mds0_aux *aux : L0 Auxiliary MDS records output: float *obmTemp : temperature of the optical bench [K] .RETURNS nothing .COMMENTS none -------------------------*/ void GET_SCIA_LV0_STATE_OBMtemp( bool sost_obm, unsigned short num_aux, const struct mds0_aux *aux, /*@out@*/ float *obmTemp ) { register unsigned short na = 0; register unsigned short numTemp = 0; register double obmSum = 0.; register const struct pmtc_frame *pmtc_ptr; /* * initialize return value */ *obmTemp = NAN; if ( num_aux == 0 ) return; /* * calculate average OBM temperature during this state */ if ( sost_obm ) { do { register unsigned short nf = 0; register double az_buff, elv_buff; do { pmtc_ptr = &aux->data_src[nf]; az_buff = GET_SCIA_LV0_AUX_azTemp( pmtc_ptr->bench_az ); elv_buff = GET_SCIA_LV0_AUX_elvTemp( pmtc_ptr->bench_elv ); if ( isnormal( az_buff ) && isnormal( elv_buff ) ) { numTemp++; obmSum += (az_buff + elv_buff ) / 2; } } while ( ++nf < NUM_LV0_AUX_PMTC_FRAME ); aux++; } while ( ++na < num_aux ); if ( numTemp > 0 ) *obmTemp = (float) (obmSum / numTemp - 2.2); } else { do { register unsigned short nf = 0; register double rad_buff; do { pmtc_ptr = &aux->data_src[nf]; rad_buff = GET_SCIA_LV0_AUX_azTemp( pmtc_ptr->bench_rad ); if ( isnormal( rad_buff ) ) { numTemp++; obmSum += rad_buff; } } while ( ++nf < NUM_LV0_AUX_PMTC_FRAME ); aux++; } while ( ++na < num_aux ); if ( numTemp > 0 ) *obmTemp = (float) (0.7 + obmSum / numTemp); } }
/* compute ln(a + b) safely, given ln(a) and ln(b). */ double safe_sum(double ln_a, double ln_b) { if (isnormal(ln_a) && isnormal(ln_b)) return ln_a < ln_b ? ln_b + gsl_sf_log(gsl_sf_exp(ln_a - ln_b) + 1.0) : ln_a + gsl_sf_log(gsl_sf_exp(ln_b - ln_a) + 1.0); else if (isnormal(ln_a)) return ln_a; else return ln_b; }
calculated_number grouping_flush_median(RRDR *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr) { struct grouping_median *g = (struct grouping_median *)r->grouping_data; calculated_number value; if(unlikely(!g->next_pos)) { value = 0.0; *rrdr_value_options_ptr |= RRDR_VALUE_EMPTY; } else { if(g->next_pos > 1) { sort_series(g->series, g->next_pos); value = (calculated_number)median_on_sorted_series(g->series, g->next_pos); } else value = (calculated_number)g->series[0]; if(!isnormal(value)) { value = 0.0; *rrdr_value_options_ptr |= RRDR_VALUE_EMPTY; } //log_series_to_stderr(g->series, g->next_pos, value, "median"); } g->next_pos = 0; return value; }
virtual void search (Feature const &query, SearchRequest const &sp, std::vector<Match> *matches) const { matches->clear(); if (lsh_index) { int K = sp.hint_K; if (K <= 0) K = default_K; float R = sp.hint_R; if (!isnormal(R)) R = default_R; vector<std::pair<Key, float>> m; lsh_index->search(query, R, &m); //TODO: use sp.hint_K, too matches->resize(m.size()); for (unsigned i = 0; i < m.size(); ++i) { auto &to = matches->at(i); auto const &from = m[i]; to.object = from.first.object; to.tag = from.first.tag; to.distance = from.second; } if (matches->size() > K) { if (FeatureSimilarity::POLARITY >= 0) { sort(matches->begin(), matches->end(), [](Match const &h1, Match const &h2) { return h1.distance > h2.distance;}); } else { sort(matches->begin(), matches->end(), [](Match const &h1, Match const &h2) { return h1.distance < h2.distance;}); } matches->resize(K); } } }
/* * returns the maximum Lyapunov exponent from n-dimensional time series * this algorithm was proposed by A. Wolf et al. (Physica D 16, 285-317, 1985) * * @parameter data : n-dimensional time series * @parameter t : length of time series * @parameter n : dimension of time series * @parameter epsilon : supremum of distance * * @return : maximum Lyapunov exponent */ double lyapunov_exponent_wolf ( const double* const* data, int t, int n, double epsilon) { int I, J, T; double lyap_exp; lyap_exp = 0; I = 0; while ((J = index_of_nearest_point_in_epsilon_neighborhood( (const double* const*)data, I, t-1, n, epsilon)) != -1) { for (T = 1; I+T < t-1 && J+T < t-1; T++) { if ( get_distance(data[I+T], data[J+T], n) > epsilon ) break; } double dist_0 = get_distance(data[I], data[J], n); double dist_T = get_distance(data[I+T], data[J+T], n); if (isnormal(dist_0)) { /* check dist_0 > 0 */ lyap_exp += log(dist_T/dist_0); } I = I + T; if (I >= t - 1) break; } if (I != 0) lyap_exp /= I; return lyap_exp; }
void rvc_z_for_y(const rt_vector_t * const ray_position, const rt_vector_t * const ray_direction, rt_fp_dim_t y, rt_fp_dim_t * const z) { rt_fp_dim_t angle, direction_vector_length; assert(isnormal(ray_direction->dim[0])); assert(isnormal(ray_direction->dim[1])); assert(isnormal(ray_direction->dim[2])); direction_vector_length = y - ray_position->dim[1]; angle = (ray_direction->dim[2] / ray_direction->dim[1]); assert(isnormal(angle)); *z = (angle * direction_vector_length) + ray_position->dim[2]; }
void rvc_y_for_z(const rt_vector_t * const ray_position, const rt_vector_t * const ray_direction, rt_fp_dim_t z, rt_fp_dim_t * const y) { rt_fp_dim_t angle, direction_vector_length; assert(isnormal(ray_direction->dim[0])); assert(isnormal(ray_direction->dim[1])); assert(isnormal(ray_direction->dim[2])); direction_vector_length = z - ray_position->dim[2]; angle = (ray_direction->dim[1] / ray_direction->dim[2]); assert(isnormal(angle)); *y = (angle * direction_vector_length) + ray_position->dim[1]; }
int gaussian_valid(const gaussian_t* dist) { if (!(dist && dist->dim > 0 && dist->mean->size == dist->dim)) { return 0; } // check positive definite if (gaussian_isdiagonal(dist)) { size_t i = 0; for (i = 0; i < dist->dim; i++) { double x = gsl_vector_get(dist->diag, i); if (!isnormal(x) || x <= 0) { return 0; } } } else { gsl_matrix* v = gsl_matrix_alloc(dist->dim, dist->dim); gsl_matrix_memcpy(v, dist->cov); gsl_set_error_handler_off(); int status = gsl_linalg_cholesky_decomp(v); gsl_set_error_handler(NULL); gsl_matrix_free(v); if (status == GSL_EDOM) { return 0; } } return 1; }
// if it finds any strange number, sets it to zero static void normalize_float_array_inplace(float *x, int n) { for (int i = 0; i < n; i++) if (!isnormal(x[i])) x[i] = 0; }
/* Render the number nicely from the given item into a string. */ static char *print_number(cJSON *item,printbuffer *p) { char *str=0; double d=item->valuedouble; if (d==0) { if (p) str=ensure(p,2); else str=(char*)cJSON_malloc(2); /* special case for 0. */ if (str) strcpy(str,"0"); } else if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN) { if (p) str=ensure(p,21); else str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */ if (str) sprintf(str,"%d",item->valueint); } else { if (p) str=ensure(p,64); else str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */ if (str) { if (fpclassify(d) != FP_ZERO && !isnormal(d)) sprintf(str,"null"); else if (fabs(floor(d)-d)<=DBL_EPSILON && fabs(d)<1.0e60) sprintf(str,"%.0f",d); else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d); else sprintf(str,"%f",d); } } return str; }
int main() { double d; #ifndef _MSC_VER // first check constants if(!(isnormal(FLT_MAX))) __VERIFIER_error(); if(!(isinf(HUGE_VAL))) __VERIFIER_error(); if(!(isinf(HUGE_VALF))) __VERIFIER_error(); // if(!(isinf(HUGE_VALL))) __VERIFIER_error(); if(!(isinf(INFINITY))) __VERIFIER_error(); if(!(isnan(NAN))) __VERIFIER_error(); // check + if(!(isinf(INFINITY+INFINITY))) __VERIFIER_error(); if(!(isnan(-INFINITY+INFINITY))) __VERIFIER_error(); if(!(INFINITY+INFINITY>0)) __VERIFIER_error(); if(!(isnan(NAN+d))) __VERIFIER_error(); if(!(isnan(NAN+INFINITY))) __VERIFIER_error(); // check - if(!(isnan(INFINITY-INFINITY))) __VERIFIER_error(); if(!(isinf(-INFINITY-INFINITY))) __VERIFIER_error(); if(!(-INFINITY-INFINITY<0)) __VERIFIER_error(); if(!(isnan(NAN-d))) __VERIFIER_error(); if(!(isnan(NAN-INFINITY))) __VERIFIER_error(); // check * if(!(isinf(INFINITY*INFINITY))) __VERIFIER_error(); if(!(isinf(-INFINITY*INFINITY))) __VERIFIER_error(); if(!(INFINITY*INFINITY>0)) __VERIFIER_error(); if(!(-INFINITY*INFINITY<0)) __VERIFIER_error(); if(!(isnan(NAN*d))) __VERIFIER_error(); if(!(isnan(NAN*INFINITY))) __VERIFIER_error(); if(!(isnan(INFINITY*0))) __VERIFIER_error(); if(!(signbit(1.0*-0.0))) __VERIFIER_error(); if(!(!signbit(1.0*0.0))) __VERIFIER_error(); // check / if(!(isnan(INFINITY/INFINITY))) __VERIFIER_error(); if(!(isnan(-INFINITY/INFINITY))) __VERIFIER_error(); // work around compiler warning int zero=0; if(!(isinf(INFINITY/zero))) __VERIFIER_error(); if(!(0.0/INFINITY==0)) __VERIFIER_error(); if(!(1.0/INFINITY==0)) __VERIFIER_error(); if(!(signbit(-1.0/INFINITY))) __VERIFIER_error(); if(!(signbit(1.0/-INFINITY))) __VERIFIER_error(); if(!(INFINITY/-2<0)) __VERIFIER_error(); if(!(isinf(1.0/0.0))) __VERIFIER_error(); if(!(isinf(INFINITY/2))) __VERIFIER_error(); if(!(isnan(0.0/0.0))) __VERIFIER_error(); if(!(isnan(NAN/d))) __VERIFIER_error(); if(!(isnan(NAN/INFINITY))) __VERIFIER_error(); if(!(signbit(-0.0/1))) __VERIFIER_error(); #endif }
/*+++++++++++++++++++++++++ .IDENTifer GET_SCIA_LV0_STATE_DETtemp .PURPOSE average Detector block temperature during a number of L0 packages .INPUT/OUTPUT call as GET_SCIA_LV0_STATE_DETtemp( num_mds, det, detTemp ); input: unsigned short num_mds : number of MDS records struct mds0_det *det : L0 Detector MDS records output: float *detTemp : temperature of the detector blocks [K] .RETURNS nothing .COMMENTS none -------------------------*/ void GET_SCIA_LV0_STATE_DETtemp( unsigned short num_mds, const struct mds0_det *det, float *detTemp ) { register unsigned short nd, nchan; unsigned short numTemp[SCIENCE_CHANNELS] = { 0, 0, 0, 0, 0, 0, 0, 0 }; double detSum [SCIENCE_CHANNELS] = { 0., 0., 0., 0., 0., 0., 0., 0. }; float detBuff[SCIENCE_CHANNELS]; for ( nd = 0; nd < num_mds; nd++ ) { GET_SCIA_LV0_MDS_TEMP( SCIA_DET_PACKET, det+nd, detBuff ); for ( nchan = 0; nchan < SCIENCE_CHANNELS; nchan++ ) { if ( isnormal( detBuff[nchan] ) ) { numTemp[nchan] += 1; detSum[nchan] += detBuff[nchan]; } } } for ( nchan = 0; nchan < SCIENCE_CHANNELS; nchan++ ) { if ( numTemp[nchan] > 0 ) detTemp[nchan] = (float)(detSum[nchan] / numTemp[nchan]); else detTemp[nchan] = NAN; } }
static double ell_pee_distance(float *x, float *y, int n, float p) { double r = 0; if (isinf(p)) { r = -INFINITY; for (int i = 0; i < n; i++) { double t = fabs(x[i] - y[i]); if (t > r) r = t; } } else if (fabs(p) == 0) { for (int i = 0; i < n; i++) if (x[i] != y[i]) r += 1; if (signbit(p)) r /= n; } else if (isnormal(p)) { for (int i = 0; i < n; i++) r += pow(fabs(x[i] - y[i]), fabs(p)); r = pow(r, 1/fabs(p)); if (p < 0) r /= pow(n, 1/fabs(p)); } return r; }
void BigReal::init(const Double80 &x) { DEFINEMETHODNAME; init(); if(!isnormal(x)) { if(isnan(x)) { setToNan(); } else if(isinf(x)) { setToInf(); if(x.isNegative()) { changeSign(); } } return; } // x is normal and != 0 const int expo2 = getExpo2(x) - 63; if(expo2 == 0) { init(getSignificand(x)); } else { DigitPool *pool = getDigitPool(); const BigReal significand(getSignificand(x), pool); const bool isConstPool = pool->getId() == CONST_DIGITPOOL_ID; if(isConstPool) ConstDigitPool::releaseInstance(); // unlock it or we will get a deadlock const BigReal &p2 = pow2(expo2, CONVERSION_POW2DIGITCOUNT); if(isConstPool) ConstDigitPool::requestInstance(); shortProductNoZeroCheck(significand, p2, 5).rRound(22); } if(x.isNegative()) { m_negative = true; } }
Index::Index (Config const &config) : default_K(config.get<int>("donkey.defaults.hint_K", 1)), default_R(config.get<float>("donkey.defaults.hint_R", donkey::default_hint_R())) { if (default_K <= 0) throw ConfigError("invalid defaults.hint_K"); if (!isnormal(default_R)) throw ConfigError("invalid defaults.hint_R"); }
static inline float sanitize_denormal(float value) { if (!isnormal(value)) { value = 0.f; } return value; }
// Find the homography that changes the canonical projective basis // into the given four points (x, y, z, w) static void homography_from_four_points(double H[3][3], double x[2], double w[2], double z[2], double y[2]) { // fix the degree of freedom (assuming the four points are finite) double t = 1; // translation coefficients double p = x[0]; double q = x[1]; // "core" 2x2 system double A = w[0] - z[0]; double B = y[0] - z[0]; double C = w[1] - z[1]; double D = y[1] - z[1]; double P = z[0] - y[0] - w[0] + p; double Q = z[1] - y[1] - w[1] + q; double DET = A * D - B * C; double r = (D * P - B * Q) / DET; double s = (A * Q - C * P) / DET; if (!isnormal(DET)) fprintf(stderr, "denormal! DET = %g\n", DET); // solve the rest of the diagonal system double a = w[0] * ( 1 + r ) - p; double b = y[0] * ( 1 + s ) - p; double c = w[1] * ( 1 + r ) - q; double d = y[1] * ( 1 + s ) - q; // fill-in the output H[0][0] = a; H[0][1] = b; H[0][2] = p; H[1][0] = c; H[1][1] = d; H[1][2] = q; H[2][0] = r; H[2][1] = s; H[2][2] = t; }
void PhpResultGenerator::generateAtom (StringBuffer& output, float value) const { output.appendText("d:"); if (value == 0.0) { output.appendText("0.0", 3); } else if (isnormal(value)) { output.appendDecimal(value); } else { int a = isinf(value); if (a == -1) { output.appendText("-INF"); } else if (a == 1) { output.appendText("INF"); } else /* if (isnan(value)) */ { output.appendText("NAN"); } } output.appendText(";"); }
int dcen3x3(float *image, float *xcen, float *ycen) { float mx0=0, mx1=0, mx2=0; float my0=0, my1=0, my2=0; float bx, by, mx , my; int badcen = 0; // Find the peak of the quadratic along each row... badcen += dcen3(image[0 + 3*0], image[1 + 3*0], image[2 + 3*0], &mx0); badcen += dcen3(image[0 + 3*1], image[1 + 3*1], image[2 + 3*1], &mx1); badcen += dcen3(image[0 + 3*2], image[1 + 3*2], image[2 + 3*2], &mx2); // Now along each column... badcen += dcen3(image[0 + 3*0], image[0 + 3*1], image[0 + 3*2], &my0); badcen += dcen3(image[1 + 3*0], image[1 + 3*1], image[1 + 3*2], &my1); badcen += dcen3(image[2 + 3*0], image[2 + 3*1], image[2 + 3*2], &my2); /* are we not okay? */ if (badcen != 6) return 0; // Fit straight line to peak positions along the rows... /* x = (y-1) mx + bx */ bx = (mx0 + mx1 + mx2) / 3.; mx = (mx2 - mx0) / 2.; // ... and along the columns... /* y = (x-1) my + by */ by = (my0 + my1 + my2) / 3.; my = (my2 - my0) / 2.; /* find intersection */ (*xcen) = (mx * (by - my - 1.) + bx) / (1. + mx * my); (*ycen) = ((*xcen) - 1.) * my + by; /* check that we are in the box */ if (((*xcen) < 0.0) || ((*xcen) > 2.0) || ((*ycen) < 0.0) || ((*ycen) > 2.0)){ return (0); } /* check for nan's and inf's */ if (!isnormal(*xcen) || !isnormal(*ycen)) return 0; return (1); } /* end dcen3x3 */
AREXPORT bool ArUtil::floatIsNormal(double f) { #ifdef WIN32 return (!::_isnan(f) && ::_finite(f)); #else return isnormal(f); #endif }
void check_unstable(void) { int c = isnormal(phi[xdim/2][ydim/2])&&isnormal(psi[xdim/2][ydim/2]); if (!c) { printf("It's not stable\n"); s -= TSTP1; if (s<TMIN1) { s += TSTP1; s -= TSTP2; } if (s<TMIN2) { printf("\"t\" cannot be lowered enough to maintain stability.\n"); done = 1; } saverepeat = repeat; repeat = 0; } }
static void get_bitmaps(struct sd *sd, struct mp_osd_res dim, int format, double pts, struct sub_bitmaps *res) { struct sd_ass_priv *ctx = sd->priv; struct MPOpts *opts = sd->opts; bool no_ass = !opts->ass_enabled || ctx->on_top || opts->ass_style_override == 5; bool converted = ctx->is_converted || no_ass; ASS_Track *track = no_ass ? ctx->shadow_track : ctx->ass_track; ASS_Renderer *renderer = ctx->ass_renderer; if (pts == MP_NOPTS_VALUE || !renderer) return; double scale = dim.display_par; if (!converted && (!opts->ass_style_override || opts->ass_vsfilter_aspect_compat)) { // Let's use the original video PAR for vsfilter compatibility: double par = ctx->video_params.p_w / (double)ctx->video_params.p_h; if (isnormal(par)) scale *= par; } configure_ass(sd, &dim, converted, track); ass_set_pixel_aspect(renderer, scale); if (!converted && (!opts->ass_style_override || opts->ass_vsfilter_blur_compat)) { ass_set_storage_size(renderer, ctx->video_params.w, ctx->video_params.h); } else { ass_set_storage_size(renderer, 0, 0); } long long ts = find_timestamp(sd, pts); if (ctx->duration_unknown && pts != MP_NOPTS_VALUE) { mp_ass_flush_old_events(track, ts); ctx->num_seen_packets = 0; sd->preload_ok = false; } if (no_ass) fill_plaintext(sd, pts); int changed; ASS_Image *imgs = ass_render_frame(renderer, track, ts, &changed); mp_ass_packer_pack(ctx->packer, &imgs, 1, changed, format, res); if (!converted && res->num_parts > 0) { // mangle_colors() modifies the color field, so copy the thing. MP_TARRAY_GROW(ctx, ctx->bs, res->num_parts); memcpy(ctx->bs, res->parts, sizeof(ctx->bs[0]) * res->num_parts); res->parts = ctx->bs; mangle_colors(sd, res); } }
void grouping_add_median(RRDR *r, calculated_number value) { struct grouping_median *g = (struct grouping_median *)r->grouping_data; if(unlikely(g->next_pos >= g->series_size)) { error("INTERNAL ERROR: median buffer overflow on chart '%s' - next_pos = %zu, series_size = %zu, r->group = %ld, r->group_points = %ld.", r->st->name, g->next_pos, g->series_size, r->group, r->group_points); } else { if(isnormal(value)) g->series[g->next_pos++] = (LONG_DOUBLE)value; } }
int dcen3a(float f0, float f1, float f2, float *xcen, float* maxval ) { float s, d, aa, sod, kk; kk = (4.0/3.0); s = 0.5 * (f2 - f0); d = 2. * f1 - (f0 + f2); if (d <= 1.e-10*f0) { return (0); } aa = f1 + 0.5 * s * s / d; sod = s / d; if (!isnormal(aa) || !isnormal(s)) return 0; (*xcen) = sod * (1. + kk * (0.25 * d / aa) * (1. - 4. * sod * sod)) + 1.; return (1); }
static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts, struct sub_bitmaps *res) { struct sd_lavc_priv *priv = sd->priv; struct MPOpts *opts = sd->opts; struct sub *current = NULL; for (int n = 0; n < MAX_QUEUE; n++) { struct sub *sub = &priv->subs[n]; if (!sub->valid) continue; if (pts == MP_NOPTS_VALUE || ((sub->pts == MP_NOPTS_VALUE || pts >= sub->pts) && (sub->endpts == MP_NOPTS_VALUE || pts < sub->endpts))) { // Ignore "trailing" subtitles with unknown length after 1 minute. if (sub->endpts == MP_NOPTS_VALUE && pts >= sub->pts + 60) break; current = sub; break; } } if (!current) return; MP_TARRAY_GROW(priv, priv->outbitmaps, current->count); for (int n = 0; n < current->count; n++) priv->outbitmaps[n] = current->inbitmaps[n]; res->parts = priv->outbitmaps; res->num_parts = current->count; if (priv->displayed_id != current->id) res->change_id++; priv->displayed_id = current->id; res->format = SUBBITMAP_INDEXED; double video_par = 0; if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE && opts->stretch_dvd_subs) { // For DVD subs, try to keep the subtitle PAR at display PAR. double par = (priv->video_params.d_w / (double)priv->video_params.d_h) / (priv->video_params.w / (double)priv->video_params.h); if (isnormal(par)) video_par = par; } if (priv->avctx->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE) video_par = -1; int insize[2]; get_resolution(sd, insize); osd_rescale_bitmaps(res, insize[0], insize[1], d, video_par); }