ホーム › Graphics.Gdi › DIBSECTION
DIBSECTION
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| dsBm | BITMAP | 32/24 | +0 | +0 | DIBセクションのビットマップ情報を表すBITMAP構造体。 |
| dsBmih | BITMAPINFOHEADER | 40 | +32 | +24 | DIBのヘッダ情報を表すBITMAPINFOHEADER構造体。 |
| dsBitfields | DWORD | 12 | +72 | +64 | ビットフィールド方式時の赤緑青の各カラーマスクを表す配列。 |
| dshSection | HANDLE | 8/4 | +88 | +76 | CreateDIBSectionでファイルマッピングを使った場合のセクションハンドル。NULL可。 |
| dsOffset | DWORD | 4 | +96 | +80 | ファイルマッピング内のビット配列へのオフセットをバイト単位で表す。 |
各言語での定義
#include <windows.h>
// BITMAP (x64 32 / x86 24 バイト)
typedef struct BITMAP {
INT bmType;
INT bmWidth;
INT bmHeight;
INT bmWidthBytes;
WORD bmPlanes;
WORD bmBitsPixel;
void* bmBits;
} BITMAP;
// BITMAPINFOHEADER (x64 40 / x86 40 バイト)
typedef struct BITMAPINFOHEADER {
DWORD biSize;
INT biWidth;
INT biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
INT biXPelsPerMeter;
INT biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;
// DIBSECTION (x64 104 / x86 84 バイト)
typedef struct DIBSECTION {
BITMAP dsBm;
BITMAPINFOHEADER dsBmih;
DWORD dsBitfields[3];
HANDLE dshSection;
DWORD dsOffset;
} DIBSECTION;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BITMAP
{
public int bmType;
public int bmWidth;
public int bmHeight;
public int bmWidthBytes;
public ushort bmPlanes;
public ushort bmBitsPixel;
public IntPtr bmBits;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BITMAPINFOHEADER
{
public uint biSize;
public int biWidth;
public int biHeight;
public ushort biPlanes;
public ushort biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public uint biClrUsed;
public uint biClrImportant;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DIBSECTION
{
public BITMAP dsBm;
public BITMAPINFOHEADER dsBmih;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public uint[] dsBitfields;
public IntPtr dshSection;
public uint dsOffset;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BITMAP
Public bmType As Integer
Public bmWidth As Integer
Public bmHeight As Integer
Public bmWidthBytes As Integer
Public bmPlanes As UShort
Public bmBitsPixel As UShort
Public bmBits As IntPtr
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BITMAPINFOHEADER
Public biSize As UInteger
Public biWidth As Integer
Public biHeight As Integer
Public biPlanes As UShort
Public biBitCount As UShort
Public biCompression As UInteger
Public biSizeImage As UInteger
Public biXPelsPerMeter As Integer
Public biYPelsPerMeter As Integer
Public biClrUsed As UInteger
Public biClrImportant As UInteger
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DIBSECTION
Public dsBm As BITMAP
Public dsBmih As BITMAPINFOHEADER
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> Public dsBitfields() As UInteger
Public dshSection As IntPtr
Public dsOffset As UInteger
End Structureimport ctypes
from ctypes import wintypes
class BITMAP(ctypes.Structure):
_fields_ = [
("bmType", ctypes.c_int),
("bmWidth", ctypes.c_int),
("bmHeight", ctypes.c_int),
("bmWidthBytes", ctypes.c_int),
("bmPlanes", ctypes.c_ushort),
("bmBitsPixel", ctypes.c_ushort),
("bmBits", ctypes.c_void_p),
]
class BITMAPINFOHEADER(ctypes.Structure):
_fields_ = [
("biSize", wintypes.DWORD),
("biWidth", ctypes.c_int),
("biHeight", ctypes.c_int),
("biPlanes", ctypes.c_ushort),
("biBitCount", ctypes.c_ushort),
("biCompression", wintypes.DWORD),
("biSizeImage", wintypes.DWORD),
("biXPelsPerMeter", ctypes.c_int),
("biYPelsPerMeter", ctypes.c_int),
("biClrUsed", wintypes.DWORD),
("biClrImportant", wintypes.DWORD),
]
class DIBSECTION(ctypes.Structure):
_fields_ = [
("dsBm", BITMAP),
("dsBmih", BITMAPINFOHEADER),
("dsBitfields", wintypes.DWORD * 3),
("dshSection", ctypes.c_void_p),
("dsOffset", wintypes.DWORD),
]#[repr(C)]
pub struct BITMAP {
pub bmType: i32,
pub bmWidth: i32,
pub bmHeight: i32,
pub bmWidthBytes: i32,
pub bmPlanes: u16,
pub bmBitsPixel: u16,
pub bmBits: *mut core::ffi::c_void,
}
#[repr(C)]
pub struct BITMAPINFOHEADER {
pub biSize: u32,
pub biWidth: i32,
pub biHeight: i32,
pub biPlanes: u16,
pub biBitCount: u16,
pub biCompression: u32,
pub biSizeImage: u32,
pub biXPelsPerMeter: i32,
pub biYPelsPerMeter: i32,
pub biClrUsed: u32,
pub biClrImportant: u32,
}
#[repr(C)]
pub struct DIBSECTION {
pub dsBm: BITMAP,
pub dsBmih: BITMAPINFOHEADER,
pub dsBitfields: [u32; 3],
pub dshSection: *mut core::ffi::c_void,
pub dsOffset: u32,
}import "golang.org/x/sys/windows"
type BITMAP struct {
bmType int32
bmWidth int32
bmHeight int32
bmWidthBytes int32
bmPlanes uint16
bmBitsPixel uint16
bmBits uintptr
}
type BITMAPINFOHEADER struct {
biSize uint32
biWidth int32
biHeight int32
biPlanes uint16
biBitCount uint16
biCompression uint32
biSizeImage uint32
biXPelsPerMeter int32
biYPelsPerMeter int32
biClrUsed uint32
biClrImportant uint32
}
type DIBSECTION struct {
dsBm BITMAP
dsBmih BITMAPINFOHEADER
dsBitfields [3]uint32
dshSection uintptr
dsOffset uint32
}type
BITMAP = record
bmType: Integer;
bmWidth: Integer;
bmHeight: Integer;
bmWidthBytes: Integer;
bmPlanes: Word;
bmBitsPixel: Word;
bmBits: Pointer;
end;
BITMAPINFOHEADER = record
biSize: DWORD;
biWidth: Integer;
biHeight: Integer;
biPlanes: Word;
biBitCount: Word;
biCompression: DWORD;
biSizeImage: DWORD;
biXPelsPerMeter: Integer;
biYPelsPerMeter: Integer;
biClrUsed: DWORD;
biClrImportant: DWORD;
end;
DIBSECTION = record
dsBm: BITMAP;
dsBmih: BITMAPINFOHEADER;
dsBitfields: array[0..2] of DWORD;
dshSection: Pointer;
dsOffset: DWORD;
end;const BITMAP = extern struct {
bmType: i32,
bmWidth: i32,
bmHeight: i32,
bmWidthBytes: i32,
bmPlanes: u16,
bmBitsPixel: u16,
bmBits: ?*anyopaque,
};
const BITMAPINFOHEADER = extern struct {
biSize: u32,
biWidth: i32,
biHeight: i32,
biPlanes: u16,
biBitCount: u16,
biCompression: u32,
biSizeImage: u32,
biXPelsPerMeter: i32,
biYPelsPerMeter: i32,
biClrUsed: u32,
biClrImportant: u32,
};
const DIBSECTION = extern struct {
dsBm: BITMAP,
dsBmih: BITMAPINFOHEADER,
dsBitfields: [3]u32,
dshSection: ?*anyopaque,
dsOffset: u32,
};type
BITMAP {.bycopy.} = object
bmType: int32
bmWidth: int32
bmHeight: int32
bmWidthBytes: int32
bmPlanes: uint16
bmBitsPixel: uint16
bmBits: pointer
BITMAPINFOHEADER {.bycopy.} = object
biSize: uint32
biWidth: int32
biHeight: int32
biPlanes: uint16
biBitCount: uint16
biCompression: uint32
biSizeImage: uint32
biXPelsPerMeter: int32
biYPelsPerMeter: int32
biClrUsed: uint32
biClrImportant: uint32
DIBSECTION {.bycopy.} = object
dsBm: BITMAP
dsBmih: BITMAPINFOHEADER
dsBitfields: array[3, uint32]
dshSection: pointer
dsOffset: uint32struct BITMAP
{
int bmType;
int bmWidth;
int bmHeight;
int bmWidthBytes;
ushort bmPlanes;
ushort bmBitsPixel;
void* bmBits;
}
struct BITMAPINFOHEADER
{
uint biSize;
int biWidth;
int biHeight;
ushort biPlanes;
ushort biBitCount;
uint biCompression;
uint biSizeImage;
int biXPelsPerMeter;
int biYPelsPerMeter;
uint biClrUsed;
uint biClrImportant;
}
struct DIBSECTION
{
BITMAP dsBm;
BITMAPINFOHEADER dsBmih;
uint[3] dsBitfields;
void* dshSection;
uint dsOffset;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; DIBSECTION サイズ: 84 バイト(x86)
dim st, 21 ; 4byte整数×21(構造体サイズ 84 / 4 切り上げ)
; dsBm : BITMAP (+0, 24byte) varptr(st)+0 を基点に操作(24byte:入れ子/配列)
; dsBmih : BITMAPINFOHEADER (+24, 40byte) varptr(st)+24 を基点に操作(40byte:入れ子/配列)
; dsBitfields : DWORD (+64, 12byte) varptr(st)+64 を基点に操作(12byte:入れ子/配列)
; dshSection : HANDLE (+76, 4byte) st.19 = 値 / 値 = st.19 (lpoke/lpeek も可)
; dsOffset : DWORD (+80, 4byte) st.20 = 値 / 値 = st.20 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; DIBSECTION サイズ: 104 バイト(x64)
dim st, 26 ; 4byte整数×26(構造体サイズ 104 / 4 切り上げ)
; dsBm : BITMAP (+0, 32byte) varptr(st)+0 を基点に操作(32byte:入れ子/配列)
; dsBmih : BITMAPINFOHEADER (+32, 40byte) varptr(st)+32 を基点に操作(40byte:入れ子/配列)
; dsBitfields : DWORD (+72, 12byte) varptr(st)+72 を基点に操作(12byte:入れ子/配列)
; dshSection : HANDLE (+88, 8byte) qpoke st,88,値 / qpeek(st,88) ※IronHSPのみ。3.7/3.8は lpoke st,88,下位 : lpoke st,92,上位
; dsOffset : DWORD (+96, 4byte) st.24 = 値 / 値 = st.24 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global BITMAP
#field int bmType
#field int bmWidth
#field int bmHeight
#field int bmWidthBytes
#field short bmPlanes
#field short bmBitsPixel
#field intptr bmBits
#endstruct
#defstruct global BITMAPINFOHEADER
#field int biSize
#field int biWidth
#field int biHeight
#field short biPlanes
#field short biBitCount
#field int biCompression
#field int biSizeImage
#field int biXPelsPerMeter
#field int biYPelsPerMeter
#field int biClrUsed
#field int biClrImportant
#endstruct
#defstruct global DIBSECTION
#field BITMAP dsBm
#field BITMAPINFOHEADER dsBmih
#field int dsBitfields 3
#field intptr dshSection
#field int dsOffset
#endstruct
stdim st, DIBSECTION ; NSTRUCT 変数を確保
st->dsOffset = 100
mes "dsOffset=" + st->dsOffset