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/heap.h"
34 #include "wine/list.h"
38 #define GP_DEFAULT_PENSTYLE (PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT | PS_JOIN_MITER)
39 #define MAX_ARC_PTS (13)
40 #define MAX_DASHLEN (16) /* this is a limitation of gdi */
41 #define INCH_HIMETRIC (2540)
43 #define VERSION_MAGIC 0xdbc01001
44 #define VERSION_MAGIC2 0xdbc01002
45 #define VALID_MAGIC(x) (((x) & 0xfffff000) == 0xdbc01000)
46 #define TENSION_CONST (0.3)
48 #define GIF_DISPOSE_UNSPECIFIED 0
49 #define GIF_DISPOSE_DO_NOT_DISPOSE 1
50 #define GIF_DISPOSE_RESTORE_TO_BKGND 2
51 #define GIF_DISPOSE_RESTORE_TO_PREV 3
54 COLORREF
ARGB2COLORREF(ARGB color
);
55 HBITMAP
ARGB2BMP(ARGB color
);
56 extern INT
arc2polybezier(GpPointF
* points
, REAL x1
, REAL y1
, REAL x2
, REAL y2
,
57 REAL startAngle
, REAL sweepAngle
);
58 extern REAL
gdiplus_atan2(REAL dy
, REAL dx
);
59 extern GpStatus
hresult_to_status(HRESULT res
);
60 extern REAL
units_to_pixels(REAL units
, GpUnit unit
, REAL dpi
, BOOL printer_display
);
61 extern REAL
pixels_to_units(REAL pixels
, GpUnit unit
, REAL dpi
, BOOL printer_display
);
62 extern REAL
units_scale(GpUnit from
, GpUnit to
, REAL dpi
, BOOL printer_display
);
64 #define WineCoordinateSpaceGdiDevice ((GpCoordinateSpace)4)
66 extern GpStatus
gdi_transform_acquire(GpGraphics
*graphics
);
67 extern GpStatus
gdi_transform_release(GpGraphics
*graphics
);
68 extern GpStatus
get_graphics_transform(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
69 GpCoordinateSpace src_space
, GpMatrix
*matrix
);
70 extern GpStatus
gdip_transform_points(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
71 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
);
72 void transform_properties(GpGraphics
*, GDIPCONST GpMatrix
*, BOOL
, REAL
*, REAL
*, REAL
*);
74 extern GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
);
75 extern GpStatus
encode_image_png(GpImage
*image
, IStream
* stream
, GDIPCONST EncoderParameters
* params
);
76 extern GpStatus
terminate_encoder_wic(GpImage
*image
);
78 extern GpStatus
METAFILE_GetGraphicsContext(GpMetafile
* metafile
, GpGraphics
**result
);
79 extern GpStatus
METAFILE_GetDC(GpMetafile
* metafile
, HDC
*hdc
);
80 extern GpStatus
METAFILE_ReleaseDC(GpMetafile
* metafile
, HDC hdc
);
81 extern GpStatus
METAFILE_GraphicsClear(GpMetafile
* metafile
, ARGB color
);
82 extern GpStatus
METAFILE_FillRectangles(GpMetafile
* metafile
, GpBrush
* brush
,
83 GDIPCONST GpRectF
* rects
, INT count
);
84 extern GpStatus
METAFILE_SetClipRect(GpMetafile
* metafile
,
85 REAL x
, REAL y
, REAL width
, REAL height
, CombineMode mode
);
86 extern GpStatus
METAFILE_SetClipRegion(GpMetafile
* metafile
, GpRegion
* region
, CombineMode mode
);
87 extern GpStatus
METAFILE_SetPageTransform(GpMetafile
* metafile
, GpUnit unit
, REAL scale
);
88 extern GpStatus
METAFILE_SetWorldTransform(GpMetafile
* metafile
, GDIPCONST GpMatrix
* transform
);
89 extern GpStatus
METAFILE_ScaleWorldTransform(GpMetafile
* metafile
, REAL sx
, REAL sy
, MatrixOrder order
);
90 extern GpStatus
METAFILE_MultiplyWorldTransform(GpMetafile
* metafile
, GDIPCONST GpMatrix
* matrix
, MatrixOrder order
);
91 extern GpStatus
METAFILE_RotateWorldTransform(GpMetafile
* metafile
, REAL angle
, MatrixOrder order
);
92 extern GpStatus
METAFILE_TranslateWorldTransform(GpMetafile
* metafile
, REAL dx
, REAL dy
, MatrixOrder order
);
93 extern GpStatus
METAFILE_ResetWorldTransform(GpMetafile
* metafile
);
94 extern GpStatus
METAFILE_BeginContainer(GpMetafile
* metafile
, GDIPCONST GpRectF
*dstrect
,
95 GDIPCONST GpRectF
*srcrect
, GpUnit unit
, DWORD StackIndex
);
96 extern GpStatus
METAFILE_BeginContainerNoParams(GpMetafile
* metafile
, DWORD StackIndex
);
97 extern GpStatus
METAFILE_EndContainer(GpMetafile
* metafile
, DWORD StackIndex
);
98 extern GpStatus
METAFILE_SaveGraphics(GpMetafile
* metafile
, DWORD StackIndex
);
99 extern GpStatus
METAFILE_RestoreGraphics(GpMetafile
* metafile
, DWORD StackIndex
);
100 extern GpStatus
METAFILE_GraphicsDeleted(GpMetafile
* metafile
);
101 extern GpStatus
METAFILE_DrawImagePointsRect(GpMetafile
* metafile
, GpImage
*image
,
102 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
103 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
104 DrawImageAbort callback
, VOID
*callbackData
);
105 extern GpStatus
METAFILE_AddSimpleProperty(GpMetafile
*metafile
, SHORT prop
, SHORT val
);
106 extern GpStatus
METAFILE_DrawPath(GpMetafile
*metafile
, GpPen
*pen
, GpPath
*path
);
107 extern GpStatus
METAFILE_FillPath(GpMetafile
*metafile
, GpBrush
*brush
, GpPath
*path
);
108 extern GpStatus
METAFILE_DrawDriverString(GpMetafile
*metafile
, GDIPCONST UINT16
*text
, INT length
,
109 GDIPCONST GpFont
*font
, GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
,
110 GDIPCONST PointF
*positions
, INT flags
, GDIPCONST GpMatrix
*matrix
);
111 extern GpStatus
METAFILE_FillRegion(GpMetafile
* metafile
, GpBrush
* brush
,
113 extern void METAFILE_Free(GpMetafile
*metafile
);
114 extern GpStatus
METAFILE_DrawEllipse(GpMetafile
*metafile
, GpPen
*pen
, GpRectF
*rect
);
115 extern GpStatus
METAFILE_FillEllipse(GpMetafile
*metafile
, GpBrush
*brush
, GpRectF
*rect
);
116 extern GpStatus
METAFILE_DrawRectangles(GpMetafile
*metafile
, GpPen
*pen
, const GpRectF
*rects
, INT count
);
117 extern GpStatus
METAFILE_FillPie(GpMetafile
*metafile
, GpBrush
*brush
, const GpRectF
*rect
,
118 REAL startAngle
, REAL sweepAngle
);
119 extern GpStatus
METAFILE_DrawArc(GpMetafile
*metafile
, GpPen
*pen
, const GpRectF
*rect
,
120 REAL startAngle
, REAL sweepAngle
);
121 extern GpStatus
METAFILE_OffsetClip(GpMetafile
*metafile
, REAL dx
, REAL dy
);
122 extern GpStatus
METAFILE_ResetClip(GpMetafile
*metafile
);
123 extern GpStatus
METAFILE_SetClipPath(GpMetafile
*metafile
, GpPath
*path
, CombineMode mode
);
124 extern GpStatus
METAFILE_SetRenderingOrigin(GpMetafile
*metafile
, INT x
, INT y
);
126 extern void calc_curve_bezier(const GpPointF
*pts
, REAL tension
, REAL
*x1
,
127 REAL
*y1
, REAL
*x2
, REAL
*y2
);
128 extern void calc_curve_bezier_endp(REAL xend
, REAL yend
, REAL xadj
, REAL yadj
,
129 REAL tension
, REAL
*x
, REAL
*y
);
131 extern void free_installed_fonts(void);
133 extern BOOL
lengthen_path(GpPath
*path
, INT len
);
135 extern DWORD
write_region_data(const GpRegion
*region
, void *data
);
136 extern DWORD
write_path_data(GpPath
*path
, void *data
);
138 extern GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
);
140 typedef struct region_element region_element
;
141 extern void delete_element(region_element
*element
);
143 extern GpStatus
get_hatch_data(GpHatchStyle hatchstyle
, const unsigned char **result
);
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
);
205 extern const char *debugstr_pointf(const PointF
* pt
);
207 extern const char *debugstr_matrix(const GpMatrix
* matrix
);
209 extern void convert_32bppARGB_to_32bppPARGB(UINT width
, UINT height
,
210 BYTE
*dst_bits
, INT dst_stride
, const BYTE
*src_bits
, INT src_stride
);
212 extern GpStatus
convert_pixels(INT width
, INT height
,
213 INT dst_stride
, BYTE
*dst_bits
, PixelFormat dst_format
, ColorPalette
*dst_palette
,
214 INT src_stride
, const BYTE
*src_bits
, PixelFormat src_format
, ColorPalette
*src_palette
);
216 extern PixelFormat
apply_image_attributes(const GpImageAttributes
*attributes
, LPBYTE data
,
217 UINT width
, UINT height
, INT stride
, ColorAdjustType type
, PixelFormat fmt
);
230 GpCustomLineCap
*customstart
;
231 GpCustomLineCap
*customend
;
237 REAL offset
; /* dash offset */
239 GpPenAlignment align
;
241 REAL
*compound_array
;
242 INT compound_array_size
;
250 BOOL printer_display
;
252 ImageType image_type
;
253 SmoothingMode smoothing
;
254 CompositingQuality compqual
;
255 InterpolationMode interpolation
;
256 PixelOffsetMode pixeloffset
;
257 CompositingMode compmode
;
258 TextRenderingHint texthint
;
259 GpUnit unit
; /* page unit */
260 REAL scale
; /* page scale */
262 GpMatrix worldtrans
; /* world transform */
263 BOOL busy
; /* hdc handle obtained by GdipGetDC */
264 GpRegion
*clip
; /* in device coords */
265 UINT textcontrast
; /* not used yet. get/set only */
266 struct list containers
;
267 GraphicsContainer contid
; /* last-issued container ID */
268 INT origin_x
, origin_y
;
269 INT gdi_transform_acquire_count
, gdi_transform_save
;
270 GpMatrix gdi_transform
;
272 /* For giving the caller an HDC when we technically can't: */
273 HBITMAP temp_hbitmap
;
274 int temp_hbitmap_width
;
275 int temp_hbitmap_height
;
286 GpHatchStyle hatchstyle
;
296 struct GpPathGradient
{
304 REAL
* blendfac
; /* blend factors */
305 REAL
* blendpos
; /* blend positions */
307 ARGB
*surroundcolors
;
308 INT surroundcolorcount
;
309 ARGB
* pblendcolor
; /* preset blend colors */
310 REAL
* pblendpos
; /* preset blend positions */
315 struct GpLineGradient
{
322 REAL
* blendfac
; /* blend factors */
323 REAL
* blendpos
; /* blend positions */
325 ARGB
* pblendcolor
; /* preset blend colors */
326 REAL
* pblendpos
; /* preset blend positions */
335 GpImageAttributes
*imageattributes
;
336 BYTE
*bitmap_bits
; /* image bits converted to ARGB and run through imageattributes */
342 BOOL newfigure
; /* whether the next drawing action starts a new figure */
343 INT datalen
; /* size of the arrays in pathdata */
346 struct GpPathIterator
{
348 INT subpath_pos
; /* for NextSubpath methods */
349 INT marker_pos
; /* for NextMarker methods */
350 INT pathtype_pos
; /* for NextPathType methods */
353 struct GpCustomLineCap
{
354 CustomLineCapType type
;
356 BOOL fill
; /* TRUE for fill, FALSE for stroke */
357 GpLineCap basecap
; /* cap used together with customLineCap */
358 REAL inset
; /* distance between line end and cap beginning */
359 GpLineCap strokeStartCap
;
360 GpLineCap strokeEndCap
;
361 GpLineJoin join
; /* joins used for drawing custom cap*/
365 struct GpAdjustableArrowCap
{
373 IWICBitmapDecoder
*decoder
;
374 IWICBitmapEncoder
*encoder
;
378 UINT frame_count
, current_frame
;
379 ColorPalette
*palette
;
384 #define EmfPlusObjectTableSize 64
386 typedef enum EmfPlusObjectType
395 ObjectTypeStringFormat
,
396 ObjectTypeImageAttributes
,
397 ObjectTypeCustomLineCap
,
398 ObjectTypeMax
= ObjectTypeCustomLineCap
,
401 /* Deserialized EmfPlusObject record. */
402 struct emfplus_object
{
403 EmfPlusObjectType type
;
411 GpImageAttributes
*image_attributes
;
420 MetafileType metafile_type
;
422 int preserve_hemf
; /* if true, hemf belongs to the app and should not be deleted */
426 GpGraphics
*record_graphics
;
428 DWORD comment_data_size
;
429 DWORD comment_data_length
;
430 IStream
*record_stream
;
431 BOOL auto_frame
; /* If true, determine the frame automatically */
432 GpPointF auto_frame_min
, auto_frame_max
;
433 DWORD next_object_id
;
435 BOOL printer_display
;
440 GpGraphics
*playback_graphics
;
442 GpPointF playback_points
[3];
444 HANDLETABLE
*handle_table
;
446 GpMatrix
*world_transform
;
449 GpRegion
*base_clip
; /* clip region in device space for all metafile output */
450 GpRegion
*clip
; /* clip region within the metafile */
451 struct list containers
;
452 struct emfplus_object objtable
[EmfPlusObjectTableSize
];
460 ImageLockMode lockmode
;
461 BYTE
*bitmapbits
; /* pointer to the buffer we passed in BitmapLockBits */
464 BYTE
*bits
; /* actual image bits if this is a DIB */
465 INT stride
; /* stride of bits if this is a DIB */
466 BYTE
*own_bits
; /* image bits that need to be freed with this object */
467 INT lockx
, locky
; /* X and Y coordinates of the rect when a bitmap is locked for writing. */
468 IWICMetadataReader
*metadata_reader
; /* NULL if there is no metadata */
470 PropertyItem
*prop_item
; /* cached image properties */
473 struct GpCachedBitmap
{
485 ColorMatrixFlags flags
;
486 ColorMatrix colormatrix
;
487 ColorMatrix graymatrix
;
490 struct color_remap_table
{
497 IMAGEATTR_NOOP_UNDEFINED
,
499 IMAGEATTR_NOOP_CLEAR
,
502 struct GpImageAttributes
{
506 struct color_key colorkeys
[ColorAdjustTypeCount
];
507 struct color_matrix colormatrices
[ColorAdjustTypeCount
];
508 struct color_remap_table colorremaptables
[ColorAdjustTypeCount
];
509 BOOL gamma_enabled
[ColorAdjustTypeCount
];
510 REAL gamma
[ColorAdjustTypeCount
];
511 enum imageattr_noop noop
[ColorAdjustTypeCount
];
515 GpFontFamily
*family
;
516 OUTLINETEXTMETRICW otm
;
517 REAL emSize
; /* in font units */
521 extern const struct GpStringFormat default_drawstring_format
;
523 struct GpStringFormat
{
527 StringAlignment align
;
528 StringTrimming trimming
;
529 HotkeyPrefix hkprefix
;
530 StringAlignment line_align
;
531 StringDigitSubstitute digitsub
;
535 CharacterRange
*character_ranges
;
537 BOOL generic_typographic
;
540 extern void init_generic_string_formats(void);
541 extern void free_generic_string_formats(void);
543 struct GpFontCollection
{
544 GpFontFamily
**FontFamilies
;
550 WCHAR FamilyName
[LF_FACESIZE
];
551 UINT16 em_height
, ascent
, descent
, line_spacing
; /* in font units */
558 typedef enum RegionType
560 RegionDataRect
= 0x10000000,
561 RegionDataPath
= 0x10000001,
562 RegionDataEmptyRect
= 0x10000002,
563 RegionDataInfiniteRect
= 0x10000003,
566 struct region_element
568 DWORD type
; /* Rectangle, Path, SpecialRectangle, or CombineMode */
575 struct region_element
*left
; /* the original region */
576 struct region_element
*right
; /* what *left was combined with */
592 static inline void init_memory_buffer(struct memory_buffer
*mbuf
, const BYTE
*buffer
, INT size
)
594 mbuf
->buffer
= buffer
;
599 static inline const void *buffer_read(struct memory_buffer
*mbuf
, INT size
)
601 if (mbuf
->size
- mbuf
->pos
>= size
)
603 const void *data
= mbuf
->buffer
+ mbuf
->pos
;
610 typedef GpStatus (*gdip_format_string_callback
)(HDC hdc
,
611 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
612 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
613 INT lineno
, const RectF
*bounds
, INT
*underlined_indexes
,
614 INT underlined_index_count
, void *user_data
);
616 GpStatus
gdip_format_string(HDC hdc
,
617 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
618 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, int ignore_empty_clip
,
619 gdip_format_string_callback callback
, void *user_data
);
621 void get_log_fontW(const GpFont
*, GpGraphics
*, LOGFONTW
*);
623 static inline BOOL
image_lock(GpImage
*image
)
625 return TryAcquireSRWLockExclusive(&image
->lock
);
628 static inline void image_unlock(GpImage
*image
)
630 ReleaseSRWLockExclusive(&image
->lock
);
633 static inline void set_rect(GpRectF
*rect
, REAL x
, REAL y
, REAL width
, REAL height
)
638 rect
->Height
= height
;