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_
25 #define WIN32_NO_STATUS
27 #define COM_NO_WINDOWS_H
29 #define NONAMELESSUNION
36 #include <wincodecsdk.h>
39 #include <wine/unicode.h>
40 #include <wine/list.h>
42 #include <wine/debug.h>
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 #define GP_DEFAULT_PENSTYLE (PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT | PS_JOIN_MITER)
46 #define MAX_ARC_PTS (13)
47 #define MAX_DASHLEN (16) /* this is a limitation of gdi */
48 #define INCH_HIMETRIC (2540)
50 #define VERSION_MAGIC 0xdbc01001
51 #define VERSION_MAGIC2 0xdbc01002
52 #define VALID_MAGIC(x) (((x) & 0xfffff000) == 0xdbc01000)
53 #define TENSION_CONST (0.3)
55 #define GIF_DISPOSE_UNSPECIFIED 0
56 #define GIF_DISPOSE_DO_NOT_DISPOSE 1
57 #define GIF_DISPOSE_RESTORE_TO_BKGND 2
58 #define GIF_DISPOSE_RESTORE_TO_PREV 3
60 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc(size_t size
)
62 return HeapAlloc(GetProcessHeap(), 0, size
);
65 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t size
)
67 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
70 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc(void *mem
, size_t size
)
72 return HeapReAlloc(GetProcessHeap(), 0, mem
, size
);
75 static inline BOOL
heap_free(void *mem
)
77 return HeapFree(GetProcessHeap(), 0, mem
);
80 COLORREF
ARGB2COLORREF(ARGB color
) DECLSPEC_HIDDEN
;
81 HBITMAP
ARGB2BMP(ARGB color
) DECLSPEC_HIDDEN
;
82 extern INT
arc2polybezier(GpPointF
* points
, REAL x1
, REAL y1
, REAL x2
, REAL y2
,
83 REAL startAngle
, REAL sweepAngle
) DECLSPEC_HIDDEN
;
84 extern REAL
gdiplus_atan2(REAL dy
, REAL dx
) DECLSPEC_HIDDEN
;
85 extern GpStatus
hresult_to_status(HRESULT res
) DECLSPEC_HIDDEN
;
86 extern REAL
units_to_pixels(REAL units
, GpUnit unit
, REAL dpi
) DECLSPEC_HIDDEN
;
87 extern REAL
pixels_to_units(REAL pixels
, GpUnit unit
, REAL dpi
) DECLSPEC_HIDDEN
;
88 extern REAL
units_scale(GpUnit from
, GpUnit to
, REAL dpi
) DECLSPEC_HIDDEN
;
90 #define WineCoordinateSpaceGdiDevice ((GpCoordinateSpace)4)
92 extern GpStatus
gdi_transform_acquire(GpGraphics
*graphics
);
93 extern GpStatus
gdi_transform_release(GpGraphics
*graphics
);
94 extern GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
95 GpCoordinateSpace src_space
, GpMatrix
*matrix
) DECLSPEC_HIDDEN
;
96 extern GpStatus
gdip_transform_points(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
97 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
) DECLSPEC_HIDDEN
;
99 extern GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
) DECLSPEC_HIDDEN
;
100 extern GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
, GDIPCONST EncoderParameters
* params
) DECLSPEC_HIDDEN
;
102 extern GpStatus
METAFILE_GetGraphicsContext(GpMetafile
* metafile
, GpGraphics
**result
) DECLSPEC_HIDDEN
;
103 extern GpStatus
METAFILE_GetDC(GpMetafile
* metafile
, HDC
*hdc
) DECLSPEC_HIDDEN
;
104 extern GpStatus
METAFILE_ReleaseDC(GpMetafile
* metafile
, HDC hdc
) DECLSPEC_HIDDEN
;
105 extern GpStatus
METAFILE_GraphicsClear(GpMetafile
* metafile
, ARGB color
) DECLSPEC_HIDDEN
;
106 extern GpStatus
METAFILE_FillRectangles(GpMetafile
* metafile
, GpBrush
* brush
,
107 GDIPCONST GpRectF
* rects
, INT count
) DECLSPEC_HIDDEN
;
108 extern GpStatus
METAFILE_SetClipRect(GpMetafile
* metafile
,
109 REAL x
, REAL y
, REAL width
, REAL height
, CombineMode mode
) DECLSPEC_HIDDEN
;
110 extern GpStatus
METAFILE_SetClipRegion(GpMetafile
* metafile
, GpRegion
* region
, CombineMode mode
) DECLSPEC_HIDDEN
;
111 extern GpStatus
METAFILE_SetPageTransform(GpMetafile
* metafile
, GpUnit unit
, REAL scale
) DECLSPEC_HIDDEN
;
112 extern GpStatus
METAFILE_SetWorldTransform(GpMetafile
* metafile
, GDIPCONST GpMatrix
* transform
) DECLSPEC_HIDDEN
;
113 extern GpStatus
METAFILE_ScaleWorldTransform(GpMetafile
* metafile
, REAL sx
, REAL sy
, MatrixOrder order
) DECLSPEC_HIDDEN
;
114 extern GpStatus
METAFILE_MultiplyWorldTransform(GpMetafile
* metafile
, GDIPCONST GpMatrix
* matrix
, MatrixOrder order
) DECLSPEC_HIDDEN
;
115 extern GpStatus
METAFILE_RotateWorldTransform(GpMetafile
* metafile
, REAL angle
, MatrixOrder order
) DECLSPEC_HIDDEN
;
116 extern GpStatus
METAFILE_TranslateWorldTransform(GpMetafile
* metafile
, REAL dx
, REAL dy
, MatrixOrder order
) DECLSPEC_HIDDEN
;
117 extern GpStatus
METAFILE_ResetWorldTransform(GpMetafile
* metafile
) DECLSPEC_HIDDEN
;
118 extern GpStatus
METAFILE_BeginContainer(GpMetafile
* metafile
, GDIPCONST GpRectF
*dstrect
,
119 GDIPCONST GpRectF
*srcrect
, GpUnit unit
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
120 extern GpStatus
METAFILE_BeginContainerNoParams(GpMetafile
* metafile
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
121 extern GpStatus
METAFILE_EndContainer(GpMetafile
* metafile
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
122 extern GpStatus
METAFILE_SaveGraphics(GpMetafile
* metafile
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
123 extern GpStatus
METAFILE_RestoreGraphics(GpMetafile
* metafile
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
124 extern GpStatus
METAFILE_GraphicsDeleted(GpMetafile
* metafile
) DECLSPEC_HIDDEN
;
125 extern GpStatus
METAFILE_DrawImagePointsRect(GpMetafile
* metafile
, GpImage
*image
,
126 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
127 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
128 DrawImageAbort callback
, VOID
*callbackData
) DECLSPEC_HIDDEN
;
129 extern GpStatus
METAFILE_AddSimpleProperty(GpMetafile
*metafile
, SHORT prop
, SHORT val
) DECLSPEC_HIDDEN
;
130 extern GpStatus
METAFILE_DrawPath(GpMetafile
*metafile
, GpPen
*pen
, GpPath
*path
) DECLSPEC_HIDDEN
;
131 extern GpStatus
METAFILE_FillPath(GpMetafile
*metafile
, GpBrush
*brush
, GpPath
*path
) DECLSPEC_HIDDEN
;
132 extern void METAFILE_Free(GpMetafile
*metafile
) DECLSPEC_HIDDEN
;
134 extern void calc_curve_bezier(const GpPointF
*pts
, REAL tension
, REAL
*x1
,
135 REAL
*y1
, REAL
*x2
, REAL
*y2
) DECLSPEC_HIDDEN
;
136 extern void calc_curve_bezier_endp(REAL xend
, REAL yend
, REAL xadj
, REAL yadj
,
137 REAL tension
, REAL
*x
, REAL
*y
) DECLSPEC_HIDDEN
;
139 extern void free_installed_fonts(void) DECLSPEC_HIDDEN
;
141 extern BOOL
lengthen_path(GpPath
*path
, INT len
) DECLSPEC_HIDDEN
;
143 extern DWORD
write_region_data(const GpRegion
*region
, void *data
) DECLSPEC_HIDDEN
;
144 extern DWORD
write_path_data(GpPath
*path
, void *data
) DECLSPEC_HIDDEN
;
146 extern GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
) DECLSPEC_HIDDEN
;
148 typedef struct region_element region_element
;
149 extern void delete_element(region_element
*element
) DECLSPEC_HIDDEN
;
151 extern GpStatus
get_hatch_data(GpHatchStyle hatchstyle
, const char **result
) DECLSPEC_HIDDEN
;
153 static inline INT
gdip_round(REAL x
)
155 return (INT
) floorf(x
+ 0.5);
158 static inline INT
ceilr(REAL x
)
160 return (INT
) ceilf(x
);
163 static inline REAL
deg2rad(REAL degrees
)
165 return M_PI
* degrees
/ 180.0;
168 static inline ARGB
color_over(ARGB bg
, ARGB fg
)
171 BYTE bg_alpha
, fg_alpha
;
173 fg_alpha
= (fg
>>24)&0xff;
175 if (fg_alpha
== 0xff) return fg
;
177 if (fg_alpha
== 0) return bg
;
179 bg_alpha
= (((bg
>>24)&0xff) * (0xff-fg_alpha
)) / 0xff;
181 if (bg_alpha
== 0) return fg
;
183 a
= bg_alpha
+ fg_alpha
;
184 b
= ((bg
&0xff)*bg_alpha
+ (fg
&0xff)*fg_alpha
)/a
;
185 g
= (((bg
>>8)&0xff)*bg_alpha
+ ((fg
>>8)&0xff)*fg_alpha
)/a
;
186 r
= (((bg
>>16)&0xff)*bg_alpha
+ ((fg
>>16)&0xff)*fg_alpha
)/a
;
188 return (a
<<24)|(r
<<16)|(g
<<8)|b
;
191 /* fg is premult, bg and return value are not */
192 static inline ARGB
color_over_fgpremult(ARGB bg
, ARGB fg
)
195 BYTE bg_alpha
, fg_alpha
;
197 fg_alpha
= (fg
>>24)&0xff;
199 if (fg_alpha
== 0) return bg
;
201 bg_alpha
= (((bg
>>24)&0xff) * (0xff-fg_alpha
)) / 0xff;
203 a
= bg_alpha
+ fg_alpha
;
204 b
= ((bg
&0xff)*bg_alpha
+ (fg
&0xff)*0xff)/a
;
205 g
= (((bg
>>8)&0xff)*bg_alpha
+ ((fg
>>8)&0xff)*0xff)/a
;
206 r
= (((bg
>>16)&0xff)*bg_alpha
+ ((fg
>>16)&0xff)*0xff)/a
;
208 return (a
<<24)|(r
<<16)|(g
<<8)|b
;
211 extern const char *debugstr_rectf(const RectF
* rc
) DECLSPEC_HIDDEN
;
213 extern const char *debugstr_pointf(const PointF
* pt
) DECLSPEC_HIDDEN
;
215 extern void convert_32bppARGB_to_32bppPARGB(UINT width
, UINT height
,
216 BYTE
*dst_bits
, INT dst_stride
, const BYTE
*src_bits
, INT src_stride
) DECLSPEC_HIDDEN
;
218 extern GpStatus
convert_pixels(INT width
, INT height
,
219 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
220 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
, ColorPalette
*palette
) DECLSPEC_HIDDEN
;
222 extern PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
223 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
) DECLSPEC_HIDDEN
;
236 GpCustomLineCap
*customstart
;
237 GpCustomLineCap
*customend
;
243 REAL offset
; /* dash offset */
245 GpPenAlignment align
;
255 ImageType image_type
;
256 SmoothingMode smoothing
;
257 CompositingQuality compqual
;
258 InterpolationMode interpolation
;
259 PixelOffsetMode pixeloffset
;
260 CompositingMode compmode
;
261 TextRenderingHint texthint
;
262 GpUnit unit
; /* page unit */
263 REAL scale
; /* page scale */
265 GpMatrix worldtrans
; /* world transform */
266 BOOL busy
; /* hdc handle obtained by GdipGetDC */
267 GpRegion
*clip
; /* in device coords */
268 UINT textcontrast
; /* not used yet. get/set only */
269 struct list containers
;
270 GraphicsContainer contid
; /* last-issued container ID */
271 INT origin_x
, origin_y
;
272 INT gdi_transform_acquire_count
, gdi_transform_save
;
273 GpMatrix gdi_transform
;
275 /* For giving the caller an HDC when we technically can't: */
276 HBITMAP temp_hbitmap
;
277 int temp_hbitmap_width
;
278 int temp_hbitmap_height
;
289 GpHatchStyle hatchstyle
;
299 struct GpPathGradient
{
307 REAL
* blendfac
; /* blend factors */
308 REAL
* blendpos
; /* blend positions */
310 ARGB
*surroundcolors
;
311 INT surroundcolorcount
;
312 ARGB
* pblendcolor
; /* preset blend colors */
313 REAL
* pblendpos
; /* preset blend positions */
318 struct GpLineGradient
{
327 REAL
* blendfac
; /* blend factors */
328 REAL
* blendpos
; /* blend positions */
330 ARGB
* pblendcolor
; /* preset blend colors */
331 REAL
* pblendpos
; /* preset blend positions */
340 GpImageAttributes
*imageattributes
;
341 BYTE
*bitmap_bits
; /* image bits converted to ARGB and run through imageattributes */
347 BOOL newfigure
; /* whether the next drawing action starts a new figure */
348 INT datalen
; /* size of the arrays in pathdata */
351 struct GpPathIterator
{
353 INT subpath_pos
; /* for NextSubpath methods */
354 INT marker_pos
; /* for NextMarker methods */
355 INT pathtype_pos
; /* for NextPathType methods */
358 struct GpCustomLineCap
{
359 CustomLineCapType type
;
361 BOOL fill
; /* TRUE for fill, FALSE for stroke */
362 GpLineCap cap
; /* as far as I can tell, this value is ignored */
363 REAL inset
; /* how much to adjust the end of the line */
368 struct GpAdjustableArrowCap
{
373 IWICBitmapDecoder
*decoder
;
377 UINT frame_count
, current_frame
;
378 ColorPalette
*palette
;
383 #define EmfPlusObjectTableSize 64
385 typedef enum EmfPlusObjectType
394 ObjectTypeStringFormat
,
395 ObjectTypeImageAttributes
,
396 ObjectTypeCustomLineCap
,
397 ObjectTypeMax
= ObjectTypeCustomLineCap
,
400 /* Deserialized EmfPlusObject record. */
401 struct emfplus_object
{
402 EmfPlusObjectType type
;
410 GpImageAttributes
*image_attributes
;
419 MetafileType metafile_type
;
421 int preserve_hemf
; /* if true, hemf belongs to the app and should not be deleted */
425 GpGraphics
*record_graphics
;
427 DWORD comment_data_size
;
428 DWORD comment_data_length
;
429 IStream
*record_stream
;
430 BOOL auto_frame
; /* If true, determine the frame automatically */
431 GpPointF auto_frame_min
, auto_frame_max
;
432 DWORD next_object_id
;
435 GpGraphics
*playback_graphics
;
437 GpPointF playback_points
[3];
439 HANDLETABLE
*handle_table
;
441 XFORM gdiworldtransform
;
442 GpMatrix
*world_transform
;
445 GpRegion
*base_clip
; /* clip region in device space for all metafile output */
446 GpRegion
*clip
; /* clip region within the metafile */
447 struct list containers
;
448 struct emfplus_object objtable
[EmfPlusObjectTableSize
];
456 ImageLockMode lockmode
;
457 BYTE
*bitmapbits
; /* pointer to the buffer we passed in BitmapLockBits */
460 BYTE
*bits
; /* actual image bits if this is a DIB */
461 INT stride
; /* stride of bits if this is a DIB */
462 BYTE
*own_bits
; /* image bits that need to be freed with this object */
463 INT lockx
, locky
; /* X and Y coordinates of the rect when a bitmap is locked for writing. */
464 IWICMetadataReader
*metadata_reader
; /* NULL if there is no metadata */
466 PropertyItem
*prop_item
; /* cached image properties */
469 struct GpCachedBitmap
{
481 ColorMatrixFlags flags
;
482 ColorMatrix colormatrix
;
483 ColorMatrix graymatrix
;
486 struct color_remap_table
{
493 IMAGEATTR_NOOP_UNDEFINED
,
495 IMAGEATTR_NOOP_CLEAR
,
498 struct GpImageAttributes
{
502 struct color_key colorkeys
[ColorAdjustTypeCount
];
503 struct color_matrix colormatrices
[ColorAdjustTypeCount
];
504 struct color_remap_table colorremaptables
[ColorAdjustTypeCount
];
505 BOOL gamma_enabled
[ColorAdjustTypeCount
];
506 REAL gamma
[ColorAdjustTypeCount
];
507 enum imageattr_noop noop
[ColorAdjustTypeCount
];
511 GpFontFamily
*family
;
512 OUTLINETEXTMETRICW otm
;
513 REAL emSize
; /* in font units */
517 extern const struct GpStringFormat default_drawstring_format DECLSPEC_HIDDEN
;
519 struct GpStringFormat
{
523 StringAlignment align
;
524 StringTrimming trimming
;
525 HotkeyPrefix hkprefix
;
526 StringAlignment line_align
;
527 StringDigitSubstitute digitsub
;
531 CharacterRange
*character_ranges
;
533 BOOL generic_typographic
;
536 extern void init_generic_string_formats(void) DECLSPEC_HIDDEN
;
537 extern void free_generic_string_formats(void) DECLSPEC_HIDDEN
;
539 struct GpFontCollection
{
540 GpFontFamily
**FontFamilies
;
546 WCHAR FamilyName
[LF_FACESIZE
];
547 UINT16 em_height
, ascent
, descent
, line_spacing
; /* in font units */
552 typedef enum RegionType
554 RegionDataRect
= 0x10000000,
555 RegionDataPath
= 0x10000001,
556 RegionDataEmptyRect
= 0x10000002,
557 RegionDataInfiniteRect
= 0x10000003,
560 struct region_element
562 DWORD type
; /* Rectangle, Path, SpecialRectangle, or CombineMode */
569 struct region_element
*left
; /* the original region */
570 struct region_element
*right
; /* what *left was combined with */
586 static inline void init_memory_buffer(struct memory_buffer
*mbuf
, const BYTE
*buffer
, INT size
)
588 mbuf
->buffer
= buffer
;
593 static inline const void *buffer_read(struct memory_buffer
*mbuf
, INT size
)
595 if (mbuf
->size
- mbuf
->pos
>= size
)
597 const void *data
= mbuf
->buffer
+ mbuf
->pos
;
604 typedef GpStatus (*gdip_format_string_callback
)(HDC hdc
,
605 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
606 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
607 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
608 INT underlined_index_count
, void *user_data
);
610 GpStatus
gdip_format_string(HDC hdc
,
611 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
612 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
613 gdip_format_string_callback callback
, void *user_data
) DECLSPEC_HIDDEN
;
615 void get_log_fontW(const GpFont
*, GpGraphics
*, LOGFONTW
*) DECLSPEC_HIDDEN
;
617 static inline BOOL
image_lock(GpImage
*image
, BOOL
*unlock
)
619 LONG tid
= GetCurrentThreadId(), owner_tid
;
620 owner_tid
= InterlockedCompareExchange(&image
->busy
, tid
, 0);
621 *unlock
= !owner_tid
;
622 return !owner_tid
|| owner_tid
==tid
;
625 static inline void image_unlock(GpImage
*image
, BOOL unlock
)
627 if (unlock
) image
->busy
= 0;
630 #endif /* __WINE_GP_PRIVATE_H_ */