gdiplus: Don't require specific gdi+ versions in metafile structures.
[wine.git] / dlls / gdiplus / gdiplus_private.h
blobd6806cc94a9a75e6c5e7b9f01ba8d9e6ca342013
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 VALID_MAGIC(x) (((x) & 0xfffff000) == 0xdbc01000)
45 #define TENSION_CONST (0.3)
47 #define GIF_DISPOSE_UNSPECIFIED 0
48 #define GIF_DISPOSE_DO_NOT_DISPOSE 1
49 #define GIF_DISPOSE_RESTORE_TO_BKGND 2
50 #define GIF_DISPOSE_RESTORE_TO_PREV 3
52 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc(size_t size)
54 return HeapAlloc(GetProcessHeap(), 0, size);
57 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t size)
59 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
62 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t size)
64 return HeapReAlloc(GetProcessHeap(), 0, mem, size);
67 static inline BOOL heap_free(void *mem)
69 return HeapFree(GetProcessHeap(), 0, mem);
72 COLORREF ARGB2COLORREF(ARGB color) DECLSPEC_HIDDEN;
73 HBITMAP ARGB2BMP(ARGB color) DECLSPEC_HIDDEN;
74 extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
75 REAL startAngle, REAL sweepAngle) DECLSPEC_HIDDEN;
76 extern REAL gdiplus_atan2(REAL dy, REAL dx) DECLSPEC_HIDDEN;
77 extern GpStatus hresult_to_status(HRESULT res) DECLSPEC_HIDDEN;
78 extern REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
79 extern REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
80 extern REAL units_scale(GpUnit from, GpUnit to, REAL dpi) DECLSPEC_HIDDEN;
82 extern GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
83 GpCoordinateSpace src_space, GpMatrix *matrix) DECLSPEC_HIDDEN;
85 extern GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics) DECLSPEC_HIDDEN;
86 extern GpStatus encode_image_png(GpImage *image, IStream* stream, GDIPCONST EncoderParameters* params) DECLSPEC_HIDDEN;
88 extern GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result) DECLSPEC_HIDDEN;
89 extern GpStatus METAFILE_GetDC(GpMetafile* metafile, HDC *hdc) DECLSPEC_HIDDEN;
90 extern GpStatus METAFILE_ReleaseDC(GpMetafile* metafile, HDC hdc) DECLSPEC_HIDDEN;
91 extern GpStatus METAFILE_GraphicsClear(GpMetafile* metafile, ARGB color) DECLSPEC_HIDDEN;
92 extern GpStatus METAFILE_FillRectangles(GpMetafile* metafile, GpBrush* brush,
93 GDIPCONST GpRectF* rects, INT count) DECLSPEC_HIDDEN;
94 extern GpStatus METAFILE_SetClipRect(GpMetafile* metafile,
95 REAL x, REAL y, REAL width, REAL height, CombineMode mode) DECLSPEC_HIDDEN;
96 extern GpStatus METAFILE_SetPageTransform(GpMetafile* metafile, GpUnit unit, REAL scale) DECLSPEC_HIDDEN;
97 extern GpStatus METAFILE_SetWorldTransform(GpMetafile* metafile, GDIPCONST GpMatrix* transform) DECLSPEC_HIDDEN;
98 extern GpStatus METAFILE_ScaleWorldTransform(GpMetafile* metafile, REAL sx, REAL sy, MatrixOrder order) DECLSPEC_HIDDEN;
99 extern GpStatus METAFILE_MultiplyWorldTransform(GpMetafile* metafile, GDIPCONST GpMatrix* matrix, MatrixOrder order) DECLSPEC_HIDDEN;
100 extern GpStatus METAFILE_RotateWorldTransform(GpMetafile* metafile, REAL angle, MatrixOrder order) DECLSPEC_HIDDEN;
101 extern GpStatus METAFILE_TranslateWorldTransform(GpMetafile* metafile, REAL dx, REAL dy, MatrixOrder order) DECLSPEC_HIDDEN;
102 extern GpStatus METAFILE_ResetWorldTransform(GpMetafile* metafile) DECLSPEC_HIDDEN;
103 extern GpStatus METAFILE_BeginContainer(GpMetafile* metafile, GDIPCONST GpRectF *dstrect,
104 GDIPCONST GpRectF *srcrect, GpUnit unit, DWORD StackIndex) DECLSPEC_HIDDEN;
105 extern GpStatus METAFILE_BeginContainerNoParams(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
106 extern GpStatus METAFILE_EndContainer(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
107 extern GpStatus METAFILE_SaveGraphics(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
108 extern GpStatus METAFILE_RestoreGraphics(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
109 extern GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) DECLSPEC_HIDDEN;
110 extern GpStatus METAFILE_DrawImagePointsRect(GpMetafile* metafile, GpImage *image,
111 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
112 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
113 DrawImageAbort callback, VOID *callbackData) DECLSPEC_HIDDEN;
114 extern GpStatus METAFILE_AddSimpleProperty(GpMetafile *metafile, SHORT prop, SHORT val) DECLSPEC_HIDDEN;
115 extern GpStatus METAFILE_DrawPath(GpMetafile *metafile, GpPen *pen, GpPath *path) DECLSPEC_HIDDEN;
116 extern GpStatus METAFILE_FillPath(GpMetafile *metafile, GpBrush *brush, GpPath *path) DECLSPEC_HIDDEN;
118 extern void calc_curve_bezier(const GpPointF *pts, REAL tension, REAL *x1,
119 REAL *y1, REAL *x2, REAL *y2) DECLSPEC_HIDDEN;
120 extern void calc_curve_bezier_endp(REAL xend, REAL yend, REAL xadj, REAL yadj,
121 REAL tension, REAL *x, REAL *y) DECLSPEC_HIDDEN;
123 extern void free_installed_fonts(void) DECLSPEC_HIDDEN;
125 extern BOOL lengthen_path(GpPath *path, INT len) DECLSPEC_HIDDEN;
127 extern GpStatus trace_path(GpGraphics *graphics, GpPath *path) DECLSPEC_HIDDEN;
129 typedef struct region_element region_element;
130 extern void delete_element(region_element *element) DECLSPEC_HIDDEN;
132 extern GpStatus get_hatch_data(HatchStyle hatchstyle, const char **result) DECLSPEC_HIDDEN;
134 static inline INT gdip_round(REAL x)
136 return (INT) floorf(x + 0.5);
139 static inline INT ceilr(REAL x)
141 return (INT) ceilf(x);
144 static inline REAL deg2rad(REAL degrees)
146 return M_PI * degrees / 180.0;
149 static inline ARGB color_over(ARGB bg, ARGB fg)
151 BYTE b, g, r, a;
152 BYTE bg_alpha, fg_alpha;
154 fg_alpha = (fg>>24)&0xff;
156 if (fg_alpha == 0xff) return fg;
158 if (fg_alpha == 0) return bg;
160 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
162 if (bg_alpha == 0) return fg;
164 a = bg_alpha + fg_alpha;
165 b = ((bg&0xff)*bg_alpha + (fg&0xff)*fg_alpha)/a;
166 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*fg_alpha)/a;
167 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*fg_alpha)/a;
169 return (a<<24)|(r<<16)|(g<<8)|b;
172 /* fg is premult, bg and return value are not */
173 static inline ARGB color_over_fgpremult(ARGB bg, ARGB fg)
175 BYTE b, g, r, a;
176 BYTE bg_alpha, fg_alpha;
178 fg_alpha = (fg>>24)&0xff;
180 if (fg_alpha == 0) return bg;
182 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
184 a = bg_alpha + fg_alpha;
185 b = ((bg&0xff)*bg_alpha + (fg&0xff)*0xff)/a;
186 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*0xff)/a;
187 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*0xff)/a;
189 return (a<<24)|(r<<16)|(g<<8)|b;
192 extern const char *debugstr_rectf(const RectF* rc) DECLSPEC_HIDDEN;
194 extern const char *debugstr_pointf(const PointF* pt) DECLSPEC_HIDDEN;
196 extern void convert_32bppARGB_to_32bppPARGB(UINT width, UINT height,
197 BYTE *dst_bits, INT dst_stride, const BYTE *src_bits, INT src_stride) DECLSPEC_HIDDEN;
199 extern GpStatus convert_pixels(INT width, INT height,
200 INT dst_stride, BYTE *dst_bits, PixelFormat dst_format,
201 INT src_stride, const BYTE *src_bits, PixelFormat src_format, ColorPalette *palette) DECLSPEC_HIDDEN;
203 extern PixelFormat apply_image_attributes(const GpImageAttributes *attributes, LPBYTE data,
204 UINT width, UINT height, INT stride, ColorAdjustType type, PixelFormat fmt) DECLSPEC_HIDDEN;
206 struct GpMatrix{
207 REAL matrix[6];
210 struct GpPen{
211 UINT style;
212 GpUnit unit;
213 REAL width;
214 GpLineCap endcap;
215 GpLineCap startcap;
216 GpDashCap dashcap;
217 GpCustomLineCap *customstart;
218 GpCustomLineCap *customend;
219 GpLineJoin join;
220 REAL miterlimit;
221 GpDashStyle dash;
222 REAL *dashes;
223 INT numdashes;
224 REAL offset; /* dash offset */
225 GpBrush *brush;
226 GpPenAlignment align;
227 GpMatrix transform;
230 struct GpGraphics{
231 HDC hdc;
232 HWND hwnd;
233 BOOL owndc;
234 BOOL alpha_hdc;
235 GpImage *image;
236 ImageType image_type;
237 SmoothingMode smoothing;
238 CompositingQuality compqual;
239 InterpolationMode interpolation;
240 PixelOffsetMode pixeloffset;
241 CompositingMode compmode;
242 TextRenderingHint texthint;
243 GpUnit unit; /* page unit */
244 REAL scale; /* page scale */
245 REAL xres, yres;
246 GpMatrix worldtrans; /* world transform */
247 BOOL busy; /* hdc handle obtained by GdipGetDC */
248 GpRegion *clip; /* in device coords */
249 UINT textcontrast; /* not used yet. get/set only */
250 struct list containers;
251 GraphicsContainer contid; /* last-issued container ID */
252 INT origin_x, origin_y;
253 /* For giving the caller an HDC when we technically can't: */
254 HBITMAP temp_hbitmap;
255 int temp_hbitmap_width;
256 int temp_hbitmap_height;
257 BYTE *temp_bits;
258 HDC temp_hdc;
261 struct GpBrush{
262 GpBrushType bt;
265 struct GpHatch{
266 GpBrush brush;
267 HatchStyle hatchstyle;
268 ARGB forecol;
269 ARGB backcol;
272 struct GpSolidFill{
273 GpBrush brush;
274 ARGB color;
277 struct GpPathGradient{
278 GpBrush brush;
279 GpPath* path;
280 ARGB centercolor;
281 GpWrapMode wrap;
282 BOOL gamma;
283 GpPointF center;
284 GpPointF focus;
285 REAL* blendfac; /* blend factors */
286 REAL* blendpos; /* blend positions */
287 INT blendcount;
288 ARGB *surroundcolors;
289 INT surroundcolorcount;
290 ARGB* pblendcolor; /* preset blend colors */
291 REAL* pblendpos; /* preset blend positions */
292 INT pblendcount;
293 GpMatrix transform;
296 struct GpLineGradient{
297 GpBrush brush;
298 GpPointF startpoint;
299 GpPointF endpoint;
300 ARGB startcolor;
301 ARGB endcolor;
302 RectF rect;
303 GpWrapMode wrap;
304 BOOL gamma;
305 REAL* blendfac; /* blend factors */
306 REAL* blendpos; /* blend positions */
307 INT blendcount;
308 ARGB* pblendcolor; /* preset blend colors */
309 REAL* pblendpos; /* preset blend positions */
310 INT pblendcount;
313 struct GpTexture{
314 GpBrush brush;
315 GpMatrix transform;
316 GpImage *image;
317 GpImageAttributes *imageattributes;
318 BYTE *bitmap_bits; /* image bits converted to ARGB and run through imageattributes */
321 struct GpPath{
322 GpFillMode fill;
323 GpPathData pathdata;
324 BOOL newfigure; /* whether the next drawing action starts a new figure */
325 INT datalen; /* size of the arrays in pathdata */
328 struct GpPathIterator{
329 GpPathData pathdata;
330 INT subpath_pos; /* for NextSubpath methods */
331 INT marker_pos; /* for NextMarker methods */
332 INT pathtype_pos; /* for NextPathType methods */
335 struct GpCustomLineCap{
336 CustomLineCapType type;
337 GpPathData pathdata;
338 BOOL fill; /* TRUE for fill, FALSE for stroke */
339 GpLineCap cap; /* as far as I can tell, this value is ignored */
340 REAL inset; /* how much to adjust the end of the line */
341 GpLineJoin join;
342 REAL scale;
345 struct GpAdjustableArrowCap{
346 GpCustomLineCap cap;
349 struct GpImage{
350 IWICBitmapDecoder *decoder;
351 ImageType type;
352 GUID format;
353 UINT flags;
354 UINT frame_count, current_frame;
355 ColorPalette *palette;
356 REAL xres, yres;
357 LONG busy;
360 struct GpMetafile{
361 GpImage image;
362 GpRectF bounds;
363 GpUnit unit;
364 MetafileType metafile_type;
365 HENHMETAFILE hemf;
366 int preserve_hemf; /* if true, hemf belongs to the app and should not be deleted */
368 /* recording */
369 HDC record_dc;
370 GpGraphics *record_graphics;
371 BYTE *comment_data;
372 DWORD comment_data_size;
373 DWORD comment_data_length;
374 IStream *record_stream;
375 BOOL auto_frame; /* If true, determine the frame automatically */
376 GpPointF auto_frame_min, auto_frame_max;
377 DWORD next_object_id;
379 /* playback */
380 GpGraphics *playback_graphics;
381 HDC playback_dc;
382 GpPointF playback_points[3];
383 GpRectF src_rect;
384 HANDLETABLE *handle_table;
385 int handle_count;
386 XFORM gdiworldtransform;
387 GpMatrix *world_transform;
388 GpUnit page_unit;
389 REAL page_scale;
390 GpRegion *base_clip; /* clip region in device space for all metafile output */
391 GpRegion *clip; /* clip region within the metafile */
392 struct list containers;
395 struct GpBitmap{
396 GpImage image;
397 INT width;
398 INT height;
399 PixelFormat format;
400 ImageLockMode lockmode;
401 BYTE *bitmapbits; /* pointer to the buffer we passed in BitmapLockBits */
402 HBITMAP hbitmap;
403 HDC hdc;
404 BYTE *bits; /* actual image bits if this is a DIB */
405 INT stride; /* stride of bits if this is a DIB */
406 BYTE *own_bits; /* image bits that need to be freed with this object */
407 INT lockx, locky; /* X and Y coordinates of the rect when a bitmap is locked for writing. */
408 IWICMetadataReader *metadata_reader; /* NULL if there is no metadata */
409 UINT prop_count;
410 PropertyItem *prop_item; /* cached image properties */
413 struct GpCachedBitmap{
414 GpImage *image;
417 struct color_key{
418 BOOL enabled;
419 ARGB low;
420 ARGB high;
423 struct color_matrix{
424 BOOL enabled;
425 ColorMatrixFlags flags;
426 ColorMatrix colormatrix;
427 ColorMatrix graymatrix;
430 struct color_remap_table{
431 BOOL enabled;
432 INT mapsize;
433 ColorMap *colormap;
436 struct GpImageAttributes{
437 WrapMode wrap;
438 ARGB outside_color;
439 BOOL clamp;
440 struct color_key colorkeys[ColorAdjustTypeCount];
441 struct color_matrix colormatrices[ColorAdjustTypeCount];
442 struct color_remap_table colorremaptables[ColorAdjustTypeCount];
443 BOOL gamma_enabled[ColorAdjustTypeCount];
444 REAL gamma[ColorAdjustTypeCount];
447 struct GpFont{
448 GpFontFamily *family;
449 OUTLINETEXTMETRICW otm;
450 REAL emSize; /* in font units */
451 Unit unit;
454 extern const struct GpStringFormat default_drawstring_format DECLSPEC_HIDDEN;
456 struct GpStringFormat{
457 INT attr;
458 LANGID lang;
459 LANGID digitlang;
460 StringAlignment align;
461 StringTrimming trimming;
462 HotkeyPrefix hkprefix;
463 StringAlignment line_align;
464 StringDigitSubstitute digitsub;
465 INT tabcount;
466 REAL firsttab;
467 REAL *tabs;
468 CharacterRange *character_ranges;
469 INT range_count;
470 BOOL generic_typographic;
473 extern void init_generic_string_formats(void) DECLSPEC_HIDDEN;
474 extern void free_generic_string_formats(void) DECLSPEC_HIDDEN;
476 struct GpFontCollection{
477 GpFontFamily **FontFamilies;
478 INT count;
479 INT allocated;
482 struct GpFontFamily{
483 WCHAR FamilyName[LF_FACESIZE];
484 UINT16 em_height, ascent, descent, line_spacing; /* in font units */
485 int dpi;
488 /* internal use */
489 typedef enum RegionType
491 RegionDataRect = 0x10000000,
492 RegionDataPath = 0x10000001,
493 RegionDataEmptyRect = 0x10000002,
494 RegionDataInfiniteRect = 0x10000003,
495 } RegionType;
497 struct region_element
499 DWORD type; /* Rectangle, Path, SpecialRectangle, or CombineMode */
500 union
502 GpRectF rect;
503 GpPath *path;
504 struct
506 struct region_element *left; /* the original region */
507 struct region_element *right; /* what *left was combined with */
508 } combine;
509 } elementdata;
512 struct GpRegion{
513 DWORD num_children;
514 region_element node;
517 typedef GpStatus (*gdip_format_string_callback)(HDC hdc,
518 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
519 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
520 INT lineno, const RectF *bounds, INT *underlined_indexes,
521 INT underlined_index_count, void *user_data);
523 GpStatus gdip_format_string(HDC hdc,
524 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
525 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, int ignore_empty_clip,
526 gdip_format_string_callback callback, void *user_data) DECLSPEC_HIDDEN;
528 void get_log_fontW(const GpFont *, GpGraphics *, LOGFONTW *) DECLSPEC_HIDDEN;
530 static inline BOOL image_lock(GpImage *image, BOOL *unlock)
532 LONG tid = GetCurrentThreadId(), owner_tid;
533 owner_tid = InterlockedCompareExchange(&image->busy, tid, 0);
534 *unlock = !owner_tid;
535 return !owner_tid || owner_tid==tid;
538 static inline void image_unlock(GpImage *image, BOOL unlock)
540 if (unlock) image->busy = 0;
543 #endif