📄 wexbitmp.c
字号:
* This routine stops the bitmap example program.** RETURNS: ** ERRNO: N/A** SEE ALSO: wexbitmap() **/void wexbitmapStop (void) { stopWex = 1; }/**************************************************************************** windMLExampleBitmap - set up demo program and render graphics images** This routine initializes the graphics device and input device and then* performs various bitmap operations.** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL**/int windMLExampleBitmap (void) { /* For registry lookups. */ UGL_REG_DATA *pRegistryData; /* An int for miscellaneous counters,etc. */ int i; /* * The UGL Graphics Context (GC) is an important concept in UGL. * The GC contains data that various UGL functions can use. * If there were no such thing as a GC, most function calls * would require several more parameters to communicate that * information. */ UGL_GC_ID gc; /* * 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; /* * As mentioned in the comments to transparentMask, the mask pattern * is defined as a monochrome bitmap. To create the bitmap * (UGL_MDDB_ID), a Device Independent Bitmap (DIB) is used; in * particular a monochrome DIB (UGL_MDIB). The "DDB" in UGL_MDDB_ID * stands for Device Dependent Bitmap. Often the DDB is simply * referred to as a "bitmap" and the DIB is called a "dib" (it's * easier to pronounce dib than ddb). */ UGL_MDIB transMdib; /* * transDib is of type UGL_DIB since there is no such thing as an * UGL_TDIB. transDib is the DIB that will be used to create a * transparent bitmap, though, in conjunction with the MDIB. */ UGL_DIB transDib; UGL_TDDB_ID transBitmap; /* * We will also create a regular, non-transparent, bitmap. We will * use the same DIB as for the transparent bitmap. Since the DIB * information probably is not in the format required by the DDB, * the bitmap will not share any data with a bitmap. In other * words, the DIB can be discarded after the bitmap is created. * Or, as in this case, we will use the DIB to create another * bitmap. */ UGL_DDB_ID testBitmap; /* * A pointer to the image data that will be allocated for the color * DIB. */ UGL_COLOR * colorData; /* * 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) { uglDeinitialize(); return (UGL_STATUS_ERROR); } devId = (UGL_DEVICE_ID)pRegistryData->id; /* Obtain the input service */ pRegistryData = uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { uglDeinitialize(); return (UGL_STATUS_ERROR); } 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); /* * 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). */ 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); uglColorAlloc(devId, imageDib.pClut, UGL_NULL, imageColorTable, 6); /* * colorData is an array representing the image using UGL_COLOR * data elements for each pixel. UGL_COLOR is a container of * frame buffer type color information, so when the bitmap * is created from this information, no color conversion will be * required. This is one way of creating a bitmap from indexed * color image data. Alternatively, a clut could be created and * passed to the bitmap create functions, where the color * look-ups would occur. */ colorData = (UGL_COLOR *)UGL_MALLOC(32 * 32 * sizeof(UGL_COLOR)); for (i = 0; i < 32 * 32; i++) colorData[i] = colorTable[transparentData[i]].uglColor; /* * Create a DIB. The DIB, or Device Independent Bitmap, is a * linearly addressed bitmap format that can use different color * representations. The DIB does not need to use the color * representation used in the hardware frame buffer nor use its * addressing mode; ergo the DIB is "independent". This frees * us to define the format we want to use to create the DIB. */ /* * colorData is a linear array of UGL_COLOR elements which we * indicate in the DIB header using UGL_DEVICE_COLOR_32. */ transDib.pImage = (void *)colorData; transDib.colorFormat = UGL_DEVICE_COLOR_32; /* * Since we already derived the "direct" representation of the * color from the colorTable, we are not using a clut in the * DIB. We indicate that we have a direct representation in * the image data using UGL_DIB_DIRECT. */ transDib.clutSize = 0; transDib.pClut = UGL_NULL; transDib.imageFormat = UGL_DIB_DIRECT; /* * Set up the dimensions, which happen to all be 32 here. * Typically the stride will be equal to the width, but for * special cases (such as creating bitmaps from sub-sections * of a larger DIB) it can be larger. */ transDib.width = transDib.height = transDib.stride = 32; /* * We have set up everything for the creation of a regular * bitmap from a regular DIB. But, we are going to create * both a transparent bitmap and a regular bitmap from this * DIB. So now we set up the monochrome DIB for the creation * of the transparent bitmap. */ /* The mask has the same dimensions as the color bitmap. */ transMdib.width = transMdib.stride = transMdib.height = 32; /* * The monochome DIB is just bits (see transparentMask); nothing * more to set. */ transMdib.pImage = transparentMask; /* * When the bitmaps are created, the DIB format is converted to the * hardware frame buffer format. Knowledge of the frame buffer's * format is not required in order to manipulate, draw to, or blit * bitmaps using the UGL 2-D API. */ transBitmap = uglTransBitmapCreate(devId, &transDib, &transMdib, UGL_DIB_INIT_DATA, 0, UGL_NULL); testBitmap = uglBitmapCreate(devId, &imageDib, UGL_DIB_INIT_DATA, 0, UGL_NULL); /* Time to blit some images to the screen */ /* * It's not required, but it helps things along by locking resources * with the batch call. */ uglBatchStart(gc); ClearScreen(gc); /* * Blitting can only be done between bitmaps. We specify the rectangular * area within the originating bitmap to be blitted, and the destination * position. When the GC is created its "default bitmap" is set to the * screen bitmap, UGL_DISPLAY_ID. Since we have not changed it to another * bitmap, we can blit to the screen by using the UGL_DEFAULT_ID bitmap. */ uglBitmapBlt(gc, testBitmap,0,0,100,100, UGL_DEFAULT_ID, displayWidth / 2, displayHeight / 2 - 50); /* * Added flexibility is provided through the stretch blits, but at the * expense of speed for an blits that actually use a stretch * (i.e. other than 1:1). Here the destination coordinates must be * fully specified, so there are two more coordinates in the parameters. */ uglBitmapStretchBlt(gc,testBitmap,0,0,99,99,UGL_DEFAULT_ID, displayWidth / 2, 0,displayWidth-1, 100); /* * In addition to creating bitmaps and blitting them, we can draw on * them while "off-screen" and then blit the result to the screen. */ /* Select into the GC the bitmap we want to draw onto. */ uglDefaultBitmapSet(gc,testBitmap); /* Set the colors and line width (1 pixel wide) for drawing. */ uglForegroundColorSet(gc,colorTable[RED].uglColor); uglBackgroundColorSet(gc,colorTable[CYAN].uglColor); uglLineWidthSet(gc,1); /* Draw an ellipse onto the off-screen bitmap */ uglEllipse(gc,27,27,43,43,0,0,0,0); /* Set the GC to the screen so we can blit it. */ uglDefaultBitmapSet(gc,UGL_DISPLAY_ID); /* * Blit the modified bitmap image to the screen. We are stretching * it so the rectangle's single pixel width border will be displayed * as being several pixels wide. */ uglBitmapStretchBlt(gc,testBitmap,0,0,99,99,UGL_DEFAULT_ID, 0, 0, displayWidth / 2, displayHeight / 2); /* If we use a normal blit, the rectangle's border will be 1 pixel. */ uglBitmapBlt(gc, testBitmap,0,0,99,99, UGL_DEFAULT_ID, 3 * displayWidth / 4, displayHeight / 2 - 50); /* * Now lets blt a transparent bitmap.. */ uglBitmapBlt(gc, transBitmap,0,0,31,31,UGL_DEFAULT_ID, displayWidth / 2 - 50, 15); /* * UGL provides a function for "writing" a DIB to a bitmap (in fact, this * is used in the creation of the bitmap). Writing includes the * conversion of the DIB's format to that of the bitmap. This operation * is typically slower than blits. Since the frame buffer's format * defines the format of bitmaps, the frame buffer can be considered a * bitmap itself. The frame buffer bitmap is identified using * UGL_DISPLAY_ID. */ uglBitmapWrite(devId, &transDib, 0,0,31,31,UGL_DISPLAY_ID, displayWidth / 2 - 50, 50); /* Done with the UGL resources for graphics operations, so end batch. */ uglBatchEnd(gc); wexPause(); /* Clean Up */ UGL_FREE(colorData); /* Free DIB image data. */ uglBitmapDestroy(devId, testBitmap); uglTransBitmapDestroy (devId, transBitmap); uglGcDestroy (gc); uglDeinitialize(); return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -