gboolean checkcover (gint tag) { gint playlist_position; //gchar *playlist_uri = NULL; gchar *playlist_filename = NULL; gint playlist = aud_playlist_get_active(); gboolean processed = 0; gboolean fast_call = 0; gdk_threads_enter (); playlist_position = aud_playlist_get_position(playlist); //playlist_uri = aud_playlist_get_filename (playlist); const Tuple *tuple = aud_playlist_entry_get_tuple(playlist, playlist_position, fast_call); if (tuple) { playlist_filename = g_strdup((gchar *) tuple_get_string(tuple, FIELD_FILE_PATH, NULL)); if (playlist_filename) { /*playlist_filename = g_filename_from_uri(playlist_uri, NULL, NULL); if (playlist_filename) {*/ if (strcmp (playlist_filename,current_filename) && !mainwindow_data.loading_cover) { mainwindow_data.loading_cover = TRUE; // Filename has changed current_filename = realloc (current_filename,strlen(playlist_filename)+1); strcpy (current_filename,playlist_filename); DPRINT (__DEBUG_GENERAL__,"New playfile detected: %s",current_filename); // Find new cover if possible findcover_search (current_filename); DPRINT (__DEBUG_GENERAL__,"Cover to display: %s",findcover_filename); loadimage (findcover_filename); mainwindow_data.loading_cover = FALSE; } free (playlist_filename); //free (playlist_uri); processed = 1; /*}*/ } } if (!processed) { mainwindow_data.loading_cover = TRUE; loadimage (NULL); mainwindow_data.loading_cover = FALSE; } gdk_threads_leave (); return TRUE; }
Image* and2img(Icon *icon, uint8_t *and) { uint8_t *data; Image *img; int inxlen; int outxlen; uint8_t *from, *to; int x, y; inxlen = 4*((icon->w+31)/32); to = data = malloc(inxlen*icon->h); /* rotate around the y axis and invert bits */ outxlen = (icon->w+7)/8; for(y = 0; y < icon->h; y++){ from = and + (icon->h - 1 - y)*inxlen; for(x = 0; x < outxlen; x++){ *to++ = ~(*from++); } } /* stick in an image */ img = allocimage(display, Rect(0,0,icon->w,icon->h), GREY1, 0, DNofill); loadimage(img, Rect(0,0,icon->w,icon->h), data, icon->h*outxlen); free(data); return img; }
int main(void) { int i; LOGFONT f; int where_table[] = {2, 3, 4, 6, 8, 10, 12, 15, 16, 20}; initgraph(640, 480); loadimage(&welcome_bk, "images/welcome_bk.jpg"); getfont(&f); f.lfHeight = 16; strcpy(f.lfFaceName, "宋体"); f.lfQuality = ANTIALIASED_QUALITY; setfont(&f); // 设置字体样式 welcome(); for(i = 0; i < 10; i++) { cleardevice(); draw_map(where_table[i]); game(where_table[i], i); fflush(stdin); getch(); } cleardevice(); f.lfHeight = 72; setfont(&f); outtextxy(150, 180, "通关训练!"); f.lfHeight = 12; setfont(&f); outtextxy(180, 400, "恭喜您获得了“点灯”挑战资格,敬请期待后序内容!"); Sleep(5000); closegraph(); return 0; }
void begin() { IMAGE img; initgraph(700,630); setbkcolor(GREEN); cleardevice(); loadimage(&img,"E:\\5.jpg"); putimage(0,0,&img); setcolor(RED); setfont(100,0,"华文行楷"); outtextxy(110,10,"聪明的小蛇"); setcolor(WHITE); setfont(70,0,"楷体"); outtextxy(10,130,"开始游戏"); setcolor(BROWN); setfont(70,0,"楷体"); outtextxy(10,230,"游戏规则"); setcolor(YELLOW); setfont(70,0,"楷体"); outtextxy(10,330,"关卡选择"); setcolor(BLUE); setfont(70,0,"楷体"); outtextxy(10,430,"得分排名"); setcolor(WHITE); setfont(70,0,"楷体"); outtextxy(10,530,"退出游戏"); }
bool Game::gm_init(float w, float h) { SCREEN_WIDTH = w; SCREEN_HEIGHT = h; //Initialize OpenGL states glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_TEXTURE_2D); //Set up screen projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrthof(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1, 1); GLOBALS_GAME_STATE = GAME_STATE_TITLE; GLOBALS_GAME_STATE_LAST = -1; GLOBALS_GAME_STATE_NEXT = GAME_STATE_MENU; //load sound buffers //loadsound(SOUND_EXPLODE,"explode"); //load images GLOBALS_PIXMAP_MAN = loadimage("16x16", 16, 16); return true; }
void loadcar( int x ) { IMAGE img; loadimage( &img, _T("res/car.jpg")); putimage( x, 420, &img ); }
Subfont* getdefont(Display *d) { char *hdr, *p; int n; Fontchar *fc; Subfont *f; int ld; Rectangle r; Image *i; /* * make sure data is word-aligned. this is true with Plan 9 compilers * but not in general. the byte order is right because the data is * declared as char*, not ulong*. */ p = (char*)defontdata; n = (ulong)p & 3; if(n != 0){ memmove(p+(4-n), p, sizeofdefont-n); p += 4-n; } ld = atoi(p+0*12); r.min.x = atoi(p+1*12); r.min.y = atoi(p+2*12); r.max.x = atoi(p+3*12); r.max.y = atoi(p+4*12); i = allocimage(d, r, drawld2chan[ld], 0, 0); if(i == 0) return 0; p += 5*12; n = loadimage(i, r, (uchar*)p, (defontdata+sizeofdefont)-(uchar*)p); if(n < 0){ freeimage(i); return 0; } hdr = p+n; n = atoi(hdr); p = hdr+3*12; fc = malloc(sizeof(Fontchar)*(n+1)); if(fc == 0){ freeimage(i); return 0; } _unpackinfo(fc, (uchar*)p, n); f = allocsubfont("*default*", n, atoi(hdr+12), atoi(hdr+24), fc, i); if(f == 0){ freeimage(i); free(fc); return 0; } return f; }
void eloadimage(Image *i, Rectangle r, uint8_t *d, int nd) { int n; n = loadimage(i, r, d, nd); if(n < nd) { fprint(2, "loadimage fails: %r\n"); exits("loadimage"); } }
void flipnormalmapy(char *destfile, char *normalfile) // jpg/png /tga-> tga { ImageData ns; if(!loadimage(normalfile, ns)) return; ImageData d(ns.w, ns.h, 3); readwritetex(d, ns, dst[0] = src[0]; dst[1] = 255 - src[1]; dst[2] = src[2]; );
//主页菜单 int MainMenu(){ int i = 1, y1 = 250; cleardevice(); IMAGE img; loadimage(&img, "1.jpg", 1000, 600, true); putimage(0, 0, &img); //设置主菜单文字 setlocale(LC_ALL, "chs");//解决中文乱码,在头文件locale.h中 settextstyle(80, 0, "华文彩云",0,0,10000,0,0,0); settextcolor(MAGENTA); setbkmode(TRANSPARENT);/*处理文字后面的黑色,使文字后的背景为图片*/ outtextxy(400, 150, "菜单"); settextcolor(DARKGRAY); settextstyle(40, 0, "幼圆",0,0,1000,0,1,0); int WIDTH = textwidth(_T("1 画图")); outtextxy(WDIS, 250, _T("1 画图")); outtextxy(WDIS, 300, _T("2 分形")); outtextxy(WDIS, 350, _T("3 配置")); outtextxy(WDIS, 400, _T("4 退出")); //获取鼠标信息 FlushMouseMsgBuffer(); while (true){ if (MouseHit()){ //检测 m = GetMouseMsg();//获取鼠标状态 if (m.uMsg == WM_LBUTTONDOWN){ while (m.x >= WDIS&&m.x <= WIDTH+WDIS&&m.y >= 250 && m.y <= 425){ if (m.y >= y1&&m.y <= 25 + y1) return i; else if (y1 >= 400) break; else y1 += 50, i++; } } } //通过按键也可以实现主菜单跳转 if (_kbhit()){ char c = _getch(); if (c >= '1'&&c <= '4') return (c - '0'); } } _getch(); closegraph(); }
void init(void) { mailfs = nsmount("mail", nil); if(mailfs == nil) sysfatal("mount mail: %r"); mousectl = initmouse(nil, screen); if(mousectl == nil) sysfatal("initmouse: %r"); initplumb(); /* make background color */ bgrnd = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DWhite); blue = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x008888FF); /* blue-green */ left = allocimage(display, leftright, GREY1, 0, DWhite); right = allocimage(display, leftright, GREY1, 0, DWhite); if(bgrnd==nil || blue==nil || left==nil || right==nil){ fprint(2, "faces: can't create images: %r\n"); threadexitsall("image"); } loadimage(left, leftright, leftdata, sizeof leftdata); loadimage(right, leftright, rightdata, sizeof rightdata); /* initialize little fonts */ tinyfont = openfont(display, "/lib/font/bit/misc/ascii.5x7.font"); if(tinyfont == nil) tinyfont = font; mediumfont = openfont(display, "/lib/font/bit/pelm/latin1.8.font"); if(mediumfont == nil) mediumfont = font; datefont = font; facep.y += datefont->height; if(datefont->height & 1) /* stipple parity */ facep.y++; faces = nil; }
void init(void) { mousefd = open("/dev/mouse", OREAD); if(mousefd < 0){ fprint(2, "faces: can't open mouse: %r\n"); exits("mouse"); } initplumb(); /* make background color */ bgrnd = allocimagemix(display, DPalebluegreen, DWhite); blue = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x008888FF); /* blue-green */ left = allocimage(display, leftright, GREY1, 0, DWhite); right = allocimage(display, leftright, GREY1, 0, DWhite); if(bgrnd==nil || blue==nil || left==nil || right==nil){ fprint(2, "faces: can't create images: %r\n"); exits("image"); } loadimage(left, leftright, leftdata, sizeof leftdata); loadimage(right, leftright, rightdata, sizeof rightdata); /* initialize little fonts */ tinyfont = openfont(display, "/lib/font/bit/misc/ascii.5x7.font"); if(tinyfont == nil) tinyfont = font; mediumfont = openfont(display, "/lib/font/bit/pelm/latin1.8.font"); if(mediumfont == nil) mediumfont = font; datefont = font; facep.y += datefont->height; if(datefont->height & 1) /* stipple parity */ facep.y++; faces = nil; }
static int loadnextimage(img_t *image) { struct dirent *d; lprintf("loadnextimage\n"); if(terminate) return -1; if(!dir) { terminate = 1; return loadimage(initpath, image); } while( (d = readdir(dir)) ) if(d->d_type == DT_REG) { char filepath[256]; snprintf(filepath, sizeof(filepath), "%s/%s", initpath, d->d_name); if(!loadimage(filepath, image)) return 0; } lprintf("End of directory\n"); return -1; }
//游戏初始化 void gameInit() { initgraph(LENGTH, WIDTH); setcolor(FGCLR); setbkcolor(BKCLR); setfillstyle(FGCLR, SOLID_FILL); BeginBatchDraw(); setfont(25, 0, "华文行楷"); setbkmode(TRANSPARENT); cleardevice(); loadimage(&bkImg, BKIMG, LENGTH, WIDTH); putimage(0, 0, &bkImg); srand((unsigned)time(NULL));//初始化种子 setPlayer(1, "player1", 0, createPt(160, 0), createBlk(), true, createPt(10, 10)); setPlayer(2, "player2", 0, createPt(400, 0), createBlk(), true, createPt(10, 240)); drawStageLine(); }
void getimage(Cimage *ci, Rune *altr) { Rectangle r; Memimage *mi; Image *i, *i2; char buf[128]; uchar *bits; int nbits; mi = ci->mi; if(mi == nil) { snprint(buf, sizeof(buf), "[%S]", altr ? altr : L"IMG"); r.min = Pt(0, 0); r.max.x = 2*Space + stringwidth(font, buf); r.max.y = 2*Space + font->height; ci->i = eallocimage(display, r, GREY1, 1, DBlack); r.min.x += Space; r.min.y += Space; string(ci->i, r.min, display->white, ZP, font, buf); return; } nbits = bytesperline(mi->r, mi->depth)*Dy(mi->r); bits = emalloc(nbits); unloadmemimage(mi, mi->r, bits, nbits); /* /* get rid of alpha channel from transparent gif * / if(mi->depth == 16){ for(y=1; y<nbits; y+=2) bits[y>>1] = bits[y]; } */ i = eallocimage(display, mi->r, mi->chan, 0, DNofill); loadimage(i, i->r, bits, nbits); i2 = eallocimage(display, i->r, RGB24, 1, DNofill); draw(i2, i2->r, display->black, nil, ZP); draw(i2, i2->r, i, nil, i->r.min); free(bits); freememimage(mi); freeimage(i); ci->i = i2; ci->mi = nil; }
int main(){ int i,j,k, n,pixl, count=0; PIX *pixs; glob_t *flist; FILE *file=fopen("train_file.trn","w"); for(n=0;n<10;n++){ flist=list_files(n); if(flist->gl_pathc==0) { fprintf(stderr,"No files in directory %d... Exiting...\n",n); exit(1); } for(i=0;i<flist->gl_pathc;i++){ pixs=loadimage(flist->gl_pathv[i]); if(pixs==NULL){ fprintf(stderr,"Pix error... Exiting...\n"); exit(1); } for(j=0;j<pixGetHeight(pixs);j++){ for(k=0;k<pixGetWidth(pixs);k++){ pixGetPixel(pixs,k,j,&pixl); fprintf(file,"%d",pixl); /* funny transformation of rows/columns. TODO: works with intels, but others??? */ } fprintf(file,"\n"); } count++; fprintf(file," %d\n",n); } globfree(flist); free(flist); } fclose(file); // *file=fopen("train_file.trn","r"); FILE *file1=fopen("train_file_header.trn","w"); insert_header(file1,count); fclose(file1); return (0); }
static void previmage() { int n; unloadimage(); for (n = cmdopts.numfiles; n > 0; --n) { --gs.filenum; if (gs.filenum < 0) { if (cmdopts.loop) { gs.filenum = cmdopts.numfiles - 1; } else { cleanupandexit(EXIT_SUCCESS); } } if (!loadimage()) { return; } } cleanupandexit(EXIT_SUCCESS); }
//Buttons void createbutton(widget *data, uint16 x, uint16 y, uint16 height, uint16 width, char *image) { button *box; initwidget(data); data->pos.x = x; data->pos.y = y; data->height = height; data->width = width; data->imgpos.x = 0; data->imgpos.y = 0; data->type = BUTTON; data->draw = &drawbuttons; box = (button *)calloc(1,sizeof(button)); box->click = 0; data ->control = box; loadimage(getpath(image), &data->img); }
static void nextimage() { int n; unloadimage(); for (n = cmdopts.numfiles; n > 0; --n) { ++gs.filenum; if (gs.filenum >= cmdopts.numfiles) { if (cmdopts.loop) { gs.filenum = 0; } else { cleanupandexit(EXIT_SUCCESS); } } if (!loadimage()) { return; } jas_eprintf("cannot load image\n"); } cleanupandexit(EXIT_SUCCESS); }
int load_txtures(t_mlxdata *data) { int size; size = 256; data->txtures.sky = loadimage(data, "images/sky.xpm", size, size); data->txtures.stone = loadimage(data, "images/stonewall.xpm", size, size); data->txtures.wood = loadimage(data, "images/woodwall.xpm", size, size); data->txtures.hell = loadimage(data, "images/hell.xpm", size, size); data->txtures.grass = loadimage(data, "images/grass.xpm", size, size); data->txtures.weapon = loadimage(data, "images/weapons/weapon.xpm", 255, 133); data->txtures.weaponfiring = loadimage(data, "images/weapons/weaponfiring.xpm", 255, 133); load64textures(data); return (1); }
void init() { /* 初始化位置方向速度 */ xiaoming.positionx = 1; xiaoming.positiony = 1; xiaoming.direction = DIR_RIGHT; xiaoming.speed = 100; xiaohong.positionx = 12; xiaohong.positiony = 1; xiaohong.direction = DIR_RIGHT; xiaohong.speed = 50; endx = 19; endy = 18; /* 墙 */ loadimage(&WallImg, "wall.bmp", IMGWIDTH, IMGHEIGHT, true); /* 空地 */ loadimage(&BlankImg, "blank.bmp", IMGWIDTH, IMGHEIGHT, true); /* 终点 */ loadimage(&EndImg, "end.bmp", IMGWIDTH, IMGHEIGHT, true); /* 人物 */ loadimage(&PersonImg[DIR_RIGHT], "right.bmp", IMGWIDTH, IMGHEIGHT, true); loadimage(&PersonImg[DIR_UP], "up.bmp", IMGWIDTH, IMGHEIGHT, true); loadimage(&PersonImg[DIR_LEFT], "left.bmp", IMGWIDTH, IMGHEIGHT, true); loadimage(&PersonImg[DIR_DOWN], "down.bmp", IMGWIDTH, IMGHEIGHT, true); setfont(14, 0, _T("黑体")); outtextxy(410, 310, _T("操作说明")); outtextxy(410, 330, _T("s:走一步")); outtextxy(410, 350, _T("l:左转")); outtextxy(410, 370, _T("m:自定义移动")); drawing(); return ; }
void mainwindow_loadskin (gchar *skinpath,_loadskin_types loadtype) { // Have we got a window at all ? if (mainwindow_data.window==NULL) return; DPRINT (__DEBUG_GTK__,"Loading skin"); // Prevent any display operations while loading mainwindow_data.loading_skin = TRUE; // Load skin configuration init_skin (skinpath,loadtype); // Create double-buffered pixmap // unref pixmap, in case we call this function again if (mainwindow_data.dbuf_pixmap!=NULL) gdk_pixmap_unref (mainwindow_data.dbuf_pixmap); mainwindow_data.dbuf_pixmap = gdk_pixmap_new (mainwindow_data.window->window, plugin_config->skin_width,plugin_config->skin_height, -1); // Set new window size gtk_widget_set_usize (mainwindow_data.window,plugin_config->skin_width,plugin_config->skin_height); // Allow window operations again mainwindow_data.loading_skin = FALSE; // Repaint the new window loadimage (findcover_filename); }
static void load64textures(t_mlxdata *data) { int size; size = 64; data->txtures.wool = loadimage(data, "images/wool_colored_red.xpm", size, size); data->txtures.flower_rose = loadimage(data, "images/flower_rose.xpm", size, size); data->txtures.bush = loadimage(data, "images/leaves_jungle.xpm", size, size); data->txtures.planks = loadimage(data, "images/planks_jungle.xpm", size, size); data->txtures.dirt = loadimage(data, "images/dirt.xpm", size, size); data->txtures.glowstone = loadimage(data, "images/glowstone.xpm", size, size); }
Image* xor2img(Icon *icon, uint8_t *xor, uint8_t *map) { uint8_t *data; Image *img; int inxlen; uint8_t *from, *to; int s, byte, mask; int x, y; inxlen = 4*((icon->bits*icon->w+31)/32); to = data = malloc(icon->w*icon->h); /* rotate around the y axis, go to 8 bits, and convert color */ mask = (1<<icon->bits)-1; for(y = 0; y < icon->h; y++){ s = -1; byte = 0; from = xor + (icon->h - 1 - y)*inxlen; for(x = 0; x < icon->w; x++){ if(s < 0){ byte = *from++; s = 8-icon->bits; } *to++ = map[(byte>>s) & mask]; s -= icon->bits; } } /* stick in an image */ img = allocimage(display, Rect(0,0,icon->w,icon->h), CMAP8, 0, DNofill); loadimage(img, Rect(0,0,icon->w,icon->h), data, icon->h*icon->w); free(data); return img; }
void loadarchive(FILE* ar, program* prog, jt_clist* objects) { char armagic[SARMAG]; struct ar_hdr arheader; int entry = 0; int havesymtab = 0; fread(armagic, 1, SARMAG, ar); if (strncmp(armagic, ARMAG, SARMAG) != 0) { fprintf(stderr, "This does not look like an archive file\n"); exit(1); } #ifdef DEBUG fprintf(stderr, "Got archive file!\n"); #endif while (!feof(ar)) { long posn = ftell(ar); int size; if ((posn & 1) == 1) { /* odd byte boundary, we must read another character, a newline */ int c = fgetc(ar); if (c != '\n') { fprintf(stderr, "Was expecting newline padding for header\n"); exit(1); } } /* first thing we try to read from the file this iteration: if it * fails, we've hit the end of the file (feof() didn't seem to work) */ if (fread(&arheader, 1, sizeof(arheader), ar) != sizeof(arheader)) break; if (strncmp(arheader.ar_fmag, ARFMAG, sizeof(ARFMAG)-1) != 0) { fprintf(stderr, "Bad archive header\n"); exit(1); } sscanf(arheader.ar_size, "%d", &size); posn = ftell(ar); #ifdef DEBUG fprintf(stderr, "Good archive header, length=%d\n", size); #endif if (entry==0 && !havesymtab && arheader.ar_name[0] == '/' && arheader.ar_name[1] == ' ') { archive_symtab* symtab = jt_new(archive_symtab); /* unnamed first entry is probably a symtab */ if (readsymtab(ar, &arheader, symtab)) { fprintf(stderr, "Error reading symbol table\n"); exit(1); } havesymtab = 1; /* don't really want one of those, was just being polite */ free(symtab->loc); free(symtab->name); free(symtab->nameidx); free(symtab); } else if (arheader.ar_name[0] == '/' && arheader.ar_name[1] == '/') { int posn = ftell(ar), size; #ifdef DEBUG fprintf(stderr, "Detected long filename section\n"); #endif sscanf(arheader.ar_size, "%d", &size); fseek(ar, posn+size, SEEK_SET); #ifdef DEBUG fprintf(stderr, "Skipped %d bytes\n", size); #endif } else { jt_clist* newobj = jt_clist_append(objects); image* img; #ifdef DEBUG uint5 i; #endif /* read a file from the archive */ #ifdef DEBUG fprintf(stderr, "Original filename: "); if (arheader.ar_name[0]=='/') { fprintf(stderr, "(long)\n"); } else { for (i=0; i<16; i++) { if (arheader.ar_name[i]=='/') break; fputc(arheader.ar_name[i], stderr); } fputc('\n', stderr); } #endif newobj->data = img = loadimage(ar, 1); readsymbols(&img->symtab, &img->strtab, &img->symbolmap); findglobals(img, &prog->globalsymbolmap); } /* position over file */ fseek(ar, posn+size, SEEK_SET); entry++; } #ifdef DEBUG fprintf(stderr, "Read library, returning...\n"); #endif }
static AnimeBitmap* loadBMP(const char* filename){ AnimeBitmap* ret = (AnimeBitmap*)malloc(sizeof(AnimeBitmap)); loadimage(filename,&ret->pixels,&ret->width,&ret->height); return ret; }
int main(int argc, char **argv) { THNETWORK *net; float *result; int i, n = 0, rc, outwidth, outheight, runs = 1, print = 0, alg = 1, nbatch = 1; const char *modelsdir = 0, *inputfile = 0; for(i = 1; i < argc; i++) { if(argv[i][0] != '-') continue; switch(argv[i][1]) { case 'm': if(i+1 < argc) modelsdir = argv[++i]; break; case 'i': if(i+1 < argc) inputfile = argv[++i]; break; case 'a': if(i+1 < argc) alg = atoi(argv[++i]); break; case 'p': print = 1; break; case 'r': if(i+1 < argc) runs = atoi(argv[++i]); break; case 'b': if(i+1 < argc) { nbatch = atoi(argv[++i]); if(nbatch > 256 || nbatch < 1) nbatch = 256; } break; } } if(!modelsdir || !inputfile) { fprintf(stderr, "Syntax: test -m <models directory> -i <input file>\n"); fprintf(stderr, " [-r <number of runs] [-p(rint results)]\n"); fprintf(stderr, " [-a <alg=0:norm,1:MM (default),2:virtMM,3:cuDNN,4:cudNNhalf>]\n"); fprintf(stderr, " [-b <nbatch>]\n"); return -1; } if(alg == 4) { alg = 3; THCudaHalfFloat(1); } THInit(); net = THLoadNetwork(modelsdir); if(net) { THMakeSpatial(net); if(alg == 0) THUseSpatialConvolutionMM(net, 0); else if(alg == 1 || alg == 2) THUseSpatialConvolutionMM(net, alg); else if(alg == 3) { THNETWORK *net2 = THCreateCudaNetwork(net); if(!net2) THError("CUDA not compiled in"); THFreeNetwork(net); net = net2; } if(strstr(inputfile, ".t7")) { struct thobject input_o; rc = loadtorch(inputfile, &input_o, 8); if(!rc) { THFloatTensor *in = THFloatTensor_newFromObject(&input_o); // In CuDNN the first one has to do some initializations, so don't count it for timing if(alg == 3) THProcessFloat(net, in->storage->data, 1, in->size[2], in->size[1], &result, &outwidth, &outheight); t = seconds(); for(i = 0; i < runs; i++) n = THProcessFloat(net, in->storage->data, 1, in->size[2], in->size[1], &result, &outwidth, &outheight); t = (seconds() - t) / runs; THFloatTensor_free(in); freeobject(&input_o); } else printf("Error loading %s\n", inputfile); } else { img_t image; rc = loadimage(inputfile, &image); if(!rc) { unsigned char *bitmaps[256]; for(i = 0; i < nbatch; i++) bitmaps[i] = image.bitmap; // In CuDNN the first one has to do some initializations, so don't count it for timing if(alg == 3) THProcessImages(net, &image.bitmap, 1, image.width, image.height, 3*image.width, &result, &outwidth, &outheight, 0); t = seconds(); for(i = 0; i < runs; i++) n = THProcessImages(net, bitmaps, nbatch, image.width, image.height, 3*image.width, &result, &outwidth, &outheight, 0); t = (seconds() - t) / runs; #ifdef USECUDAHOSTALLOC cudaFreeHost(image.bitmap); #else free(image.bitmap); #endif } else printf("Error loading image %s\n", inputfile); } if(print) for(i = 0; i < n; i++) printf("(%d,%d,%d): %f\n", i/(outwidth*outheight), i % (outwidth*outheight) / outwidth, i % outwidth, result[i]); printf("1 run processing time: %lf\n", t); THFreeNetwork(net); } else printf("The network could not be loaded: %d\n", THLastError()); #ifdef MEMORYDEBUG debug_memorydump(stderr); #endif return 0; }
void loadmedia() { cnc_head = loadimage("arch/simulator/media/cnc_head.bmp"); font = loadfont("arch/simulator/media/FreeSans.ttf", POINTSIZE); }
static struct DiskObject *int_load_do(char *filename) { FILE *f; struct DiskObject *diskobj; char buf[78], *p=buf; int error=0; if((f=fopen(filename, "r"))) { if(1==fread(buf, 78, 1, f) && (diskobj=calloc(1, sizeof(struct DiskObject)))) { diskobj->do_Magic=getu16(&p); diskobj->do_Version=getu16(&p); if(diskobj->do_Magic!=WB_DISKMAGIC) { free(diskobj); return NULL; } diskobj->do_Gadget.NextGadget=(struct Gadget *)getu32(&p); diskobj->do_Gadget.LeftEdge=get16(&p); diskobj->do_Gadget.TopEdge=get16(&p); diskobj->do_Gadget.Width=get16(&p); diskobj->do_Gadget.Height=get16(&p); diskobj->do_Gadget.Flags=getu16(&p); diskobj->do_Gadget.Activation=getu16(&p); diskobj->do_Gadget.GadgetType=getu16(&p); diskobj->do_Gadget.GadgetRender=(APTR)getu32(&p); diskobj->do_Gadget.SelectRender=(APTR)getu32(&p); diskobj->do_Gadget.GadgetText=(struct IntuiText *)getu32(&p); diskobj->do_Gadget.MutualExclude=get32(&p); diskobj->do_Gadget.SpecialInfo=(APTR)getu32(&p); diskobj->do_Gadget.GadgetID=getu16(&p); diskobj->do_Gadget.UserData=(APTR)getu32(&p); diskobj->do_Type=*p; p+=2; diskobj->do_DefaultTool=(char *)getu32(&p); diskobj->do_ToolTypes=(char **)getu32(&p); diskobj->do_CurrentX=get32(&p); diskobj->do_CurrentY=get32(&p); diskobj->do_DrawerData=(struct DrawerData *)getu32(&p); diskobj->do_ToolWindow=(char *)getu32(&p); diskobj->do_StackSize=get32(&p); if(diskobj->do_DrawerData) { struct DrawerData *dd; if(1==fread(buf, 56, 1, f) && (diskobj->do_DrawerData=dd=calloc(1, sizeof(struct DrawerData)))) { p=buf; dd->dd_NewWindow.LeftEdge=get16(&p); dd->dd_NewWindow.TopEdge=get16(&p); dd->dd_NewWindow.Width=get16(&p); dd->dd_NewWindow.Height=get16(&p); dd->dd_NewWindow.DetailPen=*p++; dd->dd_NewWindow.BlockPen=*p++; dd->dd_NewWindow.IDCMPFlags=getu32(&p); dd->dd_NewWindow.Flags=getu32(&p); dd->dd_NewWindow.FirstGadget=(struct Gadget *)getu32(&p); dd->dd_NewWindow.CheckMark=(struct Image *)getu32(&p); dd->dd_NewWindow.Title=(UBYTE *)getu32(&p); dd->dd_NewWindow.Screen=(struct Screen *)getu32(&p); dd->dd_NewWindow.BitMap=(struct BitMap *)getu32(&p); dd->dd_NewWindow.MinWidth=get16(&p); dd->dd_NewWindow.MinHeight=get16(&p); dd->dd_NewWindow.MaxWidth=getu16(&p); dd->dd_NewWindow.MaxHeight=getu16(&p); dd->dd_NewWindow.Type=getu16(&p); dd->dd_CurrentX=get32(&p); dd->dd_CurrentY=get32(&p); } else error++; } if(!(diskobj->do_Gadget.GadgetRender=loadimage(f))) error++; if(diskobj->do_Gadget.Flags&2) if(!(diskobj->do_Gadget.SelectRender=loadimage(f))) error++; else ; else if(diskobj->do_Gadget.Flags&1) if(!(diskobj->do_Gadget.SelectRender= backfillimage((struct Image *)diskobj->do_Gadget.GadgetRender))) error++; else ; else diskobj->do_Gadget.SelectRender=NULL; if(diskobj->do_DefaultTool) if(!(diskobj->do_DefaultTool=loadstring(f))) error++; if(diskobj->do_ToolTypes) if(!(diskobj->do_ToolTypes=loadtooltypes(f))) error++; if(diskobj->do_ToolWindow) if(!(diskobj->do_ToolWindow=loadstring(f))) error++; if(diskobj->do_DrawerData && diskobj->do_Version) { char buf[6], *p=buf; if(1==fread(buf, 6, 1, f)) { diskobj->do_DrawerData->dd_Flags=getu32(&p); diskobj->do_DrawerData->dd_ViewModes=getu16(&p); } } if(diskobj->do_Version) { /* Check for GlowIcon */ char buf[8], *p = buf, *glowicon; LONG len; if(1==fread(buf, 4, 1, f) && !strncmp(buf, "FORM", 4) && 1==fread(buf, 8, 1, f) && !strncmp(buf+4, "ICON", 4) && (len = get32(&p))>4 && (glowicon = malloc(len))!=NULL) { if(1==fread(glowicon, len-4, 1, f)) decode_glowicon(diskobj, glowicon, len-4); free(glowicon); } } if(!error) { fclose(f); return diskobj; } FreeDiskObject(diskobj); } fclose(f); } return NULL; }
bool wxIcon::LoadFile( const wxString& filename, wxBitmapType type, int desiredWidth, int desiredHeight ) { UnRef(); if ( type == wxBITMAP_TYPE_ICON_RESOURCE ) { OSType theId = 0 ; if ( filename == wxT("wxICON_INFORMATION") ) { theId = kAlertNoteIcon ; } else if ( filename == wxT("wxICON_QUESTION") ) { theId = kAlertCautionIcon ; } else if ( filename == wxT("wxICON_WARNING") ) { theId = kAlertCautionIcon ; } else if ( filename == wxT("wxICON_ERROR") ) { theId = kAlertStopIcon ; } else { #if 0 Str255 theName ; OSType theType ; wxMacStringToPascal( name , theName ) ; Handle resHandle = GetNamedResource( 'cicn' , theName ) ; if ( resHandle != 0L ) { GetResInfo( resHandle , &theId , &theType , theName ) ; ReleaseResource( resHandle ) ; } #endif } if ( theId != 0 ) { IconRef iconRef = NULL ; verify_noerr( GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef ) ) ; if ( iconRef ) { m_refData = new wxIconRefData( (WXHICON) iconRef ) ; return true ; } } return false ; } else { wxBitmapHandler *handler = wxBitmap::FindHandler( type ); if ( handler ) { wxBitmap bmp ; if ( handler->LoadFile( &bmp , filename, type, desiredWidth, desiredHeight )) { CopyFromBitmap( bmp ) ; return true ; } return false ; } else { #if wxUSE_IMAGE wxImage loadimage( filename, type ); if (loadimage.Ok()) { if ( desiredWidth == -1 ) desiredWidth = loadimage.GetWidth() ; if ( desiredHeight == -1 ) desiredHeight = loadimage.GetHeight() ; if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() ) loadimage.Rescale( desiredWidth , desiredHeight ) ; wxBitmap bmp( loadimage ); CopyFromBitmap( bmp ) ; return true; } #endif } } return true ; }