📄 uglvdemo.c
字号:
/* uglvdemo.c - Video demonstration program *//* Copyright 1999-2000 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01m,22feb02,msr Backward compatability for input API.01l,15nov01,gav Fixed event bug.01k,05nov01,gav Fixed misnamed devIds01j,05nov01,gav Change to new registry01i,05nov01,gav Change to new registry01h,09oct01,msr Ported to new UGL_Q_EVENT architecture.01g,03may01,rfm Fixed font find error01f,19dec00,gav Entry point identical to filename w/o extension.01e,18dec00,jlb Change freeze to toggle, do not freeze for capture, fix spellings, made functions static, corrected instructions01d,22nov00,jlb Added instructions, runtime options for mode/jpeg (SPR 36072)01c,23oct00,wdf Changed copyright date.01b,16oct00,rbp Added code to demonstrate Alpha-Blending.01a,20jan00,jlb written.*//*************************************************************** WindML Example - Video image handling** This example program demonstrates how a video stream may be displayed* to an overlay surface. ** To start the video demonstration program:** -> ld <uglvdemo_ugl.o* -> uglvdemo mode, jpegFile** Where <mode> specifies the type of window that will be created. A * value of 0 specifies a window using alpha blending. A value of 1* specifies that the window should be created using color key.** Where <jpegFile> specifies the file to save a jpeg image to when* the 'J' command is entered. When a value is not provided, then* the file is saved to 'capture.jpg' within the root directory.** This creates a video region that may be manipulated, as follows:*** Change the video attributes* Zoom in and out* Move the video window* Capture the image to a JPEG image* Place a object over the window and adjust the alpha value* Freeze the video*** The program is controlled via single keystrokes, as follows:** a = decrease the alpha level and turn off ball bounce* A = increase the alpha level and enable ball bounce* B = increase brightness* b = decrease the brightness* C = increase the contrast* c = decrease the contrast* f,F = freeze/unfreeze the video image* H = increase the hue* h = decrease the hue* j,J = capture the image to file capture.jpg * m,M = move the video image* q,Q = quit program* S = increase the saturation* s = decrease the saturation* z = zoom out the image* Z = zoom in the image*** 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.* **************************************************************************/ /* includes */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <ugl/ugl.h>#include <ugl/uglos.h>#include <ugl/uglfont.h>#include <ugl/uglMsg.h>#include <ugl/uglinput.h>#include <ugl/ugldib.h>#include <ugl/ext/video/uglvideo.h>#include <ugl/ext/jpeg/ugljpeg.h>#ifdef AGFA_ALPHA_BLENDING#include <ugl/driver/font/udAgfa.h>#endif /* AGFA_ALPHA_BLENDING */ /* file to write JPEG captured image */#define JPEG_IMG_FILE "capture.jpg"/* Video overlay display method */#define OVERLAY_MODE_ALPHA UGL_OVERLAY_WINDOW_MODE | UGL_OVERLAY_ALPHA_BLEND#define OVERLAY_MODE_COLORKEY UGL_OVERLAY_COLORKEY_MODE/* Color definitions */#define BLACK (0)#define BLUE (1)#define GREEN (2)#define CYAN (3)#define RED (4)#define MAGENTA (5)#define BROWN (6)#define LIGHTGRAY (7)#define DARKGRAY (8)#define LIGHTBLUE (9)#define LIGHTGREEN (10)#define LIGHTCYAN (11)#define LIGHTRED (12)#define LIGHTMAGENTA (13)#define YELLOW (14)#define WHITE (15)#define TRANS_BLACK (16)#define TRANS_BLUE (17)#define TRANS_GREEN (18)#define TRANS_CYAN (19)#define TRANS_RED (20)#define TRANS_MAGENTA (21)#define TRANS_BROWN (22)#define TRANS_LIGHTGRAY (23)#define TRANS_DARKGRAY (24)#define TRANS_LIGHTBLUE (25)#define TRANS_LIGHTGREEN (26)#define TRANS_LIGHTCYAN (27)#define TRANS_LIGHTRED (28)#define TRANS_LIGHTMAGENTA (29)#define TRANS_YELLOW (30)#define TRANS_WHITE (31)#define ALMOST_BLACK (32)#define TRANS (255)#define INVERT (254)struct _colorStruct { UGL_RGB rgbColor; UGL_COLOR uglColor; }colorTable[] = { { UGL_MAKE_ARGB(0xff, 0, 0, 0), 0}, /* Black */ { UGL_MAKE_ARGB(0xff, 0, 0, 168), 0}, /* Blue */ { UGL_MAKE_ARGB(0xff, 0, 168, 0), 0}, /* Green */ { UGL_MAKE_ARGB(0xff, 0, 168, 168), 0}, /* Cyan */ { UGL_MAKE_ARGB(0xff, 168, 0, 0), 0}, /* Red */ { UGL_MAKE_ARGB(0xff, 168, 0, 168), 0}, /* Magenta */ { UGL_MAKE_ARGB(0xff, 168, 84, 0), 0}, /* Brown */ { UGL_MAKE_ARGB(0xff, 168, 168, 168), 0}, /* Light gray */ { UGL_MAKE_ARGB(0xff, 84, 84, 84), 0}, /* Dark Gray */ { UGL_MAKE_ARGB(0xff, 84, 84, 255), 0}, /* Light blue */ { UGL_MAKE_ARGB(0xff, 84, 255, 84), 0}, /* Light green */ { UGL_MAKE_ARGB(0xff, 84, 255, 255), 0}, /* Light cyan */ { UGL_MAKE_ARGB(0xff, 255, 84, 84), 0}, /* Light red */ { UGL_MAKE_ARGB(0xff, 255, 84, 255), 0}, /* Light magenta */ { UGL_MAKE_ARGB(0xff, 255, 255, 84), 0}, /* yellow */ { UGL_MAKE_ARGB(0xff, 255, 255, 255), 0}, /* White */ { UGL_MAKE_ARGB(0x00, 0, 0, 0), 0}, /* Trans Black */ { UGL_MAKE_ARGB(0x00, 0, 0, 168), 0}, /* Trans Blue */ { UGL_MAKE_ARGB(0x00, 0, 168, 0), 0}, /* Trans Green */ { UGL_MAKE_ARGB(0x00, 0, 168, 168), 0}, /* Trans Cyan */ { UGL_MAKE_ARGB(0x00, 168, 0, 0), 0}, /* Trans Red */ { UGL_MAKE_ARGB(0x00, 168, 0, 168), 0}, /* Trans Magenta */ { UGL_MAKE_ARGB(0x00, 168, 84, 0), 0}, /* Trans Brown */ { UGL_MAKE_ARGB(0x00, 168, 168, 168), 0}, /* Trans Light gray */ { UGL_MAKE_ARGB(0x00, 84, 84, 84), 0}, /* Trans Dark Gray */ { UGL_MAKE_ARGB(0x00, 84, 84, 255), 0}, /* Trans Light blue */ { UGL_MAKE_ARGB(0x00, 84, 255, 84), 0}, /* Trans Light green */ { UGL_MAKE_ARGB(0x00, 84, 255, 255), 0}, /* Trans Light cyan */ { UGL_MAKE_ARGB(0x00, 255, 84, 84), 0}, /* Trans Light red */ { UGL_MAKE_ARGB(0x00, 255, 84, 255), 0}, /* Trans Light magenta */ { UGL_MAKE_ARGB(0x00, 255, 255, 84), 0}, /* Trans yellow */ { UGL_MAKE_ARGB(0x00, 255, 255, 255), 0}, /* Trans White */ { UGL_MAKE_ARGB(0x00, 0, 0, 0x10), 0} /* Almost black */ };#define REPORT_KBD 1#define REPORT_PTR 2#define REPORT_BOTH (REPORT_KBD | REPORT_PTR)UGL_DEVICE_ID devId; /* graphics device identifier */UGL_DEVICE_ID ovlyId; /* overlay device identifier */UGL_JPEG_ID jpegId; /* jpeg identifier */UGL_INPUT_SERVICE_ID inputServiceId; /* input service identifier */UGL_VIDEO_ID videoId; /* video device identifier */UGL_CDDB_ID pointerImage; /* DDB used for pointer */UGL_GC_ID gc; /* graphics context */UGL_FB_INFO modeInfo; /* frame buffer data */UGL_FONT_ID fontFixed; /* font used */UGL_VIDEO_ATTRIB attrib = {0}; /* color attributes for video */UGL_VIDEO_INFO videoInfo; /* video info for current port */int port = -1; /* current video port */UGL_UINT32 availPorts; /* list of ports available */float zoomFactor; /* zoom factor on video */UGL_UINT32 overlayTop; /* current top line of overlay */UGL_UINT32 overlayBottom; /* current bottom line of overlay */static char * blank = " ";char * pJpegFile; /* name of JPEG file */int winMode; /* window mode (alpha or color key) *//* Characteristics of video region */#define VIDEO_REGION_BORDER_COLOR BLUE#define VIDEO_REGION_BORDER_WIDTH 3#define VIDEO_COLOR_KEY ALMOST_BLACK#define VIDEO_REGION_LEFT 50#define VIDEO_REGION_TOP 50#define VIDEO_REGION_RIGHT 520#define VIDEO_REGION_BOTTOM 410#define VIDEO_REGION_TOP2 420#define VIDEO_REGION_BOTTOM2 700#define BOX_IN_1_TOP 100#define BOX_IN_1_BOTTOM 300#define BOX_IN_1_LEFT 100#define BOX_IN_1_RIGHT 300#define BOX_IN_2_TOP 450#define BOX_IN_2_BOTTOM 525#define BOX_IN_2_LEFT 100#define BOX_IN_2_RIGHT 200#define TEXT_REGION2_LINE 500/* Freeze video modes */#define FREEZE_VIDEO 0#define UNFREEZE_VIDEO 1#define FREEZE_VIDEO_TOGGLE 2/* status region */#define LINE_HT 20#define ACTIVE_LINE 200#define FREEZE_LINE (ACTIVE_LINE + LINE_HT)#define ZOOM_LINE (FREEZE_LINE + LINE_HT)#define CONTRAST_LINE (ZOOM_LINE + LINE_HT)#define HUE_LINE (CONTRAST_LINE + LINE_HT)#define SATURATION_LINE (HUE_LINE + LINE_HT)#define BRIGHTNESS_LINE (SATURATION_LINE + LINE_HT)#define PAN_LINE (BRIGHTNESS_LINE + LINE_HT) char * attribName[] = {"Hue","Saturation","Contrast","Brightness"};int attribLine[] = {HUE_LINE,SATURATION_LINE,CONTRAST_LINE,BRIGHTNESS_LINE}; int bounceBall = 0;/* Forward references */extern int sysClkRateGet();/**************************************************************************** clearScreen - clear the display screen** This routine clears the display screen, set it to black.** RETURNS: ** ERRNO: N/A** SEE ALSO: */static void clearScreen ( UGL_GC_ID gc ) { uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[BLACK].uglColor); uglRectangle(gc, 0, 0, modeInfo.width - 1, modeInfo.height - 1); }/**************************************************************************** displayInit - initializes the display system** This routine initializes the UGL display system.** RETURNS: ** ERRNO: N/A** SEE ALSO: **/static void displayInit (void) { int i; UGL_FONT_DRIVER_ID fontDrvId; UGL_FONT_DEF fixedFontDef; /* Initialize UGL */ uglInitialize(); /* Obtain display device identifier */ devId = (UGL_DEVICE_ID)uglRegistryFind (UGL_DISPLAY_TYPE, 0, 0,0)->id; /* Obtain the input service identifier */ inputServiceId = (UGL_INPUT_SERVICE_ID)uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0,0)->id; /* Obtain the font driver identifier */ fontDrvId = (UGL_FONT_DRIVER_ID)uglRegistryFind (UGL_FONT_ENGINE_TYPE, 0, 0,0)->id; /* Obtain the characteristics of the display */ uglInfo(devId, UGL_FB_INFO_REQ, &modeInfo); /* Initialize colors */ for (i = 0; i <= ALMOST_BLACK; i++) uglColorAlloc (devId, &colorTable[i].rgbColor, UGL_NULL, &colorTable[i].uglColor, 1); /* create a font */ uglFontFindString(fontDrvId, "pixelSize = 13; name=Fixed", &fixedFontDef); if ((fontFixed = uglFontCreate(fontDrvId, &fixedFontDef)) == UGL_NULL) { printf ("Font not found. Exiting.\n"); exit (0); }#ifdef AGFA_ALPHA_BLENDING uglAgfaFontGrayscaleSet (fontFixed, UGL_AGFA_GAGG, 4, 4, 1, 1);#endif /* AGFA_ALPHA_BLENDING */ }/**************************************************************************** centerTextDraw - draw text centered on line** This routine draws text centered on a specified line.** RETURNS: ** ERRNO: N/A** SEE ALSO: **/static void centerTextDraw ( UGL_GC_ID gc, /* graphics context */ UGL_FONT_ID fontId, /* font to draw text */ UGL_ORD bgColor, /* background color */ UGL_ORD fgColor, /* foreground color */ UGL_ORD line, /* Y position to draw text */ UGL_ORD left, /* left X */ UGL_ORD right, /* right X */ char * textStr /* string to draw */ ) { int numChars, width, height, center; uglBackgroundColorSet(gc, colorTable[bgColor].uglColor); uglForegroundColorSet(gc, colorTable[fgColor].uglColor); uglFontSet(gc, fontId); numChars = strlen(textStr); uglTextSizeGet(fontId, &width, &height, numChars, textStr); center = (right - left - width)/2; uglBatchStart(gc); uglTextDraw(gc, (left+center), (line + height), numChars, textStr); uglBatchEnd(gc); }/**************************************************************************** textDraw - draw text** This routine draws text on the display at a specified location.** RETURNS: ** ERRNO: N/A** SEE ALSO: **/static void textDraw ( UGL_GC_ID gc, /* graphics context to use */ UGL_FONT_ID fontId, /* font to use */ UGL_ORD bgColor, /* background color */ UGL_ORD fgColor, /* foreground color */ UGL_ORD line, /* Y position */ UGL_ORD left, /* X position */ char * textStr /* string to draw */ ) { uglBackgroundColorSet(gc, colorTable[bgColor].uglColor); uglForegroundColorSet(gc, colorTable[fgColor].uglColor); uglFontSet(gc, fontId); uglTextDraw(gc, left, line, strlen(textStr), textStr); } /**************************************************************************** cursorInit - initializes the cursor** This routine initializes the cursor.** RETURNS: ** ERRNO: N/A** SEE ALSO: **/static void cursorInit (void) { UGL_CDIB pointerDib; /* bitmap of cursor image */ static UGL_UINT8 pointerData[] = {#define T UGL_CURSOR_COLOR_TRANSPARENT,#define B 0,#define W 1, B T T T T T T T T T T B B T T T T T T T T T B W B T T T T T T T T B W W B T T T T T T T B W W W B T T T T T T B W W W W B T T T T T
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -