ホーム › Web.InternetExplorer › DitherTo8
DitherTo8
関数画像ビットを8ビットカラーへディザリング変換する。
シグネチャ
// ImgUtil.dll
#include <windows.h>
HRESULT DitherTo8(
BYTE* pDestBits,
INT nDestPitch,
BYTE* pSrcBits,
INT nSrcPitch,
const GUID* bfidSrc,
RGBQUAD* prgbDestColors,
RGBQUAD* prgbSrcColors,
BYTE* pbDestInvMap,
INT x,
INT y,
INT cx,
INT cy,
INT lDestTrans,
INT lSrcTrans
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pDestBits | BYTE* | inout | ディザリング結果を書き込む8bit出力ビットマップのピクセルデータへのポインタを指定する。 |
| nDestPitch | INT | in | 出力ビットマップの1走査線あたりのバイト数(ピッチ)を指定する。 |
| pSrcBits | BYTE* | inout | 変換元ビットマップのピクセルデータへのポインタを指定する。 |
| nSrcPitch | INT | in | 変換元ビットマップの1走査線あたりのバイト数(ピッチ)を指定する。 |
| bfidSrc | GUID* | in | 変換元のピクセル形式を識別するビットフィールドGUIDへのポインタを指定する。 |
| prgbDestColors | RGBQUAD* | inout | 出力先の8bitパレットを表すRGBQUAD配列へのポインタを指定する。 |
| prgbSrcColors | RGBQUAD* | inout | 変換元の色パレットを表すRGBQUAD配列へのポインタを指定する。NULL可。 |
| pbDestInvMap | BYTE* | inout | 出力先パレットに対応する逆カラーマップへのポインタを指定する。 |
| x | INT | in | 処理対象矩形の左上X座標を指定する。 |
| y | INT | in | 処理対象矩形の左上Y座標を指定する。 |
| cx | INT | in | 処理対象矩形の幅をピクセル単位で指定する。 |
| cy | INT | in | 処理対象矩形の高さをピクセル単位で指定する。 |
| lDestTrans | INT | in | 出力先で透明として扱うパレットインデックスを指定する。未使用時は-1。 |
| lSrcTrans | INT | in | 変換元で透明として扱う色インデックスを指定する。未使用時は-1。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// ImgUtil.dll
#include <windows.h>
HRESULT DitherTo8(
BYTE* pDestBits,
INT nDestPitch,
BYTE* pSrcBits,
INT nSrcPitch,
const GUID* bfidSrc,
RGBQUAD* prgbDestColors,
RGBQUAD* prgbSrcColors,
BYTE* pbDestInvMap,
INT x,
INT y,
INT cx,
INT cy,
INT lDestTrans,
INT lSrcTrans
);[DllImport("ImgUtil.dll", ExactSpelling = true)]
static extern int DitherTo8(
IntPtr pDestBits, // BYTE* in/out
int nDestPitch, // INT
IntPtr pSrcBits, // BYTE* in/out
int nSrcPitch, // INT
ref Guid bfidSrc, // GUID*
IntPtr prgbDestColors, // RGBQUAD* in/out
IntPtr prgbSrcColors, // RGBQUAD* in/out
IntPtr pbDestInvMap, // BYTE* in/out
int x, // INT
int y, // INT
int cx, // INT
int cy, // INT
int lDestTrans, // INT
int lSrcTrans // INT
);<DllImport("ImgUtil.dll", ExactSpelling:=True)>
Public Shared Function DitherTo8(
pDestBits As IntPtr, ' BYTE* in/out
nDestPitch As Integer, ' INT
pSrcBits As IntPtr, ' BYTE* in/out
nSrcPitch As Integer, ' INT
ByRef bfidSrc As Guid, ' GUID*
prgbDestColors As IntPtr, ' RGBQUAD* in/out
prgbSrcColors As IntPtr, ' RGBQUAD* in/out
pbDestInvMap As IntPtr, ' BYTE* in/out
x As Integer, ' INT
y As Integer, ' INT
cx As Integer, ' INT
cy As Integer, ' INT
lDestTrans As Integer, ' INT
lSrcTrans As Integer ' INT
) As Integer
End Function' pDestBits : BYTE* in/out
' nDestPitch : INT
' pSrcBits : BYTE* in/out
' nSrcPitch : INT
' bfidSrc : GUID*
' prgbDestColors : RGBQUAD* in/out
' prgbSrcColors : RGBQUAD* in/out
' pbDestInvMap : BYTE* in/out
' x : INT
' y : INT
' cx : INT
' cy : INT
' lDestTrans : INT
' lSrcTrans : INT
Declare PtrSafe Function DitherTo8 Lib "imgutil" ( _
ByVal pDestBits As LongPtr, _
ByVal nDestPitch As Long, _
ByVal pSrcBits As LongPtr, _
ByVal nSrcPitch As Long, _
ByVal bfidSrc As LongPtr, _
ByVal prgbDestColors As LongPtr, _
ByVal prgbSrcColors As LongPtr, _
ByVal pbDestInvMap As LongPtr, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal lDestTrans As Long, _
ByVal lSrcTrans As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DitherTo8 = ctypes.windll.imgutil.DitherTo8
DitherTo8.restype = ctypes.c_int
DitherTo8.argtypes = [
ctypes.POINTER(ctypes.c_ubyte), # pDestBits : BYTE* in/out
ctypes.c_int, # nDestPitch : INT
ctypes.POINTER(ctypes.c_ubyte), # pSrcBits : BYTE* in/out
ctypes.c_int, # nSrcPitch : INT
ctypes.c_void_p, # bfidSrc : GUID*
ctypes.c_void_p, # prgbDestColors : RGBQUAD* in/out
ctypes.c_void_p, # prgbSrcColors : RGBQUAD* in/out
ctypes.POINTER(ctypes.c_ubyte), # pbDestInvMap : BYTE* in/out
ctypes.c_int, # x : INT
ctypes.c_int, # y : INT
ctypes.c_int, # cx : INT
ctypes.c_int, # cy : INT
ctypes.c_int, # lDestTrans : INT
ctypes.c_int, # lSrcTrans : INT
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ImgUtil.dll')
DitherTo8 = Fiddle::Function.new(
lib['DitherTo8'],
[
Fiddle::TYPE_VOIDP, # pDestBits : BYTE* in/out
Fiddle::TYPE_INT, # nDestPitch : INT
Fiddle::TYPE_VOIDP, # pSrcBits : BYTE* in/out
Fiddle::TYPE_INT, # nSrcPitch : INT
Fiddle::TYPE_VOIDP, # bfidSrc : GUID*
Fiddle::TYPE_VOIDP, # prgbDestColors : RGBQUAD* in/out
Fiddle::TYPE_VOIDP, # prgbSrcColors : RGBQUAD* in/out
Fiddle::TYPE_VOIDP, # pbDestInvMap : BYTE* in/out
Fiddle::TYPE_INT, # x : INT
Fiddle::TYPE_INT, # y : INT
Fiddle::TYPE_INT, # cx : INT
Fiddle::TYPE_INT, # cy : INT
Fiddle::TYPE_INT, # lDestTrans : INT
Fiddle::TYPE_INT, # lSrcTrans : INT
],
Fiddle::TYPE_INT)#[link(name = "imgutil")]
extern "system" {
fn DitherTo8(
pDestBits: *mut u8, // BYTE* in/out
nDestPitch: i32, // INT
pSrcBits: *mut u8, // BYTE* in/out
nSrcPitch: i32, // INT
bfidSrc: *const GUID, // GUID*
prgbDestColors: *mut RGBQUAD, // RGBQUAD* in/out
prgbSrcColors: *mut RGBQUAD, // RGBQUAD* in/out
pbDestInvMap: *mut u8, // BYTE* in/out
x: i32, // INT
y: i32, // INT
cx: i32, // INT
cy: i32, // INT
lDestTrans: i32, // INT
lSrcTrans: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ImgUtil.dll")]
public static extern int DitherTo8(IntPtr pDestBits, int nDestPitch, IntPtr pSrcBits, int nSrcPitch, ref Guid bfidSrc, IntPtr prgbDestColors, IntPtr prgbSrcColors, IntPtr pbDestInvMap, int x, int y, int cx, int cy, int lDestTrans, int lSrcTrans);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ImgUtil_DitherTo8' -Namespace Win32 -PassThru
# $api::DitherTo8(pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans)#uselib "ImgUtil.dll"
#func global DitherTo8 "DitherTo8" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DitherTo8 varptr(pDestBits), nDestPitch, varptr(pSrcBits), nSrcPitch, varptr(bfidSrc), varptr(prgbDestColors), varptr(prgbSrcColors), varptr(pbDestInvMap), x, y, cx, cy, lDestTrans, lSrcTrans ; 戻り値は stat
; pDestBits : BYTE* in/out -> "sptr"
; nDestPitch : INT -> "sptr"
; pSrcBits : BYTE* in/out -> "sptr"
; nSrcPitch : INT -> "sptr"
; bfidSrc : GUID* -> "sptr"
; prgbDestColors : RGBQUAD* in/out -> "sptr"
; prgbSrcColors : RGBQUAD* in/out -> "sptr"
; pbDestInvMap : BYTE* in/out -> "sptr"
; x : INT -> "sptr"
; y : INT -> "sptr"
; cx : INT -> "sptr"
; cy : INT -> "sptr"
; lDestTrans : INT -> "sptr"
; lSrcTrans : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ImgUtil.dll" #cfunc global DitherTo8 "DitherTo8" var, int, var, int, var, var, var, var, int, int, int, int, int, int ; res = DitherTo8(pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans) ; pDestBits : BYTE* in/out -> "var" ; nDestPitch : INT -> "int" ; pSrcBits : BYTE* in/out -> "var" ; nSrcPitch : INT -> "int" ; bfidSrc : GUID* -> "var" ; prgbDestColors : RGBQUAD* in/out -> "var" ; prgbSrcColors : RGBQUAD* in/out -> "var" ; pbDestInvMap : BYTE* in/out -> "var" ; x : INT -> "int" ; y : INT -> "int" ; cx : INT -> "int" ; cy : INT -> "int" ; lDestTrans : INT -> "int" ; lSrcTrans : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ImgUtil.dll" #cfunc global DitherTo8 "DitherTo8" sptr, int, sptr, int, sptr, sptr, sptr, sptr, int, int, int, int, int, int ; res = DitherTo8(varptr(pDestBits), nDestPitch, varptr(pSrcBits), nSrcPitch, varptr(bfidSrc), varptr(prgbDestColors), varptr(prgbSrcColors), varptr(pbDestInvMap), x, y, cx, cy, lDestTrans, lSrcTrans) ; pDestBits : BYTE* in/out -> "sptr" ; nDestPitch : INT -> "int" ; pSrcBits : BYTE* in/out -> "sptr" ; nSrcPitch : INT -> "int" ; bfidSrc : GUID* -> "sptr" ; prgbDestColors : RGBQUAD* in/out -> "sptr" ; prgbSrcColors : RGBQUAD* in/out -> "sptr" ; pbDestInvMap : BYTE* in/out -> "sptr" ; x : INT -> "int" ; y : INT -> "int" ; cx : INT -> "int" ; cy : INT -> "int" ; lDestTrans : INT -> "int" ; lSrcTrans : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT DitherTo8(BYTE* pDestBits, INT nDestPitch, BYTE* pSrcBits, INT nSrcPitch, GUID* bfidSrc, RGBQUAD* prgbDestColors, RGBQUAD* prgbSrcColors, BYTE* pbDestInvMap, INT x, INT y, INT cx, INT cy, INT lDestTrans, INT lSrcTrans) #uselib "ImgUtil.dll" #cfunc global DitherTo8 "DitherTo8" var, int, var, int, var, var, var, var, int, int, int, int, int, int ; res = DitherTo8(pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans) ; pDestBits : BYTE* in/out -> "var" ; nDestPitch : INT -> "int" ; pSrcBits : BYTE* in/out -> "var" ; nSrcPitch : INT -> "int" ; bfidSrc : GUID* -> "var" ; prgbDestColors : RGBQUAD* in/out -> "var" ; prgbSrcColors : RGBQUAD* in/out -> "var" ; pbDestInvMap : BYTE* in/out -> "var" ; x : INT -> "int" ; y : INT -> "int" ; cx : INT -> "int" ; cy : INT -> "int" ; lDestTrans : INT -> "int" ; lSrcTrans : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT DitherTo8(BYTE* pDestBits, INT nDestPitch, BYTE* pSrcBits, INT nSrcPitch, GUID* bfidSrc, RGBQUAD* prgbDestColors, RGBQUAD* prgbSrcColors, BYTE* pbDestInvMap, INT x, INT y, INT cx, INT cy, INT lDestTrans, INT lSrcTrans) #uselib "ImgUtil.dll" #cfunc global DitherTo8 "DitherTo8" intptr, int, intptr, int, intptr, intptr, intptr, intptr, int, int, int, int, int, int ; res = DitherTo8(varptr(pDestBits), nDestPitch, varptr(pSrcBits), nSrcPitch, varptr(bfidSrc), varptr(prgbDestColors), varptr(prgbSrcColors), varptr(pbDestInvMap), x, y, cx, cy, lDestTrans, lSrcTrans) ; pDestBits : BYTE* in/out -> "intptr" ; nDestPitch : INT -> "int" ; pSrcBits : BYTE* in/out -> "intptr" ; nSrcPitch : INT -> "int" ; bfidSrc : GUID* -> "intptr" ; prgbDestColors : RGBQUAD* in/out -> "intptr" ; prgbSrcColors : RGBQUAD* in/out -> "intptr" ; pbDestInvMap : BYTE* in/out -> "intptr" ; x : INT -> "int" ; y : INT -> "int" ; cx : INT -> "int" ; cy : INT -> "int" ; lDestTrans : INT -> "int" ; lSrcTrans : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
imgutil = windows.NewLazySystemDLL("ImgUtil.dll")
procDitherTo8 = imgutil.NewProc("DitherTo8")
)
// pDestBits (BYTE* in/out), nDestPitch (INT), pSrcBits (BYTE* in/out), nSrcPitch (INT), bfidSrc (GUID*), prgbDestColors (RGBQUAD* in/out), prgbSrcColors (RGBQUAD* in/out), pbDestInvMap (BYTE* in/out), x (INT), y (INT), cx (INT), cy (INT), lDestTrans (INT), lSrcTrans (INT)
r1, _, err := procDitherTo8.Call(
uintptr(pDestBits),
uintptr(nDestPitch),
uintptr(pSrcBits),
uintptr(nSrcPitch),
uintptr(bfidSrc),
uintptr(prgbDestColors),
uintptr(prgbSrcColors),
uintptr(pbDestInvMap),
uintptr(x),
uintptr(y),
uintptr(cx),
uintptr(cy),
uintptr(lDestTrans),
uintptr(lSrcTrans),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction DitherTo8(
pDestBits: Pointer; // BYTE* in/out
nDestPitch: Integer; // INT
pSrcBits: Pointer; // BYTE* in/out
nSrcPitch: Integer; // INT
bfidSrc: PGUID; // GUID*
prgbDestColors: Pointer; // RGBQUAD* in/out
prgbSrcColors: Pointer; // RGBQUAD* in/out
pbDestInvMap: Pointer; // BYTE* in/out
x: Integer; // INT
y: Integer; // INT
cx: Integer; // INT
cy: Integer; // INT
lDestTrans: Integer; // INT
lSrcTrans: Integer // INT
): Integer; stdcall;
external 'ImgUtil.dll' name 'DitherTo8';result := DllCall("ImgUtil\DitherTo8"
, "Ptr", pDestBits ; BYTE* in/out
, "Int", nDestPitch ; INT
, "Ptr", pSrcBits ; BYTE* in/out
, "Int", nSrcPitch ; INT
, "Ptr", bfidSrc ; GUID*
, "Ptr", prgbDestColors ; RGBQUAD* in/out
, "Ptr", prgbSrcColors ; RGBQUAD* in/out
, "Ptr", pbDestInvMap ; BYTE* in/out
, "Int", x ; INT
, "Int", y ; INT
, "Int", cx ; INT
, "Int", cy ; INT
, "Int", lDestTrans ; INT
, "Int", lSrcTrans ; INT
, "Int") ; return: HRESULT●DitherTo8(pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans) = DLL("ImgUtil.dll", "int DitherTo8(void*, int, void*, int, void*, void*, void*, void*, int, int, int, int, int, int)")
# 呼び出し: DitherTo8(pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans)
# pDestBits : BYTE* in/out -> "void*"
# nDestPitch : INT -> "int"
# pSrcBits : BYTE* in/out -> "void*"
# nSrcPitch : INT -> "int"
# bfidSrc : GUID* -> "void*"
# prgbDestColors : RGBQUAD* in/out -> "void*"
# prgbSrcColors : RGBQUAD* in/out -> "void*"
# pbDestInvMap : BYTE* in/out -> "void*"
# x : INT -> "int"
# y : INT -> "int"
# cx : INT -> "int"
# cy : INT -> "int"
# lDestTrans : INT -> "int"
# lSrcTrans : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "imgutil" fn DitherTo8(
pDestBits: [*c]u8, // BYTE* in/out
nDestPitch: i32, // INT
pSrcBits: [*c]u8, // BYTE* in/out
nSrcPitch: i32, // INT
bfidSrc: [*c]GUID, // GUID*
prgbDestColors: [*c]RGBQUAD, // RGBQUAD* in/out
prgbSrcColors: [*c]RGBQUAD, // RGBQUAD* in/out
pbDestInvMap: [*c]u8, // BYTE* in/out
x: i32, // INT
y: i32, // INT
cx: i32, // INT
cy: i32, // INT
lDestTrans: i32, // INT
lSrcTrans: i32 // INT
) callconv(std.os.windows.WINAPI) i32;proc DitherTo8(
pDestBits: ptr uint8, # BYTE* in/out
nDestPitch: int32, # INT
pSrcBits: ptr uint8, # BYTE* in/out
nSrcPitch: int32, # INT
bfidSrc: ptr GUID, # GUID*
prgbDestColors: ptr RGBQUAD, # RGBQUAD* in/out
prgbSrcColors: ptr RGBQUAD, # RGBQUAD* in/out
pbDestInvMap: ptr uint8, # BYTE* in/out
x: int32, # INT
y: int32, # INT
cx: int32, # INT
cy: int32, # INT
lDestTrans: int32, # INT
lSrcTrans: int32 # INT
): int32 {.importc: "DitherTo8", stdcall, dynlib: "ImgUtil.dll".}pragma(lib, "imgutil");
extern(Windows)
int DitherTo8(
ubyte* pDestBits, // BYTE* in/out
int nDestPitch, // INT
ubyte* pSrcBits, // BYTE* in/out
int nSrcPitch, // INT
GUID* bfidSrc, // GUID*
RGBQUAD* prgbDestColors, // RGBQUAD* in/out
RGBQUAD* prgbSrcColors, // RGBQUAD* in/out
ubyte* pbDestInvMap, // BYTE* in/out
int x, // INT
int y, // INT
int cx, // INT
int cy, // INT
int lDestTrans, // INT
int lSrcTrans // INT
);ccall((:DitherTo8, "ImgUtil.dll"), stdcall, Int32,
(Ptr{UInt8}, Int32, Ptr{UInt8}, Int32, Ptr{GUID}, Ptr{RGBQUAD}, Ptr{RGBQUAD}, Ptr{UInt8}, Int32, Int32, Int32, Int32, Int32, Int32),
pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans)
# pDestBits : BYTE* in/out -> Ptr{UInt8}
# nDestPitch : INT -> Int32
# pSrcBits : BYTE* in/out -> Ptr{UInt8}
# nSrcPitch : INT -> Int32
# bfidSrc : GUID* -> Ptr{GUID}
# prgbDestColors : RGBQUAD* in/out -> Ptr{RGBQUAD}
# prgbSrcColors : RGBQUAD* in/out -> Ptr{RGBQUAD}
# pbDestInvMap : BYTE* in/out -> Ptr{UInt8}
# x : INT -> Int32
# y : INT -> Int32
# cx : INT -> Int32
# cy : INT -> Int32
# lDestTrans : INT -> Int32
# lSrcTrans : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t DitherTo8(
uint8_t* pDestBits,
int32_t nDestPitch,
uint8_t* pSrcBits,
int32_t nSrcPitch,
void* bfidSrc,
void* prgbDestColors,
void* prgbSrcColors,
uint8_t* pbDestInvMap,
int32_t x,
int32_t y,
int32_t cx,
int32_t cy,
int32_t lDestTrans,
int32_t lSrcTrans);
]]
local imgutil = ffi.load("imgutil")
-- imgutil.DitherTo8(pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans)
-- pDestBits : BYTE* in/out
-- nDestPitch : INT
-- pSrcBits : BYTE* in/out
-- nSrcPitch : INT
-- bfidSrc : GUID*
-- prgbDestColors : RGBQUAD* in/out
-- prgbSrcColors : RGBQUAD* in/out
-- pbDestInvMap : BYTE* in/out
-- x : INT
-- y : INT
-- cx : INT
-- cy : INT
-- lDestTrans : INT
-- lSrcTrans : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ImgUtil.dll');
const DitherTo8 = lib.func('__stdcall', 'DitherTo8', 'int32_t', ['uint8_t *', 'int32_t', 'uint8_t *', 'int32_t', 'void *', 'void *', 'void *', 'uint8_t *', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t']);
// DitherTo8(pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans)
// pDestBits : BYTE* in/out -> 'uint8_t *'
// nDestPitch : INT -> 'int32_t'
// pSrcBits : BYTE* in/out -> 'uint8_t *'
// nSrcPitch : INT -> 'int32_t'
// bfidSrc : GUID* -> 'void *'
// prgbDestColors : RGBQUAD* in/out -> 'void *'
// prgbSrcColors : RGBQUAD* in/out -> 'void *'
// pbDestInvMap : BYTE* in/out -> 'uint8_t *'
// x : INT -> 'int32_t'
// y : INT -> 'int32_t'
// cx : INT -> 'int32_t'
// cy : INT -> 'int32_t'
// lDestTrans : INT -> 'int32_t'
// lSrcTrans : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ImgUtil.dll", {
DitherTo8: { parameters: ["pointer", "i32", "pointer", "i32", "pointer", "pointer", "pointer", "pointer", "i32", "i32", "i32", "i32", "i32", "i32"], result: "i32" },
});
// lib.symbols.DitherTo8(pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans)
// pDestBits : BYTE* in/out -> "pointer"
// nDestPitch : INT -> "i32"
// pSrcBits : BYTE* in/out -> "pointer"
// nSrcPitch : INT -> "i32"
// bfidSrc : GUID* -> "pointer"
// prgbDestColors : RGBQUAD* in/out -> "pointer"
// prgbSrcColors : RGBQUAD* in/out -> "pointer"
// pbDestInvMap : BYTE* in/out -> "pointer"
// x : INT -> "i32"
// y : INT -> "i32"
// cx : INT -> "i32"
// cy : INT -> "i32"
// lDestTrans : INT -> "i32"
// lSrcTrans : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t DitherTo8(
uint8_t* pDestBits,
int32_t nDestPitch,
uint8_t* pSrcBits,
int32_t nSrcPitch,
void* bfidSrc,
void* prgbDestColors,
void* prgbSrcColors,
uint8_t* pbDestInvMap,
int32_t x,
int32_t y,
int32_t cx,
int32_t cy,
int32_t lDestTrans,
int32_t lSrcTrans);
C, "ImgUtil.dll");
// $ffi->DitherTo8(pDestBits, nDestPitch, pSrcBits, nSrcPitch, bfidSrc, prgbDestColors, prgbSrcColors, pbDestInvMap, x, y, cx, cy, lDestTrans, lSrcTrans);
// pDestBits : BYTE* in/out
// nDestPitch : INT
// pSrcBits : BYTE* in/out
// nSrcPitch : INT
// bfidSrc : GUID*
// prgbDestColors : RGBQUAD* in/out
// prgbSrcColors : RGBQUAD* in/out
// pbDestInvMap : BYTE* in/out
// x : INT
// y : INT
// cx : INT
// cy : INT
// lDestTrans : INT
// lSrcTrans : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Imgutil extends StdCallLibrary {
Imgutil INSTANCE = Native.load("imgutil", Imgutil.class);
int DitherTo8(
byte[] pDestBits, // BYTE* in/out
int nDestPitch, // INT
byte[] pSrcBits, // BYTE* in/out
int nSrcPitch, // INT
Pointer bfidSrc, // GUID*
Pointer prgbDestColors, // RGBQUAD* in/out
Pointer prgbSrcColors, // RGBQUAD* in/out
byte[] pbDestInvMap, // BYTE* in/out
int x, // INT
int y, // INT
int cx, // INT
int cy, // INT
int lDestTrans, // INT
int lSrcTrans // INT
);
}@[Link("imgutil")]
lib LibImgUtil
fun DitherTo8 = DitherTo8(
pDestBits : UInt8*, # BYTE* in/out
nDestPitch : Int32, # INT
pSrcBits : UInt8*, # BYTE* in/out
nSrcPitch : Int32, # INT
bfidSrc : GUID*, # GUID*
prgbDestColors : RGBQUAD*, # RGBQUAD* in/out
prgbSrcColors : RGBQUAD*, # RGBQUAD* in/out
pbDestInvMap : UInt8*, # BYTE* in/out
x : Int32, # INT
y : Int32, # INT
cx : Int32, # INT
cy : Int32, # INT
lDestTrans : Int32, # INT
lSrcTrans : Int32 # INT
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DitherTo8Native = Int32 Function(Pointer<Uint8>, Int32, Pointer<Uint8>, Int32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint8>, Int32, Int32, Int32, Int32, Int32, Int32);
typedef DitherTo8Dart = int Function(Pointer<Uint8>, int, Pointer<Uint8>, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint8>, int, int, int, int, int, int);
final DitherTo8 = DynamicLibrary.open('ImgUtil.dll')
.lookupFunction<DitherTo8Native, DitherTo8Dart>('DitherTo8');
// pDestBits : BYTE* in/out -> Pointer<Uint8>
// nDestPitch : INT -> Int32
// pSrcBits : BYTE* in/out -> Pointer<Uint8>
// nSrcPitch : INT -> Int32
// bfidSrc : GUID* -> Pointer<Void>
// prgbDestColors : RGBQUAD* in/out -> Pointer<Void>
// prgbSrcColors : RGBQUAD* in/out -> Pointer<Void>
// pbDestInvMap : BYTE* in/out -> Pointer<Uint8>
// x : INT -> Int32
// y : INT -> Int32
// cx : INT -> Int32
// cy : INT -> Int32
// lDestTrans : INT -> Int32
// lSrcTrans : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DitherTo8(
pDestBits: Pointer; // BYTE* in/out
nDestPitch: Integer; // INT
pSrcBits: Pointer; // BYTE* in/out
nSrcPitch: Integer; // INT
bfidSrc: PGUID; // GUID*
prgbDestColors: Pointer; // RGBQUAD* in/out
prgbSrcColors: Pointer; // RGBQUAD* in/out
pbDestInvMap: Pointer; // BYTE* in/out
x: Integer; // INT
y: Integer; // INT
cx: Integer; // INT
cy: Integer; // INT
lDestTrans: Integer; // INT
lSrcTrans: Integer // INT
): Integer; stdcall;
external 'ImgUtil.dll' name 'DitherTo8';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DitherTo8"
c_DitherTo8 :: Ptr Word8 -> Int32 -> Ptr Word8 -> Int32 -> Ptr () -> Ptr () -> Ptr () -> Ptr Word8 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> IO Int32
-- pDestBits : BYTE* in/out -> Ptr Word8
-- nDestPitch : INT -> Int32
-- pSrcBits : BYTE* in/out -> Ptr Word8
-- nSrcPitch : INT -> Int32
-- bfidSrc : GUID* -> Ptr ()
-- prgbDestColors : RGBQUAD* in/out -> Ptr ()
-- prgbSrcColors : RGBQUAD* in/out -> Ptr ()
-- pbDestInvMap : BYTE* in/out -> Ptr Word8
-- x : INT -> Int32
-- y : INT -> Int32
-- cx : INT -> Int32
-- cy : INT -> Int32
-- lDestTrans : INT -> Int32
-- lSrcTrans : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ditherto8 =
foreign "DitherTo8"
((ptr uint8_t) @-> int32_t @-> (ptr uint8_t) @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr uint8_t) @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> returning int32_t)
(* pDestBits : BYTE* in/out -> (ptr uint8_t) *)
(* nDestPitch : INT -> int32_t *)
(* pSrcBits : BYTE* in/out -> (ptr uint8_t) *)
(* nSrcPitch : INT -> int32_t *)
(* bfidSrc : GUID* -> (ptr void) *)
(* prgbDestColors : RGBQUAD* in/out -> (ptr void) *)
(* prgbSrcColors : RGBQUAD* in/out -> (ptr void) *)
(* pbDestInvMap : BYTE* in/out -> (ptr uint8_t) *)
(* x : INT -> int32_t *)
(* y : INT -> int32_t *)
(* cx : INT -> int32_t *)
(* cy : INT -> int32_t *)
(* lDestTrans : INT -> int32_t *)
(* lSrcTrans : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library imgutil (t "ImgUtil.dll"))
(cffi:use-foreign-library imgutil)
(cffi:defcfun ("DitherTo8" dither-to8 :convention :stdcall) :int32
(p-dest-bits :pointer) ; BYTE* in/out
(n-dest-pitch :int32) ; INT
(p-src-bits :pointer) ; BYTE* in/out
(n-src-pitch :int32) ; INT
(bfid-src :pointer) ; GUID*
(prgb-dest-colors :pointer) ; RGBQUAD* in/out
(prgb-src-colors :pointer) ; RGBQUAD* in/out
(pb-dest-inv-map :pointer) ; BYTE* in/out
(x :int32) ; INT
(y :int32) ; INT
(cx :int32) ; INT
(cy :int32) ; INT
(l-dest-trans :int32) ; INT
(l-src-trans :int32)) ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DitherTo8 = Win32::API::More->new('ImgUtil',
'int DitherTo8(LPVOID pDestBits, int nDestPitch, LPVOID pSrcBits, int nSrcPitch, LPVOID bfidSrc, LPVOID prgbDestColors, LPVOID prgbSrcColors, LPVOID pbDestInvMap, int x, int y, int cx, int cy, int lDestTrans, int lSrcTrans)');
# my $ret = $DitherTo8->Call($pDestBits, $nDestPitch, $pSrcBits, $nSrcPitch, $bfidSrc, $prgbDestColors, $prgbSrcColors, $pbDestInvMap, $x, $y, $cx, $cy, $lDestTrans, $lSrcTrans);
# pDestBits : BYTE* in/out -> LPVOID
# nDestPitch : INT -> int
# pSrcBits : BYTE* in/out -> LPVOID
# nSrcPitch : INT -> int
# bfidSrc : GUID* -> LPVOID
# prgbDestColors : RGBQUAD* in/out -> LPVOID
# prgbSrcColors : RGBQUAD* in/out -> LPVOID
# pbDestInvMap : BYTE* in/out -> LPVOID
# x : INT -> int
# y : INT -> int
# cx : INT -> int
# cy : INT -> int
# lDestTrans : INT -> int
# lSrcTrans : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型