📄 wexjpeg.c
字号:
void wexjpeg ( int mode, /* Operating mode */ char *path /* Path to the JPEG images */ ) { printf("See the target screen for instructions on this example.\n"); uglOSTaskCreate("tWindMLJpeg", (UGL_FPTR)windMLExampleJpeg, 110, UGL_FP_TASK, 10240, mode,0,0,0,0); }#endif/**************************************************************************** windMLExampleJpeg - the JPEG demo program ** This routine initializes the graphics device and input device and then* displays the three JPEG images waiting for operator input between each of* the JPEG images. After the final JPEG image is displayed the third * JPEG image is written to a file.** If the <mode> is greater than zero then the program delays the number of* clock ticks represented in <mode> between each JPEG image display. If* the value in <mode> is zero or less than zero, the program will await * operator input before moving to the next JPEG image.** The value in <path> is the root to the JPEG test images on the file* system.** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL*/void windMLExampleJpeg ( int mode, /* Operating mode */ char *path /* Path to the JPEG images */ ) { UGL_REG_DATA *pRegistryData; UGL_SIZE jpegWidth, jpegHeight; UGL_DDB_ID jpegDdbId = UGL_NULL; UGL_JPEG_MODE jpegMode; UGL_JPEG_ID jpegId = UGL_NULL; UGL_FONT_DRIVER_ID fontDrvId; UGL_FONT_DEF fontDef; char errorMessage[150],filename[150]; int textWidth, textHeight; FILE * fp; int jpegVersion; /* * This structure is filled in with data about the frame buffer * by the uglInfo() function. */ UGL_MODE_INFO modeInfo; /* * The device ID is critical to the operation of UGL. It * identifies individual "devices" (display adapter, keyboard, * font engine, etc.) to functions that may be able to work * with more than one device. */ UGL_DEVICE_ID devId; /* * Initialize UGL. Must do this before trying to do anything * else within UGL/WindML. */ uglInitialize(); /* Obtain the device identifier for the display */ pRegistryData = uglRegistryFind (UGL_DISPLAY_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { printf("WindML: Display not found. Exiting.\n"); uglDeinitialize(); return; } devId = (UGL_DEVICE_ID)pRegistryData->id; /* Obtain the font driver */ pRegistryData = uglRegistryFind (UGL_FONT_ENGINE_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { printf("WindML: Font engine not found. Exiting.\n"); uglDeinitialize(); return; } fontDrvId = (UGL_FONT_DRIVER_ID)pRegistryData->id; /* Create the font */ uglFontFindString(fontDrvId, "pixelSize=12", &fontDef); if ((font = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL) { printf("WindML: Font not found. Exiting.\n"); uglDeinitialize(); return; } pRegistryData = uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { printf("WindML: Input service not found. Exiting.\n"); uglDeinitialize(); return; } inputServiceId = (UGL_INPUT_SERVICE_ID)pRegistryData->id; /* * Obtain the dimensions of the display. We will use these * to center some of our objects. */ uglInfo(devId, UGL_MODE_INFO_REQ, &modeInfo); displayWidth = modeInfo.width; displayHeight = modeInfo.height; /* * Create a graphics context. Default values are set during * the creation. */ gc = uglGcCreate(devId); uglFontSet(gc, font); /* * Initialize colors. UGL maintains a Color Look-Up Table (CLUT) * for devices that do not represent colors directly. Essentially * some hardware is only able to represent a subset of colors at * any given time. To manage which colors will be available for * rendering, UGL uses color allocation. If the hardware is able * to represent colors directly, then the uglColorAlloc() function * still works, but it is then essentially a no-op. * * We have set up for 16 colors, so here we will "allocate" them * within UGL's CLUT (sometimes referred to as a "palette"). Colors * can also be de-allocated, or freed, with uglColorFree. * * Since the ARGB's are intermingled with the UGL_COLORs in * the colorTable, we must allocate each color individually. * If the ARGB's had a contiguous array of ARGBs, and likewise for * the UGL_COLORs, a single uglColorAlloc call could be made. * (see the windows example). * * Note that these colors will only take effect on an pseudo color system. * Without dithering, which is not provided in this example, high color * jpeg images loose much of their quality on pseudo color systems * particularly when only 16 colors are allocated. */ uglColorAlloc (devId, &colorTable[BLACK].rgbColor, UGL_NULL, &colorTable[BLACK].uglColor, 1); uglColorAlloc(devId, &colorTable[BLUE].rgbColor, UGL_NULL, &colorTable[BLUE].uglColor, 1); uglColorAlloc(devId, &colorTable[GREEN].rgbColor, UGL_NULL, &colorTable[GREEN].uglColor, 1); uglColorAlloc(devId, &colorTable[CYAN].rgbColor, UGL_NULL, &colorTable[CYAN].uglColor, 1); uglColorAlloc(devId, &colorTable[RED].rgbColor, UGL_NULL, &colorTable[RED].uglColor, 1); uglColorAlloc(devId, &colorTable[MAGENTA].rgbColor, UGL_NULL, &colorTable[MAGENTA].uglColor, 1); uglColorAlloc(devId, &colorTable[BROWN].rgbColor, UGL_NULL, &colorTable[BROWN].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTGRAY].rgbColor, UGL_NULL, &colorTable[LIGHTGRAY].uglColor, 1); uglColorAlloc(devId, &colorTable[DARKGRAY].rgbColor, UGL_NULL, &colorTable[DARKGRAY].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTBLUE].rgbColor, UGL_NULL, &colorTable[LIGHTBLUE].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTGREEN].rgbColor, UGL_NULL, &colorTable[LIGHTGREEN].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTCYAN].rgbColor, UGL_NULL, &colorTable[LIGHTCYAN].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTRED].rgbColor, UGL_NULL, &colorTable[LIGHTRED].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTMAGENTA].rgbColor, UGL_NULL, &colorTable[LIGHTMAGENTA].uglColor, 1); uglColorAlloc(devId, &colorTable[YELLOW].rgbColor, UGL_NULL, &colorTable[YELLOW].uglColor, 1); uglColorAlloc(devId, &colorTable[WHITE].rgbColor, UGL_NULL, &colorTable[WHITE].uglColor, 1); /* Initialize the Jpeg library and extension */ jpegId = uglJpegInit(devId, &jpegVersion); /* Check to see if Jpeg is available in the driver */ if (jpegId == UGL_NULL) { sprintf(errorMessage, "Jpeg not included in the driver"); uglTextSizeGet(font, &textWidth, &textHeight, -1, errorMessage); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTRED].uglColor); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 3, -1, errorMessage); pause(mode); uglFontDestroy(font); uglGcDestroy (gc); uglDeinitialize(); return; } /* Set the desired mode for the Jpeg engine */ jpegMode.quality = 75; jpegMode.smooth = 0; jpegMode.scale = 1; uglJpegModeSet(jpegId,&jpegMode); ClearScreen(gc); /* Decode the first image */ /* If no path was provided, assume the current directory. */ if (path == UGL_NULL || path[0] == UGL_NULL) sprintf(filename, "%s", JPEG_IMG_FILE1); else sprintf(filename, "%s/%s", path, JPEG_IMG_FILE1); fp = fopen(filename, "rb"); if (fp == NULL) { sprintf(errorMessage, "Unable to open %s.", JPEG_IMG_FILE1); uglTextSizeGet(font, &textWidth, &textHeight, -1, errorMessage); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTRED].uglColor); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 3, -1, errorMessage); pause(mode); } else { uglJpegToDDBFromFile (jpegId, fp, &jpegDdbId, UGL_NULL, 0, 0); fclose (fp); uglBitmapSizeGet(jpegDdbId, &jpegWidth, &jpegHeight); uglBitmapBlt(gc, jpegDdbId, 0, 0, jpegWidth - 1, jpegHeight - 1, UGL_DEFAULT_ID, 0, 0); uglBitmapDestroy(devId, jpegDdbId); jpegDdbId = UGL_NULL; pause(mode); ClearScreen(gc); } /* Decode the second image */ if (path == UGL_NULL || path[0] == UGL_NULL) sprintf(filename, "%s", JPEG_IMG_FILE2); else sprintf(filename, "%s/%s", path, JPEG_IMG_FILE2); fp = fopen(filename, "rb"); if (fp == NULL) { sprintf(errorMessage, "Unable to open %s.", JPEG_IMG_FILE2); uglTextSizeGet(font, &textWidth, &textHeight, -1, errorMessage); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTRED].uglColor); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 3, -1, errorMessage); pause(mode); } else { uglJpegToDDBFromFile (jpegId, fp, &jpegDdbId, UGL_NULL, 0, 0); fclose (fp); uglBitmapSizeGet(jpegDdbId, &jpegWidth, &jpegHeight); uglBitmapBlt(gc, jpegDdbId, 0, 0, jpegWidth - 1, jpegHeight - 1, UGL_DEFAULT_ID, 0, 0); uglBitmapDestroy(devId, jpegDdbId); jpegDdbId = UGL_NULL; pause(mode); ClearScreen(gc); } /* Decode the third image and create a jpeg from image 3 */ if (path == UGL_NULL || path[0] == UGL_NULL) sprintf(filename, "%s", JPEG_IMG_FILE3); else sprintf(filename, "%s/%s", path, JPEG_IMG_FILE3); fp = fopen(filename, "rb"); if (fp == NULL) { sprintf(errorMessage, "Unable to open %s.", JPEG_IMG_FILE3); uglTextSizeGet(font, &textWidth, &textHeight, -1, errorMessage); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTRED].uglColor); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 3, -1, errorMessage); pause(mode); } else { uglJpegToDDBFromFile (jpegId, fp, &jpegDdbId, UGL_NULL, 0, 0); fclose (fp); uglBitmapSizeGet(jpegDdbId, &jpegWidth, &jpegHeight); uglBitmapBlt(gc, jpegDdbId, 0, 0, jpegWidth - 1, jpegHeight - 1, UGL_DEFAULT_ID, 0, 0); uglBitmapDestroy(devId, jpegDdbId); jpegDdbId = UGL_NULL; /* Create Jpeg image on host */ if (path == UGL_NULL || path[0] == UGL_NULL) sprintf(filename, "%s", JPEG_IMG_FILE4); else sprintf(filename, "%s/%s", path, JPEG_IMG_FILE4); fp = fopen(filename, "wb"); if (fp == NULL) { sprintf(errorMessage, "Unable to create %s.", JPEG_IMG_FILE4); uglTextSizeGet(font, &textWidth, &textHeight, -1, errorMessage); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTRED].uglColor); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 3, -1, errorMessage); } else { uglJpegFromDDB (jpegId, UGL_DISPLAY_ID, 0, 0, jpegWidth - 1, jpegHeight - 1, fp); fclose (fp); } pause(mode); ClearScreen(gc); } /* Clean Up */ uglFontDestroy(font); uglGcDestroy (gc); uglDeinitialize(); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -