void draw_princess_room_stars (ALLEGRO_BITMAP *bitmap, enum vm vm) { int i, min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; static struct star s[6] = { {20,97,0}, {16,104,1}, {23,110,0}, {17,116,1}, {24,120,2}, {18,128,2}}; static struct stars_bitmap sb = {.b = NULL}; if (! sb.b) { for (i = 0; i < 6; i++) { min_x = min_int (min_x, s[i].x); min_y = min_int (min_y, s[i].y); max_x = max_int (max_x, s[i].x); max_y = max_int (max_y, s[i].y); } sb.b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1); clear_bitmap (sb.b, TRANSPARENT_COLOR); sb.c.x = min_x; sb.c.y = min_y; redraw_stars_bitmap (&s[0], &sb, 6, vm); } if (vm != last_vm) { redraw_stars_bitmap (&s[0], &sb, 6, vm); last_vm = vm; } draw_stars (bitmap, s, &sb, 6, vm); }
bool intersection_rectangle (int x0, int y0, int w0, int h0, int x1, int y1, int w1, int h1, int *xrp, int *yrp, int *wrp, int *hrp) { if (w0 <= 0 || h0 <= 0 || w1 <= 0 || h1 <= 0) { *xrp = 0; *yrp = 0; *wrp = 0; *hrp = 0; return false; } int xr = max_int (x0, x1); int yr = max_int (y0, y1); int x0b = x0 + w0 - 1; int y0b = y0 + h0 - 1; int x1b = x1 + w1 - 1; int y1b = y1 + h1 - 1; int xrb = min_int (x0b, x1b); int yrb = min_int (y0b, y1b); int wr = xrb - xr + 1; int hr = yrb - yr + 1; *xrp = xr; *yrp = yr; *wrp = wr > 0 ? wr : 0; *hrp = hr > 0 ? hr : 0; return wr > 0 && hr > 0; }
static void Padding_pack(Widget *this_) { Padding * const instance = (Padding *)this_; Vector2i const desired_content_size = instance->content->desired_size; instance->content->absolute_position = this_->absolute_position; Vector2i_add_xy(&instance->content->absolute_position, instance->amount, instance->amount); instance->content->actual_size.x = max_int(min_int(desired_content_size.x, instance->base.actual_size.x) - (2 * instance->amount), 0); instance->content->actual_size.y = max_int(min_int(desired_content_size.y, instance->base.actual_size.y) - (2 * instance->amount), 0); Widget_pack(instance->content); }
void draw_princess_room_stars (ALLEGRO_BITMAP *bitmap, enum vm vm) { int i, min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; static struct star s[6] = { {20,97,0}, {16,104,1}, {23,110,0}, {17,116,1}, {24,120,2}, {18,128,2}}; static struct stars stars = {.b = NULL, .s = s, .count = 6}; if (! stars.b) { for (i = 0; i < 6; i++) { min_x = min_int (min_x, stars.s[i].x); min_y = min_int (min_y, stars.s[i].y); max_x = max_int (max_x, stars.s[i].x); max_y = max_int (max_y, stars.s[i].y); } stars.b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1); clear_bitmap (stars.b, TRANSPARENT_COLOR); stars.c.x = min_x; stars.c.y = min_y; redraw_stars_bitmap (&stars, vm); } if (vm != mr.last.vm) redraw_stars_bitmap (&stars, vm); draw_stars (bitmap, &stars, vm); } void draw_balcony_stars (ALLEGRO_BITMAP *bitmap, struct pos *p, enum vm vm) { if (con (p)->bg != BALCONY) return; struct pos np; npos (p, &np); if (! np.room) return; struct stars *stars = &mr.cell[mr.dx][mr.dy].stars[np.floor][np.place]; if (vm != mr.last.vm) redraw_stars_bitmap (stars, vm); draw_stars (bitmap, stars, vm); } static struct star * star_coord (struct pos *p, int i, struct star *s) { s->x = PLACE_WIDTH * p->place + 16 + prandom_pos_uniq (p, 2 * i, 1, 28); s->y = PLACE_HEIGHT * p->floor - 3 + prandom_pos_uniq (p, 2 * i + 1, 1, 21); return s; }
/********************************************************************** ** read_readable (int*, int, int, char_buffer_t*) ** ** Call select() on a list of file descriptors. If any are readable, ** read from each readable descriptor, appending the data to the ** provided char_buffer_t. ** ** Return value: ** 0 on success ** -1 if select() fails ** value of the bad fd on failure (e.g. if stderr encountered an ** error, the return value would be 2) */ int read_readable (int *fds, int fdcount, int timeoutsec, char_buffer_t *ls_buffer) { fd_set readfds, errorfds; struct timeval timeout; int i, readycount; FD_ZERO (&readfds); FD_ZERO (&errorfds); for (i = 0; i < fdcount; i++) { FD_SET (fds[i], &readfds); FD_SET (fds[i], &errorfds); } timeout.tv_sec = timeoutsec; timeout.tv_usec = 0; readycount = select (max_int(fds, fdcount) + 1, &readfds, NULL, &errorfds, &timeout); if (readycount == -1) return -1; if (readycount > 0) { for (i = 0; i < fdcount; i++) { if (FD_ISSET (fds[i], &errorfds)) return fds[i]; if (FD_ISSET (fds[i], &readfds)) { if (read_fd_into_char_buffer (ls_buffer, fds[i]) != 0) { return fds[i]; } } } } return 0; }
int maximum_int(int xs[], int n) { int mx = 0; for (int i = 0; i < n; i++) mx = max_int(mx, xs[i]); return mx; }
void cal_joy( int m, int n ) { int x = m-1; int y = n-1; if( x < 0 || y < 0 ) { printf( "Input bigger number!!!\n" ); return; } joy[0][0] = joy_map[0][0]; int i, j; for( i = 1; i <= x; i++ ) { joy[i][0] = joy[i-1][0] + joy_map[i][0]; } for( j = 1; j <= y; j++ ) { joy[0][j] = joy[0][j-1] + joy_map[0][j]; } for( i = 1; i <= x; i++ ) { for( j = 1; j <= y; j++ ) { joy[i][j] = max_int( joy[i-1][j], joy[i][j-1] ) + joy_map[i][j]; } } }
void joy_draw( int m, int n ) { joy[0][0] = joy_map[0][0]; int i, j; for (i = 1; i <= m; ++i) { joy[i][0] = joy[i-1][0] + joy_map[i][0]; from[i][0] = LEFT; } for (j = 1; j <= n; ++j) { joy[0][j] = joy[0][j-1] + joy_map[0][j]; from[0][j] = UP; } for (i = 1; i <= m; ++i) { for (j = 1; j <= n; ++j) { if( joy[i-1][j] > joy[i][j-1] ) { from[i][j] = LEFT; } else { from[i][j] = UP; } joy[i][j] = max_int( joy[i-1][j], joy[i][j-1] ) + joy_map[i][j]; } } }
bool union_rectangle (int x0, int y0, int w0, int h0, int x1, int y1, int w1, int h1, int *xrp, int *yrp, int *wrp, int *hrp) { if ((w0 <= 0 || h0 <= 0) && (w1 > 0 && h1 > 0)) { *xrp = x1; *yrp = y1; *wrp = w1; *hrp = h1; return true; } else if ((w1 <= 0 || h1 <= 0) && (w0 > 0 && h0 > 0)) { *xrp = x0; *yrp = y0; *wrp = w0; *hrp = h0; return true; } else if ((w0 <= 0 || h0 <= 0) && (w1 <= 0 && h1 <= 0)) { *xrp = 0; *yrp = 0; *wrp = 0; *hrp = 0; return false; } int xr = min_int (x0, x1); int yr = min_int (y0, y1); int x0b = x0 + w0 - 1; int y0b = y0 + h0 - 1; int x1b = x1 + w1 - 1; int y1b = y1 + h1 - 1; int xrb = max_int (x0b, x1b); int yrb = max_int (y0b, y1b); int wr = xrb - xr + 1; int hr = yrb - yr + 1; *xrp = xr; *yrp = yr; *wrp = wr > 0 ? wr : 0; *hrp = hr > 0 ? hr : 0; return wr > 0 && hr > 0; }
void print_max(int a,int b, int c) { int max = max_int(a,b,c); printf("MAX = %d\n", max); return; }
int main(int argc,char *arv[]) { int a[]= {1,2,34,12,45}; max_int(a,sizeof(a)/sizeof(a[0])); return 0; }
void generate_stars_for_pos (struct pos *p) { struct pos np; npos (p, &np); int x, y; if (! mr_coord (np.room, -1, &x, &y)) return; struct stars *stars = &mr.cell[x][y].stars[np.floor][np.place]; destroy_bitmap (stars->b); stars->b = NULL; if (stars->s) al_free (stars->s); stars->s = NULL; stars->count = 0; if (con (&np)->bg != BALCONY) return; stars->count = 3 + prandom_pos (&np, 5); stars->s = xcalloc (stars->count, sizeof (* stars->s)); int i, min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; for (i = 0; i < stars->count; i++) { struct star *s = &stars->s[i]; star_coord (&np, i, s); min_x = min_int (min_x, s->x); min_y = min_int (min_y, s->y); max_x = max_int (max_x, s->x); max_y = max_int (max_y, s->y); s->color = next_color (s->color); } stars->b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1); clear_bitmap (stars->b, TRANSPARENT_COLOR); new_coord (&stars->c, np.l, np.room, min_x, min_y); redraw_stars_bitmap (stars, vm); }
static void compute_stars_position (int last_room, int room) { struct pos p; p.room = room; int i, min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN; for (p.floor = FLOORS; p.floor >= -1; p.floor--) for (p.place = -1; p.place < PLACES; p.place++) { struct stars_bitmap *sb = &stars_bitmap[p.floor + 1][p.place + 1]; if (sb->b) { al_destroy_bitmap (sb->b); sb->b = NULL; } if (con (&p)->bg != BALCONY) continue; for (i = 0; i < STARS; i++) { struct star *s = &star[p.floor + 1][p.place + 1][i]; star_coord (&p, i, s); min_x = min_int (min_x, s->x); min_y = min_int (min_y, s->y); max_x = max_int (max_x, s->x); max_y = max_int (max_y, s->y); s->color = next_color (s->color); } sb->b = create_bitmap (max_x - min_x + 1, max_y - min_y + 1); clear_bitmap (sb->b, TRANSPARENT_COLOR); sb->c.room = room; sb->c.x = min_x; sb->c.y = min_y; redraw_stars_bitmap (star[p.floor + 1][p.place + 1], sb, STARS, vm); } }
int max_joy( int m, int n ) { int x = m-1; int y = n-1; if( x < 0 || y < 0 ) { printf( "Input bigger number!!!\n" ); return -1; } if( x == 0 && y == 0 ) return joy_map[0][0]; if( x > 0 && y == 0 ) return max_joy(m-1, n) + joy_map[x][y]; if( x == 0 && y > 0 ) return max_joy(m, n-1) + joy_map[x][y]; if( x > 0 && y > 0 ) return max_int( max_joy(m-1, n), max_joy(m, n-1) ) + joy_map[x][y]; }
struct multi_tcp * multi_tcp_init(int maxevents, int *maxclients) { struct multi_tcp *mtcp; const int extra_events = BASE_N_EVENTS; ASSERT(maxevents >= 1); ASSERT(maxclients); ALLOC_OBJ_CLEAR(mtcp, struct multi_tcp); mtcp->maxevents = maxevents + extra_events; mtcp->es = event_set_init(&mtcp->maxevents, 0); wait_signal(mtcp->es, MTCP_SIG); ALLOC_ARRAY(mtcp->esr, struct event_set_return, mtcp->maxevents); *maxclients = max_int(min_int(mtcp->maxevents - extra_events, *maxclients), 1); msg(D_MULTI_LOW, "MULTI: TCP INIT maxclients=%d maxevents=%d", *maxclients, mtcp->maxevents); return mtcp; }
/********************************************************************** ** write_writable (int*, int, int, char_buffer_t*) ** ** Call select() on a list of file descriptors. If any are writable, ** write the contents of the provided char_buffer_t to each writable ** descriptor. ** ** Return value: ** 0 on success ** -1 if select() fails ** -2 if only part of the buffer was written to the descriptor ** value of the bad fd on failure (e.g. if stderr encountered an ** error, the return value would be 2) */ int write_writable (int *fds, int fdcount, int timeoutsec, char_buffer_t *ls_buffer) { fd_set writefds, errorfds; struct timeval timeout; int i, readycount; ssize_t byteswritten; FD_ZERO (&writefds); FD_ZERO (&errorfds); for (i = 0; i < fdcount; i++) { FD_SET (fds[i], &writefds); FD_SET (fds[i], &errorfds); } timeout.tv_sec = timeoutsec; timeout.tv_usec = 0; readycount = select (max_int(fds, fdcount) + 1, NULL, &writefds, &errorfds, &timeout); if (readycount == -1) return -1; if (readycount > 0) { for (i = 0; i < fdcount; i++) { if (FD_ISSET (fds[i], &errorfds)) return fds[i]; if (FD_ISSET (fds[i], &writefds)) { byteswritten = write (fds[i], get_char_buffer_read_ptr (ls_buffer), get_char_buffer_contlen (ls_buffer)); if (byteswritten == -1) return fds[i]; if (byteswritten < get_char_buffer_contlen (ls_buffer)) { return -2; } } } } return 0; }
patchMatchParameterStruct * initialise_patch_match_parameters( int patchSizeX, int patchSizeY, int imgSizeX, int imgSizeY, bool verboseMode) { patchMatchParameterStruct *patchMatchParams = new patchMatchParameterStruct; //set parameter structure patchMatchParams->patchSizeX = patchSizeX; patchMatchParams->patchSizeY = patchSizeY; patchMatchParams->patchSizeT = 1; patchMatchParams->nIters = 10; //number of propagation/random search steps in patchMatch patchMatchParams->w = max_int(imgSizeX,imgSizeY); //maximum search radius patchMatchParams->alpha = 0.5; //search radius shrinkage factor (0.5 in standard PatchMatch) patchMatchParams->maxShiftDistance = -1; patchMatchParams->partialComparison = 0; patchMatchParams->fullSearch = 0; //texture attributes patchMatchParams->normGradX = NULL; patchMatchParams->normGradY = NULL; patchMatchParams->verboseMode = verboseMode; return(patchMatchParams); }
void check_param(struct param *in){ /* nstart & K */ if(in->nstart > in->nsus){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: initial number of infections greater than host population.\n"); exit(1); } /* nsus */ if(in->nsus < 1){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: less than one host in population.\n"); exit(1); } /* nstart */ if(in->nstart < 1){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: less than one initial infection.\n"); exit(1); } /* L */ if(in->L < 1){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: genome length less than one.\n"); exit(1); } if(in->L < 1){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: genome length less than one.\n"); exit(1); } /* t1 */ if(in->t1 < 1){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: time to infectiousness less than one.\n"); exit(1); } /* t2 */ if(in->t2 < 1){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: infection duration less than one.\n"); exit(1); } /* t1 & t2 */ if(in->t1 > in->t2){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: infections last less than time to infectiousness.\n"); exit(1); } /* mu */ if(in->mu < 0.0){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: negative mutation rate.\n"); exit(1); } /* beta */ if(in->beta < 0.0){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: negative reproductive number.\n"); exit(1); } /* n_sample */ if(in->n_sample < 0){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: negative sample size.\n"); exit(1); } /* t_sample */ if(min_int(in->t_sample, in->n_sample) < 0){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: negative sampling time detected.\n"); exit(1); } if(max_int(in->t_sample, in->n_sample) > in->duration){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: sampling time span (%d) longer than epidemic duration (%d).\n", max_int(in->t_sample, in->n_sample), in->duration); exit(1); } /* npop */ if(in->npop < 1){ fprintf(stderr, "\n[in: param.c->check_param]\nParameter error: number of populations < 1.\n"); exit(1); } }
ALLEGRO_BITMAP * create_loose_floor_01_bitmap (enum em em, enum vm vm) { ALLEGRO_BITMAP *loose_floor_base_01 = NULL, *loose_floor_left_01 = NULL, *loose_floor_right_01 = NULL; switch (em) { case DUNGEON: switch (vm) { case CGA: loose_floor_base_01 = dc_loose_floor_base_01; loose_floor_left_01 = dc_loose_floor_left_01; loose_floor_right_01 = dc_loose_floor_right_01; break; case EGA: loose_floor_base_01 = de_loose_floor_base_01; loose_floor_left_01 = de_loose_floor_left_01; loose_floor_right_01 = de_loose_floor_right_01; break; case VGA: loose_floor_base_01 = dv_loose_floor_base_01; loose_floor_left_01 = dv_loose_floor_left_01; loose_floor_right_01 = dv_loose_floor_right_01; break; } break; case PALACE: switch (vm) { case CGA: loose_floor_base_01 = pc_loose_floor_base_01; loose_floor_left_01 = pc_loose_floor_left_01; loose_floor_right_01 = pc_loose_floor_right_01; break; case EGA: loose_floor_base_01 = pe_loose_floor_base_01; loose_floor_left_01 = pe_loose_floor_left_01; loose_floor_right_01 = pe_loose_floor_right_01; break; case VGA: loose_floor_base_01 = pv_loose_floor_base_01; loose_floor_left_01 = pv_loose_floor_left_01; loose_floor_right_01 = pv_loose_floor_right_01; break; } break; } int wl = al_get_bitmap_width (loose_floor_left_01); int wr = al_get_bitmap_width (loose_floor_right_01); int w = wl + wr; int hl = al_get_bitmap_height (loose_floor_left_01); int hr = al_get_bitmap_height (loose_floor_right_01); int hb = al_get_bitmap_height (loose_floor_base_01); int h = max_int (hl, hr) + hb; ALLEGRO_BITMAP *bitmap = create_bitmap (w, h); clear_bitmap (bitmap, al_map_rgba (0, 0, 0, 0)); draw_bitmap (loose_floor_base_01, bitmap, 0, 14, 0); draw_bitmap (loose_floor_left_01, bitmap, 0, 1, 0); draw_bitmap (loose_floor_right_01, bitmap, 32, 0, 0); validate_bitmap_for_mingw (bitmap); return bitmap; }
void process_incoming_link (struct context *c) { struct gc_arena gc = gc_new (); bool decrypt_status; struct link_socket_info *lsi = get_link_socket_info (c); const uint8_t *orig_buf = c->c2.buf.data; perf_push (PERF_PROC_IN_LINK); if (c->c2.buf.len > 0) { c->c2.link_read_bytes += c->c2.buf.len; link_read_bytes_global += c->c2.buf.len; #ifdef ENABLE_MEMSTATS if (mmap_stats) mmap_stats->link_read_bytes = link_read_bytes_global; #endif c->c2.original_recv_size = c->c2.buf.len; #ifdef ENABLE_MANAGEMENT if (management) { management_bytes_in (management, c->c2.buf.len); #ifdef MANAGEMENT_DEF_AUTH management_bytes_server (management, &c->c2.link_read_bytes, &c->c2.link_write_bytes, &c->c2.mda_context); #endif } #endif } else c->c2.original_recv_size = 0; #ifdef ENABLE_DEBUG /* take action to corrupt packet if we are in gremlin test mode */ if (c->options.gremlin) { if (!ask_gremlin (c->options.gremlin)) c->c2.buf.len = 0; corrupt_gremlin (&c->c2.buf, c->options.gremlin); } #endif /* log incoming packet */ #ifdef LOG_RW if (c->c2.log_rw && c->c2.buf.len > 0) fprintf (stderr, "R"); #endif msg (D_LINK_RW, "%s READ [%d] from %s: %s", proto2ascii (lsi->proto, true), BLEN (&c->c2.buf), print_link_socket_actual (&c->c2.from, &gc), PROTO_DUMP (&c->c2.buf, &gc)); /* * Good, non-zero length packet received. * Commence multi-stage processing of packet, * such as authenticate, decrypt, decompress. * If any stage fails, it sets buf.len to 0 or -1, * telling downstream stages to ignore the packet. */ if (c->c2.buf.len > 0) { if (!link_socket_verify_incoming_addr (&c->c2.buf, lsi, &c->c2.from)) link_socket_bad_incoming_addr (&c->c2.buf, lsi, &c->c2.from); #ifdef ENABLE_CRYPTO #ifdef ENABLE_SSL if (c->c2.tls_multi) { /* * If tls_pre_decrypt returns true, it means the incoming * packet was a good TLS control channel packet. If so, TLS code * will deal with the packet and set buf.len to 0 so downstream * stages ignore it. * * If the packet is a data channel packet, tls_pre_decrypt * will load crypto_options with the correct encryption key * and return false. */ if (tls_pre_decrypt (c->c2.tls_multi, &c->c2.from, &c->c2.buf, &c->c2.crypto_options)) { interval_action (&c->c2.tmp_int); /* reset packet received timer if TLS packet */ if (c->options.ping_rec_timeout) event_timeout_reset (&c->c2.ping_rec_interval); } } #if P2MP_SERVER /* * Drop non-TLS packet if client-connect script/plugin has not * yet succeeded. */ if (c->c2.context_auth != CAS_SUCCEEDED) c->c2.buf.len = 0; #endif #endif /* ENABLE_SSL */ /* authenticate and decrypt the incoming packet */ decrypt_status = openvpn_decrypt (&c->c2.buf, c->c2.buffers->decrypt_buf, &c->c2.crypto_options, &c->c2.frame); if (!decrypt_status && link_socket_connection_oriented (c->c2.link_socket)) { /* decryption errors are fatal in TCP mode */ register_signal (c, SIGUSR1, "decryption-error"); /* SOFT-SIGUSR1 -- decryption error in TCP mode */ msg (D_STREAM_ERRORS, "Fatal decryption error (process_incoming_link), restarting"); goto done; } #endif /* ENABLE_CRYPTO */ #ifdef ENABLE_FRAGMENT if (c->c2.fragment) fragment_incoming (c->c2.fragment, &c->c2.buf, &c->c2.frame_fragment); #endif #ifdef ENABLE_LZO /* decompress the incoming packet */ if (lzo_defined (&c->c2.lzo_compwork)) lzo_decompress (&c->c2.buf, c->c2.buffers->lzo_decompress_buf, &c->c2.lzo_compwork, &c->c2.frame); #endif #ifdef PACKET_TRUNCATION_CHECK /* if (c->c2.buf.len > 1) --c->c2.buf.len; */ ipv4_packet_size_verify (BPTR (&c->c2.buf), BLEN (&c->c2.buf), TUNNEL_TYPE (c->c1.tuntap), "POST_DECRYPT", &c->c2.n_trunc_post_decrypt); #endif /* * Set our "official" outgoing address, since * if buf.len is non-zero, we know the packet * authenticated. In TLS mode we do nothing * because TLS mode takes care of source address * authentication. * * Also, update the persisted version of our packet-id. */ if (!TLS_MODE (c)) link_socket_set_outgoing_addr (&c->c2.buf, lsi, &c->c2.from, NULL, c->c2.es); /* reset packet received timer */ if (c->options.ping_rec_timeout && c->c2.buf.len > 0) event_timeout_reset (&c->c2.ping_rec_interval); /* increment authenticated receive byte count */ if (c->c2.buf.len > 0) { c->c2.link_read_bytes_auth += c->c2.buf.len; c->c2.max_recv_size_local = max_int (c->c2.original_recv_size, c->c2.max_recv_size_local); } /* Did we just receive an openvpn ping packet? */ if (is_ping_msg (&c->c2.buf)) { dmsg (D_PING, "RECEIVED PING PACKET"); c->c2.buf.len = 0; /* drop packet */ } #ifdef ENABLE_OCC /* Did we just receive an OCC packet? */ if (is_occ_msg (&c->c2.buf)) process_received_occ_msg (c); #endif buffer_turnover (orig_buf, &c->c2.to_tun, &c->c2.buf, &c->c2.buffers->read_link_buf); /* to_tun defined + unopened tuntap can cause deadlock */ if (!tuntap_defined (c->c1.tuntap)) c->c2.to_tun.len = 0; } else { buf_reset (&c->c2.to_tun); } done: perf_pop (); gc_free (&gc); }
ALLEGRO_BITMAP * create_broken_floor_bitmap (enum em em, enum vm vm) { ALLEGRO_BITMAP *broken_floor_left = NULL, *broken_floor_right = NULL, *floor_base = NULL; switch (em) { case DUNGEON: switch (vm) { case CGA: broken_floor_left = dc_broken_floor_left; broken_floor_right = dc_broken_floor_right; floor_base = dc_floor_base; break; case EGA: broken_floor_left = de_broken_floor_left; broken_floor_right = de_broken_floor_right; floor_base = de_floor_base; break; case VGA: broken_floor_left = dv_broken_floor_left; broken_floor_right = dv_broken_floor_right; floor_base = dv_floor_base; break; } break; case PALACE: switch (vm) { case CGA: broken_floor_left = pc_broken_floor_left; broken_floor_right = pc_broken_floor_right; floor_base = pc_floor_base; break; case EGA: broken_floor_left = pe_broken_floor_left; broken_floor_right = pe_broken_floor_right; floor_base = pe_floor_base; break; case VGA: broken_floor_left = pv_broken_floor_left; broken_floor_right = pv_broken_floor_right; floor_base = pv_floor_base; break; } break; } int wl = al_get_bitmap_width (broken_floor_left); int wr = al_get_bitmap_width (broken_floor_right); int w = wl + wr; int hl = al_get_bitmap_height (broken_floor_left); int hr = al_get_bitmap_height (broken_floor_right); int hb = al_get_bitmap_height (floor_base); int h = max_int (hl, hr) + hb; ALLEGRO_BITMAP *bitmap = create_bitmap (w, h); clear_bitmap (bitmap, al_map_rgba (0, 0, 0, 0)); draw_bitmap (floor_base, bitmap, 0, 14, 0); draw_bitmap (broken_floor_left, bitmap, 0, 1, 0); draw_bitmap (broken_floor_right, bitmap, 32, 0, 0); validate_bitmap_for_mingw (bitmap); return bitmap; }
void process_outgoing_link (struct context *c) { struct gc_arena gc = gc_new (); perf_push (PERF_PROC_OUT_LINK); if (c->c2.to_link.len > 0 && c->c2.to_link.len <= EXPANDED_SIZE (&c->c2.frame)) { /* * Setup for call to send/sendto which will send * packet to remote over the TCP/UDP port. */ int size = 0; ASSERT (link_socket_actual_defined (c->c2.to_link_addr)); #ifdef ENABLE_DEBUG /* In gremlin-test mode, we may choose to drop this packet */ if (!c->options.gremlin || ask_gremlin (c->options.gremlin)) #endif { /* * Let the traffic shaper know how many bytes * we wrote. */ #ifdef ENABLE_FEATURE_SHAPER if (c->options.shaper) shaper_wrote_bytes (&c->c2.shaper, BLEN (&c->c2.to_link) + datagram_overhead (c->options.ce.proto)); #endif /* * Let the pinger know that we sent a packet. */ if (c->options.ping_send_timeout) event_timeout_reset (&c->c2.ping_send_interval); #if PASSTOS_CAPABILITY /* Set TOS */ link_socket_set_tos (c->c2.link_socket); #endif /* Log packet send */ #ifdef LOG_RW if (c->c2.log_rw) fprintf (stderr, "W"); #endif msg (D_LINK_RW, "%s WRITE [%d] to %s: %s", proto2ascii (c->c2.link_socket->info.proto, true), BLEN (&c->c2.to_link), print_link_socket_actual (c->c2.to_link_addr, &gc), PROTO_DUMP (&c->c2.to_link, &gc)); /* Packet send complexified by possible Socks5 usage */ { struct link_socket_actual *to_addr = c->c2.to_link_addr; #ifdef ENABLE_SOCKS int size_delta = 0; #endif #ifdef ENABLE_SOCKS /* If Socks5 over UDP, prepend header */ socks_preprocess_outgoing_link (c, &to_addr, &size_delta); #endif /* Send packet */ size = link_socket_write (c->c2.link_socket, &c->c2.to_link, to_addr); #ifdef ENABLE_SOCKS /* Undo effect of prepend */ link_socket_write_post_size_adjust (&size, size_delta, &c->c2.to_link); #endif } if (size > 0) { c->c2.max_send_size_local = max_int (size, c->c2.max_send_size_local); c->c2.link_write_bytes += size; link_write_bytes_global += size; #ifdef ENABLE_MEMSTATS if (mmap_stats) mmap_stats->link_write_bytes = link_write_bytes_global; #endif #ifdef ENABLE_MANAGEMENT if (management) { management_bytes_out (management, size); #ifdef MANAGEMENT_DEF_AUTH management_bytes_server (management, &c->c2.link_read_bytes, &c->c2.link_write_bytes, &c->c2.mda_context); #endif } #endif } } /* Check return status */ check_status (size, "write", c->c2.link_socket, NULL); if (size > 0) { /* Did we write a different size packet than we intended? */ if (size != BLEN (&c->c2.to_link)) msg (D_LINK_ERRORS, "TCP/UDP packet was truncated/expanded on write to %s (tried=%d,actual=%d)", print_link_socket_actual (c->c2.to_link_addr, &gc), BLEN (&c->c2.to_link), size); } /* if not a ping/control message, indicate activity regarding --inactive parameter */ if (c->c2.buf.len > 0 ) register_activity (c, size); } else { if (c->c2.to_link.len > 0) msg (D_LINK_ERRORS, "TCP/UDP packet too large on write to %s (tried=%d,max=%d)", print_link_socket_actual (c->c2.to_link_addr, &gc), c->c2.to_link.len, EXPANDED_SIZE (&c->c2.frame)); } buf_reset (&c->c2.to_link); perf_pop (); gc_free (&gc); }
void io_wait_dowork (struct context *c, const unsigned int flags) { unsigned int socket = 0; unsigned int tuntap = 0; struct event_set_return esr[4]; /* These shifts all depend on EVENT_READ and EVENT_WRITE */ static int socket_shift = 0; /* depends on SOCKET_READ and SOCKET_WRITE */ static int tun_shift = 2; /* depends on TUN_READ and TUN_WRITE */ static int err_shift = 4; /* depends on ES_ERROR */ #ifdef ENABLE_MANAGEMENT static int management_shift = 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */ #endif /* * Decide what kind of events we want to wait for. */ event_reset (c->c2.event_set); /* * On win32 we use the keyboard or an event object as a source * of asynchronous signals. */ if (flags & IOW_WAIT_SIGNAL) wait_signal (c->c2.event_set, (void*)&err_shift); /* * If outgoing data (for TCP/UDP port) pending, wait for ready-to-send * status from TCP/UDP port. Otherwise, wait for incoming data on * TUN/TAP device. */ if (flags & IOW_TO_LINK) { if (flags & IOW_SHAPER) { /* * If sending this packet would put us over our traffic shaping * quota, don't send -- instead compute the delay we must wait * until it will be OK to send the packet. */ #ifdef ENABLE_FEATURE_SHAPER int delay = 0; /* set traffic shaping delay in microseconds */ if (c->options.shaper) delay = max_int (delay, shaper_delay (&c->c2.shaper)); if (delay < 1000) { socket |= EVENT_WRITE; } else { shaper_soonest_event (&c->c2.timeval, delay); } #else /* ENABLE_FEATURE_SHAPER */ socket |= EVENT_WRITE; #endif /* ENABLE_FEATURE_SHAPER */ } else { socket |= EVENT_WRITE; } } else if (!((flags & IOW_FRAG) && TO_LINK_FRAG (c))) { if (flags & IOW_READ_TUN) tuntap |= EVENT_READ; } /* * If outgoing data (for TUN/TAP device) pending, wait for ready-to-send status * from device. Otherwise, wait for incoming data on TCP/UDP port. */ if (flags & IOW_TO_TUN) { tuntap |= EVENT_WRITE; } else { if (flags & IOW_READ_LINK) socket |= EVENT_READ; } /* * outgoing bcast buffer waiting to be sent? */ if (flags & IOW_MBUF) socket |= EVENT_WRITE; /* * Force wait on TUN input, even if also waiting on TCP/UDP output */ if (flags & IOW_READ_TUN_FORCE) tuntap |= EVENT_READ; /* * Configure event wait based on socket, tuntap flags. */ socket_set (c->c2.link_socket, c->c2.event_set, socket, (void*)&socket_shift, NULL); tun_set (c->c1.tuntap, c->c2.event_set, tuntap, (void*)&tun_shift, NULL); #ifdef ENABLE_MANAGEMENT if (management) management_socket_set (management, c->c2.event_set, (void*)&management_shift, NULL); #endif /* * Possible scenarios: * (1) tcp/udp port has data available to read * (2) tcp/udp port is ready to accept more data to write * (3) tun dev has data available to read * (4) tun dev is ready to accept more data to write * (5) we received a signal (handler sets signal_received) * (6) timeout (tv) expired */ c->c2.event_set_status = ES_ERROR; if (!c->sig->signal_received) { if (!(flags & IOW_CHECK_RESIDUAL) || !socket_read_residual (c->c2.link_socket)) { int status; #ifdef ENABLE_DEBUG if (check_debug_level (D_EVENT_WAIT)) show_wait_status (c); #endif /* * Wait for something to happen. */ status = event_wait (c->c2.event_set, &c->c2.timeval, esr, SIZE(esr)); check_status (status, "event_wait", NULL, NULL); if (status > 0) { int i; c->c2.event_set_status = 0; for (i = 0; i < status; ++i) { const struct event_set_return *e = &esr[i]; c->c2.event_set_status |= ((e->rwflags & 3) << *((int*)e->arg)); } } else if (status == 0) { c->c2.event_set_status = ES_TIMEOUT; } } else { c->c2.event_set_status = SOCKET_READ; } } /* 'now' should always be a reasonably up-to-date timestamp */ update_time (); /* set signal_received if a signal was received */ if (c->c2.event_set_status & ES_ERROR) get_signal (&c->sig->signal_received); dmsg (D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status); }
static int apply_abr_preset(lame_global_flags * gfp, int preset, int enforce) { int k; typedef struct { int abr_kbps; int quant_comp; int quant_comp_s; int safejoint; FLOAT nsmsfix; FLOAT st_lrm; /*short threshold */ FLOAT st_s; FLOAT nsbass; FLOAT scale; FLOAT masking_adj; FLOAT ath_lower; FLOAT ath_curve; FLOAT interch; int sfscale; } abr_presets_t; /* *INDENT-OFF* */ /* * Switch mappings for ABR mode */ const abr_presets_t abr_switch_map[] = { /* kbps quant q_s safejoint nsmsfix st_lrm st_s ns-bass scale msk ath_lwr ath_curve interch , sfscale */ { 8, 9, 9, 0, 0, 6.60, 145, 0, 0.95, 0, -30.0, 11, 0.0012, 1}, /* 8, impossible to use in stereo */ { 16, 9, 9, 0, 0, 6.60, 145, 0, 0.95, 0, -25.0, 11, 0.0010, 1}, /* 16 */ { 24, 9, 9, 0, 0, 6.60, 145, 0, 0.95, 0, -20.0, 11, 0.0010, 1}, /* 24 */ { 32, 9, 9, 0, 0, 6.60, 145, 0, 0.95, 0, -15.0, 11, 0.0010, 1}, /* 32 */ { 40, 9, 9, 0, 0, 6.60, 145, 0, 0.95, 0, -10.0, 11, 0.0009, 1}, /* 40 */ { 48, 9, 9, 0, 0, 6.60, 145, 0, 0.95, 0, -10.0, 11, 0.0009, 1}, /* 48 */ { 56, 9, 9, 0, 0, 6.60, 145, 0, 0.95, 0, -6.0, 11, 0.0008, 1}, /* 56 */ { 64, 9, 9, 0, 0, 6.60, 145, 0, 0.95, 0, -2.0, 11, 0.0008, 1}, /* 64 */ { 80, 9, 9, 0, 0, 6.60, 145, 0, 0.95, 0, .0, 8, 0.0007, 1}, /* 80 */ { 96, 9, 9, 0, 2.50, 6.60, 145, 0, 0.95, 0, 1.0, 5.5, 0.0006, 1}, /* 96 */ {112, 9, 9, 0, 2.25, 6.60, 145, 0, 0.95, 0, 2.0, 4.5, 0.0005, 1}, /* 112 */ {128, 9, 9, 0, 1.95, 6.40, 140, 0, 0.95, 0, 3.0, 4, 0.0002, 1}, /* 128 */ {160, 9, 9, 1, 1.79, 6.00, 135, 0, 0.95, -2, 5.0, 3.5, 0, 1}, /* 160 */ {192, 9, 9, 1, 1.49, 5.60, 125, 0, 0.97, -4, 7.0, 3, 0, 0}, /* 192 */ {224, 9, 9, 1, 1.25, 5.20, 125, 0, 0.98, -6, 9.0, 2, 0, 0}, /* 224 */ {256, 9, 9, 1, 0.97, 5.20, 125, 0, 1.00, -8, 10.0, 1, 0, 0}, /* 256 */ {320, 9, 9, 1, 0.90, 5.20, 125, 0, 1.00, -10, 12.0, 0, 0, 0} /* 320 */ }; /* *INDENT-ON* */ /* Variables for the ABR stuff */ int r; int actual_bitrate = preset; r = nearestBitrateFullIndex(preset); (void) lame_set_VBR(gfp, vbr_abr); (void) lame_set_VBR_mean_bitrate_kbps(gfp, (actual_bitrate)); (void) lame_set_VBR_mean_bitrate_kbps(gfp, min_int(lame_get_VBR_mean_bitrate_kbps(gfp), 320)); (void) lame_set_VBR_mean_bitrate_kbps(gfp, max_int(lame_get_VBR_mean_bitrate_kbps(gfp), 8)); (void) lame_set_brate(gfp, lame_get_VBR_mean_bitrate_kbps(gfp)); /* parameters for which there is no proper set/get interface */ if (abr_switch_map[r].safejoint > 0) (void) lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | 2); /* safejoint */ if (abr_switch_map[r].sfscale > 0) (void) lame_set_sfscale(gfp, 1); /* ns-bass tweaks */ if (fabs(abr_switch_map[r].nsbass) > 0) { k = (int) (abr_switch_map[r].nsbass * 4); if (k < 0) k += 64; (void) lame_set_exp_nspsytune(gfp, lame_get_exp_nspsytune(gfp) | (k << 2)); } SET_OPTION(quant_comp, abr_switch_map[r].quant_comp, -1); SET_OPTION(quant_comp_short, abr_switch_map[r].quant_comp_s, -1); SET_OPTION(msfix, abr_switch_map[r].nsmsfix, -1); SET_OPTION(short_threshold_lrm, abr_switch_map[r].st_lrm, -1); SET_OPTION(short_threshold_s, abr_switch_map[r].st_s, -1); /* ABR seems to have big problems with clipping, especially at low bitrates */ /* so we compensate for that here by using a scale value depending on bitrate */ SET_OPTION(scale, abr_switch_map[r].scale, -1); SET_OPTION(maskingadjust, abr_switch_map[r].masking_adj, 0); if (abr_switch_map[r].masking_adj > 0) { SET_OPTION(maskingadjust_short, abr_switch_map[r].masking_adj * .9, 0); } else { SET_OPTION(maskingadjust_short, abr_switch_map[r].masking_adj * 1.1, 0); } SET_OPTION(ATHlower, abr_switch_map[r].ath_lower, 0); SET_OPTION(ATHcurve, abr_switch_map[r].ath_curve, -1); SET_OPTION(interChRatio, abr_switch_map[r].interch, -1); return preset; }
void HandleEvent (XEvent * event) { XEvent loop_ev; /* for clearing the queue of events */ switch (event->type) { case KeyPress: { XKeyEvent *key_event = (XKeyEvent *) event; char buf[128]; KeySym ks; XComposeStatus status; XLookupString (key_event, buf, 128, &ks, &status); x_key_shifted = ShiftMask & key_event->state; x_key_value = buf[0]; switch (ks) { case XK_Left: x_key_value = 1; break; case XK_Down: x_key_value = 2; break; case XK_Up: x_key_value = 3; break; case XK_Right: x_key_value = 4; break; #if defined (commentout) /* GCS: What the hell is this??? */ case 'C': if (!confine_pointer(-10,-10,200,200)) unconfine_pointer(); break; #endif case XK_BackSpace: case XK_Delete: x_key_value = 127; break; } } break; case MotionNotify: { XMotionEvent *ev = (XMotionEvent *) event; while (XCheckMaskEvent(display.dpy,PointerMotionMask,&loop_ev)) { ev = (XMotionEvent *) &loop_ev; } #ifdef DEBUG_X11_MOUSE printf("pointer motion event\n"); #endif if (ev->state & Button2Mask) drag_screen(); } break; case ButtonPress: { XButtonEvent *ev = (XButtonEvent *) event; if ((ev->state & ShiftMask) != 0) cs_mouse_shifted = 1; else cs_mouse_shifted = 0; #ifdef DEBUG_X11_MOUSE printf("button press: ev->button = %d\n",ev->button); #endif #if defined (commentout) mouse_button = ev->button; #endif switch (ev->button) { case Button1: mouse_button = LC_MOUSE_LEFTBUTTON | LC_MOUSE_PRESS; break; case Button2: mouse_button = LC_MOUSE_MIDDLEBUTTON | LC_MOUSE_PRESS; break; case Button3: mouse_button = LC_MOUSE_RIGHTBUTTON | LC_MOUSE_PRESS; break; /* Wheel mouse support Move further for Shift (in main.c: process_keystrokes() ), left to right instead of up and down for Control */ case Button4: /* Up (3); Left (1) if Control */ x_key_shifted = ShiftMask & ev->state; x_key_value = (ControlMask & ev->state) ? 1 : 3; break; case Button5: /* Down (4); Right (2) if control */ x_key_shifted = ShiftMask & ev->state; x_key_value = (ControlMask & ev->state) ? 4 : 2; break; /* XFree86-3 only supports 5 buttons, no Button6 or higher */ } cs_mouse_handler (mouse_button, 0, 0); mouse_button = 0; } break; case ButtonRelease: { XButtonEvent *ev = (XButtonEvent *) event; mouse_button = ev->button; #ifdef DEBUG_X11_MOUSE printf("button release: ev->button = %d\n",ev->button); #endif switch (ev->button) { case Button1: mouse_button = LC_MOUSE_LEFTBUTTON | LC_MOUSE_RELEASE; break; case Button2: mouse_button = LC_MOUSE_MIDDLEBUTTON | LC_MOUSE_RELEASE; break; case Button3: mouse_button = LC_MOUSE_RIGHTBUTTON | LC_MOUSE_RELEASE; break; } cs_mouse_handler (mouse_button, 0, 0); mouse_button = 0; } break; case Expose: { XExposeEvent *ev = (XExposeEvent *) event; int gx1,gy1,gx2,gy2; gx1 = ev->x; gy1 = ev->y; gx2 = ev->x + ev->width; gy2 = ev->y + ev->height; /* Coalesce waiting exposes into single redraw */ while (XCheckMaskEvent(display.dpy,ExposureMask,&loop_ev)) { ev = (XExposeEvent *) &loop_ev; gx1 = min_int (gx1,ev->x); gy1 = min_int (gy1,ev->y); gx2 = max_int (gx2,ev->x + ev->width); gy2 = max_int (gy2,ev->y + ev->height); } if (suppress_next_expose) { suppress_next_expose = 0; break; } refresh_screen (gx1,gy1,gx2,gy2); } break; case ConfigureNotify: { XConfigureEvent *ev = (XConfigureEvent *) event; while (XCheckTypedEvent(display.dpy, ConfigureNotify, &loop_ev)) { ev = (XConfigureEvent *) &loop_ev; } resize_geometry (ev->width, ev->height); } break; } //fprintf(stderr,"Handler fell through, event->type = %d\n",event->type); }
void reconstruct_video(nTupleVolume<T>* imgVol, nTupleVolume<T>* occVol, nTupleVolume<T>* dispField, float sigmaColour, int useAllPatches, int reconstructionType) { /*decalarations*/ int xSize, ySize, tSize, nTupleSize; //img Size int i,j,k; //3-D index int iMin,iMax,jMin,jMax,kMin,kMax; //Boundary of index Volume int ii,jj,kk, weightInd; int xDisp, yDisp, tDisp,xDispShift,yDispShift,tDispShift; int shiftI,shiftJ,shiftK; int hPatchSizeX,hPatchSizeY,hPatchSizeT; //half patchsize int hI,hJ,hK,doubleII,doubleJJ,doubleKK; int nbNeighbours; int correctInfo; float alpha, adaptiveSigma; float *weights,sumWeights, avgColourR, avgColourG, avgColourB, *colours; /*get image volume sizes*/ xSize = imgVol->xSize; ySize = imgVol->ySize; tSize = imgVol->tSize; nTupleSize = imgVol->nTupleSize; hPatchSizeX = imgVol->hPatchSizeX; //half patchsize hPatchSizeY = imgVol->hPatchSizeY; hPatchSizeT = imgVol->hPatchSizeT; /*allocate the (maximum) memory for the weights*/ nbNeighbours = (imgVol->patchSizeX)*(imgVol->patchSizeY)*(imgVol->patchSizeT); //number of neighbor weights = (float*)malloc((size_t)(nbNeighbours*sizeof(float))); colours = (float*)malloc((size_t)(NCHANNELS*nbNeighbours*sizeof(float))); /*check certain parameters*/ if( (imgVol->patchSizeX != (imgVol->patchSizeX)) || (imgVol->patchSizeY != (imgVol->patchSizeY)) || (imgVol->patchSizeT != (imgVol->patchSizeT)) ) /*check that the patch sizes are equal*/ //what is this for? { MY_PRINTF("Error in estimate_colour, the size of the patches are not equal in the two image volumes."); return; } if ( ( imgVol->patchSizeX > imgVol->xSize) || ( imgVol->patchSizeY > imgVol->ySize) || ( imgVol->patchSizeT > imgVol->tSize) ) /*check that the patch size is less or equal to each dimension in the images*/ { MY_PRINTF("Error in estimate_colour, the patch size is to large for one or more of the dimensions of the image volume."); return; } for (k=0; k<(occVol->tSize); k++) //run all over occVolume, t dimension for (j=0; j<(occVol->ySize); j++) // y dimension for (i=0; i<(occVol->xSize); i++)//x dimension { if ( ((occVol->get_value(i,j,k,0)) == 0) || ((occVol->get_value(i,j,k,0) == 2) ) ) //do not inpaint continue; else /*an occluded pixel (therefore to be modified)*/ { if (reconstructionType == NEAREST_NEIGHBOUR_RECONSTRUCTION ) //nearest neighbor reconstruction { xDisp = i + (int)dispField->get_value(i,j,k,0); // x Displacement yDisp = j + (int)dispField->get_value(i,j,k,1); // y Displacement tDisp = k + (int)dispField->get_value(i,j,k,2); // t displacement ////if pure replacing of pixels copy_pixel_values_nTuple_volume(imgVol, imgVol,xDisp, yDisp, tDisp, i, j, k); //copy pixel value of ANN to occluded pixel. ///set_value_nTuple_volume(occVol,i,j,k,2,0); ///set_value_nTuple_volume(imgVol,i,j,k,0,0); continue; } // init array weight and colours for (ii=0;ii<(imgVol->patchSizeX)*(imgVol->patchSizeY)*(imgVol->patchSizeT); ii++) //all the pixel in a patch { weights[ii] = (float)-1; //weight for all pixel in patch colours[ii] = (float)-1; //red colours[ii + nbNeighbours] = (float)-1;//green chanel colours[ii + 2*nbNeighbours] = (float)-1; //blue chanel } sumWeights = 0.0; alpha = FLT_MAX; correctInfo = 0; avgColourR = 0.0; avgColourG = 0.0; avgColourB = 0.0; //boudary for each patch iMin = max_int(i - hPatchSizeX,0); iMax = min_int(i + hPatchSizeX,(imgVol->xSize)-1 ); jMin = max_int(j - hPatchSizeY,0); jMax = min_int(j + hPatchSizeY,(imgVol->ySize)-1 ); kMin = max_int(k - hPatchSizeT,0); kMax = min_int(k + hPatchSizeT,(imgVol->tSize)-1 ); /* MY_PRINTF("iMin : %d, iMax : %d\n",iMin,iMax); MY_PRINTF("jMin : %d, jMax : %d\n",jMin,jMax); MY_PRINTF("kMin : %d, kMax : %d\n",kMin,kMax);*/ /*first calculate the weights*/ //run for each patch, calculate the spatial temporal neighbor of the patch for (kk=kMin; kk<=kMax;kk++) //t dimension for (jj=jMin; jj<=jMax;jj++)//y dimension for (ii=iMin; ii<=iMax;ii++) //x dimension { /*get ssd similarity*/ xDisp = ii + (int)dispField->get_value(ii,jj,kk,0); //get value dispX for pixel in the patch yDisp = jj + (int)dispField->get_value(ii,jj,kk,1); tDisp = kk + (int)dispField->get_value(ii,jj,kk,2); /*(spatio-temporally) shifted values of the covering patches*/ xDispShift = xDisp - (ii-i); //i + dispField (dispField for pixel (ii,jj,kk)) yDispShift = yDisp - (jj-j); tDispShift = tDisp - (kk-k); if (useAllPatches == 1) // if use all patches { alpha = (float)min_float(dispField->get_value(ii,jj,kk,3),alpha); //get min SSD and assign to alpha //transform matrice indice to array indice. weightInd = (int)((kk-kMin)*(imgVol->patchSizeX)*(imgVol->patchSizeY) + (jj-jMin)*(imgVol->patchSizeX) + ii-iMin); weights[weightInd] = dispField->get_value(ii,jj,kk,3); //weight is an array, SSD error of patch //colours is an array colours[weightInd] = (float)(imgVol->get_value(xDispShift,yDispShift,tDispShift,0)); //red colours[weightInd + nbNeighbours] = (float)(imgVol->get_value(xDispShift,yDispShift,tDispShift,1));//green colours[weightInd + 2*nbNeighbours] = (float)(imgVol->get_value(xDispShift,yDispShift,tDispShift,2)); //blue correctInfo = 1; } else /*only use some of the patches*/ { if (((occVol->get_value(ii,jj,kk,0)) == 0) || (occVol->get_value(ii,jj,kk,0) ==-1)) { alpha = (float)min_float(dispField->get_value(ii,jj,kk,3),alpha); weightInd = (int)((kk-kMin)*(imgVol->patchSizeX)*(imgVol->patchSizeY) + (jj-jMin)*(imgVol->patchSizeX) + ii-iMin); weights[weightInd] = dispField->get_value(ii,jj,kk,3); colours[weightInd] = (float)(imgVol->get_value(xDispShift,yDispShift,tDispShift,0)); colours[weightInd + nbNeighbours] = (float)(imgVol->get_value(xDispShift,yDispShift,tDispShift,1)); colours[weightInd + 2*nbNeighbours] = (float)(imgVol->get_value(xDispShift,yDispShift,tDispShift,2)); correctInfo = 1; } else { weightInd = (int)((kk-kMin)*(imgVol->patchSizeX)*(imgVol->patchSizeY) + (jj-jMin)*(imgVol->patchSizeX) + ii-iMin); weights[weightInd] = -1; colours[weightInd] = -1; colours[weightInd + nbNeighbours] = -1; colours[weightInd + 2*nbNeighbours] = -1; continue; } } } alpha = max_float(alpha,1); if (correctInfo == 0) continue; if (reconstructionType == BEST_PATCH_RECONSTRUCTION) { estimate_best_colour(imgVol,imgVol, weights, nbNeighbours, colours, sigmaColour, i, j, k); continue; } //get the 75th percentile of the distances for setting the adaptive sigma adaptiveSigma = get_adaptive_sigma(weights,(imgVol->patchSizeX)*(imgVol->patchSizeY)*(imgVol->patchSizeT),sigmaColour); adaptiveSigma = max_float(adaptiveSigma,(float)0.1); /* ///MY_PRINTF("alpha : %f\n",alpha); //adjust the weights : note, the indices which are outside the image boundaries //will have no influence on the final weights (they are initialised to 0) */ for (kk=kMin; kk<=kMax;kk++) for (jj=jMin; jj<=jMax;jj++) for (ii=iMin; ii<=iMax;ii++) { if (useAllPatches) { /*weights = exp( -weights/(2*sigma�*alpha))*/ weightInd = (int)((kk-kMin)*(imgVol->patchSizeX)*(imgVol->patchSizeY) + (jj-jMin)*(imgVol->patchSizeX) + ii-iMin); weights[weightInd] = (float)(exp( - ((weights[weightInd])/(2*adaptiveSigma*adaptiveSigma)) ));/*exp( - ((weights[ii])/(2*sigmaColour*sigmaColour*alpha)) );*/ // sumWeights = (float)(sumWeights+weights[weightInd]); } else /*only use some of the patches*/ { if (((occVol->get_value(ii,jj,kk,0)) == 0) || (occVol->get_value(ii,jj,kk,0) ==-1)) { /*weights = exp( -weights/(2*sigma�*alpha))*/ weightInd = (int)((kk-kMin)*(imgVol->patchSizeX)*(imgVol->patchSizeY) + (jj-jMin)*(imgVol->patchSizeX) + ii-iMin); weights[weightInd] = (float)(exp( - ((weights[weightInd])/(2*adaptiveSigma*adaptiveSigma)) ));/*exp( - ((weights[ii])/(2*sigmaColour*sigmaColour*alpha)) );*/ // sumWeights = (float)(sumWeights+weights[weightInd]); } else continue; } } /*now calculate the pixel value(s)*/ for (kk=kMin; kk<=kMax;kk++) for (jj=jMin; jj<=jMax;jj++) for (ii=iMin; ii<=iMax;ii++) { if (useAllPatches) { weightInd = (int)((kk-kMin)*(imgVol->patchSizeX)*(imgVol->patchSizeY) + (jj-jMin)*(imgVol->patchSizeX) + ii-iMin); /*get ssd similarity*/ xDisp = ii + (int)dispField->get_value(ii,jj,kk,0); yDisp = jj + (int)dispField->get_value(ii,jj,kk,1); tDisp = kk + (int)dispField->get_value(ii,jj,kk,2); /*(spatio-temporally) shifted values of the covering patches*/ xDispShift = xDisp - (ii-i); yDispShift = yDisp - (jj-j); tDispShift = tDisp - (kk-k); avgColourR = avgColourR + (float)(weights[weightInd])*(imgVol->get_value(xDispShift,yDispShift,tDispShift,0)); avgColourG = avgColourG + (float)(weights[weightInd])*(imgVol->get_value(xDispShift,yDispShift,tDispShift,1)); avgColourB = avgColourB + (float)(weights[weightInd])*(imgVol->get_value(xDispShift,yDispShift,tDispShift,2)); } else { if (((occVol->get_value(ii,jj,kk,0)) == 0) || (occVol->get_value(ii,jj,kk,0) ==-1)) { weightInd = (int)((kk-kMin)*(imgVol->patchSizeX)*(imgVol->patchSizeY) + (jj-jMin)*(imgVol->patchSizeX) + ii-iMin); /*get ssd similarity*/ xDisp = ii + (int)dispField->get_value(ii,jj,kk,0); yDisp = jj + (int)dispField->get_value(ii,jj,kk,1); tDisp = kk + (int)dispField->get_value(ii,jj,kk,2); /*(spatio-temporally) shifted values of the covering patches*/ xDispShift = xDisp - (ii-i); yDispShift = yDisp - (jj-j); tDispShift = tDisp - (kk-k); avgColourR = avgColourR + (float)(weights[weightInd])*(imgVol->get_value(xDispShift,yDispShift,tDispShift,0)); avgColourG = avgColourG + (float)(weights[weightInd])*(imgVol->get_value(xDispShift,yDispShift,tDispShift,1)); avgColourB = avgColourB + (float)(weights[weightInd])*(imgVol->get_value(xDispShift,yDispShift,tDispShift,2)); } else continue; } } /*MY_PRINTF("SumWeights : %f\n",sumWeights);*/ imgVol->set_value(i,j,k,0,(T)(avgColourR/(sumWeights))); imgVol->set_value(i,j,k,1,(T)(avgColourG/(sumWeights))); imgVol->set_value(i,j,k,2,(T)(avgColourB/(sumWeights))); /*set_value_nTuple_volume(occVol,i,j,k,0,0);*/ } } free(weights); free(colours); return; }
int64_t min_int(int bits) { return -max_int(bits) - 1; }
void mainloop(void) { fd_set rfd; fd_set wfd; fd_set efd; int nfds = max_int(cli.in, cli.fd); nfds++; struct timeval tv; int ret; while (0xDEC + 'T') { tv.tv_sec = 1; tv.tv_usec = 0; FD_ZERO(&rfd); FD_ZERO(&wfd); FD_ZERO(&efd); FD_SET(cli.in, &rfd); FD_SET(cli.fd, &rfd); FD_SET(cli.in, &efd); FD_SET(cli.fd, &efd); ret = select(nfds, &rfd, &wfd, &efd, &tv); if (ret < 0) { LOG("!!! select()\n"); exit(1); } if (FD_ISSET(cli.in, &efd)) { LOG("!!! select() on in: %s\n", strerror(errno)); exit(1); } if (FD_ISSET(cli.fd, &efd)) { LOG("!!! select() on fd: %s\n", strerror(errno)); exit(1); } if (FD_ISSET(cli.in, &rfd)) process_cli_data(); if (FD_ISSET(cli.fd, &rfd)) process_dect_data(); if( (cli.hop) && ( (cli.mode & MODE_FPSCAN) || (cli.mode & MODE_PPSCAN) || (cli.mode & MODE_CALLSCAN) || (cli.mode & MODE_JAM ) )) { if ( time(NULL) > cli.last_hop + cli.hop_ch_time ) { cli.channel++; cli.channel %= 10; set_channel(cli.channel); } } if (cli.autorec) { if ( (time (NULL) - cli.autorec_last_bfield > cli.autorec_timeout) && (cli.mode != MODE_CALLSCAN) ) { do_stop_keep_autorec(); do_callscan(); if (cli.pcap) { pcap_dump_close(cli.pcap_d); pcap_close(cli.pcap); cli.pcap_d = NULL; cli.pcap = NULL; cli.hop = 1; } //Closing dumps if (cli.imaDumping) closeIma(); if (cli.wavDumping) closeWav(); if (cli.audioPlaying) closeAlsa(); } } } }
void process_incoming_link_part2 (struct context *c, struct link_socket_info *lsi, const uint8_t *orig_buf) { if (c->c2.buf.len > 0) { #ifdef ENABLE_FRAGMENT if (c->c2.fragment) fragment_incoming (c->c2.fragment, &c->c2.buf, &c->c2.frame_fragment); #endif #ifdef USE_COMP /* decompress the incoming packet */ if (c->c2.comp_context) (*c->c2.comp_context->alg.decompress)(&c->c2.buf, c->c2.buffers->decompress_buf, c->c2.comp_context, &c->c2.frame); #endif #ifdef PACKET_TRUNCATION_CHECK /* if (c->c2.buf.len > 1) --c->c2.buf.len; */ ipv4_packet_size_verify (BPTR (&c->c2.buf), BLEN (&c->c2.buf), TUNNEL_TYPE (c->c1.tuntap), "POST_DECRYPT", &c->c2.n_trunc_post_decrypt); #endif /* * Set our "official" outgoing address, since * if buf.len is non-zero, we know the packet * authenticated. In TLS mode we do nothing * because TLS mode takes care of source address * authentication. * * Also, update the persisted version of our packet-id. */ if (!TLS_MODE (c)) link_socket_set_outgoing_addr (&c->c2.buf, lsi, &c->c2.from, NULL, c->c2.es); /* reset packet received timer */ if (c->options.ping_rec_timeout && c->c2.buf.len > 0) event_timeout_reset (&c->c2.ping_rec_interval); /* increment authenticated receive byte count */ if (c->c2.buf.len > 0) { c->c2.link_read_bytes_auth += c->c2.buf.len; c->c2.max_recv_size_local = max_int (c->c2.original_recv_size, c->c2.max_recv_size_local); } /* Did we just receive an openvpn ping packet? */ if (is_ping_msg (&c->c2.buf)) { dmsg (D_PING, "RECEIVED PING PACKET"); c->c2.buf.len = 0; /* drop packet */ } #ifdef ENABLE_OCC /* Did we just receive an OCC packet? */ if (is_occ_msg (&c->c2.buf)) process_received_occ_msg (c); #endif buffer_turnover (orig_buf, &c->c2.to_tun, &c->c2.buf, &c->c2.buffers->read_link_buf); /* to_tun defined + unopened tuntap can cause deadlock */ if (!tuntap_defined (c->c1.tuntap)) c->c2.to_tun.len = 0; } else { buf_reset (&c->c2.to_tun); } }
int main (int argc, char* argv[]) { MPI_Init (&argc, &argv); createParticleMPIType__ (); int P = mpih_getSize (MPI_COMM_WORLD); int rank = mpih_getRank (MPI_COMM_WORLD); int n; /* no. points */ const double dt = DT; /* time step */ int T; /* no. of time steps */ const char* filename = NULL; FILE* fp_out = NULL; int save_data = 0; if (rank == 0) { if (argc < 3 || argc > 4) { usage__ (argv[0]); MPI_Abort (MPI_COMM_WORLD, 1); } sscanf (argv[1], "%d", &n); mpih_assert (n > 0); sscanf (argv[2], "%d", &T); mpih_assert (T > 0); if (argc == 4) { filename = argv[3]; fp_out = fopen (filename, "wt"); assert (fp_out); save_data = 1; } } MPI_Bcast (&n, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast (&T, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast (&save_data, 1, MPI_INT, 0, MPI_COMM_WORLD); if (rank == 0) { mpih_debugmsg (MPI_COMM_WORLD, "No. of points = %d\n", n); mpih_debugmsg (MPI_COMM_WORLD, "No. of time steps = %d\n", T); if (fp_out && filename) { mpih_debugmsg (MPI_COMM_WORLD, "Will save point location data in '%s'\n", filename); } } if (rank == 0) mpih_debugmsg (MPI_COMM_WORLD, "Creating points...\n"); int n_local = 0; particle_t* particles_local = NULL; createParticles__ (n, &n_local, &particles_local, MPI_COMM_WORLD); mpih_assert (particles_local || !n_local); /* If making a movie, try to get at least DEF_NUM_FRAMES frames */ const int FRAMEFREQ = env_getInt_mpi__ (MPI_COMM_WORLD, "FRAMEFREQ", max_int (T/DEF_NUM_FRAMES, 1)); saveDistributedParticles__ (save_data, fp_out, n_local, particles_local, MPI_COMM_WORLD); /* REDISTRIBUTE PARTICLES */ fixBins(n_local, particles_local, MPI_COMM_WORLD); MPI_Recv( /* Main simulator loop */ mpih_debugmsg (MPI_COMM_WORLD, "Simulating...\n"); for (int t = 0; t < T; t += FRAMEFREQ) { const int num_steps = min_int (FRAMEFREQ, T-t); integrate (n_local, particles_local, num_steps, dt, MPI_COMM_WORLD); saveDistributedParticles__ (save_data, fp_out, n_local, particles_local, MPI_COMM_WORLD); } mpih_debugmsg (MPI_COMM_WORLD, "Done!\n"); if (rank == 0) { /* Print execution time stats */ fprintf (stdout, "%d %d %d %g %g %g %g %g %g %g\n", n, P, T, DOMAIN_SIZE, MASS, dt, VEL0, CUTOFF, t_net__, t_all__); } /* Clean-up */ if (rank == 0) { if (n_local && particles_local) free (particles_local); if (fp_out) fclose (fp_out); } MPI_Finalize (); return 0; }