1 /** \file
2 * \brief Windows DIB (Device Independent Bitmap)
3 *
4 * See Copyright Notice in im_lib.h
5 */6 moduleim.im_dib;
7 8 version(IM) :
9 version(Windows) :
10 11 importcore.stdc.config : c_long;
12 importcore.sys.windows.windows;
13 14 version(DigitalMars) { pragma(lib, "im.lib"); }
15 16 extern(C) @nogcnothrow :
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 structimDib// typedef struct _imDib imDib55 {
56 HGLOBALhandle; /**< The windows memory handle */57 BYTE* buffer; /**< The DIB as it is defined in memory */58 intfree_buffer; /**< Free the memory buffer, used only for DIB section */59 intsize; /**< 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 intpalette_count; /**< number of colors in the palette */67 intbits_size; /**< size in bytes of the Bitmap Bits */68 intline_size; /**< size in bytes of one line, includes padding */69 intpad_size; /**< number of bytes remaining in the line, lines are in a word boundary */70 71 intis_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(intwidth, intheight, intbpp);
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(HDChDC, HBITMAP* bitmap, intwidth, intheight, intbpp);
98 99 /** Destroy the DIB
100 * \ingroup dib */101 voidimDibDestroy(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 aliasimDibLineGetPixel = uintfunction(ubyte* line, intcol);
107 108 /** Returns a function to read pixels from a DIB line.
109 * \ingroup dib */110 imDibLineGetPixelimDibLineGetPixelFunc(intbpp);
111 112 /** DIB SetPixel function definition
113 * \ingroup dib */114 aliasimDibLineSetPixel = voidfunction(ubyte* line, intcol, uintpixel);
115 116 /** Returns a function to write pixels into a DIB line.
117 * \ingroup dib */118 imDibLineSetPixelimDibLineSetPixelFunc(intbpp);
119 120 /** Creates a DIB from a image handle and a palette handle.
121 * \ingroup dib */122 imDib* imDibFromHBitmap(constHBITMAPimage, constHPALETTEhPalette);
123 124 /** Creates a image handle from a DIB.
125 * \ingroup dib */126 HBITMAPimDibToHBitmap(const(imDib)* dib);
127 128 /** Returns a Logical palette from the DIB palette. \n
129 * DIB bpp must be <=8.
130 * \ingroup dib */131 HPALETTEimDibLogicalPalette(const(imDib)* dib);
132 133 /** Captures the screen into a DIB.
134 * \ingroup dib */135 imDib* imDibCaptureScreen(intx, inty, intwidth, intheight);
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 voidimDibCopyClipboard(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 intimDibIsClipboardAvailable();
152 153 /** Saves the DIB into a file ".bmp".
154 * \ingroup dib */155 intimDibSaveFile(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 voidimDibDecodeToRGBA(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 voidimDibDecodeToMap(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 voidimDibEncodeFromRGBA(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 voidimDibEncodeFromMap(imDib* dib, const(ubyte)* map, const(c_long)* palette, intpalette_count);
180 181 /** Converts a IM_RGB packed image, with or without alpha, into a DIB.
182 * \ingroup dib */183 voidimDibEncodeFromBitmap(imDib* dib, const(ubyte)* data);
184 185 /** Converts a DIB into IM_RGB packed image, with or without alpha.
186 * \ingroup dib */187 voidimDibDecodeToBitmap(const(imDib)* dib, ubyte* data);
188 189 //#ifdef __IM_IMAGE_H190 /* You must include "im_image.h" before this header to enable these declarations. */191 importim.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(HDChDC, 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(HMODULEmodule_, LPCTSTRname, intindex, int* error);
211 //#endif