📄 uglvdemo.c
字号:
* This routine adjusts the level of alpha blending ** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL */static void changeAlpha ( int alpha /* alpha up/down */ ) { UGL_LOCAL UINT8 alphaValue = 0xff; UGL_RGB rgbColor; UGL_COLOR uglColor; char textStr[80]; int alphaLevel; if ((!bounceBall) && !alpha) uglOSTaskCreate("tAlpha", (UGL_FPTR)alphaBall, 100, 0, 5000, 0,0,0,0,0); if (alpha) { bounceBall = 0; alphaValue += 0x10; } else alphaValue -= 0x10; alphaLevel = (alphaValue * 100)/255; rgbColor = UGL_MAKE_ARGB(alphaValue, 84, 84, 255); uglColorAlloc(devId, &rgbColor, UGL_NULL, &uglColor, 1); uglForegroundColorSet(gc, colorTable[WHITE].uglColor); uglBackgroundColorSet(gc, uglColor); uglLineWidthSet(gc, VIDEO_REGION_BORDER_WIDTH); uglRectangle(gc, BOX_IN_1_LEFT , BOX_IN_1_TOP, BOX_IN_1_RIGHT, BOX_IN_1_BOTTOM); sprintf (textStr,"Translucent level: %d%%",100 - alphaLevel); uglBackgroundColorSet(gc, uglColor); uglForegroundColorSet(gc, colorTable[RED].uglColor); uglFontSet(gc, fontFixed); uglTextDraw(gc, BOX_IN_1_LEFT + 20, BOX_IN_1_TOP + 20, strlen(textStr), textStr); }/**************************************************************************** captureVideo - capture video to a DDB** This routine captures video to a DDB ** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL */static void captureVideo (void) { FILE * fp; fp = fopen(pJpegFile, "w"); if (fp == NULL) printf("Unable to create JPEG file\n"); else { uglJpegFromDDB (jpegId, UGL_DISPLAY_ID, 8, 8, (VIDEO_REGION_RIGHT - VIDEO_REGION_LEFT) - 8, (overlayBottom - overlayTop) - 8, fp); fclose (fp); } }/**************************************************************************** zoomVideo - zoom video** This routine zooms the video in the video region on the display** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL */static void zoomVideo ( int zoom /* zoom in/zoom out */ ) { UGL_STATUS status; float width_f, height_f, zoom_f; char textStr[40]; UGL_UINT32 width, height; zoom_f = zoomFactor; if (zoom) zoom_f += .05; else zoom_f -= .05; /* bound the zoom amount */ if ((zoom_f < 1.00) || (zoom_f > 1.500)) return; if (zoom_f <= 1.01) { width = videoInfo.maxWidth; height = videoInfo.maxHeight; } else { width_f = videoInfo.maxWidth; height_f = videoInfo.maxHeight; width = width_f / zoomFactor; height = height_f / zoomFactor; } /* send update position to driver */ status = uglVideoStreamPut(videoId, gc, port, videoInfo.x, videoInfo.y, width, height); if (status == UGL_STATUS_OK) { /* h/w supported the operation, update the amount */ videoInfo.width = width; videoInfo.height = height; zoomFactor = zoom_f; sprintf(textStr,"Zoom factor = %1.2f ", zoomFactor); textDraw (gc,fontFixed, BLACK, WHITE, ZOOM_LINE, 560,textStr); } }/**************************************************************************** vdemo - start point for the video demo** This routine starts the video demo** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL */static UGL_STATUS vdemo (void) { int vidExtVersion; UGL_BOOL demoQuit = UGL_FALSE; UGL_UINT16 x, y, modifiers, uniCode; int value = 0; int attribType = 0; /* Initialize UGL and the display */ displayInit (); /* Create a graphics context and set GC appropriately*/ gc = uglGcCreate(devId); /* Clear the screen */ clearScreen(gc); /* Initialize a cursor */ cursorInit (); /* Initialize video extension */ videoId = uglVideoInit (devId, &vidExtVersion); if (videoId == UGL_NULL) { printf("Video extension was not initialized\n"); return (UGL_STATUS_ERROR); } /* Create the window for the video */ createVideoRegion (gc); createStatusRegion(); selectPort (0); centerTextDraw (gc,fontFixed, BLACK, RED, 5, 0, modeInfo.width, "VIDEO DEMONSTRATION PROGRAM");#ifdef AGFA_ALPHA_BLENDING centerTextDraw (gc, fontFixed, TRANS_RED, RED, 100, VIDEO_REGION_LEFT, VIDEO_REGION_RIGHT - VIDEO_REGION_LEFT + 1, "RED ALPHA-BLENDING STRING"); centerTextDraw (gc, fontFixed, TRANS_YELLOW, YELLOW, 150, VIDEO_REGION_LEFT, VIDEO_REGION_RIGHT - VIDEO_REGION_LEFT + 1, "YELLOW ALPHA-BLENDING STRING"); centerTextDraw (gc, fontFixed, TRANS_WHITE, WHITE, 200, VIDEO_REGION_LEFT, VIDEO_REGION_RIGHT - VIDEO_REGION_LEFT + 1, "WHITE ALPHA-BLENDING STRING"); centerTextDraw (gc, fontFixed, ALMOST_BLACK, BLACK, 250, VIDEO_REGION_LEFT, VIDEO_REGION_RIGHT - VIDEO_REGION_LEFT + 1, "BLACK ALPHA-BLENDING STRING");#endif /* AGFA_ALPHA_BLENDING */ /* Process input data */ while (!demoQuit) { char key; processInput (REPORT_KBD, &uniCode, &x, &y, &modifiers); key = uniCode; attribType = -1; switch (key) { case '1': case '2': /* select port 1 */ selectPort (key - '1'); break; case 'a': case 'A': /* change alpha blending level */ if (winMode == (OVERLAY_MODE_ALPHA)) changeAlpha (key - 'a'); else printf ("Alpha window not enabled\n"); break; case 'b': /* brightness down */ attribType = 3; value = --attrib.brightness; break; case 'B': /* brightness up */ attribType = 3; value = ++attrib.brightness; break; case 'c': /* contrast down */ attribType = 2; value = --attrib.contrast; break; case 'C': /* contrast up */ attribType = 2; value = ++attrib.contrast; break; case 'f': case 'F': /* freeze/unfreeze video */ freezeVideo (FREEZE_VIDEO_TOGGLE); break; case 'h': /* hue down */ attribType = 0; value = --attrib.hue; break; case 'H': /* hue up */ attribType = 0; value = ++attrib.hue; break; case 'j': case 'J': /* Capture video as JPEG image */ captureVideo(); break; case 'm': case 'M': /* move overlay */ moveOverlay(); break; case 'q': case 'Q': /* quit */ demoQuit = UGL_TRUE; break; case 's': /* saturation down */ attribType = 1; value = --attrib.saturation; break; case 'S': /* saturation up */ attribType = 1; value = ++attrib.saturation; break; case 'z': case 'Z': /* zoom video */ zoomVideo(key - 'z'); break; } if (attribType != -1) { char attribValue[40]; uglVideoAdapterInfo (videoId, port, UGL_VIDEO_ATTRIB_SET, &attrib); sprintf(attribValue,"%s = %3d ", attribName[attribType], value); textDraw (gc,fontFixed, BLACK, WHITE, attribLine[attribType], 560,attribValue ); } } bounceBall = 0; uglOSTaskDelay(sysClkRateGet()); uglCursorDeinit (devId); uglCursorBitmapDestroy (devId, pointerImage); uglOverlayDestroy (ovlyId); uglFontDestroy (fontFixed); uglDeinitialize(); return (0); }/**************************************************************************** uglvdemo - demonstrate video source handling** This routine demonstrates how WindML can work with video sources.** This example program demonstrates how to:**\ml *\m Initialize WindML*\m Identify the graphics device and input devices*\m Determine the resolution of the display*\m Create a graphics context*\m Allocate colors*\m Create an overlay within graphics device's frame buffer*\m Attach the JPEG decoder/encoder to the overlay*\m Query the video hardware for number of video sources*\m Select a video source to use and establish a configuration for the port*\m Enable alpha blending of the video source and the graphics plane*\m Change the brightness, contrast, hue, and saturation*\m Freeze the video image*\m Zoom up or down the video source*\m Move the overlay on the graphics plane*\m Capture the video source to a JPEG image*\m Releasing all resources and terminating a WindML application.*\me*** This demo can operate in two modes, color key blending with graphics plane* and alpha blending with the graphics plane. The <mode> parameter specifies * the type blending with the graphics plane. When <mode> is set to a '0', the* blending will be alpha blending. A <mode> value of '1' specifies that the * blending will be via color key.** The <jpegFile> parameter specifies the file to save a jpeg image to when a* video image is to be saved to a JPEG image file. When a value is not provided,* then the file is saved to 'capture.jpg' within the root directory.** ** The program is controlled via single keystrokes, as follows:**\is*\i a = decrease the alpha level and turn off ball bounce*\i A = increase the alpha level and enable ball bounce*\i B = increase brightness*\i b = decrease the brightness*\i C = increase the contrast*\i c = decrease the contrast*\i f,F = freeze/unfreeze the video image*\i H = increase the hue*\i h = decrease the hue*\i j,J = capture the image to file capture.jpg *\i m,M = move the video image*\i q,Q = quit program*\i S = increase the saturation*\i s = decrease the saturation*\i z = zoom out the image*\i Z = zoom in the image*\ie*** This program can also demonstrate the anti-aliasing features of the* Agfa font engine when alpha blending is used in support of the anti-* aliasing. To turn on this feature, this demo needs to be built with* Agfa support. This is accomplished by defining AGFA_ALPHA_BLENDING* which is defined within the makefile when Agfa is included.* * RETURNS: ** ERRNO: N/A** SEE ALSO: **/void uglvdemo ( int mode, /* window mode */ char *pFile /* file to capture jpeg image */ ) { /* set the jpeg file */ if (pFile == 0) pJpegFile = JPEG_IMG_FILE; else pJpegFile = pFile; switch (mode) { case 0: winMode = OVERLAY_MODE_ALPHA; printf("Window mode set to alpha blending\n"); break; case 1: winMode = OVERLAY_MODE_COLORKEY; printf("Window mode set to color key\n"); break; default: printf ("Illegal mode\n"); printf ("Usage: uglvdemo <mode>, <jpegFile>\n"); printf (" <mode> when 0, use alpha window mode\n"); printf (" when 1, use color key window mode\n"); printf (" <jpegFile> specifies the file to use for saved JPEG image\n"); return; } printf ("This program is controlled via single keystrokes, as follows:\n"); printf ("\n"); printf (" a = decrease the alpha level and turn off bouncing ball\n"); printf (" A = increase the alpha level and enable bouncing ball\n"); printf (" B = increase brightness\n"); printf (" b = decrease the brightness\n"); printf (" C = increase the contrast\n"); printf (" c = decrease the contrast\n"); printf (" f,F = freeze/unfreeze (toggle) the video image\n"); printf (" H = increase the hue\n"); printf (" h = decrease the hue\n"); printf (" j,J = capture the image to file %s\n",pJpegFile); printf (" m,M = move the video image\n"); printf (" q,Q = quit program\n"); printf (" S = increase the saturation\n"); printf (" s = decrease the saturation\n"); printf (" z = zoom out the image\n"); printf (" Z = zoom in the image\n"); uglOSTaskCreate("tWindMLvideo", (UGL_FPTR)vdemo, 110, 0, 10240, 0,0,0,0,0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -