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

ColorAdjustLuma

関数
RGB色の輝度を増減して調整する。
DLLSHLWAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

COLORREF ColorAdjustLuma(
    COLORREF clrRGB,
    INT n,
    BOOL fScale
);

パラメーター

名前方向説明
clrRGBCOLORREFin元の RGB 値。
nINTin全範囲の 0.1 パーセントを単位とする輝度。たとえば、n = 50 という値は、最大輝度の 5 パーセントに相当します。
fScaleBOOLinfScaleTRUE に設定されている場合、n は現在の輝度をどれだけ増減させるかを指定します。fScaleFALSE に設定されている場合、n は絶対的な輝度を指定します。

戻り値の型: COLORREF

公式ドキュメント

RGB 値の輝度 (luminance) を変更します。色相 (hue) と彩度 (saturation) には影響しません。

戻り値

型: COLORREF

変更後の RGB 値を返します。

解説(Remarks)

fScaleTRUE に設定されている場合、n は -1000 から +1000 の範囲を取ることができます。

fScaleFALSE に設定されている場合、n は 0 から 1000 の範囲を取ることができます。指定可能な輝度値は 0 から最大値までの範囲です。要求された値が負の値であるか最大値を超えている場合、輝度はそれぞれ 0 または最大値に設定されます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

COLORREF ColorAdjustLuma(
    COLORREF clrRGB,
    INT n,
    BOOL fScale
);
[DllImport("SHLWAPI.dll", ExactSpelling = true)]
static extern uint ColorAdjustLuma(
    uint clrRGB,   // COLORREF
    int n,   // INT
    bool fScale   // BOOL
);
<DllImport("SHLWAPI.dll", ExactSpelling:=True)>
Public Shared Function ColorAdjustLuma(
    clrRGB As UInteger,   ' COLORREF
    n As Integer,   ' INT
    fScale As Boolean   ' BOOL
) As UInteger
End Function
' clrRGB : COLORREF
' n : INT
' fScale : BOOL
Declare PtrSafe Function ColorAdjustLuma Lib "shlwapi" ( _
    ByVal clrRGB As Long, _
    ByVal n As Long, _
    ByVal fScale As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ColorAdjustLuma = ctypes.windll.shlwapi.ColorAdjustLuma
ColorAdjustLuma.restype = wintypes.DWORD
ColorAdjustLuma.argtypes = [
    wintypes.DWORD,  # clrRGB : COLORREF
    ctypes.c_int,  # n : INT
    wintypes.BOOL,  # fScale : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHLWAPI.dll')
ColorAdjustLuma = Fiddle::Function.new(
  lib['ColorAdjustLuma'],
  [
    -Fiddle::TYPE_INT,  # clrRGB : COLORREF
    Fiddle::TYPE_INT,  # n : INT
    Fiddle::TYPE_INT,  # fScale : BOOL
  ],
  -Fiddle::TYPE_INT)
#[link(name = "shlwapi")]
extern "system" {
    fn ColorAdjustLuma(
        clrRGB: u32,  // COLORREF
        n: i32,  // INT
        fScale: i32  // BOOL
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHLWAPI.dll")]
public static extern uint ColorAdjustLuma(uint clrRGB, int n, bool fScale);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_ColorAdjustLuma' -Namespace Win32 -PassThru
# $api::ColorAdjustLuma(clrRGB, n, fScale)
#uselib "SHLWAPI.dll"
#func global ColorAdjustLuma "ColorAdjustLuma" sptr, sptr, sptr
; ColorAdjustLuma clrRGB, n, fScale   ; 戻り値は stat
; clrRGB : COLORREF -> "sptr"
; n : INT -> "sptr"
; fScale : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHLWAPI.dll"
#cfunc global ColorAdjustLuma "ColorAdjustLuma" int, int, int
; res = ColorAdjustLuma(clrRGB, n, fScale)
; clrRGB : COLORREF -> "int"
; n : INT -> "int"
; fScale : BOOL -> "int"
; COLORREF ColorAdjustLuma(COLORREF clrRGB, INT n, BOOL fScale)
#uselib "SHLWAPI.dll"
#cfunc global ColorAdjustLuma "ColorAdjustLuma" int, int, int
; res = ColorAdjustLuma(clrRGB, n, fScale)
; clrRGB : COLORREF -> "int"
; n : INT -> "int"
; fScale : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
	procColorAdjustLuma = shlwapi.NewProc("ColorAdjustLuma")
)

// clrRGB (COLORREF), n (INT), fScale (BOOL)
r1, _, err := procColorAdjustLuma.Call(
	uintptr(clrRGB),
	uintptr(n),
	uintptr(fScale),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // COLORREF
function ColorAdjustLuma(
  clrRGB: DWORD;   // COLORREF
  n: Integer;   // INT
  fScale: BOOL   // BOOL
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'ColorAdjustLuma';
result := DllCall("SHLWAPI\ColorAdjustLuma"
    , "UInt", clrRGB   ; COLORREF
    , "Int", n   ; INT
    , "Int", fScale   ; BOOL
    , "UInt")   ; return: COLORREF
●ColorAdjustLuma(clrRGB, n, fScale) = DLL("SHLWAPI.dll", "dword ColorAdjustLuma(dword, int, bool)")
# 呼び出し: ColorAdjustLuma(clrRGB, n, fScale)
# clrRGB : COLORREF -> "dword"
# n : INT -> "int"
# fScale : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef ColorAdjustLumaNative = Uint32 Function(Uint32, Int32, Int32);
typedef ColorAdjustLumaDart = int Function(int, int, int);
final ColorAdjustLuma = DynamicLibrary.open('SHLWAPI.dll')
    .lookupFunction<ColorAdjustLumaNative, ColorAdjustLumaDart>('ColorAdjustLuma');
// clrRGB : COLORREF -> Uint32
// n : INT -> Int32
// fScale : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ColorAdjustLuma(
  clrRGB: DWORD;   // COLORREF
  n: Integer;   // INT
  fScale: BOOL   // BOOL
): DWORD; stdcall;
  external 'SHLWAPI.dll' name 'ColorAdjustLuma';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ColorAdjustLuma"
  c_ColorAdjustLuma :: Word32 -> Int32 -> CInt -> IO Word32
-- clrRGB : COLORREF -> Word32
-- n : INT -> Int32
-- fScale : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let coloradjustluma =
  foreign "ColorAdjustLuma"
    (uint32_t @-> int32_t @-> int32_t @-> returning uint32_t)
(* clrRGB : COLORREF -> uint32_t *)
(* n : INT -> int32_t *)
(* fScale : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)

(cffi:defcfun ("ColorAdjustLuma" color-adjust-luma :convention :stdcall) :uint32
  (clr-rgb :uint32)   ; COLORREF
  (n :int32)   ; INT
  (f-scale :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ColorAdjustLuma = Win32::API::More->new('SHLWAPI',
    'DWORD ColorAdjustLuma(DWORD clrRGB, int n, BOOL fScale)');
# my $ret = $ColorAdjustLuma->Call($clrRGB, $n, $fScale);
# clrRGB : COLORREF -> DWORD
# n : INT -> int
# fScale : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。