ホーム › Media.MediaFoundation › MFCopyImage
MFCopyImage
関数ストライドを考慮して画像データを行単位でコピーする。
シグネチャ
// MFPlat.dll
#include <windows.h>
HRESULT MFCopyImage(
BYTE* pDest,
INT lDestStride,
const BYTE* pSrc,
INT lSrcStride,
DWORD dwWidthInBytes,
DWORD dwLines
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pDest | BYTE* | out | コピー先バッファーの最初のピクセル行の先頭へのポインター。 |
| lDestStride | INT | in | コピー先バッファーのストライド(バイト単位)。 |
| pSrc | BYTE* | in | コピー元画像の最初のピクセル行の先頭へのポインター。 |
| lSrcStride | INT | in | コピー元画像のストライド(バイト単位)。 |
| dwWidthInBytes | DWORD | in | 画像の幅(バイト単位)。 |
| dwLines | DWORD | in | コピーするピクセル行の数。 |
戻り値の型: HRESULT
公式ドキュメント
画像または画像プレーンをあるバッファーから別のバッファーへコピーします。
戻り値
この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。
解説(Remarks)
この関数は画像の単一プレーンをコピーします。プラナー YUV 形式の場合は、各プレーンごとに関数を1回ずつ呼び出す必要があります。この場合、pDest と pSrc は各プレーンの先頭を指している必要があります。
この関数は、プロセッサーで MMX、SSE、または SSE2 命令セットが利用可能な場合に最適化されます。この関数はノンテンポラルストア(データはキャッシュを汚染せずにメモリへ直接書き込まれる)を実行します。
注意 Windows 7 より前では、この関数は evr.dll からエクスポートされていました。Windows 7 以降では、この関数は mfplat.dll からエクスポートされ、evr.dll は mfplat.dll を呼び出すスタブ関数をエクスポートします。詳細については、Windows 7 におけるライブラリの変更を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// MFPlat.dll
#include <windows.h>
HRESULT MFCopyImage(
BYTE* pDest,
INT lDestStride,
const BYTE* pSrc,
INT lSrcStride,
DWORD dwWidthInBytes,
DWORD dwLines
);[DllImport("MFPlat.dll", ExactSpelling = true)]
static extern int MFCopyImage(
IntPtr pDest, // BYTE* out
int lDestStride, // INT
IntPtr pSrc, // BYTE*
int lSrcStride, // INT
uint dwWidthInBytes, // DWORD
uint dwLines // DWORD
);<DllImport("MFPlat.dll", ExactSpelling:=True)>
Public Shared Function MFCopyImage(
pDest As IntPtr, ' BYTE* out
lDestStride As Integer, ' INT
pSrc As IntPtr, ' BYTE*
lSrcStride As Integer, ' INT
dwWidthInBytes As UInteger, ' DWORD
dwLines As UInteger ' DWORD
) As Integer
End Function' pDest : BYTE* out
' lDestStride : INT
' pSrc : BYTE*
' lSrcStride : INT
' dwWidthInBytes : DWORD
' dwLines : DWORD
Declare PtrSafe Function MFCopyImage Lib "mfplat" ( _
ByVal pDest As LongPtr, _
ByVal lDestStride As Long, _
ByVal pSrc As LongPtr, _
ByVal lSrcStride As Long, _
ByVal dwWidthInBytes As Long, _
ByVal dwLines As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MFCopyImage = ctypes.windll.mfplat.MFCopyImage
MFCopyImage.restype = ctypes.c_int
MFCopyImage.argtypes = [
ctypes.POINTER(ctypes.c_ubyte), # pDest : BYTE* out
ctypes.c_int, # lDestStride : INT
ctypes.POINTER(ctypes.c_ubyte), # pSrc : BYTE*
ctypes.c_int, # lSrcStride : INT
wintypes.DWORD, # dwWidthInBytes : DWORD
wintypes.DWORD, # dwLines : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('MFPlat.dll')
MFCopyImage = Fiddle::Function.new(
lib['MFCopyImage'],
[
Fiddle::TYPE_VOIDP, # pDest : BYTE* out
Fiddle::TYPE_INT, # lDestStride : INT
Fiddle::TYPE_VOIDP, # pSrc : BYTE*
Fiddle::TYPE_INT, # lSrcStride : INT
-Fiddle::TYPE_INT, # dwWidthInBytes : DWORD
-Fiddle::TYPE_INT, # dwLines : DWORD
],
Fiddle::TYPE_INT)#[link(name = "mfplat")]
extern "system" {
fn MFCopyImage(
pDest: *mut u8, // BYTE* out
lDestStride: i32, // INT
pSrc: *const u8, // BYTE*
lSrcStride: i32, // INT
dwWidthInBytes: u32, // DWORD
dwLines: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("MFPlat.dll")]
public static extern int MFCopyImage(IntPtr pDest, int lDestStride, IntPtr pSrc, int lSrcStride, uint dwWidthInBytes, uint dwLines);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MFPlat_MFCopyImage' -Namespace Win32 -PassThru
# $api::MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines)#uselib "MFPlat.dll"
#func global MFCopyImage "MFCopyImage" sptr, sptr, sptr, sptr, sptr, sptr
; MFCopyImage varptr(pDest), lDestStride, varptr(pSrc), lSrcStride, dwWidthInBytes, dwLines ; 戻り値は stat
; pDest : BYTE* out -> "sptr"
; lDestStride : INT -> "sptr"
; pSrc : BYTE* -> "sptr"
; lSrcStride : INT -> "sptr"
; dwWidthInBytes : DWORD -> "sptr"
; dwLines : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "MFPlat.dll" #cfunc global MFCopyImage "MFCopyImage" var, int, var, int, int, int ; res = MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines) ; pDest : BYTE* out -> "var" ; lDestStride : INT -> "int" ; pSrc : BYTE* -> "var" ; lSrcStride : INT -> "int" ; dwWidthInBytes : DWORD -> "int" ; dwLines : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "MFPlat.dll" #cfunc global MFCopyImage "MFCopyImage" sptr, int, sptr, int, int, int ; res = MFCopyImage(varptr(pDest), lDestStride, varptr(pSrc), lSrcStride, dwWidthInBytes, dwLines) ; pDest : BYTE* out -> "sptr" ; lDestStride : INT -> "int" ; pSrc : BYTE* -> "sptr" ; lSrcStride : INT -> "int" ; dwWidthInBytes : DWORD -> "int" ; dwLines : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT MFCopyImage(BYTE* pDest, INT lDestStride, BYTE* pSrc, INT lSrcStride, DWORD dwWidthInBytes, DWORD dwLines) #uselib "MFPlat.dll" #cfunc global MFCopyImage "MFCopyImage" var, int, var, int, int, int ; res = MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines) ; pDest : BYTE* out -> "var" ; lDestStride : INT -> "int" ; pSrc : BYTE* -> "var" ; lSrcStride : INT -> "int" ; dwWidthInBytes : DWORD -> "int" ; dwLines : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT MFCopyImage(BYTE* pDest, INT lDestStride, BYTE* pSrc, INT lSrcStride, DWORD dwWidthInBytes, DWORD dwLines) #uselib "MFPlat.dll" #cfunc global MFCopyImage "MFCopyImage" intptr, int, intptr, int, int, int ; res = MFCopyImage(varptr(pDest), lDestStride, varptr(pSrc), lSrcStride, dwWidthInBytes, dwLines) ; pDest : BYTE* out -> "intptr" ; lDestStride : INT -> "int" ; pSrc : BYTE* -> "intptr" ; lSrcStride : INT -> "int" ; dwWidthInBytes : DWORD -> "int" ; dwLines : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mfplat = windows.NewLazySystemDLL("MFPlat.dll")
procMFCopyImage = mfplat.NewProc("MFCopyImage")
)
// pDest (BYTE* out), lDestStride (INT), pSrc (BYTE*), lSrcStride (INT), dwWidthInBytes (DWORD), dwLines (DWORD)
r1, _, err := procMFCopyImage.Call(
uintptr(pDest),
uintptr(lDestStride),
uintptr(pSrc),
uintptr(lSrcStride),
uintptr(dwWidthInBytes),
uintptr(dwLines),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction MFCopyImage(
pDest: Pointer; // BYTE* out
lDestStride: Integer; // INT
pSrc: Pointer; // BYTE*
lSrcStride: Integer; // INT
dwWidthInBytes: DWORD; // DWORD
dwLines: DWORD // DWORD
): Integer; stdcall;
external 'MFPlat.dll' name 'MFCopyImage';result := DllCall("MFPlat\MFCopyImage"
, "Ptr", pDest ; BYTE* out
, "Int", lDestStride ; INT
, "Ptr", pSrc ; BYTE*
, "Int", lSrcStride ; INT
, "UInt", dwWidthInBytes ; DWORD
, "UInt", dwLines ; DWORD
, "Int") ; return: HRESULT●MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines) = DLL("MFPlat.dll", "int MFCopyImage(void*, int, void*, int, dword, dword)")
# 呼び出し: MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines)
# pDest : BYTE* out -> "void*"
# lDestStride : INT -> "int"
# pSrc : BYTE* -> "void*"
# lSrcStride : INT -> "int"
# dwWidthInBytes : DWORD -> "dword"
# dwLines : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mfplat" fn MFCopyImage(
pDest: [*c]u8, // BYTE* out
lDestStride: i32, // INT
pSrc: [*c]u8, // BYTE*
lSrcStride: i32, // INT
dwWidthInBytes: u32, // DWORD
dwLines: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc MFCopyImage(
pDest: ptr uint8, # BYTE* out
lDestStride: int32, # INT
pSrc: ptr uint8, # BYTE*
lSrcStride: int32, # INT
dwWidthInBytes: uint32, # DWORD
dwLines: uint32 # DWORD
): int32 {.importc: "MFCopyImage", stdcall, dynlib: "MFPlat.dll".}pragma(lib, "mfplat");
extern(Windows)
int MFCopyImage(
ubyte* pDest, // BYTE* out
int lDestStride, // INT
ubyte* pSrc, // BYTE*
int lSrcStride, // INT
uint dwWidthInBytes, // DWORD
uint dwLines // DWORD
);ccall((:MFCopyImage, "MFPlat.dll"), stdcall, Int32,
(Ptr{UInt8}, Int32, Ptr{UInt8}, Int32, UInt32, UInt32),
pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines)
# pDest : BYTE* out -> Ptr{UInt8}
# lDestStride : INT -> Int32
# pSrc : BYTE* -> Ptr{UInt8}
# lSrcStride : INT -> Int32
# dwWidthInBytes : DWORD -> UInt32
# dwLines : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t MFCopyImage(
uint8_t* pDest,
int32_t lDestStride,
uint8_t* pSrc,
int32_t lSrcStride,
uint32_t dwWidthInBytes,
uint32_t dwLines);
]]
local mfplat = ffi.load("mfplat")
-- mfplat.MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines)
-- pDest : BYTE* out
-- lDestStride : INT
-- pSrc : BYTE*
-- lSrcStride : INT
-- dwWidthInBytes : DWORD
-- dwLines : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('MFPlat.dll');
const MFCopyImage = lib.func('__stdcall', 'MFCopyImage', 'int32_t', ['uint8_t *', 'int32_t', 'uint8_t *', 'int32_t', 'uint32_t', 'uint32_t']);
// MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines)
// pDest : BYTE* out -> 'uint8_t *'
// lDestStride : INT -> 'int32_t'
// pSrc : BYTE* -> 'uint8_t *'
// lSrcStride : INT -> 'int32_t'
// dwWidthInBytes : DWORD -> 'uint32_t'
// dwLines : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("MFPlat.dll", {
MFCopyImage: { parameters: ["pointer", "i32", "pointer", "i32", "u32", "u32"], result: "i32" },
});
// lib.symbols.MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines)
// pDest : BYTE* out -> "pointer"
// lDestStride : INT -> "i32"
// pSrc : BYTE* -> "pointer"
// lSrcStride : INT -> "i32"
// dwWidthInBytes : DWORD -> "u32"
// dwLines : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t MFCopyImage(
uint8_t* pDest,
int32_t lDestStride,
uint8_t* pSrc,
int32_t lSrcStride,
uint32_t dwWidthInBytes,
uint32_t dwLines);
C, "MFPlat.dll");
// $ffi->MFCopyImage(pDest, lDestStride, pSrc, lSrcStride, dwWidthInBytes, dwLines);
// pDest : BYTE* out
// lDestStride : INT
// pSrc : BYTE*
// lSrcStride : INT
// dwWidthInBytes : DWORD
// dwLines : DWORD
// 構造体/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 Mfplat extends StdCallLibrary {
Mfplat INSTANCE = Native.load("mfplat", Mfplat.class);
int MFCopyImage(
byte[] pDest, // BYTE* out
int lDestStride, // INT
byte[] pSrc, // BYTE*
int lSrcStride, // INT
int dwWidthInBytes, // DWORD
int dwLines // DWORD
);
}@[Link("mfplat")]
lib LibMFPlat
fun MFCopyImage = MFCopyImage(
pDest : UInt8*, # BYTE* out
lDestStride : Int32, # INT
pSrc : UInt8*, # BYTE*
lSrcStride : Int32, # INT
dwWidthInBytes : UInt32, # DWORD
dwLines : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MFCopyImageNative = Int32 Function(Pointer<Uint8>, Int32, Pointer<Uint8>, Int32, Uint32, Uint32);
typedef MFCopyImageDart = int Function(Pointer<Uint8>, int, Pointer<Uint8>, int, int, int);
final MFCopyImage = DynamicLibrary.open('MFPlat.dll')
.lookupFunction<MFCopyImageNative, MFCopyImageDart>('MFCopyImage');
// pDest : BYTE* out -> Pointer<Uint8>
// lDestStride : INT -> Int32
// pSrc : BYTE* -> Pointer<Uint8>
// lSrcStride : INT -> Int32
// dwWidthInBytes : DWORD -> Uint32
// dwLines : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MFCopyImage(
pDest: Pointer; // BYTE* out
lDestStride: Integer; // INT
pSrc: Pointer; // BYTE*
lSrcStride: Integer; // INT
dwWidthInBytes: DWORD; // DWORD
dwLines: DWORD // DWORD
): Integer; stdcall;
external 'MFPlat.dll' name 'MFCopyImage';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MFCopyImage"
c_MFCopyImage :: Ptr Word8 -> Int32 -> Ptr Word8 -> Int32 -> Word32 -> Word32 -> IO Int32
-- pDest : BYTE* out -> Ptr Word8
-- lDestStride : INT -> Int32
-- pSrc : BYTE* -> Ptr Word8
-- lSrcStride : INT -> Int32
-- dwWidthInBytes : DWORD -> Word32
-- dwLines : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let mfcopyimage =
foreign "MFCopyImage"
((ptr uint8_t) @-> int32_t @-> (ptr uint8_t) @-> int32_t @-> uint32_t @-> uint32_t @-> returning int32_t)
(* pDest : BYTE* out -> (ptr uint8_t) *)
(* lDestStride : INT -> int32_t *)
(* pSrc : BYTE* -> (ptr uint8_t) *)
(* lSrcStride : INT -> int32_t *)
(* dwWidthInBytes : DWORD -> uint32_t *)
(* dwLines : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mfplat (t "MFPlat.dll"))
(cffi:use-foreign-library mfplat)
(cffi:defcfun ("MFCopyImage" mfcopy-image :convention :stdcall) :int32
(p-dest :pointer) ; BYTE* out
(l-dest-stride :int32) ; INT
(p-src :pointer) ; BYTE*
(l-src-stride :int32) ; INT
(dw-width-in-bytes :uint32) ; DWORD
(dw-lines :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MFCopyImage = Win32::API::More->new('MFPlat',
'int MFCopyImage(LPVOID pDest, int lDestStride, LPVOID pSrc, int lSrcStride, DWORD dwWidthInBytes, DWORD dwLines)');
# my $ret = $MFCopyImage->Call($pDest, $lDestStride, $pSrc, $lSrcStride, $dwWidthInBytes, $dwLines);
# pDest : BYTE* out -> LPVOID
# lDestStride : INT -> int
# pSrc : BYTE* -> LPVOID
# lSrcStride : INT -> int
# dwWidthInBytes : DWORD -> DWORD
# dwLines : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。