1 /** \file 2 * \brief Windows DIB (Device Independent Bitmap) 3 * 4 * See Copyright Notice in im_lib.h 5 */ 6 module im.im_dib; 7 8 version(IM) : 9 version(Windows) : 10 11 import core.stdc.config : c_long; 12 import core.sys.windows.windows; 13 14 version(DigitalMars) { pragma(lib, "im.lib"); } 15 16 extern(C) @nogc nothrow : 17 18 19 /** \defgroup dib Windows DIB 20 * 21 * \par 22 * Windows DIBs in memory are handled just like a BMP file without the file header. \n 23 * These functions will work only in Windows. They are usefull for interchanging data 24 * with the clipboard, with capture drivers, with the AVI and WMF file formats and others. 25 * \par 26 * Supported DIB aspects: 27 * \li bpp must be 1, 4, 8, 16, 24, or 32. 28 * \li BITMAPV4HEADER or BITMAPV5HEADER are handled but ignored. \n 29 * \li BITMAPCOREHEADER is not handled . 30 * \li BI_JPEG and BI_PNG compressions are not handled. 31 * \li biHeight can be negative, compression can be RLE only if created 32 * from imDibCreateReference, imDibPasteClipboard, imDibLoadFile. 33 * \li can not encode/decode Images to/from RLE compressed Dibs. 34 * \li if working with RLE Dibs bits_size is greatter than used. 35 * \li the resolution of a new Dib is taken from the screen. 36 * \li SetDIBitsToDevice(start_scan is 0, scan_lines is dib->bmih->biHeight). 37 * \li StretchDIBits(use always DIB_RGB_COLORS). 38 * \li CreateDIBPatternBrushPt(packed_dib is dib->dib). 39 * \par 40 * Must include <windows.h> before using these functions. \n 41 * Check <wingdi.h> for structures and definitions. 42 * \par 43 * See \ref im_dib.h 44 * \ingroup util */ 45 46 47 /** \brief Windows DIB Structure 48 * 49 * \par 50 * Handles a DIB in memory. \n 51 * The DIB is stored in only one buffer. 52 * The secondary members are pointers to the main buffer. 53 * \ingroup dib */ 54 struct imDib // typedef struct _imDib imDib 55 { 56 HGLOBAL handle; /**< The windows memory handle */ 57 BYTE* buffer; /**< The DIB as it is defined in memory */ 58 int free_buffer; /**< Free the memory buffer, used only for DIB section */ 59 int size; /**< Full size in memory */ 60 61 BITMAPINFO* bmi; /**< Bitmap Info = Bitmap Info Header + Palette */ 62 BITMAPINFOHEADER* bmih; /**< Bitmap Info Header */ 63 RGBQUAD* bmic; /**< Bitmap Info Colors = Palette */ 64 BYTE* bits; /**< Bitmap Bits */ 65 66 int palette_count; /**< number of colors in the palette */ 67 int bits_size; /**< size in bytes of the Bitmap Bits */ 68 int line_size; /**< size in bytes of one line, includes padding */ 69 int pad_size; /**< number of bytes remaining in the line, lines are in a word boundary */ 70 71 int is_reference; /**< only a reference, do not free pointer */ 72 } 73 74 /** Creates a new DIB. \n 75 * use bpp=-16/-32 to allocate space for BITFLIEDS. \n 76 * Allocates all fields. 77 * \ingroup dib */ 78 imDib* imDibCreate(int width, int height, int bpp); 79 80 /** Duplicates the DIB contents in a new DIB. \n 81 * A Reference DIB will be copied into a full DIB structure. 82 * \ingroup dib */ 83 imDib* imDibCreateCopy(const(imDib)* dib); 84 85 /** Creates a DIB using an already allocated memory. \n 86 * "bmi" must be a pointer to BITMAPINFOHEADER. \n 87 * "bits" can be NULL if it is inside "bmi" after the palette. \n 88 * "handle" is not allocated. buffer will point to bmi. 89 * \ingroup dib */ 90 imDib* imDibCreateReference(BYTE* bmi, BYTE* bits); 91 92 /** Creates a DIB section for drawing purposes. \n 93 * Returns the bitmap that is also created. \n 94 * "handle" is not allocated. \n 95 * You cannot paste a DIB section from one application into another application. 96 * \ingroup dib */ 97 imDib* imDibCreateSection(HDC hDC, HBITMAP* bitmap, int width, int height, int bpp); 98 99 /** Destroy the DIB 100 * \ingroup dib */ 101 void imDibDestroy(imDib* dib); 102 103 /** DIB GetPixel function definition. \n 104 * the DWORD is a raw copy of the bits, use (ubyte*)&pixel 105 * \ingroup dib */ 106 alias imDibLineGetPixel = uint function(ubyte* line, int col); 107 108 /** Returns a function to read pixels from a DIB line. 109 * \ingroup dib */ 110 imDibLineGetPixel imDibLineGetPixelFunc(int bpp); 111 112 /** DIB SetPixel function definition 113 * \ingroup dib */ 114 alias imDibLineSetPixel = void function(ubyte* line, int col, uint pixel); 115 116 /** Returns a function to write pixels into a DIB line. 117 * \ingroup dib */ 118 imDibLineSetPixel imDibLineSetPixelFunc(int bpp); 119 120 /** Creates a DIB from a image handle and a palette handle. 121 * \ingroup dib */ 122 imDib* imDibFromHBitmap(const HBITMAP image, const HPALETTE hPalette); 123 124 /** Creates a image handle from a DIB. 125 * \ingroup dib */ 126 HBITMAP imDibToHBitmap(const(imDib)* dib); 127 128 /** Returns a Logical palette from the DIB palette. \n 129 * DIB bpp must be <=8. 130 * \ingroup dib */ 131 HPALETTE imDibLogicalPalette(const(imDib)* dib); 132 133 /** Captures the screen into a DIB. 134 * \ingroup dib */ 135 imDib* imDibCaptureScreen(int x, int y, int width, int height); 136 137 /** Transfer the DIB to the clipboard. \n 138 * "dib" pointer can not be used after, or use imDibCopyClipboard(imDibCreateCopy(dib)). \n 139 * You cannot paste a DIB section from one application into another application. \n 140 * Warning: Clipboard functions in C++ can fail with Visual C++ /EHsc (Enable C++ Exceptions) 141 * \ingroup dib */ 142 void imDibCopyClipboard(imDib* dib); 143 144 /** Creates a reference for the DIB in the clipboard if any. Returns NULL otherwise. 145 * Warning: Clipboard functions in C++ can fail with Visual C++ /EHsc (Enable C++ Exceptions) 146 * \ingroup dib */ 147 imDib* imDibPasteClipboard(); 148 149 /** Checks if there is a dib at the clipboard. 150 * \ingroup dib */ 151 int imDibIsClipboardAvailable(); 152 153 /** Saves the DIB into a file ".bmp". 154 * \ingroup dib */ 155 int imDibSaveFile(const(imDib)* dib, const(char)* filename); 156 157 /** Creates a DIB from a file ".bmp". 158 * \ingroup dib */ 159 imDib* imDibLoadFile(const(char)* filename); 160 161 /** Converts a DIB into an RGBA image. alpha is optional. bpp must be >8. \n 162 * alpha is used only when bpp=32. 163 * \ingroup dib */ 164 void imDibDecodeToRGBA(const(imDib)* dib, ubyte* red, ubyte* green, ubyte* blue, ubyte* alpha); 165 166 /** Converts a DIB into an indexed image. bpp must be <=8. colors must have room for at least 256 colors. 167 * colors is rgb packed (RGBRGBRGB...) 168 * \ingroup dib */ 169 void imDibDecodeToMap(const(imDib)* dib, ubyte* map, c_long* palette); 170 171 /** Converts an RGBA image into a DIB. alpha is optional. bpp must be >8. \n 172 * alpha is used only when bpp=32. 173 * \ingroup dib */ 174 void imDibEncodeFromRGBA(imDib* dib, const(ubyte)* red, const(ubyte)* green, const(ubyte)* blue, const(ubyte)* alpha); 175 176 /** Converts an indexed image into a DIB. bpp must be <=8. \n 177 * colors is rgb packed (RGBRGBRGB...) 178 * \ingroup dib */ 179 void imDibEncodeFromMap(imDib* dib, const(ubyte)* map, const(c_long)* palette, int palette_count); 180 181 /** Converts a IM_RGB packed image, with or without alpha, into a DIB. 182 * \ingroup dib */ 183 void imDibEncodeFromBitmap(imDib* dib, const(ubyte)* data); 184 185 /** Converts a DIB into IM_RGB packed image, with or without alpha. 186 * \ingroup dib */ 187 void imDibDecodeToBitmap(const(imDib)* dib, ubyte* data); 188 189 //#ifdef __IM_IMAGE_H 190 /* You must include "im_image.h" before this header to enable these declarations. */ 191 import im.im_image : imImage; 192 193 /** Creates a imImage from the dib data. 194 * \ingroup dib */ 195 imImage* imDibToImage(const(imDib)* dib); 196 197 /** Creates a Dib from the image. It must be a bitmap image. 198 * \ingroup dib */ 199 imDib* imDibFromImage(const(imImage)* image); 200 201 /** Creates a Dib Section from the image. It must be a bitmap image. 202 * \ingroup dib */ 203 imDib* imDibSectionFromImage(HDC hDC, HBITMAP* bitmap, const(imImage)* image); 204 205 /** Creates an imImage from a RCDATA in the executable/dll resources. (Since 3.9) \n 206 * module can be NULL, it will use GetModuleHandle(NULL). \n 207 * name is the name of the resource. If using IDs, then can be obtained from MAKEINTRESOURCE(id). \n 208 * index is the image index in the file, 0 will return the first image. 209 * \ingroup dib */ 210 imImage* imImageLoadFromResource(HMODULE module_, LPCTSTR name, int index, int* error); 211 //#endif