📄 uglvdemo.c
字号:
/* uglvdemo.c - Video demonstration program *//* Copyright 1999 - 2004 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01p,12mar04,rfm SPR#93487 - Fix video dimensions01o,16apr03,jlb Improved comments and program documentation01n,01apr03,sts [SPR 86504] Use uglRegistryFind() safely.01m,22feb02,msr Backward compatibility 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.*//*DESCRIPTION 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) */ /* 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)/** The color table is where we define the colors we want* to have available. The format is an array of* ARGB values paired with their allocated uglColor. */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 519#define VIDEO_REGION_BOTTOM 409#define VIDEO_REGION_TOP2 420#define VIDEO_REGION_BOTTOM2 699#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:** NOMANUAL */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: ** NOMANUAL */static void displayInit (void) { UGL_REG_DATA *pRegistryData; int i; UGL_FONT_DRIVER_ID fontDrvId; UGL_FONT_DEF fixedFontDef; /* Initialize UGL */ uglInitialize(); /* Obtain display device identifier */ pRegistryData = uglRegistryFind (UGL_DISPLAY_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { uglDeinitialize(); return; } devId = (UGL_DEVICE_ID)pRegistryData->id; /* Obtain the input service identifier */ pRegistryData = uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { uglDeinitialize(); return; } inputServiceId = (UGL_INPUT_SERVICE_ID)pRegistryData->id; /* Obtain the font driver identifier */ pRegistryData = uglRegistryFind (UGL_FONT_ENGINE_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { uglDeinitialize(); return; } fontDrvId = (UGL_FONT_DRIVER_ID)pRegistryData->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: ** NOMANUAL */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: ** NOMANUAL */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: ** NOMANUAL */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 B W W W W W B T T T T B W W W W W W B T T T B W W W W W W W B T T B W W W W W W W W B T B W W W W W B B B B B B W W B W W B T T T T B W B T B W W B T T T B B T T B W W B T T T B T T T T B W W B T T T T T T T B W W B T T T T T T T T B W W B T T T T T T T B W W B T T T T T T T T B B T T#undef T#undef B#undef W }; /* color of cursor */ static UGL_ARGB cursorClut[] = { UGL_MAKE_ARGB (0xff,0x00, 0x00, 0x00), UGL_MAKE_ARGB (0xff,0xFF, 0xFF, 0xFF) }; uglCursorInit(devId, 20, 20, modeInfo.width / 2, modeInfo.height / 2); pointerDib.width = 11; pointerDib.stride = 11; pointerDib.height = 19;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -