Win32 API 日本語リファレンス
ホームUI.ColorSystem › CMTranslateColors

CMTranslateColors

関数
色変換を用いて入力色配列を出力色配列へ変換する。
DLLICM32.dll呼出規約winapi

シグネチャ

// ICM32.dll
#include <windows.h>

BOOL CMTranslateColors(
    INT_PTR hcmTransform,
    COLOR* lpaInputColors,
    DWORD nColors,
    COLORTYPE ctInput,
    COLOR* lpaOutputColors,
    COLORTYPE ctOutput
);

パラメーター

名前方向説明
hcmTransformINT_PTRin適用するカラー変換のハンドル(CMM内部用)。
lpaInputColorsCOLOR*in変換元の色値を格納したCOLOR共用体配列へのポインタ。
nColorsDWORDin変換する色の個数。
ctInputCOLORTYPEin入力色データの色形式を示す列挙値(RGB・CMYK等)。
lpaOutputColorsCOLOR*out変換後の色値を格納するCOLOR共用体配列へのポインタ。
ctOutputCOLORTYPEin出力色データの色形式を示す列挙値(RGB・CMYK等)。

戻り値の型: BOOL

各言語での呼び出し定義

// ICM32.dll
#include <windows.h>

BOOL CMTranslateColors(
    INT_PTR hcmTransform,
    COLOR* lpaInputColors,
    DWORD nColors,
    COLORTYPE ctInput,
    COLOR* lpaOutputColors,
    COLORTYPE ctOutput
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ICM32.dll", ExactSpelling = true)]
static extern bool CMTranslateColors(
    IntPtr hcmTransform,   // INT_PTR
    IntPtr lpaInputColors,   // COLOR*
    uint nColors,   // DWORD
    int ctInput,   // COLORTYPE
    IntPtr lpaOutputColors,   // COLOR* out
    int ctOutput   // COLORTYPE
);
<DllImport("ICM32.dll", ExactSpelling:=True)>
Public Shared Function CMTranslateColors(
    hcmTransform As IntPtr,   ' INT_PTR
    lpaInputColors As IntPtr,   ' COLOR*
    nColors As UInteger,   ' DWORD
    ctInput As Integer,   ' COLORTYPE
    lpaOutputColors As IntPtr,   ' COLOR* out
    ctOutput As Integer   ' COLORTYPE
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hcmTransform : INT_PTR
' lpaInputColors : COLOR*
' nColors : DWORD
' ctInput : COLORTYPE
' lpaOutputColors : COLOR* out
' ctOutput : COLORTYPE
Declare PtrSafe Function CMTranslateColors Lib "icm32" ( _
    ByVal hcmTransform As LongPtr, _
    ByVal lpaInputColors As LongPtr, _
    ByVal nColors As Long, _
    ByVal ctInput As Long, _
    ByVal lpaOutputColors As LongPtr, _
    ByVal ctOutput As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CMTranslateColors = ctypes.windll.icm32.CMTranslateColors
CMTranslateColors.restype = wintypes.BOOL
CMTranslateColors.argtypes = [
    ctypes.c_ssize_t,  # hcmTransform : INT_PTR
    ctypes.c_void_p,  # lpaInputColors : COLOR*
    wintypes.DWORD,  # nColors : DWORD
    ctypes.c_int,  # ctInput : COLORTYPE
    ctypes.c_void_p,  # lpaOutputColors : COLOR* out
    ctypes.c_int,  # ctOutput : COLORTYPE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ICM32.dll')
CMTranslateColors = Fiddle::Function.new(
  lib['CMTranslateColors'],
  [
    Fiddle::TYPE_INTPTR_T,  # hcmTransform : INT_PTR
    Fiddle::TYPE_VOIDP,  # lpaInputColors : COLOR*
    -Fiddle::TYPE_INT,  # nColors : DWORD
    Fiddle::TYPE_INT,  # ctInput : COLORTYPE
    Fiddle::TYPE_VOIDP,  # lpaOutputColors : COLOR* out
    Fiddle::TYPE_INT,  # ctOutput : COLORTYPE
  ],
  Fiddle::TYPE_INT)
#[link(name = "icm32")]
extern "system" {
    fn CMTranslateColors(
        hcmTransform: isize,  // INT_PTR
        lpaInputColors: *mut COLOR,  // COLOR*
        nColors: u32,  // DWORD
        ctInput: i32,  // COLORTYPE
        lpaOutputColors: *mut COLOR,  // COLOR* out
        ctOutput: i32  // COLORTYPE
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ICM32.dll")]
public static extern bool CMTranslateColors(IntPtr hcmTransform, IntPtr lpaInputColors, uint nColors, int ctInput, IntPtr lpaOutputColors, int ctOutput);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ICM32_CMTranslateColors' -Namespace Win32 -PassThru
# $api::CMTranslateColors(hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput)
#uselib "ICM32.dll"
#func global CMTranslateColors "CMTranslateColors" sptr, sptr, sptr, sptr, sptr, sptr
; CMTranslateColors hcmTransform, varptr(lpaInputColors), nColors, ctInput, varptr(lpaOutputColors), ctOutput   ; 戻り値は stat
; hcmTransform : INT_PTR -> "sptr"
; lpaInputColors : COLOR* -> "sptr"
; nColors : DWORD -> "sptr"
; ctInput : COLORTYPE -> "sptr"
; lpaOutputColors : COLOR* out -> "sptr"
; ctOutput : COLORTYPE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ICM32.dll"
#cfunc global CMTranslateColors "CMTranslateColors" sptr, var, int, int, var, int
; res = CMTranslateColors(hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput)
; hcmTransform : INT_PTR -> "sptr"
; lpaInputColors : COLOR* -> "var"
; nColors : DWORD -> "int"
; ctInput : COLORTYPE -> "int"
; lpaOutputColors : COLOR* out -> "var"
; ctOutput : COLORTYPE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CMTranslateColors(INT_PTR hcmTransform, COLOR* lpaInputColors, DWORD nColors, COLORTYPE ctInput, COLOR* lpaOutputColors, COLORTYPE ctOutput)
#uselib "ICM32.dll"
#cfunc global CMTranslateColors "CMTranslateColors" intptr, var, int, int, var, int
; res = CMTranslateColors(hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput)
; hcmTransform : INT_PTR -> "intptr"
; lpaInputColors : COLOR* -> "var"
; nColors : DWORD -> "int"
; ctInput : COLORTYPE -> "int"
; lpaOutputColors : COLOR* out -> "var"
; ctOutput : COLORTYPE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	icm32 = windows.NewLazySystemDLL("ICM32.dll")
	procCMTranslateColors = icm32.NewProc("CMTranslateColors")
)

// hcmTransform (INT_PTR), lpaInputColors (COLOR*), nColors (DWORD), ctInput (COLORTYPE), lpaOutputColors (COLOR* out), ctOutput (COLORTYPE)
r1, _, err := procCMTranslateColors.Call(
	uintptr(hcmTransform),
	uintptr(lpaInputColors),
	uintptr(nColors),
	uintptr(ctInput),
	uintptr(lpaOutputColors),
	uintptr(ctOutput),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CMTranslateColors(
  hcmTransform: NativeInt;   // INT_PTR
  lpaInputColors: Pointer;   // COLOR*
  nColors: DWORD;   // DWORD
  ctInput: Integer;   // COLORTYPE
  lpaOutputColors: Pointer;   // COLOR* out
  ctOutput: Integer   // COLORTYPE
): BOOL; stdcall;
  external 'ICM32.dll' name 'CMTranslateColors';
result := DllCall("ICM32\CMTranslateColors"
    , "Ptr", hcmTransform   ; INT_PTR
    , "Ptr", lpaInputColors   ; COLOR*
    , "UInt", nColors   ; DWORD
    , "Int", ctInput   ; COLORTYPE
    , "Ptr", lpaOutputColors   ; COLOR* out
    , "Int", ctOutput   ; COLORTYPE
    , "Int")   ; return: BOOL
●CMTranslateColors(hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput) = DLL("ICM32.dll", "bool CMTranslateColors(int, void*, dword, int, void*, int)")
# 呼び出し: CMTranslateColors(hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput)
# hcmTransform : INT_PTR -> "int"
# lpaInputColors : COLOR* -> "void*"
# nColors : DWORD -> "dword"
# ctInput : COLORTYPE -> "int"
# lpaOutputColors : COLOR* out -> "void*"
# ctOutput : COLORTYPE -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "icm32" fn CMTranslateColors(
    hcmTransform: isize, // INT_PTR
    lpaInputColors: [*c]COLOR, // COLOR*
    nColors: u32, // DWORD
    ctInput: i32, // COLORTYPE
    lpaOutputColors: [*c]COLOR, // COLOR* out
    ctOutput: i32 // COLORTYPE
) callconv(std.os.windows.WINAPI) i32;
proc CMTranslateColors(
    hcmTransform: int,  # INT_PTR
    lpaInputColors: ptr COLOR,  # COLOR*
    nColors: uint32,  # DWORD
    ctInput: int32,  # COLORTYPE
    lpaOutputColors: ptr COLOR,  # COLOR* out
    ctOutput: int32  # COLORTYPE
): int32 {.importc: "CMTranslateColors", stdcall, dynlib: "ICM32.dll".}
pragma(lib, "icm32");
extern(Windows)
int CMTranslateColors(
    ptrdiff_t hcmTransform,   // INT_PTR
    COLOR* lpaInputColors,   // COLOR*
    uint nColors,   // DWORD
    int ctInput,   // COLORTYPE
    COLOR* lpaOutputColors,   // COLOR* out
    int ctOutput   // COLORTYPE
);
ccall((:CMTranslateColors, "ICM32.dll"), stdcall, Int32,
      (Int, Ptr{COLOR}, UInt32, Int32, Ptr{COLOR}, Int32),
      hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput)
# hcmTransform : INT_PTR -> Int
# lpaInputColors : COLOR* -> Ptr{COLOR}
# nColors : DWORD -> UInt32
# ctInput : COLORTYPE -> Int32
# lpaOutputColors : COLOR* out -> Ptr{COLOR}
# ctOutput : COLORTYPE -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CMTranslateColors(
    intptr_t hcmTransform,
    void* lpaInputColors,
    uint32_t nColors,
    int32_t ctInput,
    void* lpaOutputColors,
    int32_t ctOutput);
]]
local icm32 = ffi.load("icm32")
-- icm32.CMTranslateColors(hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput)
-- hcmTransform : INT_PTR
-- lpaInputColors : COLOR*
-- nColors : DWORD
-- ctInput : COLORTYPE
-- lpaOutputColors : COLOR* out
-- ctOutput : COLORTYPE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ICM32.dll');
const CMTranslateColors = lib.func('__stdcall', 'CMTranslateColors', 'int32_t', ['intptr_t', 'void *', 'uint32_t', 'int32_t', 'void *', 'int32_t']);
// CMTranslateColors(hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput)
// hcmTransform : INT_PTR -> 'intptr_t'
// lpaInputColors : COLOR* -> 'void *'
// nColors : DWORD -> 'uint32_t'
// ctInput : COLORTYPE -> 'int32_t'
// lpaOutputColors : COLOR* out -> 'void *'
// ctOutput : COLORTYPE -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ICM32.dll", {
  CMTranslateColors: { parameters: ["isize", "pointer", "u32", "i32", "pointer", "i32"], result: "i32" },
});
// lib.symbols.CMTranslateColors(hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput)
// hcmTransform : INT_PTR -> "isize"
// lpaInputColors : COLOR* -> "pointer"
// nColors : DWORD -> "u32"
// ctInput : COLORTYPE -> "i32"
// lpaOutputColors : COLOR* out -> "pointer"
// ctOutput : COLORTYPE -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CMTranslateColors(
    intptr_t hcmTransform,
    void* lpaInputColors,
    uint32_t nColors,
    int32_t ctInput,
    void* lpaOutputColors,
    int32_t ctOutput);
C, "ICM32.dll");
// $ffi->CMTranslateColors(hcmTransform, lpaInputColors, nColors, ctInput, lpaOutputColors, ctOutput);
// hcmTransform : INT_PTR
// lpaInputColors : COLOR*
// nColors : DWORD
// ctInput : COLORTYPE
// lpaOutputColors : COLOR* out
// ctOutput : COLORTYPE
// 構造体/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 Icm32 extends StdCallLibrary {
    Icm32 INSTANCE = Native.load("icm32", Icm32.class);
    boolean CMTranslateColors(
        long hcmTransform,   // INT_PTR
        Pointer lpaInputColors,   // COLOR*
        int nColors,   // DWORD
        int ctInput,   // COLORTYPE
        Pointer lpaOutputColors,   // COLOR* out
        int ctOutput   // COLORTYPE
    );
}
@[Link("icm32")]
lib LibICM32
  fun CMTranslateColors = CMTranslateColors(
    hcmTransform : LibC::SSizeT,   # INT_PTR
    lpaInputColors : COLOR*,   # COLOR*
    nColors : UInt32,   # DWORD
    ctInput : Int32,   # COLORTYPE
    lpaOutputColors : COLOR*,   # COLOR* out
    ctOutput : Int32   # COLORTYPE
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CMTranslateColorsNative = Int32 Function(IntPtr, Pointer<Void>, Uint32, Int32, Pointer<Void>, Int32);
typedef CMTranslateColorsDart = int Function(int, Pointer<Void>, int, int, Pointer<Void>, int);
final CMTranslateColors = DynamicLibrary.open('ICM32.dll')
    .lookupFunction<CMTranslateColorsNative, CMTranslateColorsDart>('CMTranslateColors');
// hcmTransform : INT_PTR -> IntPtr
// lpaInputColors : COLOR* -> Pointer<Void>
// nColors : DWORD -> Uint32
// ctInput : COLORTYPE -> Int32
// lpaOutputColors : COLOR* out -> Pointer<Void>
// ctOutput : COLORTYPE -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CMTranslateColors(
  hcmTransform: NativeInt;   // INT_PTR
  lpaInputColors: Pointer;   // COLOR*
  nColors: DWORD;   // DWORD
  ctInput: Integer;   // COLORTYPE
  lpaOutputColors: Pointer;   // COLOR* out
  ctOutput: Integer   // COLORTYPE
): BOOL; stdcall;
  external 'ICM32.dll' name 'CMTranslateColors';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CMTranslateColors"
  c_CMTranslateColors :: CIntPtr -> Ptr () -> Word32 -> Int32 -> Ptr () -> Int32 -> IO CInt
-- hcmTransform : INT_PTR -> CIntPtr
-- lpaInputColors : COLOR* -> Ptr ()
-- nColors : DWORD -> Word32
-- ctInput : COLORTYPE -> Int32
-- lpaOutputColors : COLOR* out -> Ptr ()
-- ctOutput : COLORTYPE -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let cmtranslatecolors =
  foreign "CMTranslateColors"
    (intptr_t @-> (ptr void) @-> uint32_t @-> int32_t @-> (ptr void) @-> int32_t @-> returning int32_t)
(* hcmTransform : INT_PTR -> intptr_t *)
(* lpaInputColors : COLOR* -> (ptr void) *)
(* nColors : DWORD -> uint32_t *)
(* ctInput : COLORTYPE -> int32_t *)
(* lpaOutputColors : COLOR* out -> (ptr void) *)
(* ctOutput : COLORTYPE -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library icm32 (t "ICM32.dll"))
(cffi:use-foreign-library icm32)

(cffi:defcfun ("CMTranslateColors" cmtranslate-colors :convention :stdcall) :int32
  (hcm-transform :int64)   ; INT_PTR
  (lpa-input-colors :pointer)   ; COLOR*
  (n-colors :uint32)   ; DWORD
  (ct-input :int32)   ; COLORTYPE
  (lpa-output-colors :pointer)   ; COLOR* out
  (ct-output :int32))   ; COLORTYPE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CMTranslateColors = Win32::API::More->new('ICM32',
    'BOOL CMTranslateColors(LPARAM hcmTransform, LPVOID lpaInputColors, DWORD nColors, int ctInput, LPVOID lpaOutputColors, int ctOutput)');
# my $ret = $CMTranslateColors->Call($hcmTransform, $lpaInputColors, $nColors, $ctInput, $lpaOutputColors, $ctOutput);
# hcmTransform : INT_PTR -> LPARAM
# lpaInputColors : COLOR* -> LPVOID
# nColors : DWORD -> DWORD
# ctInput : COLORTYPE -> int
# lpaOutputColors : COLOR* out -> LPVOID
# ctOutput : COLORTYPE -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型