bool i_navigate(arg_t a) { long n = (long) a; if (mode == MODE_IMAGE) { if (prefix > 0) n *= prefix; n += fileidx; if (n < 0) n = 0; if (n >= filecnt) n = filecnt - 1; if (n != fileidx) { load_image(n); return true; } } return false; }
/***********************************************************************//** * @brief Fetch image pixels * * Fetch the image pixels. This function is in general called if pixel * values should be read or written yet no pixel array is allocated. In case * that pixels existed already before they will be deleted before fetching * new ones. * There are two possibilities to fetch the pixels: * (1) In case that a FITS file is attached to the image, the pixel array * will be loaded from the FITS file using the load_image() method. * (2) In case that no FITS file is attached, a new pixel array will be * allocated that is initalised to zero. ***************************************************************************/ void GFitsImage::fetch_data(void) { // Fetch only if there are pixels in image if (m_num_pixels > 0) { // Allocate and initialise fresh memory alloc_data(); init_data(); // If a FITS file is attached then load pixels from FITS file. if (FPTR(m_fitsfile)->Fptr != NULL) { load_image(type(), ptr_data(), ptr_nulval(), &m_anynul); } } // endif: there were pixels available // Return return; }
bool it_switch_mode(arg_t a) { if (mode == MODE_IMAGE) { if (!tns.thumbs) tns_init(&tns, filecnt, &win); img_close(&img, false); reset_timeout(reset_cursor); if (img.slideshow) { img.slideshow = false; reset_timeout(slideshow); } tns.sel = fileidx; tns.dirty = true; mode = MODE_THUMB; } else { load_image(tns.sel); mode = MODE_IMAGE; } return true; }
void testRgb2hsv() { image_rgb* rgb = load_image("tests/r2.jpg", 1); image_hsv* hsv = rgb2hsv(rgb); int width = hsv->width; CU_ASSERT_DOUBLE_EQUAL(hsv->h[35*width + 15], 0.54808, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->h[73*width + 58], 0.61667, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->h[92*width + 99], 0.56250, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->h[23*width + 70], 0.56667, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->s[35*width + 15], 0.99048, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->s[73*width + 58], 0.04202, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->s[92*width + 99], 0.41558, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->s[23*width + 70], 0.12658, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->v[35*width + 15], 0.82353, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->v[73*width + 58], 0.93333, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->v[92*width + 99], 0.90588, 0.0001); CU_ASSERT_DOUBLE_EQUAL(hsv->v[23*width + 70], 0.92941, 0.0001); image_hsv_delete(hsv); }
/** * Create a panel control * * @param children Children controls to appear in the panel * @param x, y Position, relative to parent * @param R, G, B Background colour numbers (RGB) for the parts of the panel shown */ Control* create_panel(int x, int y, int i, int j, int width, int height, char* bg_path, Link* children_head) { Control* panel; SDL_Surface *img; if (children_head == NULL) { return NULL; } img = load_image(bg_path); if (img == NULL ) { printf("ERROR: failed to load image: %s\n", SDL_GetError()); return NULL ; } panel = create_control(x, y, i, j, width, height, children_head, img, empty_select, draw_node); if (panel == NULL) { free_UI_children(children_head); } return panel; }
bool load_files() { //Load bg image background = load_image( "background.png" ); //load font font = TTF_OpenFont( "lazy.ttf", 72 ); //if problem if( background == NULL ) { return false; } if( font == NULL ) { return false; } return true; }
static int parse_image(xmlTextReaderPtr reader, tmx_image **img_adr, short strict, const char *filename) { tmx_image *res; char *value; if (!(res = alloc_image())) return 0; *img_adr = res; if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"source"))) { /* source */ res->source = value; if (!(load_image(&(res->resource_image), filename, value))) { tmx_err(E_UNKN, "xml parser: an error occured in the delegated image loading function"); return 0; } } else { tmx_err(E_MISSEL, "xml parser: missing 'source' attribute in the 'image' element"); return 0; } if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"height"))) { /* height */ res->height = atoi(value); tmx_free_func(value); } else if (strict) { tmx_err(E_MISSEL, "xml parser: missing 'height' attribute in the 'image' element"); return 0; } if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"width"))) { /* width */ res->width = atoi(value); tmx_free_func(value); } else if (strict) { tmx_err(E_MISSEL, "xml parser: missing 'width' attribute in the 'image' element"); return 0; } if ((value = (char*)xmlTextReaderGetAttribute(reader, (xmlChar*)"trans"))) { /* trans */ res->trans = get_color_rgb(value); res->uses_trans = 1; tmx_free_func(value); } return 1; }
int main( int argc, char *argv[] ) { // Create communication channel, thank you. mkfifo( "/tmp/iv_fifo", 0700 ); gtk_init( &argc, &argv ); APP app; app.file = NULL; app.fifo = open( "/tmp/iv_fifo", O_RDONLY | O_NONBLOCK ); app.fullscreen = FALSE; app.width = 300; app.height = 300; create_ui( &app ); gtk_widget_set_size_request( GTK_WIDGET( app.win ), 300, 300 ); g_signal_connect( G_OBJECT( app.win ), "key-press-event", G_CALLBACK( key_press ), &app ); g_signal_connect( G_OBJECT( app.win ), "destroy", G_CALLBACK( quit ), &app ); g_signal_connect( G_OBJECT( app.win ), "configure-event", G_CALLBACK( state_changed ), &app ); // We call every 500ms function read_from_pipe so we can // get commands from our pipe. g_timeout_add( 500, (GSourceFunc)read_from_pipe, &app ); // Load file if it is given as an argument if( argc == 2 ) { app.file = malloc( strlen( argv[1] ) ); sprintf( app.file, "%s", argv[1] ); load_image( &app ); } gtk_main(); return 0; }
/* load_bird - load the bird sprite */ void load_bird() { bird.bird = load_image("img/bird.png"); /* Instantiate the clip regions */ bird.clips[0].x = 0; bird.clips[0].y = 0; bird.clips[0].w = BIRD_WIDTH - 1; bird.clips[0].h = bird.bird->h; bird.clips[1].x = BIRD_WIDTH - 1; bird.clips[1].y = 0; bird.clips[1].w = BIRD_WIDTH - 1; bird.clips[1].h = bird.bird->h; bird.clips[2].x = 2 * BIRD_WIDTH - 2; bird.clips[2].y = 0; bird.clips[2].w = BIRD_WIDTH - 1; bird.clips[2].h = bird.bird->h; }
void display_expert_button(int win_width, int win_height, Menu* challenges) { int expert_x, expert_y, expert_w, expert_h; SDL_Texture* image = load_image("display/images/expert.bmp", &challenges->window); expert_x = win_width / LEFT_MARGIN; expert_y = challenges->intermediate.rect.y + challenges->intermediate.rect.h + (win_height / MENU_BUTTON_DIST); expert_w = MENU_BUTTON_WIDTH; expert_h = MENU_BUTTON_HEIGHT; make_rect(&challenges->window, &challenges->expert, expert_x, expert_y, expert_w, expert_h, 241, 14, 71); SDL_RenderCopy(challenges->window.renderer, image, NULL, &challenges->expert.rect); SDL_DestroyTexture(image); }
void menu_loop(t_env *e) { int start; start = 0; while (start != 1) { while (SDL_PollEvent(&e->event)) { SDL_GetWindowSize(e->win_sdl, &e->w, &e->h); start = menu_event(e); menu(e); } } if (e->texture) SDL_DestroyTexture(e->texture); if (e->sprite) SDL_FreeSurface(e->sprite); load_image(e, GUN); }
/** * Load a tilesheet from a file, and tell if the file should have transparency or chroma-key. */ void TileSheet::loadSheet(std::string filename){ if(tileSheetSurface!=NULL){ std::cout << "Freeing tileSheetSurface\n"; SDL_FreeSurface(tileSheetSurface); } std::cout << "loading tileSheetSurface from " << filename << "\n"; tileSheetSurface = load_image(filename); if(tileSheetSurface){ width = tileSheetSurface->w/32; height = tileSheetSurface->h/32; std::cout << "Tile sheet loaded successfully from " << filename << " with dimensions:" << width << "," << height << "\n"; }else { width = 0; height = 0; std::cout << "Tile sheet loading failed\n"; } }
void display_quit_button(int win_width, int win_height, Menu* main_menu) { int quit_button_x, quit_button_y, quit_button_w, quit_button_h; SDL_Texture* image = load_image("display/images/quit.bmp", &main_menu->window); quit_button_x = win_width / LEFT_MARGIN; quit_button_y = main_menu->menu_help_button.rect.y + main_menu->menu_help_button.rect.h + win_height / MENU_BUTTON_DIST; quit_button_w = main_menu->canvas_button.rect.w; quit_button_h = main_menu->canvas_button.rect.h; make_rect(&main_menu->window, &main_menu->quit_button, quit_button_x, quit_button_y, quit_button_w, quit_button_h, 100, 90, 90); SDL_RenderCopy(main_menu->window.renderer, image, NULL, &main_menu->quit_button.rect); SDL_DestroyTexture(image); }
at_bitmap input_png_reader(gchar* filename, at_input_opts_type * opts, at_msg_func msg_func, gpointer msg_data, gpointer user_data) { FILE *stream; at_bitmap image = at_bitmap_init(0, 0, 0, 1); at_exception_type exp = at_exception_new(msg_func, msg_data); stream = fopen(filename, "rb"); if (!stream) { LOG1("Can't open \"%s\"\n", filename); at_exception_fatal(&exp, "Cannot open input png file"); return image; } load_image(&image, stream, opts, &exp); fclose(stream); return image; }
cmdreturn_t i_navigate(arg_t a) { long n = (long) a; if (mode == MODE_IMAGE) { if (prefix > 0) n *= prefix; n += fileidx; if (n < 0) n = 0; if (n >= filecnt) n = filecnt - 1; if (n != fileidx) { load_image(n); return CMD_DIRTY; } } return CMD_INVALID; }
static void shix_init(int ram_size, int vga_ram_size, const char *boot_device, DisplayState * ds, const char *kernel_filename, const char *kernel_cmdline, const char *initrd_filename, const char *cpu_model) { int ret; CPUState *env; struct SH7750State *s; if (!cpu_model) cpu_model = "any"; printf("Initializing CPU\n"); env = cpu_init(cpu_model); /* Allocate memory space */ printf("Allocating ROM\n"); cpu_register_physical_memory(0x00000000, 0x00004000, IO_MEM_ROM); printf("Allocating SDRAM 1\n"); cpu_register_physical_memory(0x08000000, 0x01000000, 0x00004000); printf("Allocating SDRAM 2\n"); cpu_register_physical_memory(0x0c000000, 0x01000000, 0x01004000); /* Load BIOS in 0 (and access it through P2, 0xA0000000) */ if (bios_name == NULL) bios_name = BIOS_FILENAME; printf("%s: load BIOS '%s'\n", __func__, bios_name); ret = load_image(bios_name, phys_ram_base); if (ret < 0) { /* Check bios size */ fprintf(stderr, "ret=%d\n", ret); fprintf(stderr, "qemu: could not load SHIX bios '%s'\n", bios_name); exit(1); } /* Register peripherals */ s = sh7750_init(env); /* XXXXX Check success */ tc58128_init(s, "shix_linux_nand.bin", NULL); fprintf(stderr, "initialization terminated\n"); }
/* load images, set button to none */ void init_ui(theme_t *ui, button_t *b) { /* load images */ ui->button = load_image(BUTTON); ui->icon = load_image(ICON); ui->play = load_image(PLAY); ui->playicon = load_image(PLAYICON); ui->stopicon = load_image(STOPICON); ui->line = load_image(LINE); /* set active button to none */ b->active = BUTTON_NONE; b->before = BUTTON_NONE; }
int main(int argc, char **argv) { char* input = argv[1]; int channels = 3; list *plist = get_paths(input); //int N = plist->size; char **paths = (char **)list_to_array(plist); int m = plist->size; int count_label = 0; char labelpath[256]; sprintf(labelpath, "../labels/01_5_1.txt"); int count = 0; box_label *boxes = read_boxes(labelpath, &count); for (int i = 0; i < m; i++) { if (!paths[i]) { printf("load error!\n"); break; } image im = load_image(paths[i], 0, 0, channels); printf("load %s", paths[i]); float x, y, w, h; count_label++; x = boxes[i].x; y = boxes[i].y; w = boxes[i].w; h = boxes[i].h; box box = { x, y, w, h }; char *save_path1 = get_basename(paths[i]); char save_path[256]; sprintf(save_path, "./images/%s", save_path1); //show_image(im, save_path); image crop_im = crop_image(im, x,y,w,h); printf(" %f %f %f %f \n", x,y,w,h); show_image(crop_im, save_path); free_image(crop_im); free_image(im); } }
void display_canvas_text(Menu* main_menu) { int win_width, win_height; int canvas_text_x, canvas_text_y, canvas_text_w, canvas_text_h; SDL_Texture* image = load_image("display/images/program_a_work_of_art.bmp", &main_menu->window); SDL_GetWindowSize(main_menu->window.win, &win_width, &win_height); canvas_text_x = main_menu->canvas_button.rect.w + win_width / LEFT_MARGIN; canvas_text_y = main_menu->canvas_button.rect.y; canvas_text_w = MENU_POPUP_WIDTH; canvas_text_h = MENU_POPUP_HEIGHT; make_rect(&main_menu->window, &main_menu->canvas_text, canvas_text_x, canvas_text_y, canvas_text_w, canvas_text_h, 230, 230, 230); SDL_RenderCopy(main_menu->window.renderer, image, NULL, &main_menu->canvas_text.rect); SDL_DestroyTexture(image); }
bool i_navigate_sqrt(arg_t a) { long n = (long) a; unsigned long q = lsqrt(filecnt); if (q > 0) n *= q; if (mode == MODE_IMAGE) { if (prefix > 0) n *= prefix; n += fileidx; if (n < 0) n = 0; if (n >= filecnt) n = filecnt - 1; if (n != fileidx) { load_image(n); return true; } } return false; }
bool load_files() { //Load image background = load_image("background.png"); //Open the font font = TTF_OpenFont("lazy.ttf", 28); //If there was an error loading the images if(background == NULL) { return false; } if(font == NULL) { return false; } return true; }
void display_canvas_button(int win_width, int win_height, Menu* main_menu) { int canvas_button_x, canvas_button_y, canvas_button_w, canvas_button_h; SDL_Texture* image = load_image("display/images/canvas.bmp", &main_menu->window); canvas_button_x = win_width / LEFT_MARGIN; canvas_button_y = main_menu->logo.rect.y + main_menu->logo.rect.h + (win_height / TOP_MARGIN); canvas_button_w = MENU_BUTTON_WIDTH; canvas_button_h = MENU_BUTTON_HEIGHT; make_rect(&main_menu->window, &main_menu->canvas_button, canvas_button_x, canvas_button_y, canvas_button_w, canvas_button_h, 241, 14, 71); SDL_RenderCopy(main_menu->window.renderer, image, NULL, &main_menu->canvas_button.rect); SDL_DestroyTexture(image); }
//Initialize the BASES starting position and dimensions void init_bases() { int i; int base_total = BASE_WIDTH * 4; int space_left = WIDTH - base_total; int even_space = space_left / 5; // 5 gaps int x = even_space; int y = 470; for (i = 0; i < BASE; i++) { base[i].hitbox.x = x; base[i].hitbox.y = y; base[i].hitbox.w = BASE_WIDTH; base[i].hitbox.h = BASE_HEIGHT; x += BASE_WIDTH + even_space; //distance apart load_image("base.bmp", &base_img[i], magenta); } }
virtual bool load_raw_image (size_t image_width, size_t image_height, size_t image_depth, const char_t* image_file) { if ((image_file) && (image_width) && (image_height) && (image_depth)) { size_t image_pixel_size = ((image_depth+7)/8), image_size = (image_width*image_height*image_pixel_size); FILE* file = 0; if ((file = fopen(image_file, "rb"))) { xos::io::read::byte_file f(file); bool success = false; if ((load_image(f, image_size, image_width, image_height))) { success = true; } fclose(file); return success; } else { VEDERE_LOG_MESSAGE_ERROR("...failed on fopen(" << image_file << ", \"rb\")"); } } return false; }
void display_expert_text(Menu* challenges) { int win_width, win_height; int expert_text_x, expert_text_y, expert_text_w, expert_text_h; SDL_Texture* image = load_image("display/images/expert_text.bmp", &challenges->window); SDL_GetWindowSize(challenges->window.win, &win_width, &win_height); expert_text_x = challenges->expert.rect.w + win_width / LEFT_MARGIN; expert_text_y = challenges->expert.rect.y; expert_text_w = MENU_POPUP_WIDTH; expert_text_h = MENU_POPUP_HEIGHT; make_rect(&challenges->window, &challenges->expert_text, expert_text_x, expert_text_y, expert_text_w, expert_text_h, 230, 230, 230); SDL_RenderCopy(challenges->window.renderer, image, NULL, &challenges->expert_text.rect); SDL_DestroyTexture(image); }
int pil_force_boot(const char *name) { int ret = -EINVAL; struct pil_device *pil; pil = find_peripheral(name); if (!pil) { pr_err("%s: Couldn't find %s\n", __func__, name); return -EINVAL; } mutex_lock(&pil->lock); if (!WARN(!pil->count, "%s: Reference count mismatch\n", __func__)) ret = load_image(pil); if (!ret) pil_set_state(pil, PIL_ONLINE); mutex_unlock(&pil->lock); put_device(&pil->dev); return ret; }
/* implementation */ int main(int argc, char** argv) { pname = argv[0]; if (argc == 2) { int w, h; uint8_t *img = load_image(argv[1], &w, &h); jpec_enc_t *e = jpec_enc_new(img, w, h); int len; const uint8_t *jpeg = jpec_enc_run(e, &len); FILE *file = fopen("result.jpg", "wb"); fwrite(jpeg, sizeof(uint8_t), len, file); fclose(file); jpec_enc_del(e); free(img); } else { fprintf(stderr, "Usage:\n"); fprintf(stderr, " %s /path/to/img\n", pname); exit(1); } return 0; }
bool load_files() { //Load image square = load_image("square.bmp"); //Open the font font = TTF_OpenFont("lazy.ttf", 30); //If there was an error loading the images if(square == NULL) { return false; } if(font == NULL) { return false; } return true; }
void st::_app::lesson4::run() { SDL_Surface* image = NULL; // Could, should this be a member? Should I just have a // standard loop that I can start up. I'll refactor this // soonish. SDL_Event event; bool quit = false; initialize_screen( "Event Test" ); image = load_image( "x.png" ); apply_surface(0, 0, image); flip(); // Will need to rework event loop somehow... while ( quit == false ) { while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_QUIT ) { quit = true; } } } free_surface( image ); }
int start_linux(void) { void (*theKernel)(uint32_t zero, uint32_t arch, uint32_t *params); uint32_t i = 0, j = 0,ret; uint32_t *exec_at = ZIMAGE_LOAD_ADDRESS; uint32_t *parm_at = (uint32_t *)( DRAM_BASE + 0x100) ; // 256 bytes away from the base address of DRAM uint32_t machine_type; debug_print("about to copy linux image to load address: "); uart_print_address(exec_at); ret = load_image((uint32_t)ZIMAGE_START_BLOCK_NUMBER,(uint32_t*)exec_at,(uint16_t)ZIMAGE_BLOCK_SIZE); /* copy image into RAM */ debug_print("done copying linux image ...\n\r\0"); // debug_print("about to copy ramdisk image ..."); // load_image((uint32_t*) INITRD_LOAD_ADDRESS, INITRD_LOAD_END_ADDRESS);/* copy initial ramdisk image into RAM */ // debug_print("done copying ramdisk image ..."); debug_print("setting up ATAGS ...\n\r\0"); setup_tags(parm_at); /* sets up parameters */ machine_type = 3466; /* get machine type */ theKernel = (void (*)(uint32_t, uint32_t, uint32_t*))exec_at; /* set the kernel address */ debug_print("jumping to the kernel ... brace yourself!\n\r\0"); asm("mrc p15, 0, r1, c1, c0, 0"); /* Read Control Register configuration data*/ asm("bic r1, r1, #(0x1 << 12)"); /* Disable I Cache*/ asm("bic r1, r1, #(0x1 << 2)"); /* Disable D Cache*/ asm("mcr p15, 0, r1, c1, c0, 0"); /* Write Control Register configuration data*/ theKernel(0, machine_type, parm_at); /* jump to kernel with register set */ return 0; }