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 ...
}
}