display_lib#
若要使用此程式庫,應將標頭檔 SisoDisplay.h 新增至原始程式碼中。
#include <SisoDisplay.h>
此外, display_lib.lib 應新增至您的 Microsoft Visual Studio 專案中,或者 libdisplay_lib.so 加入您的 Linux 專案中。如果您使用 CMake,套件名稱為 SisoDisplayLib,且程式庫會儲存在變數中 ${SISODISPLAYLIB_LIBRARIES} 包含目錄儲存在變數中 ${SISODISPLAYLIB_INCLUDE_DIR}。請參閱 先決條件 以了解有關專案以及如何使用 CMake 的更多詳細資訊。
建立顯示視窗#
int CreateDisplay(
unsigned int bitsPerPixel,
unsigned int width,
unsigned int height);
void CloseDisplay(
int id);
void SetBufferWidth(
int id,
unsigned int width,
unsigned int height);
若要建立顯示視窗,可以呼叫 CreateDisplay() 函式。此函式在參數中需要每個像素的位元數和視窗尺寸。如果呼叫成功,它將傳回大於或等於零的值,這代表顯示視窗的識別碼。如果發生錯誤,則會傳回負值。
如果不再需要顯示視窗,則應呼叫 CloseDisplay() 函式。
顯示視窗的影像緩衝區尺寸最初會設為與視窗相同的寬度和高度。如果要顯示的影像非常大,可以將視窗大小設為較小的尺寸,並呼叫 SetBufferWidth() 函式來設定影像資料的緩衝區大小。
資訊
顯示程式庫僅限處理最大 2 GB 的影像。
以下範例顯示如何建立符合 applet 影像尺寸和 Pixel Format 的顯示視窗:
// get image dimensions and pixel format from applet
int result = FG_INVALID_PARAMETER;
int width = 0, height = 0, fgFormat = 0;
int widthId = Fg_getParameterIdByName(fg, "FG_WIDTH");
int heightId = Fg_getParameterIdByName(fg, "FG_HEIGHT");
int fgFormatId = Fg_getParameterIdByName(fg, "FG_FORMAT");
if (widthId > 0 && heightId > 0 && fgFormatId > 0) {
result = Fg_getParameterWithType(fg, widthId, &width, dma);
if (result == FG_OK) {
result = Fg_getParameterWithType(fg, heightId, &height, dma);
}
if (result == FG_OK) {
result = Fg_getParameterWithType(fg, fgFormatId, &fgFormat, dma);
}
}
// get number of bits per pixel for the format
int bitsPerPixel = FG_INVALID_VALUE;
if (result == FG_OK) {
bitsPerPixel = Fg_getBitsPerPixel(fgFormat);
}
if (bitsPerPixel <= 0) {
result = FG_INVALID_VALUE;
}
// create a display
int display = FG_INVALID_HANDLE;
if (result == FG_OK) {
display = CreateDisplay(bitsPerPixel, width, height);
}
if (display >= 0) {
// use display ...
CloseDisplay(display);
}
繪製至顯示視窗#
void DrawBuffer(
int id,
const void * buffer,
int frameNumber,
const char * title);
若要在顯示視窗中繪製影像資料,請使用函式 DrawBuffer() 即可呼叫。此函式在第一個參數中預期接收顯示視窗識別碼,並在第二個參數中接收指向包含影像資料之緩衝區的指標。其餘兩個參數可用於在顯示視窗的標題中顯示影格編號與一些文字。
以下範例顯示如何在簡單的擷取迴圈中顯示影像資料:
frameindex_t nextFrame = 1;
while (true) {
// wait for new images
frameindex_t newestFrame =
Fg_getLastPicNumberBlockingEx(fg, nextFrame, dma,
timeoutInSeconds, mem);
if (newestFrame > 0) {
// get pointer to current frame buffer
void * ptr = Fg_getImagePtrEx(fg, newestFrame, dma, mem);
// draw current frame buffer
DrawBuffer(display, ptr, newestFrame & 0x7fffffff,
"A Sample Image Display");
// calculate next frame
nextFrame = (newestFrame < FRAMEINDEX_MAX) ? newestFrame + 1 : 1;
} else {
// handle error ...
}
}