ルート画像の確保(import版)

Namespace: fvalgcli
Assembly: fvalgcli_fga (in fvalgcli_fga.dll) Version: 3.1.0.0 (3.1.0.3)

Syntax

C#
public static FHANDLE fnFGA_img_root_import_alloc(
	IntPtr[] adrss,
	int channels,
	int type,
	SIZE_T step,
	int width,
	int height
)
Visual Basic
Public Shared Function fnFGA_img_root_import_alloc ( 
	adrss As IntPtr(),
	channels As Integer,
	type As Integer,
	step As SIZE_T,
	width As Integer,
	height As Integer
) As FHANDLE

Parameters

adrss
Type: array<System..::..IntPtr>[]()[][]
画像メモリのポインタ列。 (チャネル0から順番になった配列で channels パラメータ個分の要素が必要)
channels
Type: System..::..Int32
チャネル数(1〜16)
type
Type: System..::..Int32
画像種別。f_imgtype に定義された定数を指定。
step
Type: fvalgcli..::..SIZE_T
画像ステップ(メモリ横幅:画素サイズ単位) 但し、下記の画像型の場合は単位が変わります。
  • F_IMG_BIN型の場合:UINTブロック数
  • F_IMG_RGBTRIPLE型の場合:バイト単位
width
Type: System..::..Int32
画像幅(1以上)
height
Type: System..::..Int32
画像高さ(1以上)

Return Value

Type: FHANDLE
外部で確保された画像メモリ空間を使用してルート画像を作成し、 確保された画像のハンドルを返します。 ライセンスエラー、未初期化エラー、またはメモリ不足で確保に失敗した場合はNULLを返します。

Examples

C# Copy imageCopy
//    $Revision: 1.2 $

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using fvalgcli;
using cudaError_t = System.Int32;

namespace TC
{
    public partial class FIE
    {
        /// <summary>
        /// ルート画像の確保(import版).
        /// </summary>
        [FvPluginExecute]
        public unsafe void fnFGA_img_root_import_alloc()
        {
            FHANDLE hroot = FHANDLE.Zero;
            int type = (int)f_imgtype.F_IMG_UC8;
            int channels = 3;
            int step = 640;
            int width = 640;
            int height = 480;
            IntPtr[] devPtrs = new IntPtr[channels];
            IntPtr cuda = LoadLibrary(cudart);

            try
            {
                // 画像メモリ空間の確保.
                if (cuda != IntPtr.Zero)
                {
                    for (int ch = 0; ch < channels; ch++)
                    {
                        cudaMalloc(ref devPtrs[ch], width * height * sizeof(byte));
                    }
                }

                // 処理の実行.
                hroot = fga.fnFGA_img_root_import_alloc(devPtrs, channels, type, step, width, height);
                if (hroot == IntPtr.Zero)
                    throw new FvException(f_err.F_ERR_NOMEMORY, "fnFGA_img_root_import_alloc: エラーが発生しました。");
            }
            finally
            {
                // オブジェクトの開放.
                hroot.Dispose();

                // メモリの開放.
                if (cuda != IntPtr.Zero)
                {
                    for (int ch = 0; ch < channels; ch++)
                    {
                        cudaFree(devPtrs[ch]);
                    }
                }
            }
        }

        // Heap API flags
        const int HEAP_ZERO_MEMORY = 0x00000008;

        [DllImport("kernel32")]
        static extern int GetProcessHeap();

        [DllImport("kernel32.dll")]
        public static extern IntPtr HeapAlloc(int hHeap, uint dwFlags, int dwBytes);

        [DllImport("kernel32.dll")]
        public static extern bool HeapFree(int hHeap, uint flags, IntPtr block);

        /// <summary>
        /// NVIDIA CUDA Runtime Library
        /// </summary>
        public const string cudart = "cudart64_101.dll";

        /// <summary>
        /// NVIDIA CUDA API: メモリ確保
        /// </summary>
        /// <param name="devPtr"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [DllImport(cudart, CallingConvention = CallingConvention.Cdecl)]
        public static extern cudaError_t cudaMalloc(ref IntPtr devPtr, SIZE_T size);

        /// <summary>
        /// NVIDIA CUDA API: メモリ解放
        /// </summary>
        /// <param name="devPtr"></param>
        /// <returns></returns>
        [DllImport(cudart, CallingConvention = CallingConvention.Cdecl)]
        public static extern cudaError_t cudaFree(IntPtr devPtr);

        /// <summary>
        /// ライブラリロード
        /// </summary>
        /// <param name="lpFileName">ファイルパス</param>
        /// <returns>ハンドル</returns>
        [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
        public static extern IntPtr LoadLibrary(string lpFileName);
    }
}

Exceptions

ExceptionCondition
System.IO..::..FileNotFoundException 実行環境に NVIDIA CUDA Runtime が存在しない場合、FGA ライブラリのロードが失敗し、この例外が発行されます。
必要な環境については FGA ライブラリ説明書 をご参照ください。
例外メッセージの例 (32bit 日本語 O/S の場合):
DLL 'fgamt.x86.3.0.0.dll' を読み込めません: 指定されたモジュールが見つかりません。 (HRESULT からの例外: 0x8007007E)

See Also