📄 gfxtest.c
字号:
{ y = scr.uHeight/2 - (x-x0)*(x0+k - x)*k*scr.uHeight/2/FACTOR; gfx_move_cursor(fgfx, x, y); usleep(7*1000); } x0 += k; k = k*29/32; if(k < 10) k = 10; } } } // generate mask { // make pattern 4x4 UINT bpl, y, i; BYTE pat=0xf0; bpl = smask.plane[0].uBytePerLine; y = smask.plane[0].uHeight; for(i=0; i<y-3; i+=4, pat = ~pat) { memset(smask.plane[0].pPlane+i*bpl, pat, 4*bpl); } } fprintf(stderr, "Show surface yuv and wait for 2 seconds\n"); gfx_attach_surface(fgfx, hyuv, GFX_VDEV_OSDIMG); // display itdrawing(fgfx, hyuv, syuv.uPlaneConfig); sleep(2); gfx_detach_surface(fgfx, hyuv, GFX_VDEV_OSDIMG); // hide it fprintf(stderr, "Show surface 1 and wait for 2 seconds\n"); gfx_attach_surface(fgfx, h1, GFX_VDEV_OSDGFX); // display it// gfx_move_cursor(fgfx, H1_X/2, H1_Y/2);drawing(fgfx, h1, s1.uPlaneConfig); gfx_fill_color_bar(fgfx, h1, &s1); if(argc > 1) { int w,h; int hbmp = gfx_LoadBitmap_Surface(fgfx, NULL, &w, &h, argv[1], 255); if(hbmp < 0) { fprintf(stderr, "Failed to load bitmap '%s' into surface 1\n", argv[1]); } gfx_bitBLT(fgfx, h1, 0,0, w, h, hbmp, 0,0, NULL, 0); gfx_destroy_surface(fgfx, hbmp); } sleep(2); gfx_attach_surface(fgfx, h2, GFX_VDEV_OSDGFX); // display it fprintf(stderr, "Show surface 2 and wait for 2 seconds\n");drawing(fgfx, h2, s2.uPlaneConfig); gfx_fill_test_pattern(fgfx, h2, &s2); if(argc > 2) { int w,h; int hbmp = gfx_LoadBitmap_Surface(fgfx, NULL, &w, &h, argv[2], 255); if(hbmp < 0) { fprintf(stderr, "Failed to load bitmap '%s' into surface 1\n", argv[2]); } gfx_bitBLT(fgfx, h2, 0,0, w, h, hbmp, 0,0, NULL, 0); gfx_destroy_surface(fgfx, hbmp); } sleep(2); gfx_attach_surface(fgfx, halpha, GFX_VDEV_OSDGFX); // display it fprintf(stderr, "Show surface alpha and wait for 2 seconds\n");drawing(fgfx, halpha, salpha.uPlaneConfig); // generate alpha pattern { UINT bpl, y, i; bpl = salpha.plane[0].uBytePerLine; y = salpha.plane[0].uHeight; for(i=0; i<y; i++) { memset(salpha.plane[0].pPlane+i*bpl, i%0xff, bpl); } } if(argc > 3) { GFX_PALETTE_T pal[256]; if(gfx_LoadBMP8b(&salpha, pal, 0,0, salpha.plane[0].uWidth, salpha.plane[0].uHeight, argv[3], 0, 0, 255)) { fprintf(stderr, "Failed to load bitmap '%s' into alpha surface\n", argv[3]); } else { // int i; // for(i=0; i<256; i++) pal[i].r = pal[i].g = pal[i].b = i, pal[i].a=255; gfx_set_surface_palette(fgfx, halpha, 0, 255, pal); } } sleep(2); // this is a test for reattachment feature, and is not needed if you // just want to detach h1. fprintf(stderr, "Show surface 2 and wait for 1 seconds\n"); gfx_attach_surface(fgfx, h2, GFX_VDEV_OSDGFX); // reattaching h2 should be handled correctly sleep(1); gfx_detach_surface(fgfx, h1, GFX_VDEV_OSDGFX); // hide it gfx_detach_surface(fgfx, halpha, GFX_VDEV_OSDGFX); // hide it fprintf(stderr, "random fill 300 \n"); { int i; for(i=0; i<300; i++) { UINT x = rand()%H1_X; UINT y = rand()%H1_Y; UINT h = rand()%H1_X + 20; UINT w = rand()%H1_Y + 20; UINT c = rand()%255 | (rand()%255<<8) | (rand()%255<<16) | (rand()%255<<24); // PINFOE("Fill (x,y,w,h, c) %d %d %d %d 0x%8.8x\n", x, y, w, h, c); gfx_fillBLT(fgfx, h2, x, y, w, h, c); } gfx_wait_for_engine(fgfx, 30000); } fprintf(stderr, "random masked fill 300 \n"); { int i; for(i=0; i<300; i++) { UINT x = rand()%H1_X; UINT y = rand()%H1_Y; UINT h = rand()%H1_X + 20; UINT w = rand()%H1_Y + 20; UINT c = rand()%255 | (rand()%255<<8) | (rand()%255<<16) | (rand()%255<<24); // PINFOE("Fill (x,y,w,h, c) %d %d %d %d 0x%8.8x\n", x, y, w, h, c); gfx_advancedFillBLT(fgfx, h2, x, y, w, h, c, hmask, 0, 0, GFX_ROP_DISABLE, 1, 0x00ff0000, 0, 0xf0f0f0f0); } gfx_wait_for_engine(fgfx, 30000); } sleep(2); fprintf(stderr, "bitBLT 1 to 2: random 300\n"); { int i; ALPHA_SELECT as; as.storedAlphaSelect = GFX_DEST_ALPHA_FROM_SOURCE; as.globalAlphaValue = 0xff; // not used for(i=0; i<300; i++) { UINT x = rand()%H2_X; UINT y = rand()%H2_Y; UINT h = rand()%H2_X+20; UINT w = rand()%H2_Y+20; UINT sh = rand()%H1_X; UINT sw = rand()%H1_Y; gfx_bitBLT(fgfx, h2, x, y, h, w, h1, sh, sw, &as, 1); } gfx_wait_for_engine(fgfx, 30000); } fprintf(stderr, "masked bitBLT 1 to 2: random 300\n"); { int i; ALPHA_SELECT as; as.storedAlphaSelect = GFX_DEST_ALPHA_FROM_SOURCE; as.globalAlphaValue = 0xff; // not used for(i=0; i<300; i++) { UINT x = rand()%H2_X; UINT y = rand()%H2_Y; UINT h = rand()%H2_X+20; UINT w = rand()%H2_Y+20; UINT sh = rand()%H1_X; UINT sw = rand()%H1_Y; gfx_advancedBitBLT(fgfx, h2, x, y, h, w, h1, sh, sw, hmask, 0, 0, GFX_ROP_DISABLE, 0, 0xf0f0f0f0, &as); } gfx_wait_for_engine(fgfx, 30000); }#if 0 //unsupported fprintf(stderr, "masked bitBLT 1 to 2 with pix mask: random 300\n"); { int i; ALPHA_SELECT as; as.storedAlphaSelect = GFX_DEST_ALPHA_FROM_SOURCE; as.globalAlphaValue = 0xff; // not used for(i=0; i<300; i++) { UINT x = rand()%H2_X; UINT y = rand()%H2_Y; UINT h = rand()%H2_X+20; UINT w = rand()%H2_Y+20; UINT sh = rand()%H1_X; UINT sw = rand()%H1_Y; gfx_advancedBitBLT(fgfx, h2, x, y, h, w, h1, sh, sw, hmask, 0, 0, GFX_ROP_DISABLE, 1, 0xf000fff0, &as); } gfx_wait_for_engine(fgfx, 30000); } sleep(2);#endif#if 1 // only supported for RGB8888 { int hrgb1, hrgb2; hrgb1 = hrgb2 = -1; hrgb1 = gfx_create_surface(fgfx, H1_X, H1_Y, GFX_SURFACE_ARGB_8888, GFX_VDEV_NULL, 0); hrgb2 = gfx_create_surface(fgfx, H2_X, H2_Y, GFX_SURFACE_ARGB_8888, GFX_VDEV_NULL, 0); if(hrgb1 >= 0 && hrgb2 >= 0) { gfx_bitBLT(fgfx, hrgb1, 0,0, H1_X, H1_Y, h1, 0,0, NULL, 0); gfx_bitBLT(fgfx, hrgb2, 0,0, H2_X, H2_Y, h2, 0,0, NULL, 0); fprintf(stderr, "blend 1 to 2: random 50\n"); { int i; ALPHA_BLEND_SELECT bs; bs.blendInputSelect = GFX_BLEND_ALPHA_FROM_GIVEN; bs.storedAlphaSelect = GFX_DEST_ALPHA_FROM_DESTINATION; for(i=0; i<50; i++) { UINT x = rand()%H2_X; UINT y = rand()%H2_Y; UINT h = rand()%H2_X+20; UINT w = rand()%H2_Y+20; UINT sh = rand()%H1_X; UINT sw = rand()%H1_Y; bs.globalAlphaValue = rand()%255; gfx_blend(fgfx, hrgb2, x, y, h, w, hrgb1, sh, sw, &bs); } gfx_wait_for_engine(fgfx, 30000); } gfx_bitBLT(fgfx, h2, 0,0, H2_X, H2_Y, hrgb2, 0,0, NULL, 0); sleep(2); fprintf(stderr, "blend with external alpha 1 to 2: random 50\n"); { int i; ALPHA_BLEND_SELECT bs; bs.blendInputSelect = GFX_BLEND_ALPHA_FROM_PATTERN; bs.storedAlphaSelect = GFX_DEST_ALPHA_FROM_GIVEN; bs.globalAlphaValue = 0xff; // not used for(i=0; i<50; i++) { UINT x = rand()%H2_X; UINT y = rand()%H2_Y; UINT h = rand()%H2_X+20; UINT w = rand()%H2_Y+20; UINT sh = rand()%H1_X; UINT sw = rand()%H1_Y; gfx_advancedBlend(fgfx, hrgb2, x, y, h, w, hrgb1, sh, sw, halpha, 0, 0, &bs); } gfx_wait_for_engine(fgfx, 30000); } gfx_bitBLT(fgfx, h2, 0,0, H2_X, H2_Y, hrgb2, 0,0, NULL, 0); sleep(2); } else { fprintf(stderr, "Failed to create RGB blend surface\n"); } if(hrgb1 >= 0) gfx_destroy_surface(fgfx, hrgb1); if(hrgb2 >= 0) gfx_destroy_surface(fgfx, hrgb2); }#endif#if 0 // not supported fprintf(stderr, "colorKey from 1 to 2: random 300\n"); { int i, x, y; COLOR_KEY_SELECT cs; ALPHA_SELECT as; GFX_SURFACE_DISPLAY_T dp; UINT dx, dy; dx = H1_X/4; dy = H1_Y/4; gfx_set_surface_clip_rect(fgfx, h1, NULL); // disable clipping on h1 gfx_fillBLT(fgfx, h1, 0, 0, dx, dy, 0x8000ff00); gfx_advancedFillBLT(fgfx, h1, 4, 4, dx-8, dy-8, 0xffff00ff, hmask, 0, 0, GFX_ROP_DISABLE, 1, 0xff000000, 0, 0xf0f0f0f0); memset(&dp, 0, sizeof(dp)); dp.uWinX = scr.uWidth/2 - dx/2; dp.uWinY = scr.uHeight/2 - dy/2; dp.uWinWidth = dx; dp.uWinHeight = dy; gfx_set_surface_display_parm(fgfx, h1, &dp); gfx_attach_surface(fgfx, h1, GFX_VDEV_OSDGFX); sleep(1); gfx_detach_surface(fgfx, h1, GFX_VDEV_OSDGFX); as.storedAlphaSelect = GFX_DEST_ALPHA_FROM_SOURCE; as.globalAlphaValue = 0xff; // not used cs.colorKeyCompareSelect = GFX_COLORKEY_COMPARE_SOURCE; cs.colorKeyCompareValue = 0xffff00ff; cs.colorKeyOutputSelect = GFX_COLORKEY_OUTPUT_KEEP; cs.replacementColor = 0xffff0000; x = dp.uWinX; y = dp.uWinY; gfx_set_surface_clip_rect(fgfx, h1, NULL); // disable clipping on h1 for(i=0; i<300; i++) { int xinc = rand()%10 - 5; int yinc = rand()%10 - 5; x += xinc; y += yinc; if(x < 0) x = 0; if(y < 0) y = 0; // save the block before do gfx_bitBLT(fgfx, h1, dx, 0, dx, dy, h2, x, y, &as, 0); gfx_colorKey(fgfx, h2, x, y, dx, dy, h1, 0, 0, &cs, &as); usleep(100*100); // restore it gfx_bitBLT(fgfx, h2, x, y, dx, dy, h1, dx, 0 , &as, 0); } gfx_wait_for_engine(fgfx, 30000); } sleep(2);#endif fprintf(stderr, "resize from 1 to 2: random 300\n"); { int i, r; for(i=0; i<300; i++) { UINT x = rand()%H2_X/2; UINT y = rand()%H2_Y/2; UINT h = rand()%H2_X + 4; UINT w = rand()%H2_Y + 4; UINT sx = rand()%H1_X/2; UINT sy = rand()%H1_Y/2; UINT sh = rand()%H1_X +4; UINT sw = rand()%H1_Y +4; // printf("%3d: %3d, %3d, %3d, %3d -> %3d, %3d, %3d, %3d ", i, sx, sy, sh, sw, x, y, h, w, r); fflush(stdout); r= gfx_resize(fgfx, h2, x, y, h, w, h1, sx, sy, sh, sw, 0xc0, 1); // printf("[%d]\n", r); fflush(stdout); } } sleep(2); fprintf(stderr, "That's all folks\n"); gfx_detach_surface(fgfx, h2, GFX_VDEV_OSDGFX); // hide it gfx_detach_surface(fgfx, hcursor, GFX_VDEV_OSDCUR); /* gfx_SaveBMP24b("save24.bmp", &s2, 0,0, s2.plane[0].uWidth, s2.plane[0].uHeight); { GFX_PALETTE_T pal[256]; gfx_get_surface_palette(fgfx, halpha, 0, 256, pal); gfx_SaveBMP8b("save8.bmp", &salpha, pal, 0,0, salpha.plane[0].uWidth, salpha.plane[0].uHeight); } */GFX_end: if(fgfx >= 0) { gfx_wait_for_engine(fgfx, 30000); if(s0.uPlaneConfig) gfx_unlock_surface(fgfx, h0, &s0); if(s1.uPlaneConfig) gfx_unlock_surface(fgfx, h1, &s1); if(s2.uPlaneConfig) gfx_unlock_surface(fgfx, h2, &s2); if(smask.uPlaneConfig) gfx_unlock_surface(fgfx, hmask, &smask); if(salpha.uPlaneConfig) gfx_unlock_surface(fgfx, halpha, &salpha); if(scursor.uPlaneConfig) gfx_unlock_surface(fgfx, hcursor, &scursor); if(syuv.uPlaneConfig) gfx_unlock_surface(fgfx, hyuv, &syuv); if(h1 >= 0) gfx_destroy_surface(fgfx, h1); if(h2 >= 0) gfx_destroy_surface(fgfx, h2); if(hyuv >= 0) gfx_destroy_surface(fgfx, hyuv); if(hmask >= 0) gfx_destroy_surface(fgfx, hmask); if(halpha >= 0) gfx_destroy_surface(fgfx, halpha); if(hcursor >= 0) gfx_destroy_surface(fgfx, hcursor); if (pid_child > 0) { kill(pid_child, SIGQUIT); wait(NULL); } gfx_close(fgfx); } return rtn;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -