void start_retriever( const cires::Params& param, const std::string& confname, const std::string& srcdir) { // load appropriate parameter. cv::FileStorage fs(confname, cv::FileStorage::READ); RuntimeCheck(fs.isOpened(), "Error: failed to load configuration."); cires::Params settings; settings.load(fs.root()); if (param.hessian != settings.hessian) settings.hessian = param.hessian; if (param.voclen != settings.voclen) settings.voclen = param.voclen; if (param.binarylen != settings.binarylen) settings.binarylen = param.binarylen; if (param.imgmaxlen != settings.imgmaxlen) settings.imgmaxlen = param.imgmaxlen; if (param.binthresh != settings.binthresh) settings.binthresh = param.binthresh; if (not param.vocabulary.empty()) settings.vocabulary = param.vocabulary; if (not param.projection.empty()) settings.projection = param.projection; if (not param.thresholds.empty()) settings.thresholds = param.thresholds; if (settings.vocabulary.empty() || settings.projection.empty() || settings.thresholds.empty()) throw std::runtime_error("Error: settings in partially empty."); std::cout << "Initializing retrieval system ...\n"; retriever.initConfig(settings); std::cout << "Loading images ...\n"; load_images(srcdir); }
button::button(CVideo& video, const std::string& label, button::TYPE type, std::string button_image_name, SPACE_CONSUMPTION spacing, const bool auto_join, std::string overlay_image) : widget(video, auto_join), type_(type), label_(label), image_(NULL), pressedImage_(NULL), activeImage_(NULL), pressedActiveImage_(NULL), disabledImage_(NULL), pressedDisabledImage_(NULL), overlayImage_(NULL), overlayPressedImage_(NULL), overlayActiveImage_(NULL), state_(NORMAL), pressed_(false), spacing_(spacing), base_height_(0), base_width_(0), button_image_name_(), button_overlay_image_name_(overlay_image) { if (button_image_name.empty()) { switch (type_) { case TYPE_PRESS: button_image_name_ = "buttons/button_normal/button_copper_H22"; break; case TYPE_TURBO: button_image_name_ = "buttons/lite"; break; case TYPE_CHECK: button_image_name_ = "buttons/checkbox"; break; case TYPE_RADIO: button_image_name_ = "buttons/radiobox"; break; default: break; } } else { button_image_name_ = "buttons/" + button_image_name; } load_images(); }
/* コマンドの初期化処理を行う */ bool init(void) { /* 画像を読み込む */ if (!load_images()) return false; /* サムネイルを隠す色を取得する */ if (!load_hide_color()) return false; /* サムネイルのサイズを取得する */ if (!load_thumbnail_size()) return false; /* サムネイルの情報を取得する */ if (!load_thumbnail_params()) return false; /* フラグの値が0であるサムネイルを色で塗り潰す */ fill_thumbnail_rects(); /* 繰り返し動作を開始する */ start_command_repetition(); /* ポイントされているボタンを初期化する */ pointed_index = -1; /* 初回の描画であることを記録する */ is_first_frame = true; return true; }
/* * Entry point. * * Unpack images, setup the MMU, jump to the kernel. */ void main(void) { int num_apps; int cpu_mode; #ifdef CONFIG_SMP_ARM_MPCORE /* If not the boot strap processor then go to non boot main */ if ( (read_cpuid_mpidr() & 0xf) != booting_cpu_id) { non_boot_main(); } #endif /* Print welcome message. */ printf("\nELF-loader started on "); print_cpuid(); platform_init(); printf(" paddr=[%p..%p]\n", _start, _end - 1); /* Unpack ELF images into memory. */ load_images(&kernel_info, &user_info, 1, &num_apps); if (num_apps != 1) { printf("No user images loaded!\n"); abort(); } /* Setup MMU. */ cpu_mode = read_cpsr() & CPSR_MODE_MASK; if(cpu_mode == CPSR_MODE_HYPERVISOR){ printf("Enabling hypervisor MMU and paging\n"); init_lpae_boot_pd(&kernel_info); arm_enable_hyp_mmu(); } /* If we are in HYP mode, we enable the SV MMU and paging * just in case the kernel does not support hyp mode. */ printf("Enabling MMU and paging\n"); init_boot_pd(&kernel_info); arm_enable_mmu(); #ifdef CONFIG_SMP_ARM_MPCORE /* Bring up any other CPUs */ init_cpus(); non_boot_lock = 1; #endif /* Enter kernel. */ if (UART_PPTR < kernel_info.virt_region_start) { printf("Jumping to kernel-image entry point...\n\n"); } else { /* Our serial port is no longer accessible */ } ((init_kernel_t)kernel_info.virt_entry)(user_info.phys_region_start, user_info.phys_region_end, user_info.phys_virt_offset, user_info.virt_entry); /* We should never get here. */ printf("Kernel returned back to the elf-loader.\n"); abort(); }
/* MAIN FUNCTION */ int main(){ initialize_game(); load_images(); play_menu_sound(); set_initial_values(); welcome_screen(); return 0; }END_OF_MAIN()
/** * logo_configure: Configure this instance of the module. See * tcmodule-data.h for function details. */ static int logo_configure(TCModuleInstance *self, const char *options, vob_t *vob, TCModuleExtraData *xdata[]) { char file[PATH_MAX + 1] = { '\0' }; /* input filename */ LogoPrivateData *pd = NULL; int ret = TC_OK; TC_MODULE_SELF_CHECK(self, "configure"); pd = self->userdata; flogo_defaults(pd, vob); ret = flogo_parse_options(pd, options, file); RETURN_IF_NOT_OK(ret); ret = tc_magick_init(&pd->magick, TC_MAGICK_QUALITY_DEFAULT); RETURN_IF_NOT_OK(ret); ret = tc_magick_filein(&pd->magick, file); RETURN_IF_NOT_OK(ret); ret = sanity_check(pd, vob, file); RETURN_IF_NOT_OK(ret); ret = load_images(pd); RETURN_IF_NOT_OK(ret); /* initial delay. real delay = 1/100 sec * delay */ /* FIXME */ pd->cur_delay = pd->magick.image->delay*vob->fps/100; if (verbose >= TC_DEBUG) tc_log_info(MOD_NAME, "Nr: %d Delay: %d ImageDelay %lu|", pd->nr_of_images, pd->cur_delay, pd->magick.image->delay); if (vob->im_v_codec == TC_CODEC_YUV420P) { ret = setup_logo_yuv(pd); RETURN_IF_NOT_OK(ret); pd->render = render_logo_yuv; } else { ret = setup_logo_rgb(pd, vob); RETURN_IF_NOT_OK(ret); pd->render = render_logo_rgb; } ret = flogo_compute_position(pd); RETURN_IF_NOT_OK(ret); return flogo_calc_coeff(pd); }
stereo_task::stereo_task(const std::string& pname, const std::string& nameLeft, const std::string& nameRight, const std::string& nameGroundLeft, const std::string& nameGroundRight, const std::string& nameOccLeft, const std::string& nameOccRight, unsigned char subsamplingGroundTruth, int dispRange) : name(pname), disp_range(dispRange), forward(disparity_range(-dispRange+1, 0)), backward(disparity_range(0, dispRange-1)) { ground_truth_sampling = subsamplingGroundTruth; load_images(nameLeft, nameRight); load_ground_truth(nameGroundLeft, nameGroundRight, ground_truth_sampling); load_occ(nameOccLeft, nameOccRight); estimate_occ(); init_single_tasks(); }
gboolean markdown_textview_load_file(MarkdownTextView * self, const gchar * file_name) { FILE *text_file; gchar *path; g_return_val_if_fail(IS_MARKDOWN_TEXTVIEW(self), FALSE); path = g_build_filename(self->image_directory, file_name, NULL); /* we do assume UTF-8 encoding */ if ((text_file = fopen(path, "rb"))) { GtkTextBuffer *text_buffer; GtkTextIter iter; gchar *line; gchar buffer[EGG_MARKDOWN_MAX_LINE_LENGTH]; text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(self)); gtk_text_buffer_set_text(text_buffer, "\n", 1); gtk_text_buffer_get_start_iter(text_buffer, &iter); egg_markdown_clear(self->markdown); while (fgets(buffer, EGG_MARKDOWN_MAX_LINE_LENGTH, text_file)) { line = egg_markdown_parse(self->markdown, buffer); if (line && *line) { gtk_text_buffer_insert_markup(text_buffer, &iter, line); gtk_text_buffer_insert(text_buffer, &iter, "\n", 1); } g_free(line); } fclose(text_file); load_images(self); g_signal_emit(self, markdown_textview_signals[FILE_LOAD_COMPLETE], 0, file_name); g_free(path); return TRUE; } g_free(path); return FALSE; }
void init_sdl(t_sdl *game, t_list *philos, pthread_t *threads) { game->threads = threads; game->philos = philos; init_game(game); if (SDL_Init(SDL_INIT_VIDEO) < 0) _error("init_sdl : Init"); if (!(game->screen = SDL_SetVideoMode(game->size[X], game->size[Y] , 32, SDL_HWSURFACE))) _error("init_sdl : SetVideoMode"); SDL_WM_SetCaption("Philosophes", NULL); load_images(game); load_background(game); if (pthread_create(&threads[NPHIL], NULL, &sdl_loop, game) < 0) _error("main() : phtread_create"); }
int init_game(t_game *game, int nb_map, char **maps) { game->map = NULL; game->maps_list = NULL; game->screen = NULL; game->images[0] = NULL; game->background = NULL; game->enemies = NULL; if (load_maps(game, nb_map, maps) == -1) return (-1); if (init_base(game) == -1) return (-1); if (load_images(game) < 0) return (-1); return (0); }
int main(int argc, const char** argv) { const char* filenames[4096]; // command line params yc_parser* parser = yc_init_parser(argc, argv, "view images"); yc_parse_argsa(parser, "image", "image filename", 0, true, filenames, 4096); yc_done_parser(parser); // loading images view_img* imgs; int nimgs = load_images(filenames, &imgs); // start ui loop ui_loop(nimgs, imgs); // done return EXIT_SUCCESS; }
static void iracer_startup() { // KERIPO MOD //load_settings(); ipr_load_settings(); load_car(); load_map(); load_images(); iracer_scale_images(); FILE *fp; if(!(fp = fopen(direc, "r"))){ new_message_window("Couldn't Find iracer Folder"); } else { iracer_scan(direc); } }
int main (void) { //save_state.print_table(); if(1) { iGraph.CreateMainWindow (SCREEN_WIDTH, SCREEN_HEIGHT, "A Lust for Power"); iGraph.SetKeyboardInput(KeyboardInput); iGraph.SetBackgroundColor (26,32,40); load_images(); iGraph.SetMainLoop(main_loop); iGraph.StartMainLoop(); }; map_builder.delete_list(); halt(); return 0; };
gboolean markdown_textview_set_text(MarkdownTextView * self, const gchar * text) { gboolean result = TRUE; gchar **lines; gint line; g_return_val_if_fail(IS_MARKDOWN_TEXTVIEW(self), FALSE); markdown_textview_clear(self); lines = g_strsplit(text, "\n", 0); for (line = 0; result && lines[line]; line++) { result = append_text(self, (const gchar *)lines[line]); } g_strfreev(lines); load_images(self); return result; }
/* ** This is the initializer function of the display structure. ** It puts every parameter to default value, then creates the window ** and prints the loading screen before loading the assets. */ int init_display(t_display *d) { if (init_structures(d) == -1) return (-1); if (SDL_Init(SDL_INIT_EVERYTHING) || TTF_Init()) return (-1); SDL_WM_SetCaption("Zappy", NULL); d->w = SDL_SetVideoMode(1440, 900, 32, SDL_SWSURFACE); d->loading_screen = SDL_LoadBMP("./assets/screens/loading_screen.bmp"); if (d->w == NULL || d->loading_screen == NULL) return (-1); display_loading_screen(d, 0); if (launch_music(d) == -1) return (-1); d->font = TTF_OpenFont("./assets/fonts/filxgirl.ttf", 30); if (!d->font) return (-1); load_images(d); if (strlen(SDL_GetError()) > 0) return (-1); if (display_loading_screen(d, 1) == -1) return (-1); return (0); }
void go(char **argv, int input_args) { int blend_wh; int i; int pitch; my_timer timer; if (!g_nooutput) { if (g_jpegquality != -1) { fopen_s(&g_jpeg, g_output_filename, "wb"); if (!g_jpeg) die("couldn't open output file"); } else { if (!g_bigtiff) g_tiff = TIFFOpen(g_output_filename, "w"); else g_tiff = TIFFOpen(g_output_filename, "w8"); if (!g_tiff) die("couldn't open output file"); } } if (input_args == 1 && g_caching) { output(1, "Only one input image; caching disabled\n"); g_caching = false; } timer.set(); load_images(argv, input_args); if (g_numimages == 0) die("no valid input files"); timer.report("load"); // calculate number of levels if (!g_wideblend) { blend_wh = 0; for (i = 0; i < g_numimages; i++) blend_wh += g_images[i].width + g_images[i].height; blend_wh = (int)(blend_wh * (0.5 / g_numimages)); } else blend_wh = min(g_workwidth, g_workheight); g_levels = 0; while (blend_wh > 4) // was >4 but that caused banding { blend_wh = (blend_wh + 1) >> 1; g_levels++; } g_levels = min(g_max_levels, g_levels); g_levels = max(0, g_levels - g_sub_levels); output(1, "%dx%d, %dbpp, %d levels\n", g_workwidth, g_workheight, g_workbpp, g_levels); pitch = (g_workwidth + 7) & (~7); g_line0 = _aligned_malloc(pitch * sizeof(int), 16); g_line1 = _aligned_malloc(pitch * sizeof(int), 16); g_line2 = _aligned_malloc(pitch * sizeof(int), 16); if (g_numimages == 1) { if (g_caching) die("Caching is still enabled but only one input image; multiblend can't " "continue!"); output(1, "Only one image; pseudo-wrapping mode assumed\n"); g_pseudowrap = true; pseudowrap_split(); } // dimension mask structs for all images for (i = 0; i < g_numimages; i++) g_images[i].masks = (float **)malloc(g_levels * sizeof(float *)); // calculate seams timer.set(); if (g_pseudowrap) { pseudowrap_seam(); } else { seam(); } timer.report("seaming"); if (!g_nooutput) { // calculate mask pyramids mask_pyramids(); // blend timer.set(); blend(); timer.report("blend"); if (g_pseudowrap) pseudowrap_unsplit(); output(1, "writing %s...\n", g_output_filename); timer.set(); if (g_jpegquality != -1) jpeg_out(); else tiff_out(); timer.report("write"); } // ppm_out(out_channels); }
virtual void init() { load_images(); }
/* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { FILE *fsrc = NULL; opj_dparameters_t parameters; /* decompression parameters */ opj_image_t* image = NULL; opj_stream_t *l_stream = NULL; /* Stream */ opj_codec_t* l_codec = NULL; /* Handle to a decompressor */ opj_codestream_index_t* cstr_index = NULL; char indexfilename[OPJ_PATH_LEN]; /* index file name */ OPJ_INT32 num_images, imageno; img_fol_t img_fol; dircnt_t *dirptr = NULL; int failed = 0; /* set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); /* FIXME Initialize indexfilename and img_fol */ *indexfilename = 0; /* Initialize img_fol */ memset(&img_fol,0,sizeof(img_fol_t)); /* parse input and get user encoding parameters */ if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) { return EXIT_FAILURE; } /* Initialize reading of directory */ if(img_fol.set_imgdir==1){ int it_image; num_images=get_num_images(img_fol.imgdirpath); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); if(dirptr){ dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); if(!dirptr->filename_buf){ return EXIT_FAILURE; } for(it_image=0;it_image<num_images;it_image++){ dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; } } if(load_images(dirptr,img_fol.imgdirpath)==1){ return EXIT_FAILURE; } if (num_images==0){ fprintf(stdout,"Folder is empty\n"); return EXIT_FAILURE; } }else{ num_images=1; } /*Decoding image one by one*/ for(imageno = 0; imageno < num_images ; imageno++) { fprintf(stderr,"\n"); if(img_fol.set_imgdir==1){ if (get_next_file(imageno, dirptr,&img_fol, ¶meters)) { fprintf(stderr,"skipping file...\n"); continue; } } /* read the input file and put it in memory */ /* ---------------------------------------- */ fsrc = fopen(parameters.infile, "rb"); if (!fsrc) { fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile); return EXIT_FAILURE; } l_stream = opj_stream_create_default_file_stream(fsrc,1); if (!l_stream){ fclose(fsrc); fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); return EXIT_FAILURE; } /* decode the JPEG2000 stream */ /* ---------------------- */ switch(parameters.decod_format) { case J2K_CFMT: /* JPEG-2000 codestream */ { /* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_J2K); break; } case JP2_CFMT: /* JPEG 2000 compressed image data */ { /* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_JP2); break; } case JPT_CFMT: /* JPEG 2000, JPIP */ { /* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_JPT); break; } default: fprintf(stderr, "skipping file..\n"); opj_stream_destroy(l_stream); continue; } /* catch events using our callbacks and give a local context */ opj_set_info_handler(l_codec, info_callback,00); opj_set_warning_handler(l_codec, warning_callback,00); opj_set_error_handler(l_codec, error_callback,00); /* Setup the decoder decoding parameters using user parameters */ if ( !opj_setup_decoder(l_codec, ¶meters) ){ fprintf(stderr, "ERROR -> opj_compress: failed to setup the decoder\n"); opj_stream_destroy(l_stream); fclose(fsrc); opj_destroy_codec(l_codec); return EXIT_FAILURE; } /* Read the main header of the codestream and if necessary the JP2 boxes*/ if(! opj_read_header(l_stream, l_codec, &image)){ fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n"); opj_stream_destroy(l_stream); fclose(fsrc); opj_destroy_codec(l_codec); opj_image_destroy(image); return EXIT_FAILURE; } if (!parameters.nb_tile_to_decode) { /* Optional if you want decode the entire image */ if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0, (OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, (OPJ_INT32)parameters.DA_y1)){ fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n"); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; } /* Get the decoded image */ if (!(opj_decode(l_codec, l_stream, image) && opj_end_decompress(l_codec, l_stream))) { fprintf(stderr,"ERROR -> opj_decompress: failed to decode image!\n"); opj_destroy_codec(l_codec); opj_stream_destroy(l_stream); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; } } else { /* It is just here to illustrate how to use the resolution after set parameters */ /*if (!opj_set_decoded_resolution_factor(l_codec, 5)) { fprintf(stderr, "ERROR -> opj_decompress: failed to set the resolution factor tile!\n"); opj_destroy_codec(l_codec); opj_stream_destroy(l_stream); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; }*/ if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) { fprintf(stderr, "ERROR -> opj_decompress: failed to decode tile!\n"); opj_destroy_codec(l_codec); opj_stream_destroy(l_stream); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; } fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index); } /* Close the byte stream */ opj_stream_destroy(l_stream); fclose(fsrc); if(image->color_space == OPJ_CLRSPC_SYCC){ color_sycc_to_rgb(image); /* FIXME */ } if( image->color_space != OPJ_CLRSPC_SYCC && image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy && image->comps[1].dx != 1 ) image->color_space = OPJ_CLRSPC_SYCC; else if (image->numcomps <= 2) image->color_space = OPJ_CLRSPC_GRAY; if(image->icc_profile_buf) { #if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) color_apply_icc_profile(image); /* FIXME */ #endif free(image->icc_profile_buf); image->icc_profile_buf = NULL; image->icc_profile_len = 0; } /* create output image */ /* ------------------- */ switch (parameters.cod_format) { case PXM_DFMT: /* PNM PGM PPM */ if (imagetopnm(image, parameters.outfile)) { fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; case PGX_DFMT: /* PGX */ if(imagetopgx(image, parameters.outfile)){ fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; case BMP_DFMT: /* BMP */ if(imagetobmp(image, parameters.outfile)){ fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; #ifdef OPJ_HAVE_LIBTIFF case TIF_DFMT: /* TIFF */ if(imagetotif(image, parameters.outfile)){ fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; #endif /* OPJ_HAVE_LIBTIFF */ case RAW_DFMT: /* RAW */ if(imagetoraw(image, parameters.outfile)){ fprintf(stderr,"Error generating raw file. Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; case RAWL_DFMT: /* RAWL */ if(imagetorawl(image, parameters.outfile)){ fprintf(stderr,"Error generating rawl file. Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; case TGA_DFMT: /* TGA */ if(imagetotga(image, parameters.outfile)){ fprintf(stderr,"Error generating tga file. Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; #ifdef OPJ_HAVE_LIBPNG case PNG_DFMT: /* PNG */ if(imagetopng(image, parameters.outfile)){ fprintf(stderr,"Error generating png file. Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; #endif /* OPJ_HAVE_LIBPNG */ /* Can happen if output file is TIFF or PNG * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined */ default: fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); failed = 1; } /* free remaining structures */ if (l_codec) { opj_destroy_codec(l_codec); } /* free image data structure */ opj_image_destroy(image); /* destroy the codestream index */ opj_destroy_cstr_index(&cstr_index); } return failed ? EXIT_FAILURE : EXIT_SUCCESS; }
void Pipeline::run(const bool save_clouds, const bool show_clouds) { Logger _log("Pipeline"); /** * Stage 0: Load images from file */ Images images; load_images(folder_path, images); /** * Stage 1: Detect features in loaded images */ CamFrames cam_Frames; DescriptorsVec descriptors_vec; extract_features(images, cam_Frames, descriptors_vec); // Free Image.gray for (int i = 0; i < images.size(); i++) const_cast<cv::Mat&>(images[i].gray).release(); /** * Stage 2: Calculate descriptors and find image pairs through matching */ ImagePairs image_pairs; find_matching_pairs(images, cam_Frames, descriptors_vec, image_pairs); // Free some memory DescriptorsVec().swap(descriptors_vec); /** * State 3: Compute pairwise R and t */ register_camera(image_pairs, cam_Frames); /** * Stage 4: Construct associativity matrix and spanning tree */ Associativity assocMat(cam_Frames.size()); for (int p = 0; p < image_pairs.size(); p++) { ImagePair* pair = &image_pairs[p]; int i = pair->pair_index.first, j = pair->pair_index.second; if (pair -> R.empty()) continue; assocMat(i, j) = pair; assocMat(j, i) = pair; assert(assocMat(i, j) == assocMat(j, i)); assert(assocMat(i, j)->pair_index.first == i && assocMat(i, j)->pair_index.second == j); } Associativity tree; const int camera_num = build_spanning_tree(image_pairs, assocMat, tree); /** * Stage 5: Compute global Rs and ts */ CameraPoses gCameraPoses; glo_cam_poses(images, gCameraPoses, image_pairs, tree); /** * Stage 6: Find and cluster depth points from local camera frame to global camera frame */ PointClusters pointClusters; PointMap pointMap; find_clusters(assocMat, gCameraPoses, cam_Frames, pointClusters, pointMap); // Free some memory ImagePairs().swap(image_pairs); /** * Stage 7: get center of mass from clusters */ PointCloud pointCloud(pointClusters.size()); find_CoM(pointClusters, pointCloud); // Free pointClusters for (int i = 0; i < pointClusters.size(); i++) PointCluster().swap(pointClusters[i]); PointClusters().swap(pointClusters); // Save cloud before BA Viewer viewer("Before BA"); auto cloud = viewer.createPointCloud(images, gCameraPoses, cameraMatrix); int n = cloud->points.size(); auto time = ptime::second_clock::local_time(); auto tstamp = ptime::to_iso_string(time); auto folder = fs::path(folder_path).filename().string(); auto fname = (fmt("%s_%s_%d_noBA.pcd") % folder % tstamp % n).str(); if (save_clouds) viewer.saveCloud(cloud, fname); if (show_clouds) viewer.showCloudPoints(cloud, false); /** * State 8: Bundle Adjustment */ bundle_adjustment(pointMap, cam_Frames, false, gCameraPoses, pointCloud); _log.tok(); /** * Show calculated point cloud */ Viewer viewer_ba("After BA no Depth"); cloud = viewer_ba.createPointCloud(images, gCameraPoses, cameraMatrix); n = cloud->points.size(); fname = (fmt("%s_%s_%d_BA_noD.pcd") % folder % tstamp % n).str(); if (save_clouds) viewer_ba.saveCloud(cloud, fname); if (show_clouds) viewer_ba.showCloudPoints(cloud,false); bundle_adjustment(pointMap, cam_Frames, true, gCameraPoses, pointCloud); // Free some memory PointMap().swap(pointMap); CamFrames().swap(cam_Frames); PointCloud().swap(pointCloud); /** * Show calculated point cloud */ Viewer viewer_baD("After BA with Depth"); cloud = viewer_baD.createPointCloud(images, gCameraPoses, cameraMatrix); n = cloud->points.size(); fname = (fmt("%s_%s_%d_BA_D.pcd") % folder % tstamp % n).str(); // Free some memory Images().swap(images); CameraPoses().swap(gCameraPoses); if (save_clouds) viewer_baD.saveCloud(cloud, fname); if (show_clouds) viewer_baD.showCloudPoints(cloud); }
/* ***********************************************************/ int main(int argc, char* argv[]) { GR_EVENT event; GR_WM_PROPERTIES props; int computer_side; char s[256]; int i; BOOL found; char temp[50]; if (GrOpen() < 0) { fprintf(stderr, "tuxchess: cannot open graphics\n"); exit(1); } load_images(); master = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, BM_WIDTH, BM_HEIGHT, 0, WHITE, WHITE); board = GrNewWindow((GR_WINDOW_ID) master, 0, 0, 394, 394, 0, WHITE, WHITE); text = GrNewWindow((GR_WINDOW_ID) master, 0, 393, 394, 20, 0, BLACK, BLACK); GrSelectEvents(master, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE; props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION | GR_WM_PROPS_CLOSEBOX; props.title = TITLE; GrSetWMProperties(master, &props); /* eliminate white background*/ props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_NOBACKGROUND; GrSetWMProperties(board, &props); GrMapWindow(master); GrMapWindow(board); GrMapWindow(text); gc = GrNewGC(); text_gc = GrNewGC(); init(); gen(); max_time = 1 << 25; max_depth = 4; if (argc > 1) computer_side = side; /* computer plays white */ else { computer_side = EMPTY; /* human plays white */ gprintf("Make a move..."); } for (;;) { if (side == computer_side) { /* think about the move and make it */ think(0); if (!pv[0][0].u) { gprintf("No legal moves"); computer_side = EMPTY; continue; } sprintf(temp,"Computer's move: %s\n", move_str(pv[0][0].b)); gprintf(temp); makemove(pv[0][0].b); ply = 0; gen(); print_board(); print_result(); continue; } GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); /* no return*/ case GR_EVENT_TYPE_EXPOSURE: print_board(); gprintf(NULL); break; case GR_EVENT_TYPE_BUTTON_DOWN: mouse_hit(event.button.x, event.button.y); break; } if (to != 999) { /* loop through the moves to see if it's legal */ found = FALSE; for (i = 0; i < first_move[1]; ++i) if (gen_dat[i].m.b.from == from && gen_dat[i].m.b.to == to) { found = TRUE; /* get the promotion piece right */ if (gen_dat[i].m.b.bits & 32) switch (s[4]) { case 'N': break; case 'B': i += 1; break; case 'R': i += 2; break; default: i += 3; break; } break; } /* if */ if (!found || !makemove(gen_dat[i].m.b)) gprintf("Illegal move.\n"); else { ply = 0; gen(); print_board(); print_result(); computer_side = side; to = 999; } } /* if to != 999 */ } /* for (;;) */ return(0); /* never reached */ }
ClipExample:: ClipExample(cmd_line_type *cmd_line): DemoKernel(cmd_line), m_shader_hoard(WRATHGLShader::shader_source() .add_source("wobbly.vert.glsl", WRATHGLShader::from_resource), WRATHGLShader::shader_source() .add_source("wobbly.frag.glsl", WRATHGLShader::from_resource)), m_first_frame(true) { /* Create the WRATHTripleBufferEnabler object which our visual items will use to sync */ m_tr=WRATHNew WRATHTripleBufferEnabler(); /* Create the WRATHLayer which will contain and draw our shape */ m_layer=WRATHNew WRATHLayer(m_tr); /* these are the transforms that will be applied to all elements contained in the WRATHLayer: + a 3D transform + a Projection transform For the purpose of this example the 3D transform will be the identity matrix. In other words no transform will be applied to the vertex data. Projection will be orthographic */ float_orthogonal_projection_params proj_params(0, width(), height(), 0); m_layer->simulation_matrix(WRATHLayer::projection_matrix, float4x4(proj_params)); /* now we make a child layer of m_layer */ m_child_layer=WRATHNew WRATHLayer(m_layer); const int num_clip_widgets=cmd_line->m_num_clip_widgets.m_value; const int num_widgets=cmd_line->m_num_widgets.m_value; /* create our clip widgets, we will set their z_order values so that: - m_ring_widget is in order of ctor - m_clip_out_widget of each is above all m_ring_widget AND below all elements in m_widgets - m_clip_in_widget is above all m_clip_out_widget So what happens is that when 2 clipwidget intesect their rings are not drawn over the clip inside region of either one. */ for(int i=0; i<num_clip_widgets; ++i) { ClipWidget *N; vec2 pos; float r1, r2; r1=static_cast<float>(rand())/static_cast<float>(RAND_MAX); r2=static_cast<float>(rand())/static_cast<float>(RAND_MAX); pos=vec2( r1*width(), r2*height()); N=WRATHNew ClipWidget(pos, m_shader_hoard, m_layer, m_child_layer, vec4(0.0f, 0.0f, 0.0f, 1.0f)); N->m_ring_widget->z_order(-i); N->m_clip_out_widget->z_order(-i-num_clip_widgets); N->m_clip_in_widget->z_order(-i-2*num_clip_widgets); m_clip_widgets.push_back(N); } load_images(); //make a background widget for m_layer: m_background_widget=make_image_widget(m_layer, m_images[0]); m_background_widget->z_order(1); //below everything in m_layer. //make a background widget for m_child_layer m_background_widget2=make_image_widget(m_child_layer, m_images[1]); m_background_widget2->z_order(-3*num_clip_widgets); //below everything in m_child_layer. for(int i=0, zi=-3*num_clip_widgets-1; i<num_widgets; ++i, --zi) { ImageWidget *widget; WRATHImage *img; img=m_images[rand()%m_images.size()]; widget=make_widget<ImageWidget>(m_child_layer, m_shader_hoard, WRATHDrawType::opaque_pass(), img); widget->translation(vec2(rand()%width(), rand()%height()) ); // widget->rotation( static_cast<float>(rand())/RAND_MAX*M_PI); widget->m_velocity=vec2( (float)rand()/RAND_MAX*190.0f - 95.0f, (float)rand()/RAND_MAX*190.0f - 95.0f); widget->m_inner_radius=rand()%100; widget->m_outer_radius=100 + rand()%100; //make the z-order of widget decrease from -1, //thus layer widgets are drawn on top. widget->z_order(zi); m_widgets.push_back(widget); } glClearColor(1.0, 1.0, 1.0, 1.0); }
int main(int argc, char *argv[]) { int ret; opj_dparameters_t parameters; /* decompression parameters */ img_fol_t img_fol; opj_image_t *image = NULL; FILE *fsrc = NULL; bool bResult; int num_images; int i,imageno; dircnt_t *dirptr; opj_codec_t* dinfo = NULL; /* handle to a decompressor */ opj_stream_t *cio = NULL; opj_codestream_info_t cstr_info; /* Codestream information structure */ char indexfilename[OPJ_PATH_LEN]; /* index file name */ OPJ_INT32 l_tile_x0,l_tile_y0; OPJ_UINT32 l_tile_width,l_tile_height,l_nb_tiles_x,l_nb_tiles_y; /* configure the event callbacks (not required) */ /* set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); /* Initialize indexfilename and img_fol */ *indexfilename = 0; memset(&img_fol,0,sizeof(img_fol_t)); /* parse input and get user encoding parameters */ if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) { return EXIT_FAILURE; } /* Initialize reading of directory */ if(img_fol.set_imgdir==1){ num_images=get_num_images(img_fol.imgdirpath); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); if(dirptr){ dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); // Stores at max 10 image file names dirptr->filename = (char**) malloc(num_images*sizeof(char*)); if(!dirptr->filename_buf){ return EXIT_FAILURE; } for(i=0;i<num_images;i++){ dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN; } } if(load_images(dirptr,img_fol.imgdirpath)==1){ return EXIT_FAILURE; } if (num_images==0){ fprintf(stdout,"Folder is empty\n"); return EXIT_FAILURE; } }else{ num_images=1; } /*Encoding image one by one*/ for(imageno = 0; imageno < num_images ; imageno++) { image = NULL; fprintf(stderr,"\n"); if(img_fol.set_imgdir==1){ if (get_next_file(imageno, dirptr,&img_fol, ¶meters)) { fprintf(stderr,"skipping file...\n"); continue; } } /* read the input file and put it in memory */ /* ---------------------------------------- */ fsrc = fopen(parameters.infile, "rb"); if (!fsrc) { fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile); return EXIT_FAILURE; } cio = opj_stream_create_default_file_stream(fsrc,true); /* decode the code-stream */ /* ---------------------- */ switch (parameters.decod_format) { case J2K_CFMT: { /* JPEG-2000 codestream */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_J2K); break; } case JP2_CFMT: { /* JPEG 2000 compressed image data */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_JP2); break; } case JPT_CFMT: { /* JPEG 2000, JPIP */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_JPT); break; } default: fprintf(stderr, "skipping file..\n"); opj_stream_destroy(cio); continue; } /* catch events using our callbacks and give a local context */ /* setup the decoder decoding parameters using user parameters */ opj_setup_decoder(dinfo, ¶meters); /* decode the stream and fill the image structure */ /* if (*indexfilename) // If need to extract codestream information image = opj_decode_with_info(dinfo, cio, &cstr_info); else */ bResult = opj_read_header( dinfo, &image, &l_tile_x0, &l_tile_y0, &l_tile_width, &l_tile_height, &l_nb_tiles_x, &l_nb_tiles_y, cio); //image = opj_decode(dinfo, cio); //bResult = bResult && (image != 00); //bResult = bResult && opj_end_decompress(dinfo,cio); //if // (!image) //{ // fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); // opj_destroy_codec(dinfo); // opj_stream_destroy(cio); // fclose(fsrc); // return EXIT_FAILURE; //} /* dump image */ if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to read header\n"); return EXIT_FAILURE; } j2k_dump_image(stdout, image); /* dump cp */ //j2k_dump_cp(stdout, image, dinfo->m_codec); /* close the byte stream */ opj_stream_destroy(cio); fclose(fsrc); /* Write the index to disk */ if (*indexfilename) { char bSuccess; bSuccess = write_index_file(&cstr_info, indexfilename); if (bSuccess) { fprintf(stderr, "Failed to output index file\n"); ret = EXIT_FAILURE; } } /* free remaining structures */ if (dinfo) { opj_destroy_codec(dinfo); } /* free codestream information structure */ if (*indexfilename) opj_destroy_cstr_info(&cstr_info); /* free image data structure */ opj_image_destroy(image); } return ret; }
/* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { FILE *fout = NULL; opj_dparameters_t parameters; /* Decompression parameters */ opj_image_t* image = NULL; /* Image structure */ opj_codec_t* l_codec = NULL; /* Handle to a decompressor */ opj_stream_t *l_stream = NULL; /* Stream */ opj_codestream_info_v2_t* cstr_info = NULL; opj_codestream_index_t* cstr_index = NULL; int32_t num_images, imageno; img_fol_t img_fol; dircnt_t *dirptr = NULL; #ifdef MSD bool l_go_on = true; uint32_t l_max_data_size = 1000; uint8_t * l_data = (uint8_t *) malloc(1000); #endif /* Set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); /* Initialize img_fol */ memset(&img_fol,0,sizeof(img_fol_t)); img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND; /* Parse input and get user encoding parameters */ if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) { return EXIT_FAILURE; } /* Initialize reading of directory */ if(img_fol.set_imgdir==1) { int it_image; num_images=get_num_images(img_fol.imgdirpath); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); if(dirptr) { dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); if(!dirptr->filename_buf) { return EXIT_FAILURE; } for(it_image=0; it_image<num_images; it_image++) { dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; } } if(load_images(dirptr,img_fol.imgdirpath)==1) { return EXIT_FAILURE; } if (num_images==0) { fprintf(stdout,"Folder is empty\n"); return EXIT_FAILURE; } } else { num_images=1; } /* Try to open for writing the output file if necessary */ if (parameters.outfile[0] != 0) { fout = fopen(parameters.outfile,"w"); if (!fout) { fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile); return EXIT_FAILURE; } } else fout = stdout; /* Read the header of each image one by one */ for(imageno = 0; imageno < num_images ; imageno++) { fprintf(stderr,"\n"); if(img_fol.set_imgdir==1) { if (get_next_file(imageno, dirptr,&img_fol, ¶meters)) { fprintf(stderr,"skipping file...\n"); continue; } } /* Read the input file and put it in memory */ /* ---------------------------------------- */ l_stream = opj_stream_create_default_file_stream(parameters.infile,1); if (!l_stream) { fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile); return EXIT_FAILURE; } /* Read the JPEG2000 stream */ /* ------------------------ */ switch(parameters.decod_format) { case J2K_CFMT: { /* JPEG-2000 codestream */ /* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_J2K); break; } case JP2_CFMT: { /* JPEG 2000 compressed image data */ /* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_JP2); break; } case JPT_CFMT: { /* JPEG 2000, JPIP */ /* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_JPT); break; } default: fprintf(stderr, "skipping file..\n"); opj_stream_destroy(l_stream); continue; } /* catch events using our callbacks and give a local context */ opj_set_info_handler(l_codec, info_callback,00); opj_set_warning_handler(l_codec, warning_callback,00); opj_set_error_handler(l_codec, error_callback,00); /* Setup the decoder decoding parameters using user parameters */ if ( !opj_setup_decoder(l_codec, ¶meters) ) { fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n"); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); fclose(fout); return EXIT_FAILURE; } /* Read the main header of the codestream and if necessary the JP2 boxes*/ if(! opj_read_header(l_stream, l_codec, &image)) { fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n"); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(image); fclose(fout); return EXIT_FAILURE; } opj_dump_codec(l_codec, img_fol.flag, fout ); cstr_info = opj_get_cstr_info(l_codec); cstr_index = opj_get_cstr_index(l_codec); /* close the byte stream */ opj_stream_destroy(l_stream); /* free remaining structures */ if (l_codec) { opj_destroy_codec(l_codec); } /* destroy the image header */ opj_image_destroy(image); /* destroy the codestream index */ opj_destroy_cstr_index(&cstr_index); /* destroy the codestream info */ opj_destroy_cstr_info(&cstr_info); } /* Close the output file */ fclose(fout); return EXIT_SUCCESS; }
int main(int argc, char **argv) { opj_dparameters_t parameters; /* decompression parameters */ img_fol_t img_fol; opj_event_mgr_t event_mgr; /* event manager */ opj_image_t *image = NULL; FILE *fsrc = NULL; unsigned char *src = NULL; int file_length; int num_images; int i,imageno; dircnt_t *dirptr = NULL; opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ opj_cio_t *cio = NULL; opj_codestream_info_t cstr_info; /* Codestream information structure */ char indexfilename[OPJ_PATH_LEN]; /* index file name */ /* configure the event callbacks (not required) */ memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); event_mgr.error_handler = error_callback; event_mgr.warning_handler = warning_callback; event_mgr.info_handler = info_callback; /* set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); /* Initialize indexfilename and img_fol */ *indexfilename = 0; memset(&img_fol,0,sizeof(img_fol_t)); /* parse input and get user encoding parameters */ if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) { return 1; } /* Initialize reading of directory */ if(img_fol.set_imgdir==1){ num_images=get_num_images(img_fol.imgdirpath); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); if(dirptr){ dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename = (char**) malloc(num_images*sizeof(char*)); if(!dirptr->filename_buf){ return 1; } for(i=0;i<num_images;i++){ dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN; } } if(load_images(dirptr,img_fol.imgdirpath)==1){ return 1; } if (num_images==0){ fprintf(stdout,"Folder is empty\n"); return 1; } }else{ num_images=1; } /*Encoding image one by one*/ for(imageno = 0; imageno < num_images ; imageno++) { image = NULL; fprintf(stderr,"\n"); if(img_fol.set_imgdir==1){ if (get_next_file(imageno, dirptr,&img_fol, ¶meters)) { fprintf(stderr,"skipping file...\n"); continue; } } /* read the input file and put it in memory */ /* ---------------------------------------- */ fsrc = fopen(parameters.infile, "rb"); if (!fsrc) { fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile); return 1; } fseek(fsrc, 0, SEEK_END); file_length = ftell(fsrc); fseek(fsrc, 0, SEEK_SET); src = (unsigned char *) malloc(file_length); if (fread(src, 1, file_length, fsrc) != (size_t)file_length) { free(src); fclose(fsrc); fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n"); return 1; } fclose(fsrc); /* decode the code-stream */ /* ---------------------- */ switch(parameters.decod_format) { case J2K_CFMT: { /* JPEG-2000 codestream */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_J2K); /* catch events using our callbacks and give a local context */ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); /* setup the decoder decoding parameters using user parameters */ opj_setup_decoder(dinfo, ¶meters); /* open a byte stream */ cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ if (*indexfilename) /* If need to extract codestream information*/ image = opj_decode_with_info(dinfo, cio, &cstr_info); else image = opj_decode(dinfo, cio); if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); opj_cio_close(cio); free(src); return 1; } /* close the byte stream */ opj_cio_close(cio); /* Write the index to disk */ if (*indexfilename) { opj_bool bSuccess; bSuccess = write_index_file(&cstr_info, indexfilename); if (bSuccess) { fprintf(stderr, "Failed to output index file\n"); } } } break; case JP2_CFMT: { /* JPEG 2000 compressed image data */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_JP2); /* catch events using our callbacks and give a local context */ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); /* setup the decoder decoding parameters using the current image and user parameters */ opj_setup_decoder(dinfo, ¶meters); /* open a byte stream */ cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ if (*indexfilename) /* If need to extract codestream information*/ image = opj_decode_with_info(dinfo, cio, &cstr_info); else image = opj_decode(dinfo, cio); if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); opj_cio_close(cio); free(src); return 1; } /* close the byte stream */ opj_cio_close(cio); /* Write the index to disk */ if (*indexfilename) { opj_bool bSuccess; bSuccess = write_index_file(&cstr_info, indexfilename); if (bSuccess) { fprintf(stderr, "Failed to output index file\n"); } } } break; case JPT_CFMT: { /* JPEG 2000, JPIP */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_JPT); /* catch events using our callbacks and give a local context */ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); /* setup the decoder decoding parameters using user parameters */ opj_setup_decoder(dinfo, ¶meters); /* open a byte stream */ cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ if (*indexfilename) /* If need to extract codestream information*/ image = opj_decode_with_info(dinfo, cio, &cstr_info); else image = opj_decode(dinfo, cio); if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); opj_cio_close(cio); free(src); return 1; } /* close the byte stream */ opj_cio_close(cio); /* Write the index to disk */ if (*indexfilename) { opj_bool bSuccess; bSuccess = write_index_file(&cstr_info, indexfilename); if (bSuccess) { fprintf(stderr, "Failed to output index file\n"); } } } break; default: fprintf(stderr, "skipping file..\n"); continue; } /* free the memory containing the code-stream */ free(src); src = NULL; if(image->color_space == CLRSPC_SYCC) { color_sycc_to_rgb(image); } if(image->icc_profile_buf) { #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) color_apply_icc_profile(image); #endif free(image->icc_profile_buf); image->icc_profile_buf = NULL; image->icc_profile_len = 0; } /* create output image */ /* ------------------- */ switch (parameters.cod_format) { case PXM_DFMT: /* PNM PGM PPM */ if (imagetopnm(image, parameters.outfile)) { fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; case PGX_DFMT: /* PGX */ if(imagetopgx(image, parameters.outfile)){ fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; case BMP_DFMT: /* BMP */ if(imagetobmp(image, parameters.outfile)){ fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; #ifdef HAVE_LIBTIFF case TIF_DFMT: /* TIFF */ if(imagetotif(image, parameters.outfile)){ fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; #endif /* HAVE_LIBTIFF */ case RAW_DFMT: /* RAW */ if(imagetoraw(image, parameters.outfile)){ fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile); } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; case TGA_DFMT: /* TGA */ if(imagetotga(image, parameters.outfile)){ fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile); } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; #ifdef HAVE_LIBPNG case PNG_DFMT: /* PNG */ if(imagetopng(image, parameters.outfile)){ fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile); } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; #endif /* HAVE_LIBPNG */ /* Can happen if output file is TIFF or PNG * and HAVE_LIBTIF or HAVE_LIBPNG is undefined */ default: fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); } /* free remaining structures */ if(dinfo) { opj_destroy_decompress(dinfo); } /* free codestream information structure */ if (*indexfilename) opj_destroy_cstr_info(&cstr_info); /* free image data structure */ opj_image_destroy(image); } return 0; }
int main(int argc, char *argv[]) { opj_dparameters_t parameters; /* decompression parameters */ img_fol_t img_fol; opj_event_mgr_t event_mgr; /* event manager */ opj_image_t *image = NULL; FILE *fsrc = NULL, *fout = NULL; unsigned char *src = NULL; int file_length; int num_images; int i,imageno; dircnt_t *dirptr = NULL; opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ opj_cio_t *cio = NULL; opj_codestream_info_t cstr_info; /* Codestream information structure */ char indexfilename[OPJ_PATH_LEN]; /* index file name */ /* configure the event callbacks (not required) */ memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); event_mgr.error_handler = error_callback; event_mgr.warning_handler = warning_callback; event_mgr.info_handler = info_callback; /* set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); /* Initialize indexfilename and img_fol */ *indexfilename = 0; memset(&img_fol,0,sizeof(img_fol_t)); /* parse input and get user encoding parameters */ if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) { return 1; } /* Initialize reading of directory */ if(img_fol.set_imgdir==1){ num_images=get_num_images(img_fol.imgdirpath); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); if(dirptr){ dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename = (char**) malloc(num_images*sizeof(char*)); if(!dirptr->filename_buf){ return 1; } for(i=0;i<num_images;i++){ dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN; } } if(load_images(dirptr,img_fol.imgdirpath)==1){ return 1; } if (num_images==0){ fprintf(stdout,"Folder is empty\n"); return 1; } }else{ num_images=1; } /* */ if (parameters.outfile[0] != 0) { fout = fopen(parameters.outfile,"w"); if (!fout) { fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.outfile); return 1; } } else fout = stdout; /*Encoding image one by one*/ for(imageno = 0; imageno < num_images ; imageno++) { image = NULL; fprintf(stderr,"\n"); if(img_fol.set_imgdir==1){ if (get_next_file(imageno, dirptr,&img_fol, ¶meters)) { fprintf(stderr,"skipping file...\n"); continue; } } /* read the input file and put it in memory */ /* ---------------------------------------- */ fsrc = fopen(parameters.infile, "rb"); if (!fsrc) { fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile); return 1; } fseek(fsrc, 0, SEEK_END); file_length = ftell(fsrc); fseek(fsrc, 0, SEEK_SET); src = (unsigned char *) malloc(file_length); if (fread(src, 1, file_length, fsrc) != (size_t)file_length) { free(src); fclose(fsrc); fclose(fout); fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n"); return 1; } fclose(fsrc); /* decode the code-stream */ /* ---------------------- */ switch(parameters.decod_format) { case J2K_CFMT: { /* JPEG-2000 codestream */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_J2K); /* catch events using our callbacks and give a local context */ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); /* setup the decoder decoding parameters using user parameters */ opj_setup_decoder(dinfo, ¶meters); /* open a byte stream */ cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ if (*indexfilename) /* If need to extract codestream information*/ image = opj_decode_with_info(dinfo, cio, &cstr_info); else image = opj_decode(dinfo, cio); if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); opj_cio_close(cio); fclose(fout); free(src); return 1; } /* dump image */ j2k_dump_image(fout, image); /* dump cp */ j2k_dump_cp(fout, image, ((opj_j2k_t*)dinfo->j2k_handle)->cp); /* close the byte stream */ opj_cio_close(cio); /* Write the index to disk */ if (*indexfilename) { opj_bool bSuccess; bSuccess = write_index_file(&cstr_info, indexfilename); if (bSuccess) { fprintf(stderr, "Failed to output index file\n"); } } } break; case JP2_CFMT: { /* JPEG 2000 compressed image data */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_JP2); /* catch events using our callbacks and give a local context */ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); /* setup the decoder decoding parameters using the current image and user parameters */ opj_setup_decoder(dinfo, ¶meters); /* open a byte stream */ cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ if (*indexfilename) /* If need to extract codestream information*/ image = opj_decode_with_info(dinfo, cio, &cstr_info); else image = opj_decode(dinfo, cio); if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); opj_cio_close(cio); fclose(fout); free(src); return 1; } /* dump image */ if(image->icc_profile_buf) { free(image->icc_profile_buf); image->icc_profile_buf = NULL; } j2k_dump_image(fout, image); /* dump cp */ j2k_dump_cp(fout, image, ((opj_jp2_t*)dinfo->jp2_handle)->j2k->cp); /* close the byte stream */ opj_cio_close(cio); /* Write the index to disk */ if (*indexfilename) { opj_bool bSuccess; bSuccess = write_index_file(&cstr_info, indexfilename); if (bSuccess) { fprintf(stderr, "Failed to output index file\n"); } } } break; case JPT_CFMT: { /* JPEG 2000, JPIP */ /* get a decoder handle */ dinfo = opj_create_decompress(CODEC_JPT); /* catch events using our callbacks and give a local context */ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); /* setup the decoder decoding parameters using user parameters */ opj_setup_decoder(dinfo, ¶meters); /* open a byte stream */ cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); /* decode the stream and fill the image structure */ if (*indexfilename) /* If need to extract codestream information*/ image = opj_decode_with_info(dinfo, cio, &cstr_info); else image = opj_decode(dinfo, cio); if(!image) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_decompress(dinfo); opj_cio_close(cio); fclose(fout); free(src); return 1; } /* close the byte stream */ opj_cio_close(cio); /* Write the index to disk */ if (*indexfilename) { opj_bool bSuccess; bSuccess = write_index_file(&cstr_info, indexfilename); if (bSuccess) { fprintf(stderr, "Failed to output index file\n"); } } } break; default: fprintf(stderr, "skipping file..\n"); continue; } /* free the memory containing the code-stream */ free(src); src = NULL; /* free remaining structures */ if(dinfo) { opj_destroy_decompress(dinfo); } /* free codestream information structure */ if (*indexfilename) opj_destroy_cstr_info(&cstr_info); /* free image data structure */ opj_image_destroy(image); } fclose(fout); return EXIT_SUCCESS; }
void button::set_overlay(const std::string& image_file) { button_overlay_image_name_ = image_file; load_images(); set_dirty(); }
int main ( int argc, char** argv ) { /// initialisation son & image /// initialisation FMOD FMOD_SYSTEM * system; FMOD_System_Create(&system); /// initialisation image & son initialisation(system); /// verification de la date struct tm Today; time_t maintenant; time(&maintenant); Today = *localtime(&maintenant); Today.tm_year += 1900; Today.tm_mon += 1; Today.tm_mday; /// username DWORD StrLen = 256; TCHAR SysInfoStr[256]; GetComputerName(SysInfoStr, &StrLen); std::string nameComputeur = SysInfoStr; GetUserName(SysInfoStr, &StrLen); std::string nameUser = SysInfoStr; /// déclaration et chargements des ressources /// create a new window putenv("SDL_VIDEO_WINDOW_POS=center"); /// pour centrer la fenêtre SDL_Surface* screen = SDL_SetVideoMode(LARGEUR_ECRAN, HAUTEUR_ECRAN, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE|SDL_FULLSCREEN); if ( !screen ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); return 1; } /// images SDL_Surface** images = NULL; images = (SDL_Surface **) malloc (sizeof(SDL_Surface*)*NOMBRE_IMAGE); load_images(images); /// sons FMOD_SOUND ** musiques = NULL; musiques = (FMOD_SOUND **) malloc (sizeof(FMOD_SOUND*)*NOMBRE_MUSIQUE); load_musiques(system, musiques); /// polices TTF_Font ** polices = NULL; polices = (TTF_Font **) malloc(sizeof(TTF_Font*) * NOMBRE_POLICE); load_polices(polices); /// Icone SDL_WM_SetIcon(images[0], NULL); /// titre SDL_WM_SetCaption("Julie", NULL); /// program main loop Input * in = new Input; int tempsPrecedent = 0, tempsActuel = 0; int ghost = 255; bool devient_ghost = true; int * menu = new int; *menu = -1; SDL_Rect place = {LARGEUR_ECRAN/2 - images[0]->w/2,HAUTEUR_ECRAN/2 - images[0]->h/2,0,0}; /// musiques FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, musiques[0], 0, NULL); /// affichage du logo int i = 0; while(i<256) { SDL_FillRect(SDL_GetVideoSurface(), 0, SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 0)); place = {LARGEUR_ECRAN/2 - images[0]->w/2,HAUTEUR_ECRAN/2 - images[0]->h/2,0,0}; SDL_SetAlpha(images[0], SDL_SRCALPHA, i); SDL_BlitSurface(images[0], NULL, SDL_GetVideoSurface(), &place); i++; SDL_Flip(SDL_GetVideoSurface()); } while(i>=0) { SDL_FillRect(SDL_GetVideoSurface(), 0, SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 0)); place = {LARGEUR_ECRAN/2 - images[0]->w/2,HAUTEUR_ECRAN/2 - images[0]->h/2,0,0}; SDL_SetAlpha(images[0], SDL_SRCALPHA, i); SDL_BlitSurface(images[0], NULL, SDL_GetVideoSurface(), &place); i--; SDL_Flip(SDL_GetVideoSurface()); } place = {LARGEUR_ECRAN/2 - images[1]->w/2,HAUTEUR_ECRAN/2 - images[1]->h/2,0,0}; while(!in->get_touche(SDLK_ESCAPE) && !in->get_exit()) /// boucle principale { /// mise à jour des events in->update(); /// gestion du frame fps(&tempsPrecedent, &tempsActuel, SCREEN_REFRESH); /// resize taille écran resize_screen(*in); if(*menu == 1 || in->get_touche(SDLK_1) || in->get_touche(SDLK_KP1)) /// jouer { in->set_touche(SDLK_1, 0); in->set_touche(SDLK_KP1, 0); Jeu * party = new Jeu(images); party->game(); delete party; in->set_touche(SDLK_ESCAPE, 0); } if(*menu == 2 || in->get_touche(SDLK_2) || in->get_touche(SDLK_KP2)) /// jouer { in->set_touche(SDLK_2, 0); in->set_touche(SDLK_KP2, 0); Jeu * party = new Jeu(images); party->conjugaison(); delete party; in->set_touche(SDLK_ESCAPE, 0); } if(*menu == -9) /// quitter le jeu { in->set_exit(1); } if(*menu == -1) { SDL_FillRect(SDL_GetVideoSurface(), 0, SDL_MapRGB(SDL_GetVideoSurface()->format, 0, 0, 0)); place = {LARGEUR_ECRAN/2 - images[1]->w/2,HAUTEUR_ECRAN/2 - images[1]->h/2,0,0}; SDL_BlitSurface(images[1], NULL, SDL_GetVideoSurface(), &place); /* if(devient_ghost) { ghost -= 8; } else { ghost += 8; } if(ghost >= 255 || ghost <= 88) { devient_ghost = !devient_ghost; } place = {LARGEUR_ECRAN/2 - images[2]->w/2,3*HAUTEUR_ECRAN/4 - images[2]->h/2,0,0}; SDL_SetAlpha(images[2], SDL_SRCALPHA, ghost); SDL_BlitSurface(images[2], NULL, SDL_GetVideoSurface(), &place); */ Texte menu1; Texte menu2; menu1.print("1 - Mathématiques", "arial", 60, {255,255,255}, SDL_GetVideoSurface()->w/3, 3*SDL_GetVideoSurface()->h/4); menu2.print("2 - Conjugaison", "arial", 60, {255,255,255}, SDL_GetVideoSurface()->w/3, 3*SDL_GetVideoSurface()->h/4+100); } SDL_Flip(screen); }/// end main loop /// nettoyage /// free pointeurs delete menu; delete in; /// free loaded bitmap and created surface SDL_FreeSurface(screen); free_images(images); free_polices(polices); /// libération des sons free_musiques(musiques); /// fermeture propre de ce qui est ouvert dans initialisation() fermeture(system); /// all is well ;) printf("Exited cleanly\n"); return 0; }
int main (int argc, char **argv) { DFBSurfaceDescription dsc; DFBSurfaceDescription back_dsc; DFBRectangle rect; IDirectFBImageProvider *provider; IDirectFBEventBuffer *keybuffer; DFBInputEvent evt; int width; int height; int quit; unsigned int cycle_len; struct timeval tv; long start_time; long current_time; long frame_delay; long delay; frame_delay = delay = FRAME_DELAY; cycle_len = CYCLE_LEN; quit = FALSE; DFBCHECK (DirectFBInit (&argc, &argv)); if (argc > 1 && argv[1] && strcmp (argv[1], "--on-crack") == 0) on_crack = TRUE; /* create the super interface */ DFBCHECK (DirectFBCreate (&dfb)); dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN); DFBCHECK (dfb->CreateInputEventBuffer (dfb, DICAPS_KEYS, DFB_FALSE, &keybuffer)); /* create the primary surface */ dsc.flags = DSDESC_CAPS; dsc.caps = DSCAPS_PRIMARY; if (!on_crack) { dsc.caps |= DSCAPS_TRIPLE; if (dfb->CreateSurface (dfb, &dsc, &primary) != DFB_OK) { dsc.caps = (dsc.caps & ~DSCAPS_TRIPLE) | DSCAPS_DOUBLE; DFBCHECK (dfb->CreateSurface (dfb, &dsc, &primary)); } } else DFBCHECK (dfb->CreateSurface (dfb, &dsc, &primary)); /* load size of background image */ DFBCHECK (dfb->CreateImageProvider (dfb, BACKGROUND_NAME, &provider)); DFBCHECK (provider->GetSurfaceDescription (provider, &back_dsc)); back_width = back_dsc.width; back_height = back_dsc.height; if (!back_width || !back_height) return -1; /* create the background surface */ DFBCHECK (dfb->CreateSurface (dfb, &back_dsc, &background)); provider->RenderTo (provider, background, NULL); provider->Release (provider); /* create subsurface in the middle of the screen */ primary->GetSize (primary, &width, &height); rect.x = (width - back_width) / 2; rect.y = (height - back_height) / 2; rect.w = back_width; rect.h = back_height; primary->GetSubSurface (primary, &rect, &sub); if (on_crack) { /* clear screen */ primary->Clear (primary, 0, 0, 0, 0xff); } else { /* fill screen and backbuffers with tiled background */ primary->TileBlit (primary, background, NULL, rect.x, rect.y); primary->Flip (primary, NULL, 0) ; primary->TileBlit (primary, background, NULL, rect.x, rect.y); primary->Flip (primary, NULL, 0) ; primary->TileBlit (primary, background, NULL, rect.x, rect.y); primary->SetClip (primary, NULL); } /* load the remaining images */ load_images (); frame_num = 0; while (!quit) { gettimeofday (&tv, NULL); start_time = tv.tv_sec * 1000 + tv.tv_usec / 1000; timeout (cycle_len); while (keybuffer->GetEvent (keybuffer, DFB_EVENT(&evt)) == DFB_OK) { if (evt.type == DIET_KEYPRESS) { switch (evt.key_id) { case DIKI_LEFT: frame_delay = MIN (500, frame_delay + 5); break; case DIKI_RIGHT: frame_delay = MAX (0, frame_delay - 5); break; case DIKI_UP: cycle_len = MIN (600, cycle_len + 6); break; case DIKI_DOWN: cycle_len = cycle_len > 6 ? cycle_len - 6 : 6; break; case DIKI_SPACE: case DIKI_ENTER: colorize = !colorize; break; case DIKI_A: alpha = !alpha; break; case DIKI_HOME: cycle_len = CYCLE_LEN; frame_delay = FRAME_DELAY; colorize = TRUE; alpha = TRUE; break; case DIKI_ESCAPE: case DIKI_Q: quit = TRUE; break; default: break; } switch (evt.key_symbol) { case DIKS_OK: colorize = !colorize; break; case DIKS_BACK: case DIKS_STOP: quit = TRUE; break; default: break; } } } if (frame_delay) { gettimeofday (&tv, NULL); current_time = tv.tv_sec * 1000 + tv.tv_usec / 1000; delay = frame_delay - (current_time - start_time); if (delay > 0) usleep (1000 * delay); } } keybuffer->Release (keybuffer); release_images (); background->Release (background); sub->Release (sub); primary->Release (primary); dfb->Release (dfb); return 0; }
/* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { opj_decompress_parameters parameters; /* decompression parameters */ opj_image_t* image = NULL; opj_stream_t *l_stream = NULL; /* Stream */ opj_codec_t* l_codec = NULL; /* Handle to a decompressor */ opj_codestream_index_t* cstr_index = NULL; char indexfilename[OPJ_PATH_LEN]; /* index file name */ OPJ_INT32 num_images, imageno; img_fol_t img_fol; dircnt_t *dirptr = NULL; int failed = 0; OPJ_FLOAT64 t, tCumulative = 0; OPJ_UINT32 numDecompressedImages = 0; /* set decoding parameters to default values */ set_default_parameters(¶meters); /* FIXME Initialize indexfilename and img_fol */ *indexfilename = 0; /* Initialize img_fol */ memset(&img_fol,0,sizeof(img_fol_t)); /* parse input and get user encoding parameters */ if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) { destroy_parameters(¶meters); return EXIT_FAILURE; } /* Initialize reading of directory */ if(img_fol.set_imgdir==1){ int it_image; num_images=get_num_images(img_fol.imgdirpath); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); if(dirptr){ dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); if(!dirptr->filename_buf){ destroy_parameters(¶meters); return EXIT_FAILURE; } for(it_image=0;it_image<num_images;it_image++){ dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; } } if(load_images(dirptr,img_fol.imgdirpath)==1){ destroy_parameters(¶meters); return EXIT_FAILURE; } if (num_images==0){ fprintf(stdout,"Folder is empty\n"); destroy_parameters(¶meters); return EXIT_FAILURE; } }else{ num_images=1; } /*Decoding image one by one*/ for(imageno = 0; imageno < num_images ; imageno++) { fprintf(stderr,"\n"); if(img_fol.set_imgdir==1){ if (get_next_file(imageno, dirptr,&img_fol, ¶meters)) { fprintf(stderr,"skipping file...\n"); destroy_parameters(¶meters); continue; } } /* read the input file and put it in memory */ /* ---------------------------------------- */ l_stream = opj_stream_create_default_file_stream(parameters.infile,1); if (!l_stream){ fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile); destroy_parameters(¶meters); return EXIT_FAILURE; } /* decode the JPEG2000 stream */ /* ---------------------- */ switch(parameters.decod_format) { case J2K_CFMT: /* JPEG-2000 codestream */ { /* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_J2K); break; } case JP2_CFMT: /* JPEG 2000 compressed image data */ { /* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_JP2); break; } case JPT_CFMT: /* JPEG 2000, JPIP */ { /* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_JPT); break; } default: fprintf(stderr, "skipping file..\n"); destroy_parameters(¶meters); opj_stream_destroy(l_stream); continue; } /* catch events using our callbacks and give a local context */ opj_set_info_handler(l_codec, info_callback,00); opj_set_warning_handler(l_codec, warning_callback,00); opj_set_error_handler(l_codec, error_callback,00); t = opj_clock(); /* Setup the decoder decoding parameters using user parameters */ if ( !opj_setup_decoder(l_codec, &(parameters.core)) ){ fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n"); destroy_parameters(¶meters); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); return EXIT_FAILURE; } /* Read the main header of the codestream and if necessary the JP2 boxes*/ if(! opj_read_header(l_stream, l_codec, &image)){ fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n"); destroy_parameters(¶meters); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(image); return EXIT_FAILURE; } if (!parameters.nb_tile_to_decode) { /* Optional if you want decode the entire image */ if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0, (OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, (OPJ_INT32)parameters.DA_y1)){ fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n"); destroy_parameters(¶meters); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(image); return EXIT_FAILURE; } /* Get the decoded image */ if (!(opj_decode(l_codec, l_stream, image) && opj_end_decompress(l_codec, l_stream))) { fprintf(stderr,"ERROR -> opj_decompress: failed to decode image!\n"); destroy_parameters(¶meters); opj_destroy_codec(l_codec); opj_stream_destroy(l_stream); opj_image_destroy(image); return EXIT_FAILURE; } } else { /* It is just here to illustrate how to use the resolution after set parameters */ /*if (!opj_set_decoded_resolution_factor(l_codec, 5)) { fprintf(stderr, "ERROR -> opj_decompress: failed to set the resolution factor tile!\n"); opj_destroy_codec(l_codec); opj_stream_destroy(l_stream); opj_image_destroy(image); return EXIT_FAILURE; }*/ if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) { fprintf(stderr, "ERROR -> opj_decompress: failed to decode tile!\n"); destroy_parameters(¶meters); opj_destroy_codec(l_codec); opj_stream_destroy(l_stream); opj_image_destroy(image); return EXIT_FAILURE; } fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index); } tCumulative += opj_clock() - t; numDecompressedImages++; /* Close the byte stream */ opj_stream_destroy(l_stream); if( image->color_space != OPJ_CLRSPC_SYCC && image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy && image->comps[1].dx != 1 ) image->color_space = OPJ_CLRSPC_SYCC; else if (image->numcomps <= 2) image->color_space = OPJ_CLRSPC_GRAY; if(image->color_space == OPJ_CLRSPC_SYCC){ color_sycc_to_rgb(image); } else if((image->color_space == OPJ_CLRSPC_CMYK) && (parameters.cod_format != TIF_DFMT)){ color_cmyk_to_rgb(image); } else if(image->color_space == OPJ_CLRSPC_EYCC){ color_esycc_to_rgb(image); } if(image->icc_profile_buf) { #if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) if(image->icc_profile_len) color_apply_icc_profile(image); else color_cielab_to_rgb(image); #endif free(image->icc_profile_buf); image->icc_profile_buf = NULL; image->icc_profile_len = 0; } /* Force output precision */ /* ---------------------- */ if (parameters.precision != NULL) { OPJ_UINT32 compno; for (compno = 0; compno < image->numcomps; ++compno) { OPJ_UINT32 precno = compno; OPJ_UINT32 prec; if (precno >= parameters.nb_precision) { precno = parameters.nb_precision - 1U; } prec = parameters.precision[precno].prec; if (prec == 0) { prec = image->comps[compno].prec; } switch (parameters.precision[precno].mode) { case OPJ_PREC_MODE_CLIP: clip_component(&(image->comps[compno]), prec); break; case OPJ_PREC_MODE_SCALE: scale_component(&(image->comps[compno]), prec); break; default: break; } } } /* Upsample components */ /* ------------------- */ if (parameters.upsample) { image = upsample_image_components(image); if (image == NULL) { fprintf(stderr, "ERROR -> opj_decompress: failed to upsample image components!\n"); destroy_parameters(¶meters); opj_destroy_codec(l_codec); return EXIT_FAILURE; } } /* Force RGB output */ /* ---------------- */ if (parameters.force_rgb) { switch (image->color_space) { case OPJ_CLRSPC_SRGB: break; case OPJ_CLRSPC_GRAY: image = convert_gray_to_rgb(image); break; default: fprintf(stderr, "ERROR -> opj_decompress: don't know how to convert image to RGB colorspace!\n"); opj_image_destroy(image); image = NULL; break; } if (image == NULL) { fprintf(stderr, "ERROR -> opj_decompress: failed to convert to RGB image!\n"); destroy_parameters(¶meters); opj_destroy_codec(l_codec); return EXIT_FAILURE; } } /* create output image */ /* ------------------- */ switch (parameters.cod_format) { case PXM_DFMT: /* PNM PGM PPM */ if (imagetopnm(image, parameters.outfile, parameters.split_pnm)) { fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); } break; case PGX_DFMT: /* PGX */ if(imagetopgx(image, parameters.outfile)){ fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); } break; case BMP_DFMT: /* BMP */ if(imagetobmp(image, parameters.outfile)){ fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); } break; #ifdef OPJ_HAVE_LIBTIFF case TIF_DFMT: /* TIFF */ if(imagetotif(image, parameters.outfile)){ fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); } break; #endif /* OPJ_HAVE_LIBTIFF */ case RAW_DFMT: /* RAW */ if(imagetoraw(image, parameters.outfile)){ fprintf(stderr,"[ERROR] Error generating raw file. Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); } break; case RAWL_DFMT: /* RAWL */ if(imagetorawl(image, parameters.outfile)){ fprintf(stderr,"[ERROR] Error generating rawl file. Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); } break; case TGA_DFMT: /* TGA */ if(imagetotga(image, parameters.outfile)){ fprintf(stderr,"[ERROR] Error generating tga file. Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); } break; #ifdef OPJ_HAVE_LIBPNG case PNG_DFMT: /* PNG */ if(imagetopng(image, parameters.outfile)){ fprintf(stderr,"[ERROR] Error generating png file. Outfile %s not generated\n",parameters.outfile); failed = 1; } else { fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); } break; #endif /* OPJ_HAVE_LIBPNG */ /* Can happen if output file is TIFF or PNG * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined */ default: fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); failed = 1; } /* free remaining structures */ if (l_codec) { opj_destroy_codec(l_codec); } /* free image data structure */ opj_image_destroy(image); /* destroy the codestream index */ opj_destroy_cstr_index(&cstr_index); if(failed) remove(parameters.outfile); } destroy_parameters(¶meters); if (numDecompressedImages) { fprintf(stdout, "decode time: %d ms\n", (int)( (tCumulative * 1000.0) / (OPJ_FLOAT64)numDecompressedImages)); } return failed ? EXIT_FAILURE : EXIT_SUCCESS; }