/** Tool for arma::mat to opencv::mat conversion * src is the source arma matrix */ void to_cvmat(mat map,mat particles,int j) { cv::Mat_<double> map_image(map.n_rows,map.n_cols,map.memptr()); map_image = map_image.t(); // to account for the row/col discrepency between opencv and armadillo for(int i=0;i<n_particles;i++) { cv::Point base(int(particles(i,0)/resolution)+distribution_display(generator_display),int(particles(i,1)/resolution)+distribution_display(generator_display)); circle(map_image,base,5.0,cv::Scalar(0.5,0.5,0.5),-1,8); } cv::namedWindow("Map", cv::WINDOW_AUTOSIZE ); cv::imshow("Map", map_image); if(j>2215){ //hold forever at the last log file reading cv::waitKey(0); } else cv::waitKey(displayDelay); }
static bool test_format(struct gl_hwdec *hw) { struct priv *p = hw->priv; bool ok = false; struct mp_image_pool *alloc = mp_image_pool_new(1); va_pool_set_allocator(alloc, p->ctx, VA_RT_FORMAT_YUV420); struct mp_image *surface = mp_image_pool_get(alloc, IMGFMT_VAAPI, 64, 64); if (surface) { struct mp_image_params params = surface->params; if (reinit(hw, ¶ms) >= 0) { GLuint textures[4]; ok = map_image(hw, surface, textures) >= 0; } unref_image(hw); } talloc_free(surface); talloc_free(alloc); return ok; }
/** * Show credits with list of contributors. * * Names of people are shown scrolling up like in movie-credits.\n * Uses map from wesnoth or campaign as background. */ void show_about(display &disp, std::string campaign) { cursor::set(cursor::WAIT); CVideo &video = disp.video(); // surface screen = video.getSurface(); // if (screen == NULL) return; std::vector<std::string> text = about::get_text(campaign); // SDL_Rect screen_rect = {0, 0, video.getx(), video.gety()}; // const surface_restorer restorer(&video, screen_rect); cursor::set(cursor::NORMAL); std::vector<shared_string> image_list; if(campaign.size() && !images[campaign].empty()){ image_list=utils::split_shared(images[campaign]); }else{ image_list=utils::split_shared(images_default,',',utils::STRIP_SPACES); } surface map_image(scale_surface(image::get_image(image_list[0]), video.getx(), video.gety())); if(! map_image){ image_list[0]=game_config::game_title; map_image=surface(scale_surface(image::get_image(image_list[0]), video.getx(), video.gety())); } gui::button close(video,_("Close")); close.set_location((video.getx()/2)-(close.width()/2), video.gety() - 30); close.set_volatile(true); const int def_size = font::SIZE_XLARGE; const SDL_Color def_color = font::NORMAL_COLOUR; //substitute in the correct control characters for '+' and '-' std::string before_header(2, ' '); before_header[0] = font::LARGE_TEXT; for(unsigned i = 0; i < text.size(); ++i) { std::string &s = text[i]; if (s.empty()) continue; char &first = s[0]; if (first == '-') first = font::SMALL_TEXT; else if (first == '+') { first = font::LARGE_TEXT; text.insert(text.begin() + i, before_header); ++i; } } text.insert(text.begin(), 10, before_header); int startline = 0; //TODO: use values proportionnal to screen ? // distance from top of map image to top of scrolling text const int top_margin = 60; // distance from bottom of scrolling text to bottom of map image const int bottom_margin = 40; // distance from left of scrolling text to the frame border const int text_left_padding = video.getx()/32; int offset = 0; bool is_new_line = true; int first_line_height = 0; SDL_Rect frame_area = { video.getx() * 3/32, top_margin, video.getx() * 13 / 16, video.gety() - top_margin - bottom_margin }; // we use a dialog to contains the text. Strange idea but at least the style // will be consistent with the titlescreen gui::dialog_frame f(video, "", gui::dialog_frame::titlescreen_style, false); // set the layout and get the interior rectangle SDL_Rect text_rect = f.layout(frame_area).interior; text_rect.x += text_left_padding; text_rect.w -= text_left_padding; // make a copy to prevent SDL_blit to change its w and h SDL_Rect text_rect_blit = text_rect; CKey key; bool last_escape; surface text_surf = create_neutral_surface(text_rect.w, text_rect.h); //create_compatible_surface(screen, text_rect.w, text_rect.h); SDL_SetAlpha(text_surf, SDL_RLEACCEL, SDL_ALPHA_OPAQUE); int image_count = 0; int scroll_speed = 4; // scroll_speed*50 = speed of scroll in pixel per second // initialy redraw all bool redraw_mapimage = true; int max_text_width = text_rect.w; do { last_escape = key[SDLK_ESCAPE] != 0; // check to see if background image has changed if(text.size() && (image_count < ((startline * static_cast<int>(image_list.size())) / static_cast<int>(text.size())))){ image_count++; surface temp=surface(scale_surface(image::get_image(image_list[image_count]), video.getx(), video.gety())); map_image=temp?temp:map_image; redraw_mapimage = true; } // if (redraw_mapimage) { // draw map to screen, thus erasing all text //SDL_BlitSurface(map_image, NULL, screen, NULL); blit_surface(0, 0, map_image); // update_rect(screen_rect); // redraw the dialog f.draw_background(); f.draw_border(); // cache the dialog background (alpha blending + blurred map) //SDL_BlitSurface(screen, &text_rect, text_surf, NULL); redraw_mapimage = false; } /* else { // redraw the saved part of the dialog where text scrolled // thus erasing all text SDL_Rect modified = {0,0, max_text_width, text_rect.h}; SDL_BlitSurface(text_surf, &modified, screen, &text_rect_blit); //update_rect(text_rect); } */ const int line_spacing = 5; int y = text_rect.y - offset; int line = startline; int cur_line = 0; max_text_width = 0; { // clip to keep text into the frame (thus the new code block) clip_rect_setter set_clip_rect(/*screen,*/ text_rect); do { // draw the text (with ellipsis if needed) // update the max_text_width for future cleaning int w = font::draw_text(&video, text_rect, def_size, def_color, text[line], text_rect.x, y).w; max_text_width = std::max<int>(max_text_width, w); // since the real drawing on screen is clipped, // we do a dummy one to get the height of the not clipped line. // (each time because special format characters may change it) const int line_height = font::draw_text(NULL, text_rect, def_size, def_color, text[line], 0,0).h; if(is_new_line) { is_new_line = false; first_line_height = line_height + line_spacing; } line++; if(size_t(line) > text.size()-1) line = 0; y += line_height + line_spacing; cur_line++; } while(y < text_rect.y + text_rect.h); } // performs the actual scrolling offset += scroll_speed; if (offset>=first_line_height) { offset -= first_line_height; is_new_line = true; startline++; if(size_t(startline) == text.size()){ startline = 0; image_count = -1; } } // handle events if (key[SDLK_UP] && scroll_speed < 20) { ++scroll_speed; } if (key[SDLK_DOWN] && scroll_speed > 0) { --scroll_speed; } events::pump(); events::raise_process_event(); events::raise_draw_event(); // flip screen and wait, so the text does not scroll too fast disp.flip(); disp.delay(20); } while(!close.pressed() && (last_escape || !key[SDLK_ESCAPE])); }
status_t load_image(char const* name, image_type type, const char* rpath, const char* requestingObjectPath, image_t** _image) { int32 pheaderSize, sheaderSize; char path[PATH_MAX]; ssize_t length; char pheaderBuffer[4096]; int32 numRegions; image_t* found; image_t* image; status_t status; int fd; elf_ehdr eheader; // Have we already loaded that image? Don't check for add-ons -- we always // reload them. if (type != B_ADD_ON_IMAGE) { found = find_loaded_image_by_name(name, APP_OR_LIBRARY_TYPE); if (found == NULL && type != B_APP_IMAGE && gProgramImage != NULL) { // Special case for add-ons that link against the application // executable, with the executable not having a soname set. if (const char* lastSlash = strrchr(name, '/')) { if (strcmp(gProgramImage->name, lastSlash + 1) == 0) found = gProgramImage; } } if (found) { atomic_add(&found->ref_count, 1); *_image = found; KTRACE("rld: load_container(\"%s\", type: %d, rpath: \"%s\") " "already loaded", name, type, rpath); return B_OK; } } KTRACE("rld: load_container(\"%s\", type: %d, rpath: \"%s\")", name, type, rpath); strlcpy(path, name, sizeof(path)); // find and open the file fd = open_executable(path, type, rpath, get_program_path(), requestingObjectPath, sSearchPathSubDir); if (fd < 0) { FATAL("Cannot open file %s: %s\n", name, strerror(fd)); KTRACE("rld: load_container(\"%s\"): failed to open file", name); return fd; } // normalize the image path status = _kern_normalize_path(path, true, path); if (status != B_OK) goto err1; // Test again if this image has been registered already - this time, // we can check the full path, not just its name as noted. // You could end up loading an image twice with symbolic links, else. if (type != B_ADD_ON_IMAGE) { found = find_loaded_image_by_name(path, APP_OR_LIBRARY_TYPE); if (found) { atomic_add(&found->ref_count, 1); *_image = found; _kern_close(fd); KTRACE("rld: load_container(\"%s\"): already loaded after all", name); return B_OK; } } length = _kern_read(fd, 0, &eheader, sizeof(eheader)); if (length != sizeof(eheader)) { status = B_NOT_AN_EXECUTABLE; FATAL("%s: Troubles reading ELF header\n", path); goto err1; } status = parse_elf_header(&eheader, &pheaderSize, &sheaderSize); if (status < B_OK) { FATAL("%s: Incorrect ELF header\n", path); goto err1; } // ToDo: what to do about this restriction?? if (pheaderSize > (int)sizeof(pheaderBuffer)) { FATAL("%s: Cannot handle program headers bigger than %lu\n", path, sizeof(pheaderBuffer)); status = B_UNSUPPORTED; goto err1; } length = _kern_read(fd, eheader.e_phoff, pheaderBuffer, pheaderSize); if (length != pheaderSize) { FATAL("%s: Could not read program headers: %s\n", path, strerror(length)); status = B_BAD_DATA; goto err1; } numRegions = count_regions(path, pheaderBuffer, eheader.e_phnum, eheader.e_phentsize); if (numRegions <= 0) { FATAL("%s: Troubles parsing Program headers, numRegions = %" B_PRId32 "\n", path, numRegions); status = B_BAD_DATA; goto err1; } image = create_image(name, path, numRegions); if (image == NULL) { FATAL("%s: Failed to allocate image_t object\n", path); status = B_NO_MEMORY; goto err1; } status = parse_program_headers(image, pheaderBuffer, eheader.e_phnum, eheader.e_phentsize); if (status < B_OK) goto err2; if (!assert_dynamic_loadable(image)) { FATAL("%s: Dynamic segment must be loadable (implementation " "restriction)\n", image->path); status = B_UNSUPPORTED; goto err2; } status = map_image(fd, path, image, eheader.e_type == ET_EXEC); if (status < B_OK) { FATAL("%s: Could not map image: %s\n", image->path, strerror(status)); status = B_ERROR; goto err2; } if (!parse_dynamic_segment(image)) { FATAL("%s: Troubles handling dynamic section\n", image->path); status = B_BAD_DATA; goto err3; } if (eheader.e_entry != 0) image->entry_point = eheader.e_entry + image->regions[0].delta; analyze_image_haiku_version_and_abi(fd, image, eheader, sheaderSize, pheaderBuffer, sizeof(pheaderBuffer)); // If this is the executable image, we init the search path // subdir, if the compiler version doesn't match ours. if (type == B_APP_IMAGE) { #if __GNUC__ == 2 if ((image->abi & B_HAIKU_ABI_MAJOR) == B_HAIKU_ABI_GCC_4) sSearchPathSubDir = "x86"; #elif __GNUC__ >= 4 if ((image->abi & B_HAIKU_ABI_MAJOR) == B_HAIKU_ABI_GCC_2) sSearchPathSubDir = "x86_gcc2"; #endif } set_abi_version(image->abi); // init gcc version dependent image flags // symbol resolution strategy if (image->abi == B_HAIKU_ABI_GCC_2_ANCIENT) image->find_undefined_symbol = find_undefined_symbol_beos; // init version infos status = init_image_version_infos(image); image->type = type; register_image(image, fd, path); image_event(image, IMAGE_EVENT_LOADED); _kern_close(fd); enqueue_loaded_image(image); *_image = image; KTRACE("rld: load_container(\"%s\"): done: id: %" B_PRId32 " (ABI: %#" B_PRIx32 ")", name, image->id, image->abi); return B_OK; err3: unmap_image(image); err2: delete_image_struct(image); err1: _kern_close(fd); KTRACE("rld: load_container(\"%s\"): failed: %s", name, strerror(status)); return status; }
/// Apply geometric transform to image. /// /// The transformation \a map is applied to the image \a in and the result /// stored in \a im. If \a adjustSize is \c true, \a im will be sized so that /// it contains all the transformed rectangle, otherwise it stays at original /// size. /// /// The returned pair of integers is the offset of the returned image \a im /// with respect to original image \a in. If \a adjustSize is \c false, this is /// (0,0), otherwise the location of upper-left corner of \a im in pixel /// coordinates of \a in. /// /// Interpolation is done by spline. Anti-aliasing filter is optional. /// /// \a vOut is the background value to put at pixels outside image. std::pair<int,int> map_image(LWImage<float> in, libNumerics::Homography map, LWImage<float>& im, int order, bool adjustSize, bool antiAlias, float vOut) { int w = in.w, h = in.h; float zoomOut = antiAlias? static_cast<float>( minZoomOut(map.mat(), w, h) ): 1.0f; const libNumerics::Homography oriMap(map); const int oriW=w, oriH=h; std::pair<int,int> offset(0,0); if(adjustSize) { offset = boundingBox(map, w, h); free(im.data); im = alloc_image<float>(w, h, in.comps); } if(zoomOut < 1.0f) { float zoomIn = 1.0f / zoomOut; // GF: added some extra space int wZoom=(int)std::ceil(w*zoomIn*1.5), hZoom=(int)std::ceil(h*zoomIn*1.5); LWImage<float> imZoom = alloc_image<float>(wZoom,hZoom,in.comps); libNumerics::matrix<double> mapZ(3,3); mapZ = 0.0; mapZ(0,0) = zoomIn; mapZ(1,1) = zoomIn; mapZ(2,2) = 1.0; map.mat() = mapZ*map.mat(); map_image(in, map, imZoom, order, false, false, vOut); float sigma = 0.8f*sqrt(zoomIn*zoomIn-1.0f); gauss_convol(imZoom, sigma); map.mat() = 0.0; map.mat()(0,0)=zoomOut; map.mat()(1,1)=zoomOut; map.mat()(2,2)=1.0; in = imZoom; } LWImage<float> tmp = alloc_image(in); if( prepare_spline(tmp,order) ) { libNumerics::Homography inv = map.inverse(); const int stepComp = im.stepComp(); float* out = new float[im.comps]; float* pixOut = im.data; for(int i = 0; i < im.h; i++) for(int j = 0; j < im.w; j++) { double x=j+offset.first, y=i+offset.second; inv(x,y); for(int k=0; k < im.comps; k++) out[k] = vOut; interpolate_spline(tmp, order, static_cast<float>(x+.5), static_cast<float>(y+.5), out); for(int k=0; k < im.comps; k++) pixOut[k*stepComp] = out[k]; pixOut += im.step(); } delete [] out; } free(tmp.data); if(zoomOut < 1.0f) { free(in.data); // Was allocated above if(! is_number(vOut)) { // Put back mask libNumerics::Homography inv = oriMap.inverse(); const int stepComp = im.stepComp(); float* pixOut = im.data; for(int i = 0; i < im.h; i++) for(int j = 0; j < im.w; j++) { double x=j+offset.first, y=i+offset.second; inv(x,y); if(x<0 || x>=oriW || y<0 || y>=oriH) for(int k=0; k < im.comps; k++) pixOut[k*stepComp] = NaN; pixOut += im.step(); } } } return offset; }