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_
32 #include "wincodecsdk.h"
33 #include "wine/list.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 #define WineCoordinateSpaceGdiDevice ((GpCoordinateSpace)4)
84 extern GpStatus
gdi_transform_acquire(GpGraphics
*graphics
);
85 extern GpStatus
gdi_transform_release(GpGraphics
*graphics
);
86 extern GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
87 GpCoordinateSpace src_space
, GpMatrix
*matrix
) DECLSPEC_HIDDEN
;
88 extern GpStatus
gdip_transform_points(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
89 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
) DECLSPEC_HIDDEN
;
91 extern GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
) DECLSPEC_HIDDEN
;
92 extern GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
, GDIPCONST EncoderParameters
* params
) DECLSPEC_HIDDEN
;
94 extern GpStatus
METAFILE_GetGraphicsContext(GpMetafile
* metafile
, GpGraphics
**result
) DECLSPEC_HIDDEN
;
95 extern GpStatus
METAFILE_GetDC(GpMetafile
* metafile
, HDC
*hdc
) DECLSPEC_HIDDEN
;
96 extern GpStatus
METAFILE_ReleaseDC(GpMetafile
* metafile
, HDC hdc
) DECLSPEC_HIDDEN
;
97 extern GpStatus
METAFILE_GraphicsClear(GpMetafile
* metafile
, ARGB color
) DECLSPEC_HIDDEN
;
98 extern GpStatus
METAFILE_FillRectangles(GpMetafile
* metafile
, GpBrush
* brush
,
99 GDIPCONST GpRectF
* rects
, INT count
) DECLSPEC_HIDDEN
;
100 extern GpStatus
METAFILE_SetClipRect(GpMetafile
* metafile
,
101 REAL x
, REAL y
, REAL width
, REAL height
, CombineMode mode
) DECLSPEC_HIDDEN
;
102 extern GpStatus
METAFILE_SetClipRegion(GpMetafile
* metafile
, GpRegion
* region
, CombineMode mode
) DECLSPEC_HIDDEN
;
103 extern GpStatus
METAFILE_SetPageTransform(GpMetafile
* metafile
, GpUnit unit
, REAL scale
) DECLSPEC_HIDDEN
;
104 extern GpStatus
METAFILE_SetWorldTransform(GpMetafile
* metafile
, GDIPCONST GpMatrix
* transform
) DECLSPEC_HIDDEN
;
105 extern GpStatus
METAFILE_ScaleWorldTransform(GpMetafile
* metafile
, REAL sx
, REAL sy
, MatrixOrder order
) DECLSPEC_HIDDEN
;
106 extern GpStatus
METAFILE_MultiplyWorldTransform(GpMetafile
* metafile
, GDIPCONST GpMatrix
* matrix
, MatrixOrder order
) DECLSPEC_HIDDEN
;
107 extern GpStatus
METAFILE_RotateWorldTransform(GpMetafile
* metafile
, REAL angle
, MatrixOrder order
) DECLSPEC_HIDDEN
;
108 extern GpStatus
METAFILE_TranslateWorldTransform(GpMetafile
* metafile
, REAL dx
, REAL dy
, MatrixOrder order
) DECLSPEC_HIDDEN
;
109 extern GpStatus
METAFILE_ResetWorldTransform(GpMetafile
* metafile
) DECLSPEC_HIDDEN
;
110 extern GpStatus
METAFILE_BeginContainer(GpMetafile
* metafile
, GDIPCONST GpRectF
*dstrect
,
111 GDIPCONST GpRectF
*srcrect
, GpUnit unit
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
112 extern GpStatus
METAFILE_BeginContainerNoParams(GpMetafile
* metafile
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
113 extern GpStatus
METAFILE_EndContainer(GpMetafile
* metafile
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
114 extern GpStatus
METAFILE_SaveGraphics(GpMetafile
* metafile
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
115 extern GpStatus
METAFILE_RestoreGraphics(GpMetafile
* metafile
, DWORD StackIndex
) DECLSPEC_HIDDEN
;
116 extern GpStatus
METAFILE_GraphicsDeleted(GpMetafile
* metafile
) DECLSPEC_HIDDEN
;
117 extern GpStatus
METAFILE_DrawImagePointsRect(GpMetafile
* metafile
, GpImage
*image
,
118 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
119 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
120 DrawImageAbort callback
, VOID
*callbackData
) DECLSPEC_HIDDEN
;
121 extern GpStatus
METAFILE_AddSimpleProperty(GpMetafile
*metafile
, SHORT prop
, SHORT val
) DECLSPEC_HIDDEN
;
122 extern GpStatus
METAFILE_DrawPath(GpMetafile
*metafile
, GpPen
*pen
, GpPath
*path
) DECLSPEC_HIDDEN
;
123 extern GpStatus
METAFILE_FillPath(GpMetafile
*metafile
, GpBrush
*brush
, GpPath
*path
) DECLSPEC_HIDDEN
;
124 extern void METAFILE_Free(GpMetafile
*metafile
) DECLSPEC_HIDDEN
;
126 extern void calc_curve_bezier(const GpPointF
*pts
, REAL tension
, REAL
*x1
,
127 REAL
*y1
, REAL
*x2
, REAL
*y2
) DECLSPEC_HIDDEN
;
128 extern void calc_curve_bezier_endp(REAL xend
, REAL yend
, REAL xadj
, REAL yadj
,
129 REAL tension
, REAL
*x
, REAL
*y
) DECLSPEC_HIDDEN
;
131 extern void free_installed_fonts(void) DECLSPEC_HIDDEN
;
133 extern BOOL
lengthen_path(GpPath
*path
, INT len
) DECLSPEC_HIDDEN
;
135 extern DWORD
write_region_data(const GpRegion
*region
, void *data
) DECLSPEC_HIDDEN
;
136 extern DWORD
write_path_data(GpPath
*path
, void *data
) DECLSPEC_HIDDEN
;
138 extern GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
) DECLSPEC_HIDDEN
;
140 typedef struct region_element region_element
;
141 extern void delete_element(region_element
*element
) DECLSPEC_HIDDEN
;
143 extern GpStatus
get_hatch_data(GpHatchStyle hatchstyle
, const char **result
) DECLSPEC_HIDDEN
;
145 static inline INT
gdip_round(REAL x
)
147 return (INT
) floorf(x
+ 0.5);
150 static inline INT
ceilr(REAL x
)
152 return (INT
) ceilf(x
);
155 static inline REAL
deg2rad(REAL degrees
)
157 return M_PI
* degrees
/ 180.0;
160 static inline ARGB
color_over(ARGB bg
, ARGB fg
)
163 BYTE bg_alpha
, fg_alpha
;
165 fg_alpha
= (fg
>>24)&0xff;
167 if (fg_alpha
== 0xff) return fg
;
169 if (fg_alpha
== 0) return bg
;
171 bg_alpha
= (((bg
>>24)&0xff) * (0xff-fg_alpha
)) / 0xff;
173 if (bg_alpha
== 0) return fg
;
175 a
= bg_alpha
+ fg_alpha
;
176 b
= ((bg
&0xff)*bg_alpha
+ (fg
&0xff)*fg_alpha
)/a
;
177 g
= (((bg
>>8)&0xff)*bg_alpha
+ ((fg
>>8)&0xff)*fg_alpha
)/a
;
178 r
= (((bg
>>16)&0xff)*bg_alpha
+ ((fg
>>16)&0xff)*fg_alpha
)/a
;
180 return (a
<<24)|(r
<<16)|(g
<<8)|b
;
183 /* fg is premult, bg and return value are not */
184 static inline ARGB
color_over_fgpremult(ARGB bg
, ARGB fg
)
187 BYTE bg_alpha
, fg_alpha
;
189 fg_alpha
= (fg
>>24)&0xff;
191 if (fg_alpha
== 0) return bg
;
193 bg_alpha
= (((bg
>>24)&0xff) * (0xff-fg_alpha
)) / 0xff;
195 a
= bg_alpha
+ fg_alpha
;
196 b
= ((bg
&0xff)*bg_alpha
+ (fg
&0xff)*0xff)/a
;
197 g
= (((bg
>>8)&0xff)*bg_alpha
+ ((fg
>>8)&0xff)*0xff)/a
;
198 r
= (((bg
>>16)&0xff)*bg_alpha
+ ((fg
>>16)&0xff)*0xff)/a
;
200 return (a
<<24)|(r
<<16)|(g
<<8)|b
;
203 extern const char *debugstr_rectf(const RectF
* rc
) DECLSPEC_HIDDEN
;
205 extern const char *debugstr_pointf(const PointF
* pt
) DECLSPEC_HIDDEN
;
207 extern void convert_32bppARGB_to_32bppPARGB(UINT width
, UINT height
,
208 BYTE
*dst_bits
, INT dst_stride
, const BYTE
*src_bits
, INT src_stride
) DECLSPEC_HIDDEN
;
210 extern GpStatus
convert_pixels(INT width
, INT height
,
211 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
,
212 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
, ColorPalette
*palette
) DECLSPEC_HIDDEN
;
214 extern PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
215 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
) DECLSPEC_HIDDEN
;
228 GpCustomLineCap
*customstart
;
229 GpCustomLineCap
*customend
;
235 REAL offset
; /* dash offset */
237 GpPenAlignment align
;
247 ImageType image_type
;
248 SmoothingMode smoothing
;
249 CompositingQuality compqual
;
250 InterpolationMode interpolation
;
251 PixelOffsetMode pixeloffset
;
252 CompositingMode compmode
;
253 TextRenderingHint texthint
;
254 GpUnit unit
; /* page unit */
255 REAL scale
; /* page scale */
257 GpMatrix worldtrans
; /* world transform */
258 BOOL busy
; /* hdc handle obtained by GdipGetDC */
259 GpRegion
*clip
; /* in device coords */
260 UINT textcontrast
; /* not used yet. get/set only */
261 struct list containers
;
262 GraphicsContainer contid
; /* last-issued container ID */
263 INT origin_x
, origin_y
;
264 INT gdi_transform_acquire_count
, gdi_transform_save
;
265 GpMatrix gdi_transform
;
267 /* For giving the caller an HDC when we technically can't: */
268 HBITMAP temp_hbitmap
;
269 int temp_hbitmap_width
;
270 int temp_hbitmap_height
;
281 GpHatchStyle hatchstyle
;
291 struct GpPathGradient
{
299 REAL
* blendfac
; /* blend factors */
300 REAL
* blendpos
; /* blend positions */
302 ARGB
*surroundcolors
;
303 INT surroundcolorcount
;
304 ARGB
* pblendcolor
; /* preset blend colors */
305 REAL
* pblendpos
; /* preset blend positions */
310 struct GpLineGradient
{
319 REAL
* blendfac
; /* blend factors */
320 REAL
* blendpos
; /* blend positions */
322 ARGB
* pblendcolor
; /* preset blend colors */
323 REAL
* pblendpos
; /* preset blend positions */
332 GpImageAttributes
*imageattributes
;
333 BYTE
*bitmap_bits
; /* image bits converted to ARGB and run through imageattributes */
339 BOOL newfigure
; /* whether the next drawing action starts a new figure */
340 INT datalen
; /* size of the arrays in pathdata */
343 struct GpPathIterator
{
345 INT subpath_pos
; /* for NextSubpath methods */
346 INT marker_pos
; /* for NextMarker methods */
347 INT pathtype_pos
; /* for NextPathType methods */
350 struct GpCustomLineCap
{
351 CustomLineCapType type
;
353 BOOL fill
; /* TRUE for fill, FALSE for stroke */
354 GpLineCap cap
; /* as far as I can tell, this value is ignored */
355 REAL inset
; /* how much to adjust the end of the line */
360 struct GpAdjustableArrowCap
{
365 IWICBitmapDecoder
*decoder
;
369 UINT frame_count
, current_frame
;
370 ColorPalette
*palette
;
375 #define EmfPlusObjectTableSize 64
377 typedef enum EmfPlusObjectType
386 ObjectTypeStringFormat
,
387 ObjectTypeImageAttributes
,
388 ObjectTypeCustomLineCap
,
389 ObjectTypeMax
= ObjectTypeCustomLineCap
,
392 /* Deserialized EmfPlusObject record. */
393 struct emfplus_object
{
394 EmfPlusObjectType type
;
402 GpImageAttributes
*image_attributes
;
411 MetafileType metafile_type
;
413 int preserve_hemf
; /* if true, hemf belongs to the app and should not be deleted */
417 GpGraphics
*record_graphics
;
419 DWORD comment_data_size
;
420 DWORD comment_data_length
;
421 IStream
*record_stream
;
422 BOOL auto_frame
; /* If true, determine the frame automatically */
423 GpPointF auto_frame_min
, auto_frame_max
;
424 DWORD next_object_id
;
427 GpGraphics
*playback_graphics
;
429 GpPointF playback_points
[3];
431 HANDLETABLE
*handle_table
;
433 XFORM gdiworldtransform
;
434 GpMatrix
*world_transform
;
437 GpRegion
*base_clip
; /* clip region in device space for all metafile output */
438 GpRegion
*clip
; /* clip region within the metafile */
439 struct list containers
;
440 struct emfplus_object objtable
[EmfPlusObjectTableSize
];
448 ImageLockMode lockmode
;
449 BYTE
*bitmapbits
; /* pointer to the buffer we passed in BitmapLockBits */
452 BYTE
*bits
; /* actual image bits if this is a DIB */
453 INT stride
; /* stride of bits if this is a DIB */
454 BYTE
*own_bits
; /* image bits that need to be freed with this object */
455 INT lockx
, locky
; /* X and Y coordinates of the rect when a bitmap is locked for writing. */
456 IWICMetadataReader
*metadata_reader
; /* NULL if there is no metadata */
458 PropertyItem
*prop_item
; /* cached image properties */
461 struct GpCachedBitmap
{
473 ColorMatrixFlags flags
;
474 ColorMatrix colormatrix
;
475 ColorMatrix graymatrix
;
478 struct color_remap_table
{
485 IMAGEATTR_NOOP_UNDEFINED
,
487 IMAGEATTR_NOOP_CLEAR
,
490 struct GpImageAttributes
{
494 struct color_key colorkeys
[ColorAdjustTypeCount
];
495 struct color_matrix colormatrices
[ColorAdjustTypeCount
];
496 struct color_remap_table colorremaptables
[ColorAdjustTypeCount
];
497 BOOL gamma_enabled
[ColorAdjustTypeCount
];
498 REAL gamma
[ColorAdjustTypeCount
];
499 enum imageattr_noop noop
[ColorAdjustTypeCount
];
503 GpFontFamily
*family
;
504 OUTLINETEXTMETRICW otm
;
505 REAL emSize
; /* in font units */
509 extern const struct GpStringFormat default_drawstring_format DECLSPEC_HIDDEN
;
511 struct GpStringFormat
{
515 StringAlignment align
;
516 StringTrimming trimming
;
517 HotkeyPrefix hkprefix
;
518 StringAlignment line_align
;
519 StringDigitSubstitute digitsub
;
523 CharacterRange
*character_ranges
;
525 BOOL generic_typographic
;
528 extern void init_generic_string_formats(void) DECLSPEC_HIDDEN
;
529 extern void free_generic_string_formats(void) DECLSPEC_HIDDEN
;
531 struct GpFontCollection
{
532 GpFontFamily
**FontFamilies
;
538 WCHAR FamilyName
[LF_FACESIZE
];
539 UINT16 em_height
, ascent
, descent
, line_spacing
; /* in font units */
544 typedef enum RegionType
546 RegionDataRect
= 0x10000000,
547 RegionDataPath
= 0x10000001,
548 RegionDataEmptyRect
= 0x10000002,
549 RegionDataInfiniteRect
= 0x10000003,
552 struct region_element
554 DWORD type
; /* Rectangle, Path, SpecialRectangle, or CombineMode */
561 struct region_element
*left
; /* the original region */
562 struct region_element
*right
; /* what *left was combined with */
578 static inline void init_memory_buffer(struct memory_buffer
*mbuf
, const BYTE
*buffer
, INT size
)
580 mbuf
->buffer
= buffer
;
585 static inline const void *buffer_read(struct memory_buffer
*mbuf
, INT size
)
587 if (mbuf
->size
- mbuf
->pos
>= size
)
589 const void *data
= mbuf
->buffer
+ mbuf
->pos
;
596 typedef GpStatus (*gdip_format_string_callback
)(HDC hdc
,
597 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
598 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
599 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
600 INT underlined_index_count
, void *user_data
);
602 GpStatus
gdip_format_string(HDC hdc
,
603 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
604 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
605 gdip_format_string_callback callback
, void *user_data
) DECLSPEC_HIDDEN
;
607 void get_log_fontW(const GpFont
*, GpGraphics
*, LOGFONTW
*) DECLSPEC_HIDDEN
;
609 static inline BOOL
image_lock(GpImage
*image
, BOOL
*unlock
)
611 LONG tid
= GetCurrentThreadId(), owner_tid
;
612 owner_tid
= InterlockedCompareExchange(&image
->busy
, tid
, 0);
613 *unlock
= !owner_tid
;
614 return !owner_tid
|| owner_tid
==tid
;
617 static inline void image_unlock(GpImage
*image
, BOOL unlock
)
619 if (unlock
) image
->busy
= 0;