/************************************************************************ * * * Filters the input data with an (mask_wd x mask_ht) weighting mask. * Output may be to the same buffer. * * Returns SUCCESS or ERROR. * * */ int filter_mask(float *in, // Input data float *out, // Output data int wd, int ht, // Width and height of the image float *mask_buf, // Length is mask_wd*mask_ht int mask_wd, // Width of mask int mask_ht, // Height of mask int (*cancelled)(), // Abort if *cancelled() returns True void (*func_notify_stat)(int), // Report progress char *err, // Message in case of ERROR return int do_median) // If TRUE, calculate median instead of mean { register float *indata = in; // Input data register float *outdata = out; // Output data register int width=wd; // Data width register float *mask; // Filter weights register int m,n; // Loop counters for mask size register int mwd=mask_wd; // Mask width register int ctr_x; // Offset to center of mask register int ctr_y; // Offset to center of mask register float result; // Filtered value register int i; // Loop counter register int j; // Loop counter int k; float *medbuf = 0; int num_col; // Number columns to process int num_row; // Number rows to process int rtn = SUCCESS; // Check the mask size if ( ((mask_wd % 2) == 0) || ((mask_ht % 2) == 0)){ if (err){ (void)sprintf(err, "filter_mask(): Mask width and height must be odd"); } return(ERROR); } ctr_x = mask_wd / 2; ctr_y = mask_ht / 2; /* Check for data width */ if ((wd < mask_wd) || (ht < mask_ht)){ if (err){ (void)sprintf(err, "filter_mask(): Filter is larger than image!"); } return(ERROR); } // Generate a temporary result buffer (if necessary) if (in == out){ outdata = new float[wd*ht]; } // Generate a normalized filter (if possible) float sum = 0; float *mask_end = mask_buf + mask_wd * mask_ht; for (mask=mask_buf; mask<mask_end; sum += *mask++); if (sum == 0){ sum = 1; }else if (sum < 0){ sum = -sum; } float *norm_mask = new float[mask_wd * mask_ht]; mask_end = mask_buf + mask_wd * mask_ht; float *outmask = norm_mask; for (mask=mask_buf; mask<mask_end; *outmask++ = *mask++ / sum); // The border of the image is not processed; fill it with zeros float *data = outdata; float *end = outdata + ctr_y * wd; // End of first "ctr_y" rows while (data<end){ *data++ = 0; // Clear TOP border } data = outdata + (ht - ctr_y - 1) * wd; end = outdata + wd * ht; // End of data while (data<end){ *data++ = 0; // Clear BOTTOM border } for (i=ctr_y; i<ht-ctr_y-1; i++){ for (j=0; j<ctr_x; j++){ *(outdata + i * wd + j) = 0; // Clear LEFT border *(outdata + i * wd + wd-1-j) = 0; // Clear RIGHT border } } if (do_median){ medbuf = new float[mask_ht * mwd]; if (!medbuf){ sprintf(err, "filter_mask(): Out of memory!"); return ERROR; } } int cursor = set_cursor_shape(IBCURS_BUSY); num_col = wd - mask_wd + 1; num_row = ht - mask_ht + 1; for (i=0; i<num_row; i++){ // Process rows /* Notify user function for status every 5% data */ if (func_notify_stat && (((100 * i / num_row) % 5) == 0)){ (*func_notify_stat)(100 * i / num_row); } for (j=0; j<num_col; j++){ // Process columns if (do_median){ for (n=k=0; n<mask_ht; n++){ // Process m x n Mask for (m=0; m<mwd; m++){ medbuf[k++] = *(indata + (i+n) * width + (j+m)); } } result = median(k, medbuf); }else{ result = 0; for (n=0; n<mask_ht; n++){ // Process m x n Mask for (m=0; m<mwd; m++){ result += ( *(indata + (i+n) * width + (j+m)) * *(norm_mask + n * mwd + m) ); } } } // Assign the result to the pixel at the center of the filter *(outdata + (i+ctr_y) * width + (j+ctr_x)) = result; } /* Check whether it is interrupted or not */ if (cancelled && (*cancelled)()){ rtn = ERROR; break; } } // Clean up delete [] norm_mask; delete [] medbuf; if (in == out && rtn == SUCCESS){ // Move result from temp buffer to I/O buffer end=out+wd*ht; float *data2 = outdata; for (data=out; data<end; *data++ = *data2++); delete [] outdata; } (void)set_cursor_shape(cursor); return rtn; }
/************************************************************************ * * * Extract a slice of data or the MIP of a list of slices. * A simple extraction is just a MIP over one slice. * Set "orientation" to front_plane, top_plane, or side_plane. * Set "slicelist" to the array of slice indices to do and "nslices" * to the number of slices in the array. * */ void VolData::extract_plane(int orientation, int nslices, int *slicelist) { int i; int j; int k; int k0; int k1; int nx; int ny; float *data; int slice; if (!vimage){ return; } // Make sure we are loading into a valid frame if ( targetframe == NULL || !framehead->exists(targetframe) ){ targetframe = framehead; Frame_routine::FindNextFreeFrame(); } gframe = targetframe; if (gframe == NULL){ msgerr_print("load_data: No Frames to load data into."); return; } selecthead->deselect(); gframe->mark(); selecthead->insert(gframe); int cursor = set_cursor_shape(IBCURS_BUSY); if (nslices > 1){ interrupt_begin(); } slice = *slicelist; // Prepare to get first slice if (orientation == front_plane){ float *buf = new float[nfast * nmedium]; // Attach a new Imginfo to the gframe detach_imginfo(gframe->imginfo); gframe->imginfo = new Imginfo(); gframe->imginfo->st = (DDLSymbolTable *)vimage->st->CloneList(FALSE); gframe->imginfo->InitializeSymTab(RANK_2D, BIT_32, TYPE_FLOAT, nfast, nmedium, 1, 1, 0); // Extract the first slice data = (float *)vimage->GetData() + slice * nfast * nmedium; for (i=0; i<nfast * nmedium; i++){ buf[i] = data[i]; } // Do the MIP of the data for (k=1; k<nslices && !interrupt(); k++){ slice = slicelist[k]; data = (float *)vimage->GetData() + slice * nfast * nmedium; for (i=0; i<nfast * nmedium; i++){ if (buf[i] < data[i]){ buf[i] = data[i]; } } } gframe->imginfo->st->SetData((char *)buf, sizeof(float) * nfast * nmedium); nx = nfast; ny = nmedium; delete[] buf; }else if (orientation == top_plane){ float *buf = new float[nfast * nslow]; // Attach a new Imginfo to the gframe detach_imginfo(gframe->imginfo); gframe->imginfo = new Imginfo(); gframe->imginfo->st = (DDLSymbolTable *)vimage->st->CloneList(FALSE); gframe->imginfo->InitializeSymTab(RANK_2D, BIT_32, TYPE_FLOAT, nfast, nslow, 1, 1, 0); // Extract the first slice data = (float *)vimage->GetData() + slice * nfast; for (j=0; j<nslow; j++){ k0 = j * nfast * nmedium; k1 = j * nfast; for (i=0; i<nfast; i++){ buf[i + k1] = data[i + k0]; } } // Do the MIP of the data for (k=1; k<nslices && !interrupt(); k++){ slice = slicelist[k]; data = (float *)vimage->GetData() + slice * nfast; for (j=0; j<nslow; j++){ k0 = j * nfast * nmedium; k1 = j * nfast; for (i=0; i<nfast; i++){ if (buf[i + k1] < data[i + k0]){ buf[i + k1] = data[i + k0]; } } } } gframe->imginfo->st->SetData((char *)buf, sizeof(float) * nfast * nslow); nx = nfast; ny = nslow; delete[] buf; }else if (orientation == side_plane){ float *buf = new float[nmedium * nslow]; // Attach a new Imginfo to the gframe detach_imginfo(gframe->imginfo); gframe->imginfo = new Imginfo(); gframe->imginfo->st = (DDLSymbolTable *)vimage->st->CloneList(FALSE); gframe->imginfo->InitializeSymTab(RANK_2D, BIT_32, TYPE_FLOAT, nmedium, nslow, 1, 1, 0); // Extract the first slice data = (float *)vimage->GetData() + slice; for (j=0; j<nslow; j++){ k0 = j * nfast * nmedium; k1 = j * nmedium; for (i=0; i<nmedium; i++){ buf[i + k1] = data[i*nfast + k0]; } } // Do the MIP of the data for (k=1; k<nslices && !interrupt(); k++){ slice = slicelist[k]; data = (float *)vimage->GetData() + slice; for (j=0; j<nslow; j++){ k0 = j * nfast * nmedium; k1 = j * nmedium; for (i=0; i<nmedium; i++){ if (buf[i + k1] < data[i*nfast + k0]){ buf[i + k1] = data[i*nfast + k0]; } } } } gframe->imginfo->st->SetData((char *)buf, sizeof(float) * nmedium * nslow); nx = nmedium; ny = nslow; delete[] buf; }else{ fprintf(stderr, "VolData::extract_plane(): Internal error %d\n", orientation); return; } extract_plane_header(gframe->imginfo, orientation, nslices, slicelist); gframe->imginfo->display_ood = gframe->imginfo->pixmap_ood = TRUE; Frame_data::display_data(gframe, 0, 0, nx, ny, gframe->imginfo->vs); Frame_routine::FindNextFreeFrame(); (void)set_cursor_shape(cursor); if (nslices > 1){ interrupt_end(); } }
void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { last_button_state=0; dpad_last[0]=0; dpad_last[1]=0; xmbstring=NULL; event_id=0; x11_window=0; last_click_ms=0; args=OS::get_singleton()->get_cmdline_args(); current_videomode=p_desired; main_loop=NULL; last_timestamp=0; last_mouse_pos_valid=false; last_keyrelease_time=0; if (get_render_thread_mode()==RENDER_SEPARATE_THREAD) { XInitThreads(); } /** XLIB INITIALIZATION **/ x11_display = XOpenDisplay(NULL); char * modifiers = XSetLocaleModifiers ("@im=none"); ERR_FAIL_COND( modifiers == NULL ); xim = XOpenIM (x11_display, NULL, NULL, NULL); if (xim == NULL) { WARN_PRINT("XOpenIM failed"); xim_style=NULL; } else { ::XIMStyles *xim_styles=NULL; xim_style=0; char *imvalret=NULL; imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL); if (imvalret != NULL || xim_styles == NULL) { fprintf (stderr, "Input method doesn't support any styles\n"); } if (xim_styles) { xim_style = 0; for (int i=0;i<xim_styles->count_styles;i++) { if (xim_styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing)) { xim_style = xim_styles->supported_styles[i]; break; } } XFree (xim_styles); } } /* char* windowid = getenv("GODOT_WINDOWID"); if (windowid) { //freopen("/home/punto/stdout", "w", stdout); //reopen("/home/punto/stderr", "w", stderr); x11_window = atol(windowid); XWindowAttributes xwa; XGetWindowAttributes(x11_display,x11_window,&xwa); current_videomode.width = xwa.width; current_videomode.height = xwa.height; }; */ // maybe contextgl wants to be in charge of creating the window //print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height)); #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); context_gl->initialize(); if (true) { rasterizer = memnew( RasterizerGLES2 ); } else { //rasterizer = memnew( RasterizerGLES1 ); }; #endif visual_server = memnew( VisualServerRaster(rasterizer) ); if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); } // borderless fullscreen window mode if (current_videomode.fullscreen) { // needed for lxde/openbox, possibly others Hints hints; Atom property; hints.flags = 2; hints.decorations = 0; property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); XWindowAttributes xwa; XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); // code for netwm-compliants XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); Atom fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); memset(&xev, 0, sizeof(xev)); xev.type = ClientMessage; xev.xclient.window = x11_window; xev.xclient.message_type = wm_state; xev.xclient.format = 32; xev.xclient.data.l[0] = 1; xev.xclient.data.l[1] = fullscreen; xev.xclient.data.l[2] = 0; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); } // disable resizeable window if (!current_videomode.resizable) { XSizeHints *xsh; xsh = XAllocSizeHints(); xsh->flags = PMinSize | PMaxSize; XWindowAttributes xwa; if (current_videomode.fullscreen) { XGetWindowAttributes(x11_display,DefaultRootWindow(x11_display),&xwa); } else { XGetWindowAttributes(x11_display,x11_window,&xwa); } xsh->min_width = xwa.width; xsh->max_width = xwa.width; xsh->min_height = xwa.height; xsh->max_height = xwa.height; XSetWMNormalHints(x11_display, x11_window, xsh); } AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { ERR_PRINT("Initializing audio failed."); } sample_manager = memnew( SampleManagerMallocSW ); audio_server = memnew( AudioServerSW(sample_manager) ); audio_server->init(); spatial_sound_server = memnew( SpatialSoundServerSW ); spatial_sound_server->init(); spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); spatial_sound_2d_server->init(); ERR_FAIL_COND(!visual_server); ERR_FAIL_COND(x11_window==0); XSetWindowAttributes new_attr; new_attr.event_mask=KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | Button1MotionMask | Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask | ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask | StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask | FocusChangeMask | PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask; XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr); XClassHint* classHint; /* set the titlebar name */ XStoreName(x11_display, x11_window, "Godot"); /* set the name and class hints for the window manager to use */ classHint = XAllocClassHint(); if (classHint) { classHint->res_name = "Godot"; classHint->res_class = "Godot"; } XSetClassHint(x11_display, x11_window, classHint); XFree(classHint); wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true); XSetWMProtocols(x11_display, x11_window, &wm_delete, 1); if (xim && xim_style) { xic = XCreateIC (xim,XNInputStyle, xim_style,XNClientWindow,x11_window,XNFocusWindow, x11_window, (char*)NULL); } else { xic=NULL; WARN_PRINT("XCreateIC couldn't create xic"); } XcursorSetTheme(x11_display,"default"); cursor_size = XcursorGetDefaultSize(x11_display); cursor_theme = XcursorGetTheme(x11_display); if (!cursor_theme) { print_line("not found theme"); cursor_theme="default"; } for(int i=0;i<CURSOR_MAX;i++) { cursors[i]=None; } current_cursor=CURSOR_ARROW; if (cursor_theme) { //print_line("cursor theme: "+String(cursor_theme)); for(int i=0;i<CURSOR_MAX;i++) { static const char *cursor_file[]={ "left_ptr", "xterm", "hand2", "cross", "watch", "left_ptr_watch", "fleur", "hand1", "X_cursor", "sb_v_double_arrow", "sb_h_double_arrow", "size_bdiag", "size_fdiag", "hand1", "sb_v_double_arrow", "sb_h_double_arrow", "question_arrow" }; XcursorImage *img = XcursorLibraryLoadImage(cursor_file[i],cursor_theme,cursor_size); if (img) { cursors[i]=XcursorImageLoadCursor(x11_display,img); //print_line("found cursor: "+String(cursor_file[i])+" id "+itos(cursors[i])); } else { if (OS::is_stdout_verbose()) print_line("failed cursor: "+String(cursor_file[i])); } } } { Pixmap cursormask; XGCValues xgc; GC gc; XColor col; Cursor cursor; cursormask = XCreatePixmap(x11_display, RootWindow(x11_display,DefaultScreen(x11_display)), 1, 1, 1); xgc.function = GXclear; gc = XCreateGC(x11_display, cursormask, GCFunction, &xgc); XFillRectangle(x11_display, cursormask, gc, 0, 0, 1, 1); col.pixel = 0; col.red = 0; col.flags = 4; cursor = XCreatePixmapCursor(x11_display, cursormask, cursormask, &col, &col, 0, 0); XFreePixmap(x11_display, cursormask); XFreeGC(x11_display, gc); if (cursor == None) { ERR_PRINT("FAILED CREATING CURSOR"); } null_cursor=cursor; } set_cursor_shape(CURSOR_BUSY); visual_server->init(); // physics_server = memnew( PhysicsServerSW ); physics_server->init(); physics_2d_server = memnew( Physics2DServerSW ); physics_2d_server->init(); input = memnew( InputDefault ); probe_joystick(); _ensure_data_dir(); net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False); //printf("got map notify\n"); }
void read_value(char *name, char *value) { //The *name and *value are derived from sargv which is given one by one through //a loop from conf_init() if (name != NULL && value != NULL) { if (name[0] == '#') return; g_strstrip(name); g_strstrip(value); if (!strcmp("font", name) || !strcmp("-fn", name)) strcpy(_font, value); else if (!strcmp("background", name) || !strcmp("-bg", name)) { if (!parse_hex_color(value, &_bg)) gdk_color_parse("black", &_bg); } else if (!strcmp("foreground", name) || !strcmp("-fg", name)) { if (!parse_hex_color(value, &_fg)) gdk_color_parse("white", &_fg); } else if (!strcmp("scrollbar", name) || !strcmp("-s", name)) { if (!strcmp(value, "true")) _scrollpos = POS_RIGHT; else if (!strcmp(value, "left")) _scrollpos = POS_LEFT; else if (!strcmp(value, "right")) _scrollpos = POS_RIGHT; else _scrollpos = -1; } else if (!strcmp("border", name) || !strcmp("-b", name)) set_border(value); else if (!strcmp("opacity", name) || !strcmp("-o", name)) _opacity = atof(value); else if (!strcmp("bgimage", name) || !strcmp("-bgimg", name)) strcpy(_bgimage, value); else if (!strcmp("width", name) || !strcmp("-w", name)) _width = atoi(value); else if (!strcmp("height", name) || !strcmp("-h", name)) _height = atoi(value); else if (!strcmp("position", name) || !strcmp("-p", name)) set_pos(value); else if (!strcmp("mod", name) || !strcmp("-m", name)) set_mod(value); else if (!strcmp("key", name) || !strcmp("-k", name)) set_key(value); else if (!strcmp("shell", name) || !strcmp("-sh", name)) strcpy(_shell, value); else if (!strcmp("lines", name) || !strcmp("-l", name)) _lines = atoi(value); else if (!strcmp("showtab", name) || !strcmp("-showtab", name)) { if (!strcasecmp(value, "always")) _showtab = TABS_ALWAYS; else if (!strcasecmp(value, "never")) _showtab = TABS_NEVER; } else if (!strcmp("tabpos", name) || !strcmp("-tabpos", name)) _tabpos = read_pos(value); else if (!strcmp("tablabel", name) || !strcmp("-tablabel", name)) strcpy(_termname, value); else if (!strcmp("cursorblink", name) || !strcmp("-cb", name)) set_cursor_blink(value); else if (!strcmp("cursorshape", name) || !strcmp("-cs", name)) set_cursor_shape(value); else if (g_str_has_prefix(name, "color") || g_str_has_prefix(name, "-c")) { g_strcanon(name, "0123456789", ' '); g_strchug(name); parse_hex_color(value, &_palette[atoi(name)]); read_colors++; } else if (!strcmp("tabfill", name) || !strcmp("-tf", name)) _tabfill = parse_bool_str(value, _tabfill); else if (!strcmp("allowbold", name) || !strcmp("-ab", name)) _allowbold = parse_bool_str(value, _allowbold); else if (!strcmp("keymod", name) || !strcmp("-km", name)) { char **list; list = g_strsplit_set(value, "+", -1); GdkModifierType tmp = 0; int i = 0; while (list[i] != NULL) tmp = tmp | parse_mod(list[i++]); g_strfreev(list); if (tmp != 0) _keymod = tmp; } else if (!strcmp("autohide", name) || !strcmp("-ah", name)) _autohide = parse_bool_str(value, _autohide); else if (!strcmp("scroll", name) || !strcmp("-sc", name)) _scrolloutput = parse_bool_str(value, _scrolloutput); else if (!strcmp("bell", name) || !strcmp("-bell", name)) if (!strcasecmp(value, "false")) _bell = FALSE; } }