/* * Check if the thresholds against the value and return the appropriate * status code. */ static int check_thresholds(intmax_t value) { if (!warning.defined && !critical.defined) return (NAGIOS_UNKNOWN); if (critical.defined && !inside_range(value, &critical)) return (NAGIOS_CRITICAL); if (warning.defined && !inside_range(value, &warning)) return (NAGIOS_WARNING); return (NAGIOS_OK); }
static void linearize_rx_timestamp(wr_timestamp_t *ts, wr_socket_t *sock, int cntr_ahead) { struct my_socket *s = (struct my_socket *) sock; int trip_lo, trip_hi; int phase; update_dmtd(sock); // "phase" transition: DMTD output value (in picoseconds) // at which the transition of rising edge // TS counter will appear ts->raw_phase = s->dmtd_phase; phase = s->clock_period -1 -s->dmtd_phase; // calculate the range within which falling edge timestamp is stable // (no possible transitions) trip_lo = s->phase_transition - s->clock_period / 4; if(trip_lo < 0) trip_lo += s->clock_period; trip_hi = s->phase_transition + s->clock_period / 4; if(trip_hi >= s->clock_period) trip_hi -= s->clock_period; if(inside_range(trip_lo, trip_hi, phase)) { // We are within +- 25% range of transition area of // rising counter. Take the falling edge counter value as the // "reliable" one. cntr_ahead will be 1 when the rising edge //counter is 1 tick ahead of the falling edge counter ts->nsec -= cntr_ahead ? (s->clock_period / 1000) : 0; // check if the phase is before the counter transition value // and eventually increase the counter by 1 to simulate a // timestamp transition exactly at s->phase_transition //DMTD phase value if(inside_range(trip_lo, s->phase_transition, phase)) ts->nsec += s->clock_period / 1000; } ts->phase = phase - s->phase_transition - 1; if(ts->phase < 0) ts->phase += s->clock_period; ts->phase = s->clock_period - 1 -ts->phase; }
insula::height_map::vec3 const insula::height_map::random_point( object const &o, scalar const water_level, random_engine &engine, flatness_range const &f) { // For now, generate just some random point std::uniform_real_distribution<scalar> xdist( o.extents().left(), o.extents().right()), ydist( o.extents().front(), o.extents().back()); vec2 result; unsigned long iterations = 0; do { result = vec2( xdist( engine), ydist( engine)); if (iterations++ > iteration_threshold) { fcppt::io::cerr << FCPPT_TEXT("I've tried my best to generate a point in the gradient range ") << f << FCPPT_TEXT(" but it didn't work. Now I'll just take the next best point.\n"); break; } } while( o.project(result) < water_level || !inside_range( o.gradient()[ array::dim( static_cast<array::size_type>( result.x()/o.cell_size()), static_cast<array::size_type>( result.y()/o.cell_size()))], f.x(), f.y())); return vec3( result.x(), o.project( result), result.y()); }
void ptpd_netif_linearize_rx_timestamp(wr_timestamp_t *ts, int32_t dmtd_phase, int cntr_ahead, int transition_point, int clock_period) { int trip_lo, trip_hi; int phase; // "phase" transition: DMTD output value (in picoseconds) // at which the transition of rising edge // TS counter will appear ts->raw_phase = dmtd_phase; phase = clock_period -1 - dmtd_phase; // calculate the range within which falling edge timestamp is stable // (no possible transitions) trip_lo = transition_point - clock_period / 4; if(trip_lo < 0) trip_lo += clock_period; trip_hi = transition_point + clock_period / 4; if(trip_hi >= clock_period) trip_hi -= clock_period; if(inside_range(trip_lo, trip_hi, phase)) { // We are within +- 25% range of transition area of // rising counter. Take the falling edge counter value as the // "reliable" one. cntr_ahead will be 1 when the rising edge //counter is 1 tick ahead of the falling edge counter ts->nsec -= cntr_ahead ? (clock_period / 1000) : 0; // check if the phase is before the counter transition value // and eventually increase the counter by 1 to simulate a // timestamp transition exactly at s->phase_transition //DMTD phase value if(inside_range(trip_lo, transition_point, phase)) ts->nsec += clock_period / 1000; } ts->phase = phase - transition_point - 1; if(ts->phase < 0) ts->phase += clock_period; ts->phase = clock_period - 1 -ts->phase; }
/* write 1 line of decoded raster data */ static void write_line(image_t*img,FILE* fp,int pos_y){ int i; unsigned int x; unsigned int written; unsigned char* line=malloc(img->width*3); color_t* C=get_color(img,'C'); color_t* M=get_color(img,'M'); color_t* Y=get_color(img,'Y'); color_t* K=get_color(img,'K'); color_t* c=get_color(img,'c'); color_t* m=get_color(img,'m'); color_t* y=get_color(img,'y'); color_t* k=get_color(img,'k'); /* color_t* H=get_color(img,'H'); */ /*color_t* R=get_color(img,'R');*/ /*color_t* G=get_color(img,'G');*/ /* experimenting with strange colors */ /* color_t* P=get_color2(img,'P'); color_t* Q=get_color2(img,'Q'); color_t* R=get_color2(img,'R'); color_t* S=get_color2(img,'S'); color_t* T=get_color2(img,'T'); */ /* color_t* A=get_color(img,'A'); */ /* color_t* B=get_color(img,'B'); */ /* color_t* D=get_color(img,'D'); */ /* color_t* E=get_color(img,'E'); */ /* color_t* F=get_color(img,'F'); */ /* color_t* I=get_color(img,'I'); */ /* color_t* J=get_color(img,'J'); */ /* color_t* L=get_color(img,'L'); */ /* color_t* N=get_color(img,'N'); */ /* color_t* O=get_color(img,'O'); */ /* color_t* P=get_color(img,'P'); */ /* color_t* Q=get_color(img,'Q'); */ /* color_t* S=get_color(img,'S'); */ /* color_t* T=get_color(img,'T'); */ /* color_t* U=get_color(img,'U'); */ /* color_t* V=get_color(img,'V'); */ /* color_t* W=get_color(img,'W'); */ /* color_t* X=get_color(img,'X'); */ /* color_t* Z=get_color(img,'Z'); */ /* color_t* a=get_color(img,'a'); */ /* color_t* b=get_color(img,'b'); */ /* color_t* d=get_color(img,'d'); */ /* color_t* e=get_color(img,'e'); */ /* color_t* f=get_color(img,'f'); */ GetBitContext gb[MAX_COLORS]; /* move iterator */ advance(img,pos_y); /* init get bits */ for(i=0;i<MAX_COLORS;i++){ if(inside_range(&(img->color[i]),0,pos_y)){ init_get_bits(&(gb[i]),img->color[i].pos->buf,img->color[i].pos->len); } } for(x=0;x<img->width;x++){ int lK=0,lM=0,lY=0,lC=0; /* initialize so can add same colors together later */ for(i=0;i<MAX_COLORS;i++){ img->color[i].value=0; } for(i=0;i<MAX_COLORS;i++){ if(inside_range(&img->color[i],x,pos_y)) { /*img->color[i].value = get_bits(&gb[i],img->color[i].bpp);*/ img->color[i].value += get_bits(&gb[i],img->color[i].bpp); /* printf("getting pixel values for color %d\n",i);*/ /*if (img->color[i].value != 0) printf("what pixel values for color %d: %x\n",i,img->color[i].value);*/ if (i>7){ fprintf(stderr,"getting pixel values for color %d\n",i);/* only going 0 1 2 4 5 --- missing i>7 bugger! */ /*img->color[i].value = 1;*/ fprintf(stderr,"color %c has value %d\n",img->color[i].name,img->color[i].value); } /* add 0x80 to colors where 0x80 is seen added in inkset */ } else if(i>7) { /* can we force some results here? */ /*img->color[i].value = 1;*/ /*get_bits(&gb[i],img->color[i].bpp);*/ } else { /*printf(" NOT getting pixel values for color %d\n",i);*/ img->color[i].value = 0; } /* update statistics */ (img->color[i].dots)[img->color[i].value] += 1; /* set to 1 if the level is used */ (img->color[i].usedlevels)[img->color[i].value]=1; } /* calculate CMYK values */ /* lK=K->density * K->value/(K->level-1) + k->density * k->value/(k->level-1); lM=M->density * M->value/(M->level-1) + m->density * m->value/(m->level-1); lY=Y->density * Y->value/(Y->level-1) + y->density * y->value/(y->level-1); lC=C->density * C->value/(C->level-1) + c->density * c->value/(c->level-1);*/ lK=K->density * K->value/(K->level-1) + k->density * k->value/(k->level-1); lM=M->density * M->value/(M->level-1) + m->density * m->value/(m->level-1); lY=Y->density * Y->value/(Y->level-1) + y->density * y->value/(y->level-1); lC=C->density * C->value/(C->level-1) + c->density * c->value/(c->level-1); /* detect image edges */ if(lK || lM || lY || lC){ if(!img->image_top) img->image_top = pos_y; img->image_bottom = pos_y; if(x < img->image_left) img->image_left = x; if(x > img->image_right) img->image_right = x; } /* clip values */ if(lK > 255) lK = 255; if(lM > 255) lM = 255; if(lC > 255) lC = 255; if(lY > 255) lY = 255; /* convert to RGB */ /* 0 == black, 255 == white */ line[x*3]=255 - lC - lK; line[x*3+1]=255 - lM -lK; line[x*3+2]=255 - lY -lK; ++img->dots; } /* output line */ if((written = fwrite(line,img->width,3,fp)) != 3) { fprintf(stderr,"fwrite failed %u vs %u\n",written,img->width*3); } free(line); }