wined3d: Pass a texture and sub-resource index to wined3d_volume_download_data().
[wine.git] / dlls / gdiplus / gdiplus_private.h
blob25ae5ee24d6af200204807f4e31d0fd44d165ef7
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #ifndef __WINE_GP_PRIVATE_H_
20 #define __WINE_GP_PRIVATE_H_
22 #include <math.h>
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "winbase.h"
28 #include "winuser.h"
30 #include "objbase.h"
31 #include "ocidl.h"
32 #include "wincodecsdk.h"
33 #include "wine/list.h"
35 #include "gdiplus.h"
37 #define GP_DEFAULT_PENSTYLE (PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT | PS_JOIN_MITER)
38 #define MAX_ARC_PTS (13)
39 #define MAX_DASHLEN (16) /* this is a limitation of gdi */
40 #define INCH_HIMETRIC (2540)
42 #define VERSION_MAGIC 0xdbc01001
43 #define VERSION_MAGIC2 0xdbc01002
44 #define TENSION_CONST (0.3)
46 #define GIF_DISPOSE_UNSPECIFIED 0
47 #define GIF_DISPOSE_DO_NOT_DISPOSE 1
48 #define GIF_DISPOSE_RESTORE_TO_BKGND 2
49 #define GIF_DISPOSE_RESTORE_TO_PREV 3
51 static void *heap_alloc(size_t len) __WINE_ALLOC_SIZE(1);
52 static inline void *heap_alloc(size_t len)
54 return HeapAlloc(GetProcessHeap(), 0, len);
57 static void *heap_alloc_zero(size_t len) __WINE_ALLOC_SIZE(1);
58 static inline void *heap_alloc_zero(size_t len)
60 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
63 static void *heap_realloc(void *mem, size_t len) __WINE_ALLOC_SIZE(2);
64 static inline void *heap_realloc(void *mem, size_t len)
66 return HeapReAlloc(GetProcessHeap(), 0, mem, len);
69 static inline BOOL heap_free(void *mem)
71 return HeapFree(GetProcessHeap(), 0, mem);
74 COLORREF ARGB2COLORREF(ARGB color) DECLSPEC_HIDDEN;
75 HBITMAP ARGB2BMP(ARGB color) DECLSPEC_HIDDEN;
76 extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
77 REAL startAngle, REAL sweepAngle) DECLSPEC_HIDDEN;
78 extern REAL gdiplus_atan2(REAL dy, REAL dx) DECLSPEC_HIDDEN;
79 extern GpStatus hresult_to_status(HRESULT res) DECLSPEC_HIDDEN;
80 extern REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
81 extern REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
82 extern REAL units_scale(GpUnit from, GpUnit to, REAL dpi) DECLSPEC_HIDDEN;
84 extern GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics) DECLSPEC_HIDDEN;
86 extern GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result) DECLSPEC_HIDDEN;
87 extern GpStatus METAFILE_GetDC(GpMetafile* metafile, HDC *hdc) DECLSPEC_HIDDEN;
88 extern GpStatus METAFILE_ReleaseDC(GpMetafile* metafile, HDC hdc) DECLSPEC_HIDDEN;
89 extern GpStatus METAFILE_GraphicsClear(GpMetafile* metafile, ARGB color) DECLSPEC_HIDDEN;
90 extern GpStatus METAFILE_FillRectangles(GpMetafile* metafile, GpBrush* brush,
91 GDIPCONST GpRectF* rects, INT count) DECLSPEC_HIDDEN;
92 extern GpStatus METAFILE_SetPageTransform(GpMetafile* metafile, GpUnit unit, REAL scale) DECLSPEC_HIDDEN;
93 extern GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) DECLSPEC_HIDDEN;
95 extern void calc_curve_bezier(const GpPointF *pts, REAL tension, REAL *x1,
96 REAL *y1, REAL *x2, REAL *y2) DECLSPEC_HIDDEN;
97 extern void calc_curve_bezier_endp(REAL xend, REAL yend, REAL xadj, REAL yadj,
98 REAL tension, REAL *x, REAL *y) DECLSPEC_HIDDEN;
100 extern void free_installed_fonts(void) DECLSPEC_HIDDEN;
102 extern BOOL lengthen_path(GpPath *path, INT len) DECLSPEC_HIDDEN;
104 extern GpStatus trace_path(GpGraphics *graphics, GpPath *path) DECLSPEC_HIDDEN;
106 typedef struct region_element region_element;
107 extern void delete_element(region_element *element) DECLSPEC_HIDDEN;
109 extern GpStatus get_hatch_data(HatchStyle hatchstyle, const char **result) DECLSPEC_HIDDEN;
111 static inline INT gdip_round(REAL x)
113 return (INT) floorf(x + 0.5);
116 static inline INT ceilr(REAL x)
118 return (INT) ceilf(x);
121 static inline REAL deg2rad(REAL degrees)
123 return M_PI * degrees / 180.0;
126 static inline ARGB color_over(ARGB bg, ARGB fg)
128 BYTE b, g, r, a;
129 BYTE bg_alpha, fg_alpha;
131 fg_alpha = (fg>>24)&0xff;
133 if (fg_alpha == 0xff) return fg;
135 if (fg_alpha == 0) return bg;
137 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
139 if (bg_alpha == 0) return fg;
141 a = bg_alpha + fg_alpha;
142 b = ((bg&0xff)*bg_alpha + (fg&0xff)*fg_alpha)/a;
143 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*fg_alpha)/a;
144 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*fg_alpha)/a;
146 return (a<<24)|(r<<16)|(g<<8)|b;
149 /* fg is premult, bg and return value are not */
150 static inline ARGB color_over_fgpremult(ARGB bg, ARGB fg)
152 BYTE b, g, r, a;
153 BYTE bg_alpha, fg_alpha;
155 fg_alpha = (fg>>24)&0xff;
157 if (fg_alpha == 0) return bg;
159 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
161 a = bg_alpha + fg_alpha;
162 b = ((bg&0xff)*bg_alpha + (fg&0xff)*0xff)/a;
163 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*0xff)/a;
164 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*0xff)/a;
166 return (a<<24)|(r<<16)|(g<<8)|b;
169 extern const char *debugstr_rectf(const RectF* rc) DECLSPEC_HIDDEN;
171 extern const char *debugstr_pointf(const PointF* pt) DECLSPEC_HIDDEN;
173 extern void convert_32bppARGB_to_32bppPARGB(UINT width, UINT height,
174 BYTE *dst_bits, INT dst_stride, const BYTE *src_bits, INT src_stride) DECLSPEC_HIDDEN;
176 extern GpStatus convert_pixels(INT width, INT height,
177 INT dst_stride, BYTE *dst_bits, PixelFormat dst_format,
178 INT src_stride, const BYTE *src_bits, PixelFormat src_format, ColorPalette *palette) DECLSPEC_HIDDEN;
180 extern PixelFormat apply_image_attributes(const GpImageAttributes *attributes, LPBYTE data,
181 UINT width, UINT height, INT stride, ColorAdjustType type, PixelFormat fmt) DECLSPEC_HIDDEN;
183 struct GpMatrix{
184 REAL matrix[6];
187 struct GpPen{
188 UINT style;
189 GpUnit unit;
190 REAL width;
191 GpLineCap endcap;
192 GpLineCap startcap;
193 GpDashCap dashcap;
194 GpCustomLineCap *customstart;
195 GpCustomLineCap *customend;
196 GpLineJoin join;
197 REAL miterlimit;
198 GpDashStyle dash;
199 REAL *dashes;
200 INT numdashes;
201 REAL offset; /* dash offset */
202 GpBrush *brush;
203 GpPenAlignment align;
204 GpMatrix transform;
207 struct GpGraphics{
208 HDC hdc;
209 HWND hwnd;
210 BOOL owndc;
211 BOOL alpha_hdc;
212 GpImage *image;
213 ImageType image_type;
214 SmoothingMode smoothing;
215 CompositingQuality compqual;
216 InterpolationMode interpolation;
217 PixelOffsetMode pixeloffset;
218 CompositingMode compmode;
219 TextRenderingHint texthint;
220 GpUnit unit; /* page unit */
221 REAL scale; /* page scale */
222 REAL xres, yres;
223 GpMatrix worldtrans; /* world transform */
224 BOOL busy; /* hdc handle obtained by GdipGetDC */
225 GpRegion *clip; /* in device coords */
226 UINT textcontrast; /* not used yet. get/set only */
227 struct list containers;
228 GraphicsContainer contid; /* last-issued container ID */
229 INT origin_x, origin_y;
230 /* For giving the caller an HDC when we technically can't: */
231 HBITMAP temp_hbitmap;
232 int temp_hbitmap_width;
233 int temp_hbitmap_height;
234 BYTE *temp_bits;
235 HDC temp_hdc;
238 struct GpBrush{
239 GpBrushType bt;
242 struct GpHatch{
243 GpBrush brush;
244 HatchStyle hatchstyle;
245 ARGB forecol;
246 ARGB backcol;
249 struct GpSolidFill{
250 GpBrush brush;
251 ARGB color;
254 struct GpPathGradient{
255 GpBrush brush;
256 GpPath* path;
257 ARGB centercolor;
258 GpWrapMode wrap;
259 BOOL gamma;
260 GpPointF center;
261 GpPointF focus;
262 REAL* blendfac; /* blend factors */
263 REAL* blendpos; /* blend positions */
264 INT blendcount;
265 ARGB *surroundcolors;
266 INT surroundcolorcount;
267 ARGB* pblendcolor; /* preset blend colors */
268 REAL* pblendpos; /* preset blend positions */
269 INT pblendcount;
270 GpMatrix transform;
273 struct GpLineGradient{
274 GpBrush brush;
275 GpPointF startpoint;
276 GpPointF endpoint;
277 ARGB startcolor;
278 ARGB endcolor;
279 RectF rect;
280 GpWrapMode wrap;
281 BOOL gamma;
282 REAL* blendfac; /* blend factors */
283 REAL* blendpos; /* blend positions */
284 INT blendcount;
285 ARGB* pblendcolor; /* preset blend colors */
286 REAL* pblendpos; /* preset blend positions */
287 INT pblendcount;
290 struct GpTexture{
291 GpBrush brush;
292 GpMatrix transform;
293 GpImage *image;
294 GpImageAttributes *imageattributes;
295 BYTE *bitmap_bits; /* image bits converted to ARGB and run through imageattributes */
298 struct GpPath{
299 GpFillMode fill;
300 GpPathData pathdata;
301 BOOL newfigure; /* whether the next drawing action starts a new figure */
302 INT datalen; /* size of the arrays in pathdata */
305 struct GpPathIterator{
306 GpPathData pathdata;
307 INT subpath_pos; /* for NextSubpath methods */
308 INT marker_pos; /* for NextMarker methods */
309 INT pathtype_pos; /* for NextPathType methods */
312 struct GpCustomLineCap{
313 GpPathData pathdata;
314 BOOL fill; /* TRUE for fill, FALSE for stroke */
315 GpLineCap cap; /* as far as I can tell, this value is ignored */
316 REAL inset; /* how much to adjust the end of the line */
317 GpLineJoin join;
318 REAL scale;
321 struct GpAdjustableArrowCap{
322 GpCustomLineCap cap;
325 struct GpImage{
326 IPicture *picture;
327 IWICBitmapDecoder *decoder;
328 ImageType type;
329 GUID format;
330 UINT flags;
331 UINT frame_count, current_frame;
332 ColorPalette *palette;
333 REAL xres, yres;
336 struct GpMetafile{
337 GpImage image;
338 GpRectF bounds;
339 GpUnit unit;
340 MetafileType metafile_type;
341 HENHMETAFILE hemf;
342 int preserve_hemf; /* if true, hemf belongs to the app and should not be deleted */
344 /* recording */
345 HDC record_dc;
346 GpGraphics *record_graphics;
347 BYTE *comment_data;
348 DWORD comment_data_size;
349 DWORD comment_data_length;
350 IStream *record_stream;
351 BOOL auto_frame; /* If true, determine the frame automatically */
352 GpPointF auto_frame_min, auto_frame_max;
354 /* playback */
355 GpGraphics *playback_graphics;
356 HDC playback_dc;
357 GpPointF playback_points[3];
358 GpRectF src_rect;
359 HANDLETABLE *handle_table;
360 int handle_count;
361 GpMatrix *world_transform;
362 GpUnit page_unit;
363 REAL page_scale;
364 GpRegion *base_clip; /* clip region in device space for all metafile output */
367 struct GpBitmap{
368 GpImage image;
369 INT width;
370 INT height;
371 PixelFormat format;
372 ImageLockMode lockmode;
373 INT numlocks;
374 BYTE *bitmapbits; /* pointer to the buffer we passed in BitmapLockBits */
375 HBITMAP hbitmap;
376 HDC hdc;
377 BYTE *bits; /* actual image bits if this is a DIB */
378 INT stride; /* stride of bits if this is a DIB */
379 BYTE *own_bits; /* image bits that need to be freed with this object */
380 INT lockx, locky; /* X and Y coordinates of the rect when a bitmap is locked for writing. */
381 IWICMetadataReader *metadata_reader; /* NULL if there is no metadata */
382 UINT prop_count;
383 PropertyItem *prop_item; /* cached image properties */
386 struct GpCachedBitmap{
387 GpImage *image;
390 struct color_key{
391 BOOL enabled;
392 ARGB low;
393 ARGB high;
396 struct color_matrix{
397 BOOL enabled;
398 ColorMatrixFlags flags;
399 ColorMatrix colormatrix;
400 ColorMatrix graymatrix;
403 struct color_remap_table{
404 BOOL enabled;
405 INT mapsize;
406 ColorMap *colormap;
409 struct GpImageAttributes{
410 WrapMode wrap;
411 ARGB outside_color;
412 BOOL clamp;
413 struct color_key colorkeys[ColorAdjustTypeCount];
414 struct color_matrix colormatrices[ColorAdjustTypeCount];
415 struct color_remap_table colorremaptables[ColorAdjustTypeCount];
416 BOOL gamma_enabled[ColorAdjustTypeCount];
417 REAL gamma[ColorAdjustTypeCount];
420 struct GpFont{
421 GpFontFamily *family;
422 OUTLINETEXTMETRICW otm;
423 REAL emSize; /* in font units */
424 Unit unit;
427 struct GpStringFormat{
428 INT attr;
429 LANGID lang;
430 LANGID digitlang;
431 StringAlignment align;
432 StringTrimming trimming;
433 HotkeyPrefix hkprefix;
434 StringAlignment vertalign;
435 StringDigitSubstitute digitsub;
436 INT tabcount;
437 REAL firsttab;
438 REAL *tabs;
439 CharacterRange *character_ranges;
440 INT range_count;
441 BOOL generic_typographic;
444 struct GpFontCollection{
445 GpFontFamily **FontFamilies;
446 INT count;
447 INT allocated;
450 struct GpFontFamily{
451 WCHAR FamilyName[LF_FACESIZE];
452 UINT16 em_height, ascent, descent, line_spacing; /* in font units */
453 int dpi;
456 /* internal use */
457 typedef enum RegionType
459 RegionDataRect = 0x10000000,
460 RegionDataPath = 0x10000001,
461 RegionDataEmptyRect = 0x10000002,
462 RegionDataInfiniteRect = 0x10000003,
463 } RegionType;
465 struct region_element
467 DWORD type; /* Rectangle, Path, SpecialRectangle, or CombineMode */
468 union
470 GpRectF rect;
471 GpPath *path;
472 struct
474 struct region_element *left; /* the original region */
475 struct region_element *right; /* what *left was combined with */
476 } combine;
477 } elementdata;
480 struct GpRegion{
481 DWORD num_children;
482 region_element node;
485 typedef GpStatus (*gdip_format_string_callback)(HDC hdc,
486 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
487 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
488 INT lineno, const RectF *bounds, INT *underlined_indexes,
489 INT underlined_index_count, void *user_data);
491 GpStatus gdip_format_string(HDC hdc,
492 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
493 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, int ignore_empty_clip,
494 gdip_format_string_callback callback, void *user_data) DECLSPEC_HIDDEN;
496 void get_log_fontW(const GpFont *, GpGraphics *, LOGFONTW *) DECLSPEC_HIDDEN;
498 #endif