コンテンツにスキップ

display_lib#

ライブラリ display_lib は、画像データをシンプルなウィンドウに表示するための機能を提供します。このライブラリはGUIツールキットの代わりになるものではなく、GUIを持たないアプリケーションのデバッグ目的のみを想定しています。具体的には、このライブラリは画像の Scaling や変換のための機能を実装しておらず、画面サイズまでの画像データの表示に制限されています。

ライブラリを使用するには、インクルードファイル 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までの画像の処理に制限されています。

次の例は、アプレットの画像寸法と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() を呼び出すことができます。この関数は、第1パラメータにディスプレイウィンドウIDを、第2パラメータに画像データを含むバッファへのポインタを受け取ります。残りの2つのパラメータを使用して、フレーム番号やテキストをディスプレイウィンドウのタイトルに表示することができます。

次の例は、簡単な取り込みループで画像データを表示する方法を示しています。

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