int main(int argc, char* argv[]) { //初始化NGE分为VIDEO,AUDIO,这里是只初始化VIDEO,如果初始化所有用INIT_VIDEO|INIT_AUDIO,或者INIT_ALL NGE_Init(INIT_VIDEO); //初始化按键处理btn_down是按下响应,后面是弹起时的响应,0是让nge处理home消息(直接退出),填1就是让PSP系统处理 //home消息,通常填1正常退出(1.50版的自制程序需要填0) InitInput(btn_down,NULL,1); //最后一个参数是psp swizzle优化,通常填1 p_bg = image_load("images/demo0.jpg",DISPLAY_PIXEL_FORMAT_8888,1); if(p_bg == NULL) { printf("can not open file\n"); } p_logo = image_load("images/nge2logo.png",DISPLAY_PIXEL_FORMAT_4444,1); if(p_logo == NULL) { printf("can not open file\n"); } //创建一个半透明的图片遮罩color logomask1 = CreateColor(255,255,255,128,p_logo->dtype); //随便创建一个图片遮罩color logomask2 = CreateColor(100,100,100,255,p_logo->dtype); while ( !game_quit ) { ShowFps(); InputProc(); DrawScene(); } image_free(p_bg); image_free(p_logo); NGE_Quit(); return 0; }
int main(int argc, char* argv[]) { PFont pf[2] ; int i; NGE_Init(INIT_VIDEO); //NGE_SetFontEncoding(NGE_ENCODING_UTF_8); InitInput(btn_down,btn_up,1); int maxid = GetInfoCount(); //创建一个显示image,字就显示在这个上面注意DISPLAY_PIXEL_FORMAT必须与创建字体的DISPLAY_PIXEL_FORMAT一致 pimage_text = image_create(512,512,DISPLAY_PIXEL_FORMAT_4444); //创建字体 pf[0] = create_font_hzk("fonts/GBK14","fonts/ASC14",14,DISPLAY_PIXEL_FORMAT_4444); pf[1] = create_font_freetype("fonts/simfang.ttf",13,DISPLAY_PIXEL_FORMAT_4444); char str[3][128]={"【小萝莉】","众芳摇落独暄妍,占尽风情向小园。","疏影横斜水清浅,暗香浮动月黄昏。"}; //显示GBK Font font_setcolor(pf[0],MAKE_RGBA_4444(128,0,0,255)); font_drawtext(pf[0],str[0],strlen(str[0]),pimage_text,100,195,FONT_SHOW_NORMAL); NGE_SetFontEncoding(NGE_ENCODING_GBK); for(i = 0;i<maxid;i++){ font_drawtext(pf[0],CreateInfoByid(i),strlen(CreateInfoByid(i)),pimage_text,120,200+i*20,FONT_SHOW_SHADOW); font_setcolor(pf[0],MAKE_RGBA_4444(255,0,0,255)); } //显示freetype font_setcolor(pf[1],MAKE_RGBA_4444(128,0,0,255)); NGE_SetFontEncoding(NGE_ENCODING_UTF_8); font_drawtext(pf[1],str[0],strlen(str[0]),pimage_text,100,30,FONT_SHOW_NORMAL); //for(i =1;i<3;i++){ // font_drawtext(pf[1],str[i],strlen(str[i]),pimage_text,120,35+i*20,FONT_SHOW_NORMAL); // font_setcolor(pf[1],MAKE_RGBA_4444(255,0,0,255)); //} pimage_bg = image_load("images/demo1_bg.jpg",DISPLAY_PIXEL_FORMAT_8888,1); if(pimage_bg == NULL) { printf("can not open file\n"); } pimage_box = image_load("images/demo1_box.jpg",DISPLAY_PIXEL_FORMAT_8888,1); if(pimage_box == NULL) { printf("can not open file\n"); } pimage_icon[0] = image_load_colorkey("images/demo1_icon0.bmp",DISPLAY_PIXEL_FORMAT_8888,MAKE_RGB(0,0,0),1); pimage_icon[1] = image_load_colorkey("images/demo1_icon1.png",DISPLAY_PIXEL_FORMAT_8888,MAKE_RGB(0,0,0),1); while ( !game_quit ) { ShowFps(); InputProc(); DrawScene(); } font_destory(pf[0]); font_destory(pf[1]); image_free(pimage_bg); image_free(pimage_text); image_free(pimage_box); NGE_Quit(); return 0; }
/* * load_sprite_images() * Loads the sprite by reading the spritesheet */ void load_sprite_images(spriteinfo_t *spr) { int i, cur_x, cur_y; image_t *sheet; spr->frame_count = (spr->rect_w / spr->frame_w) * (spr->rect_h / spr->frame_h); spr->frame_data = mallocx(spr->frame_count * sizeof(*(spr->frame_data))); /* reading the images... */ if(NULL == (sheet = image_load(spr->source_file))) fatal_error("FATAL ERROR: couldn't load spritesheet \"%s\"", spr->source_file); cur_x = spr->rect_x; cur_y = spr->rect_y; for(i=0; i<spr->frame_count; i++) { spr->frame_data[i] = image_create_shared(sheet, cur_x, cur_y, spr->frame_w, spr->frame_h); cur_x += spr->frame_w; if(cur_x >= spr->rect_x+spr->rect_w) { cur_x = spr->rect_x; cur_y += spr->frame_h; } } image_unref(spr->source_file); }
/** * Load images of the gems and allocate gems structures * @return TRUE if it completed successfully or FALSE otherwise */ bool bonus_once_init (void) { bonus_free (); /* extract gems sprites images (80,868 bytes) */ if (!image_load ("graphics/sprites/bonus_gems.spr", &bonus[0][0], GEM_NUMOF_TYPES, GEM_NUMOF_IMAGES)) { return FALSE; } /* allocate gems data structure */ if (gems == NULL) { gems = (gem_str *) memory_allocation (MAX_NUMOF_GEMS_ON_SCREEN * sizeof (gem_str)); if (gems == NULL) { LOG_ERR ("not enough memory to allocate 'gems' structure"); return FALSE; } } return 1; }
void TestBlockArrayDCT(CuTest* tc) { struct Image* imagep = image_load("testdata/tiny.ppm"); struct BlockArray array; const int32_t quality = 75; image_to_ycbcr(imagep); image_to_blockarray(imagep, &array); compress_blockarray_dct(&array, quality); compress_blockarray_dct_inverse(&array, quality); struct Image* result = blockarray_to_image(&array); image_to_rgb(result); CuAssertTrue(tc, result != NULL); //image_save("temp/dctpic.ppm", result); double error = stat_image_mean_absolute_error(imagep, result); // With pure noise the error is around 70 CuAssertTrue(tc, error < 50.0); // Equality checks are not useful for us, since the compression // can introduce single pixel artifacts even though rest of // the picture matches quite well. //check_images_equal(tc, imagep, result, 10); image_del(result); blockarray_free(&array); image_del(imagep); }
void action_compress_image(void) { struct Image* imagep = image_load(input_path); printf("Picture dimensions: %dx%d\n", imagep->width, imagep->height); uint64_t length = 0; uint64_t result = 0; uint8_t* data = compress_image_full(imagep, quality, (uint64_t*) &length); printf("Saving %lu bytes to %s...", (long unsigned int) length, output_path); result = write_file(output_path, data, length); if (result == length) { printf("OK!\n"); } else { printf("ERROR: Only wrote %lu bytes!\n", result); } if (length > 0) free(data); image_del(imagep); }
game_status state_game_over(SDL_Surface *screen, game* p_game) { bool done=false; image* game_over; game_over = image_load("./res/images/game_over.png"); SDL_Rect srcrect = {0,0,160,144}; SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH); while (!done) { //events SDL_Event event; while (SDL_PollEvent(&event)) { switch ( event.type ) { case SDL_QUIT: done = true; break; case SDL_KEYUP: switch ( event.key.keysym.sym ) { default:break; } default:break; } } image_draw(game_over, get_backbuffer_surface(), 0, 0); SDL_SoftStretch(get_backbuffer_surface(), &srcrect, screen, &dstrect); SDL_Flip(screen); } return MAIN_MENU; }
static void handle_image_load(int wfd, void *params) { Slave_Msg_Image_Load *load_args = params; Slave_Msg_Image_Loaded resp; Error_Type err; const char *shmfile; const char *file, *key, *loader; if (!load_args->has_loader_data) { error_send(wfd, CSERVE2_UNKNOWN_FORMAT); return; } memset(&resp, 0, sizeof(resp)); shmfile = ((const char *)params) + sizeof(Slave_Msg_Image_Load); file = shmfile + strlen(shmfile) + 1; key = file + strlen(file) + 1; loader = key + strlen(key) + 1; if ((err = image_load(file, key, shmfile, load_args, &resp, loader)) != CSERVE2_NONE) { error_send(wfd, err); return; } response_send(wfd, IMAGE_LOAD, &resp, sizeof(resp)); }
void image_loadFile(img_t *img,WCHAR *filename) { WCHAR buf[BUFLEN]; FILE *f; int sz; BYTE *imgbuf; if(!filename||!*filename)return; wsprintf(buf,L"%s\\themes\\%s",data_dir,filename); //printf("Loading '%ws'\n",buf); f=_wfopen(buf,L"rb"); if(!f) { log_err("ERROR in image_loadFile(): file '%ws' not found\n",buf); return; } fseek(f,0,SEEK_END); sz=ftell(f); fseek(f,0,SEEK_SET); imgbuf=malloc(sz); sz=fread(imgbuf,1,sz,f); if(!sz) { log_err("ERROR in image_loadFile(): cannnot read from file '%ws'\n",buf); return; } fclose(f); image_load(img,imgbuf,sz); free(imgbuf); }
int main(int argc, char* argv[]) { //初始化NGE分为VIDEO,AUDIO,这里是只初始化VIDEO,如果初始化所有用INIT_VIDEO|INIT_AUDIO,或者INIT_ALL NGE_Init(INIT_VIDEO); //初始化按键处理btn_down是按下响应,后面是弹起时的响应,0是让nge处理home消息(直接退出),填1就是让PSP系统处理 //home消息,通常填1正常退出(1.50版的自制程序需要填0) InitInput(btn_down,NULL,1); //最后一个参数是psp swizzle优化,通常填1 p_logo = image_load("images/nge2logo.png",DISPLAY_PIXEL_FORMAT_8888,1); if(p_logo == NULL) printf("can not open file\n"); p_par = image_load("par/particles.png",DISPLAY_PIXEL_FORMAT_8888,1); if(p_par == NULL) printf("can not open file\n"); //设置sprite子图 mParticle = (sprite_p)malloc(sizeof(sprite_t)); memset(mParticle,0,sizeof(sprite_t)); mParticle->sprite_image = p_par; mParticle->sprite_clip.left= 0.0f; mParticle->sprite_clip.top= 0.0f; mParticle->sprite_clip.right= 32.0f; mParticle->sprite_clip.bottom = 32.0f; mParticle->sprite_center.x = 16.0f; mParticle->sprite_center.y = 16.0f; mParticleSys = new hgeParticleSystem("par/particle1.psi", mParticle); mParticleSys->MoveTo(480.0f/2, 272.0f/2,0); mParticleSys->Fire(); timer = timer_create(); timer->start(timer); while ( !game_quit ) { ShowFps(); InputProc(); Update(); DrawScene(); LimitFps(60); } image_free(p_logo); image_free(p_par); SAFE_FREE(mParticle); delete mParticleSys; NGE_Quit(); return 0; }
void ui_run(void) { img_bg = image_load("images/tittel.tga"); img_soldier = image_load("images/soldat.tga"); img_tank = image_load("images/tanks.tga"); img_grass = image_load("images/gress.tga"); img_dirt = image_load("images/brent.tga"); img_soldier_win = image_load("images/gameover-soldier.tga"); img_tank_win = image_load("images/gameover-tank.tga"); while (1) { switch (ui_state) { case UI_GAME_SOLDIER: case UI_GAME_DIRECTION: case UI_GAME_STRENGTH: ui_state_game(); break; case UI_SCOREBOARD: ui_state_scoreboard(); break; default: case UI_TITLE: ui_state_title(); break; } } }
int main(int argc, char **argv) { int i, num_failed = 0; char delta, delta_b, delta_g, delta_r; double perc_failed; if (argc != 3) { fprintf(stderr, "Usage: %s <reference image> <target image>\n", argv[0]); return 1; } struct Image *ref_img = image_load(argv[1]); struct Image *tst_img = image_load(argv[2]); if (ref_img->width != tst_img->width) { fprintf(stderr, "Images have different width: %ld vs %ld\n", ref_img->width, tst_img->width); return 1; } if (ref_img->height != tst_img->height) { fprintf(stderr, "Images have different height: %ld vs %ld\n", ref_img->height, tst_img->height); return 1; } for (i = 0; i < ref_img->array_size; i += 3) { delta_r = ref_img->array[i] - tst_img->array[i]; delta_g = ref_img->array[i+1] - tst_img->array[i+1]; delta_b = ref_img->array[i+2] - tst_img->array[i+2]; delta = delta_r + delta_g + delta_b; if (delta < 0) delta = -delta; if (delta > 3) num_failed++; } perc_failed = ((float) num_failed / (ref_img->width * ref_img->height)) * 100; fprintf(stdout, "Number of incorrect pixels: %d\n", num_failed); fprintf(stdout, "Percentage of incorrect pixels: %lf%%\n", perc_failed); if (perc_failed > 5) { fprintf(stdout, "You have FAILED the test!\n"); return 1; } else { fprintf(stdout, "You have PASSED the test!\n"); return 0; } return 0; }
void TestImageCompression(CuTest* tc) { struct Image* imagep = image_load("testdata/small.ppm"); uint8_t* data = NULL; uint64_t length = 0; data = compress_image_full(imagep, 85, &length); CuAssertTrue(tc, data != NULL); CuAssertTrue(tc, length > 0); image_del(imagep); }
int trap_LoadImage(lua_State *s) { IMAGE *image; const char *imgfile; trap_args(s, "LoadImage", "s", &imgfile); image = image_load(imgfile); lua_pushlightuserdata(s, image); return 1; }
int main(int argc, char** argv, char** envp) { FILE* elf = fopen(argv[1], "rb"); fseek(elf, 0, SEEK_END); size_t size = ftell(elf); rewind(elf); char* buffer = (char*) malloc (sizeof(char) * size); size_t s = fread(buffer, 1, size, elf); return ((int (*)(int, char**, char**)) image_load(buffer, size))(argc,argv,envp); }
void image_loadRes(img_t *img,int id) { int sz; HGLOBAL myResourceData; get_resource(id,&myResourceData,&sz); if(!sz) { log_err("ERROR in image_loadRes(): failed get_resource\n"); return; } image_load(img,myResourceData,sz); }
game_status state_main_menu(SDL_Surface *screen, game* p_game) { bool done=false; image* main_title; main_title = image_load("./res/images/main_title.png"); SDL_Rect srcrect = {0,0,160,144}; SDL_Rect dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH); int next_state=STAY; while (!done) { //events SDL_Event event; while (SDL_PollEvent(&event)) { switch ( event.type ) { case SDL_QUIT: done = true; break; default: break; } } image_draw(main_title, get_backbuffer_surface(), 0, 0); SDL_SoftStretch(get_backbuffer_surface(), &srcrect, screen, &dstrect); SDL_Flip(screen); if(next_state == STAY)next_state = menu_main(screen, p_game); else if(next_state!=QUIT){ switch(next_state){ case LOAD: menu_load(screen, &p_game); next_state = state_in_game(screen, p_game); break; case 1: p_game = game_load("./res/scripts/state.xml"); next_state = state_in_game(screen, p_game); break; default: break; } } else if(next_state==QUIT)done=true; } image_free(main_title); return QUIT; }
static int decode(image& ctx, const std::vector<std::string>& inp_filenames, const std::string& fec_filename, std::string& out_filename) { const std::string& inp_filename = inp_filenames.front(); if (ctx.inplace && ctx.sparse) { FATAL("invalid parameters: inplace cannot be used with sparse " "files\n"); } if (!image_ecc_load(fec_filename, &ctx) || !image_load(inp_filenames, &ctx, !out_filename.empty())) { FATAL("failed to read input\n"); } if (ctx.inplace) { INFO("correcting '%s' using RS(255, %d) from '%s'\n", inp_filename.c_str(), ctx.rs_n, fec_filename.c_str()); out_filename = inp_filename; } else { INFO("decoding '%s' to '%s' using RS(255, %d) from '%s'\n", inp_filename.c_str(), out_filename.empty() ? out_filename.c_str() : "<none>", ctx.rs_n, fec_filename.c_str()); } if (ctx.verbose) { INFO("\traw fec size: %u\n", ctx.fec_size); INFO("\tblocks: %" PRIu64 "\n", ctx.blocks); INFO("\trounds: %" PRIu64 "\n", ctx.rounds); } if (!image_process(decode_rs, &ctx)) { FATAL("failed to process input\n"); } if (ctx.rv) { INFO("corrected %" PRIu64 " errors\n", ctx.rv); } else { INFO("no errors found\n"); } if (!out_filename.empty() && !image_save(out_filename, &ctx)) { FATAL("failed to write output\n"); } image_free(&ctx); return 0; }
void level_load(const char *path) { struct level *level; char *bg_path,*mask_path,*settings_path; FILE *settings; if (current_level) level_unload(); obj_type_clear_counts(); level = xcalloc(1, sizeof(*level)); level->path = path; bg_path = strjoin3("levels/",level->path,"/bg.jpg"); mask_path = strjoin3("levels/",level->path,"/mask.png"); settings_path = strjoin3("levels/",level->path,"/settings"); level->name = "Untitled Level"; level->gravity = 0.05; level->bounce = 0; level->ground_friction = 0.03; current_level = level; settings = fopen(settings_path,"r"); if (!settings) { fprintf(stderr,"Error: level (file '%s') not found!\n", settings_path); exit(EXIT_FAILURE); } shell_eval_file(settings); fclose(settings); fprintf(stderr,"Loading level %s\n",level->name); level->bg_image = image_load(bg_path,mask_path); level->bg_sprite.image = level->bg_image; level->bg_sprite.x = 0; level->bg_sprite.y = 0; level->width = level->bg_image->img->w; level->height = level->bg_image->img->h; free(bg_path); free(mask_path); free(settings_path); level->state = LEVEL_STATE_INPROGRESS; if (level->init) level->init(level); display_set_background(level->bg_image->img); }
int init() { //初始化NGE分为VIDEO,AUDIO,这里是只初始化VIDEO,如果初始化所有用INIT_VIDEO|INIT_AUDIO,或者INIT_ALL NGE_Init(INIT_VIDEO); //初始化按键处理btn_down是按下响应,后面是弹起时的响应,0是让nge处理home消息(直接退出),填1就是让PSP系统处理 //home消息,通常填1正常退出(1.50版的自制程序需要填0) #ifdef NGE_INPUT_BUTTON_SUPPORT InitInput(btn_down,NULL,1); #endif //最后一个参数是psp swizzle优化,通常填1 p_bg = image_load(RES_PATH("images/demo0.jpg"),DISPLAY_PIXEL_FORMAT_8888,1); if(p_bg == NULL) { nge_print("can not open file\n"); } p_logo = image_load(RES_PATH("images/nge2logo.png"),DISPLAY_PIXEL_FORMAT_4444,1); if(p_logo == NULL) { nge_print("can not open file\n"); } //创建一个半透明的图片遮罩color logomask1 = CreateColor(255,255,255,128,p_logo->dtype); //随便创建一个图片遮罩color logomask2 = CreateColor(100,100,100,255,p_logo->dtype); return 0; }
font font_init(const char *path) { font Font; debug_print("Loading Font ...\n"); Font.m_image = image_load(path, true, 0xff, 0x00, 0xff); int iW, iH; image_get_size(Font.m_image, &iW, &iH); if (iW % 16 != 0 || iH % 16 != 0) { debug_print("WARNING: Font has invalid dimensions.\n"); } Font.m_iGlyphWidth = iW / 16; Font.m_iGlyphHeight = iH / 16; return Font; }
void fuzzy_clock_init(struct aquarium *aquarium) { int i; if(aquarium->fuzzy_clock == AL_NO) return; for (i = 0; i < FUZZY_IMAGES; i++) { fuzzy_images[i] = image_load(fuzzy_image_names[i]); image_change_color(fuzzy_images[i], RED(aquarium->fuzzy_clock_color), GREEN(aquarium->fuzzy_clock_color), BLUE(aquarium->fuzzy_clock_color)); } }
int init() { //初始化NGE分为VIDEO,AUDIO,这里是只初始化VIDEO,如果初始化所有用INIT_VIDEO|INIT_AUDIO,或者INIT_ALL NGE_Init(INIT_VIDEO); //初始化按键处理btn_down是按下响应,后面是弹起时的响应,0是让nge处理home消息(直接退出),填1就是让PSP系统处理 //home消息,通常填1正常退出(1.50版的自制程序需要填0) #ifdef NGE_INPUT_BUTTON_SUPPORT InitInput(btn_down,NULL,1); #endif //最后一个参数是psp swizzle优化,通常填1 p_logo = image_load(RES_PATH("images/nge2logo.png"),DISPLAY_PIXEL_FORMAT_8888,1); if(p_logo == NULL) { nge_print("can not open file\n"); } p_par = image_load(RES_PATH("par/particles.png"),DISPLAY_PIXEL_FORMAT_8888,1); if(p_par == NULL) { nge_print("can not open file\n"); } //设置sprite子图 mParticle = (sprite_p)malloc(sizeof(sprite_t)); memset(mParticle,0,sizeof(sprite_t)); mParticle->sprite_image = p_par; mParticle->sprite_clip.left= 0.0f; mParticle->sprite_clip.top= 0.0f; mParticle->sprite_clip.right= 32.0f; mParticle->sprite_clip.bottom = 32.0f; mParticle->sprite_center.x = 16.0f; mParticle->sprite_center.y = 16.0f; mParticleSys = new hgeParticleSystem(RES_PATH("par/particle1.psi"), mParticle); mParticleSys->MoveTo(480.0f/2, 272.0f/2,0); mParticleSys->Fire(); timer = timer_create(); timer->start(timer); return 0; }
void Tetrimino::loadResource() { std::srand(std::time(NULL)); ResourceData::display = SDL_SetVideoMode( StableData::screenSize.x, StableData::screenSize.y, 0, SDL_SWSURFACE); ResourceData::background = image_load( StableData::backgroundFile.c_str()); ResourceData::font = TTF_OpenFont( StableData::fontFile.c_str(), 30); ResourceData::clock = new Clock(StableData::fps); ResourceData::sound = new Sound(); }
int main(int argc, char **argv) { unsigned short *image565 = screen_init(); struct image *image = image_new(WIDTH, HEIGHT); struct image *font = image_new(BLOCK_X, BLOCK_Y*50); struct Glyph glyph[50]; int i; recognize_init(); event_init(); image_load(font, "data.raw"); memset(glyph, 0, sizeof(glyph)); printf("Press any key to start..."); getc(stdin); printf("Recognizing 1~25 ...\n"); screen_capture(image565); rgb565_to_rgb24(image->buf, image565); threshold(THRESHOLD, image->buf); recognize(image, font, glyph, 0); for (i = 0; i < 25; ++i) { send_touch(glyph[i].x, glyph[i].y); usleep(100); } printf("\n\nPress any key to continue..."); getc(stdin); printf("Recognizing 26~50 ...\n"); screen_capture(image565); rgb565_to_rgb24(image->buf, image565); threshold(THRESHOLD, image->buf); recognize(image, font, glyph, 1); for (i = 24; i < 50; ++i) { send_touch(glyph[i].x, glyph[i].y); usleep(100); } image_destroy(font); event_destroy(); image_destroy(image); screen_destroy(image565); return 0; }
int main(int argc, char **argv) { opsoup_t ctx; int round = 1; FILE *f; o = &ctx; memset(o, 0, sizeof (opsoup_t)); if(argc == 2 && strcmp(argv[1], "-v") == 0) o->verbose = 1; if(image_load() != 0) return 1; init_sync(); dis_pass1(); while(dis_pass2(round)) { o->nref = 0; round++; } label_reloc_upgrade(); label_gen_names(); label_sort(); f = fopen(OUTPUT_FILE, "w"); if(f == NULL) { printf("main: couldn't open '" OUTPUT_FILE "' for writing: %s\n", strerror(errno)); return 1; } label_extern_output(f); dis_pass3(f); data_output(f); data_bss_output(f); fclose(f); //label_print_unused(); return 0; }
struct image * texture_load(const char * filename, bool generate_alpha, bool use_mipmapping, bool linear) { struct image * bmp; bmp = image_load(filename, generate_alpha); if(bmp != NULL) { texture_setup_from_image(bmp, generate_alpha, use_mipmapping, linear); } else { fprintf(stderr, "Failed to load texture '%s': %s\n", filename, SDL_GetError()); } return bmp; }
struct charRecognition *charRecognition_learn(char *rootPath, char chars[], size_t size, size_t variants) { struct charRecognition *charReg = malloc(sizeof(struct charRecognition)); struct NeuralNetwork *myNeuralNetwork = neuralNetwork_main(256, HIDDEN_LAYER_COUNT, size); unsignedArray2D input = new_unsignedArray2D(size * variants, 256); unsignedArray2D output = new_unsignedArray2D(size * variants, size); unsigned count = 0; for(unsigned i = 0; i < size; i++) { for(unsigned j = 0; j < variants; j++) { char toAscii[15]; sprintf(toAscii, "%d", (int)chars[i]); char *path = string_concat(rootPath, toAscii); path = string_concat(path, "/"); char filename[5]; sprintf(filename, "%d", j); path = string_concat(path, filename); path = string_concat(path, ".bmp"); SDL_Surface *s = image_scale( image_crop(image_load(path)), 16, 16); for (unsigned k = 0; k < 16; k++) for (unsigned l = 0; l < 16; l++) input.elements[count].elements[k + l * 16] = image_getPixelBool(s, k, l); for(unsigned k = 0; k < size; k++) output.elements[count].elements[k] = ((count / variants) == k); count++; } } NeuralNetwork_train(myNeuralNetwork, input, output, 0.05, 0.1, 0.9); charReg->letters = chars; charReg->size = size; charReg->network = myNeuralNetwork; return charReg; }
static GLuint theme_image(const char *path) { const int W = video.device_w; const int H = video.device_h; int W2, H2; int w, h, b; void *p; GLuint o = 0; /* * Disable mipmapping and do a manual downscale. Heuristic for * downscaling the texture: assume target size to be roughly 1/16 * of a full screen texture, smallest size being 32x32. */ image_near2(&W2, &H2, W, H); W2 = MAX(W2 / 16, 32); H2 = MAX(H2 / 16, 32); if ((p = image_load(path, &w, &h, &b))) { void *q; /* Prefer a small scale factor. */ int s = MAX(w, h) / MAX(W2, H2); if (s > 1 && (q = image_scale(p, w, h, b, &w, &h, s))) { free(p); p = q; } o = make_texture(p, w, h, b, 0); free(p); p = NULL; } return o; }
bool texture::load( const std::string &pathFile, bool mirror_w, bool mirror_h ) { #if 0 destroy(); create(); std::string error = image_load( pathFile, mirror_w, mirror_h, false, true, w, h, delay, *this ); if( error.size() ) { std::cerr << error << std::endl; return false; } return true; #else return load( moon9::image( pathFile ), mirror_w, mirror_h ); #endif }