dibdrv.h 13.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * DIB driver include file.
 *
 * Copyright 2011 Huw Davies
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

21 22 23
typedef struct
{
    int bit_count, width, height;
24
    int compression;
25
    RECT rect;  /* visible rectangle relative to bitmap origin */
26 27 28 29 30 31 32
    int stride; /* stride in bytes.  Will be -ve for bottom-up dibs (see bits). */
    struct gdi_image_bits bits; /* bits.ptr points to the top-left corner of the dib. */

    DWORD red_mask, green_mask, blue_mask;
    int red_shift, green_shift, blue_shift;
    int red_len, green_len, blue_len;

33
    const RGBQUAD *color_table;
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    DWORD color_table_size;

    const struct primitive_funcs *funcs;
} dib_info;

typedef struct
{
    DWORD count;
    DWORD dashes[16]; /* 16 is the maximum number for a PS_USERSTYLE pen */
    DWORD total_len;  /* total length of the dashes, should be multiplied by 2 if there are an odd number of dash lengths */
} dash_pattern;

typedef struct
{
    int left_in_dash;
    int cur_dash;
    BOOL mark;
} dash_pos;

typedef struct
{
    DWORD and;
    DWORD xor;
} rop_mask;

typedef struct
{
    void *and;
    void *xor;
} rop_mask_bits;

65
struct dibdrv_physdev;
66
struct cached_font;
67 68 69 70 71 72 73 74

typedef struct dib_brush
{
    UINT     style;
    UINT     hatch;
    INT      rop;   /* rop2 last used to create the brush bits */
    COLORREF colorref;
    dib_info dib;
75
    rop_mask_bits masks;
76 77
    struct brush_pattern pattern;
    BOOL (*rects)(struct dibdrv_physdev *pdev, struct dib_brush *brush, dib_info *dib,
78
                  int num, const RECT *rects, const POINT *brush_org, INT rop);
79 80
} dib_brush;

81 82 83 84 85 86 87
struct intensity_range
{
    BYTE r_min, r_max;
    BYTE g_min, g_max;
    BYTE b_min, b_max;
};

88 89 90 91 92 93
struct font_intensities
{
    struct intensity_range ranges[17];
    struct font_gamma_ramp *gamma_ramp;
};

94 95 96 97
typedef struct dibdrv_physdev
{
    struct gdi_physdev dev;
    dib_info dib;
98
    dib_brush brush;
99 100

    HRGN clip;
101
    RECT *bounds;
102
    struct cached_font *font;
103 104

    /* pen */
105
    DWORD pen_style, pen_endcap, pen_join;
106
    BOOL pen_uses_region, pen_is_ext;
107
    int pen_width;
108
    dib_brush pen_brush;
109 110
    dash_pattern pen_pattern;
    dash_pos dash_pos;
111
    rop_mask dash_masks[2];
112
    BOOL   (* pen_lines)(struct dibdrv_physdev *pdev, int num, POINT *pts, BOOL close, HRGN region);
113 114
} dibdrv_physdev;

115 116
extern BOOL     dibdrv_AlphaBlend( PHYSDEV dst_dev, struct bitblt_coords *dst,
                                   PHYSDEV src_dev, struct bitblt_coords *src, BLENDFUNCTION blend ) DECLSPEC_HIDDEN;
117 118 119 120
extern BOOL     dibdrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                            INT start_x, INT start_y, INT end_x, INT end_y ) DECLSPEC_HIDDEN;
extern BOOL     dibdrv_ArcTo( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                              INT start_x, INT start_y, INT end_x, INT end_y ) DECLSPEC_HIDDEN;
121 122
extern DWORD    dibdrv_BlendImage( PHYSDEV dev, BITMAPINFO *info, const struct gdi_image_bits *bits,
                                   struct bitblt_coords *src, struct bitblt_coords *dst, BLENDFUNCTION func ) DECLSPEC_HIDDEN;
123 124
extern BOOL     dibdrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                              INT start_x, INT start_y, INT end_x, INT end_y ) DECLSPEC_HIDDEN;
125
extern BOOL     dibdrv_Ellipse( PHYSDEV dev, INT left, INT top, INT right, INT bottom ) DECLSPEC_HIDDEN;
126
extern BOOL     dibdrv_ExtFloodFill( PHYSDEV dev, INT x, INT y, COLORREF color, UINT type ) DECLSPEC_HIDDEN;
127 128
extern BOOL     dibdrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags,
                                   const RECT *rect, LPCWSTR str, UINT count, const INT *dx ) DECLSPEC_HIDDEN;
129
extern BOOL     dibdrv_FillPath( PHYSDEV dev ) DECLSPEC_HIDDEN;
130 131
extern DWORD    dibdrv_GetImage( PHYSDEV dev, BITMAPINFO *info, struct gdi_image_bits *bits,
                                 struct bitblt_coords *src ) DECLSPEC_HIDDEN;
132
extern COLORREF dibdrv_GetNearestColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN;
Huw Davies's avatar
Huw Davies committed
133
extern COLORREF dibdrv_GetPixel( PHYSDEV dev, INT x, INT y ) DECLSPEC_HIDDEN;
134 135
extern BOOL     dibdrv_GradientFill( PHYSDEV dev, TRIVERTEX *vert_array, ULONG nvert,
                                     void *grad_array, ULONG ngrad, ULONG mode ) DECLSPEC_HIDDEN;
136 137 138
extern BOOL     dibdrv_LineTo( PHYSDEV dev, INT x, INT y ) DECLSPEC_HIDDEN;
extern BOOL     dibdrv_PatBlt( PHYSDEV dev, struct bitblt_coords *dst, DWORD rop ) DECLSPEC_HIDDEN;
extern BOOL     dibdrv_PaintRgn( PHYSDEV dev, HRGN hrgn ) DECLSPEC_HIDDEN;
139 140
extern BOOL     dibdrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                            INT start_x, INT start_y, INT end_x, INT end_y ) DECLSPEC_HIDDEN;
141
extern BOOL     dibdrv_PolyPolygon( PHYSDEV dev, const POINT *pt, const INT *counts, DWORD polygons ) DECLSPEC_HIDDEN;
142 143
extern BOOL     dibdrv_PolyPolyline( PHYSDEV dev, const POINT* pt, const DWORD* counts,
                                     DWORD polylines ) DECLSPEC_HIDDEN;
144
extern BOOL     dibdrv_Polygon( PHYSDEV dev, const POINT *pt, INT count ) DECLSPEC_HIDDEN;
145
extern BOOL     dibdrv_Polyline( PHYSDEV dev, const POINT* pt, INT count ) DECLSPEC_HIDDEN;
146
extern DWORD    dibdrv_PutImage( PHYSDEV dev, HRGN clip, BITMAPINFO *info,
147 148
                                 const struct gdi_image_bits *bits, struct bitblt_coords *src,
                                 struct bitblt_coords *dst, DWORD rop ) DECLSPEC_HIDDEN;
149
extern BOOL     dibdrv_Rectangle( PHYSDEV dev, INT left, INT top, INT right, INT bottom ) DECLSPEC_HIDDEN;
150 151
extern BOOL     dibdrv_RoundRect( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                                  INT ellipse_width, INT ellipse_height ) DECLSPEC_HIDDEN;
152
extern HBRUSH   dibdrv_SelectBrush( PHYSDEV dev, HBRUSH hbrush, const struct brush_pattern *pattern ) DECLSPEC_HIDDEN;
153
extern HFONT    dibdrv_SelectFont( PHYSDEV dev, HFONT font, UINT *aa_flags ) DECLSPEC_HIDDEN;
154
extern HPEN     dibdrv_SelectPen( PHYSDEV dev, HPEN hpen, const struct brush_pattern *pattern ) DECLSPEC_HIDDEN;
155 156
extern COLORREF dibdrv_SetDCBrushColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN;
extern COLORREF dibdrv_SetDCPenColor( PHYSDEV dev, COLORREF color ) DECLSPEC_HIDDEN;
Huw Davies's avatar
Huw Davies committed
157
extern COLORREF dibdrv_SetPixel( PHYSDEV dev, INT x, INT y, COLORREF color ) DECLSPEC_HIDDEN;
158 159
extern BOOL     dibdrv_StretchBlt( PHYSDEV dst_dev, struct bitblt_coords *dst,
                                   PHYSDEV src_dev, struct bitblt_coords *src, DWORD rop ) DECLSPEC_HIDDEN;
160 161
extern BOOL     dibdrv_StrokeAndFillPath( PHYSDEV dev ) DECLSPEC_HIDDEN;
extern BOOL     dibdrv_StrokePath( PHYSDEV dev ) DECLSPEC_HIDDEN;
162
extern struct opengl_funcs *dibdrv_wine_get_wgl_driver( PHYSDEV dev, UINT version ) DECLSPEC_HIDDEN;
163

164 165 166 167
static inline dibdrv_physdev *get_dibdrv_pdev( PHYSDEV dev )
{
    return (dibdrv_physdev *)dev;
}
168

169 170 171 172 173 174 175 176
struct line_params
{
    int err_start, err_add_1, err_add_2, bias;
    unsigned int length;
    int x_inc, y_inc;
    BOOL x_major;
};

177 178 179 180 181 182 183
struct stretch_params
{
    int err_start, err_add_1, err_add_2;
    unsigned int length;
    int dst_inc, src_inc;
};

184 185
typedef struct primitive_funcs
{
186
    void            (* solid_rects)(const dib_info *dib, int num, const RECT *rc, DWORD and, DWORD xor);
187 188
    void             (* solid_line)(const dib_info *dib, const POINT *start, const struct line_params *params,
                                    DWORD and, DWORD xor);
189
    void          (* pattern_rects)(const dib_info *dib, int num, const RECT *rc, const POINT *origin,
190
                                    const dib_info *brush, const rop_mask_bits *bits);
191 192
    void              (* copy_rect)(const dib_info *dst, const RECT *rc, const dib_info *src,
                                    const POINT *origin, int rop2, int overlap);
193 194
    void             (* blend_rect)(const dib_info *dst, const RECT *rc, const dib_info *src,
                                    const POINT *origin, BLENDFUNCTION blend);
195
    BOOL          (* gradient_rect)(const dib_info *dib, const RECT *rc, const TRIVERTEX *v, int mode);
196 197
    void              (* mask_rect)(const dib_info *dst, const RECT *rc, const dib_info *src,
                                    const POINT *origin, int rop2);
198 199
    void             (* draw_glyph)(const dib_info *dst, const RECT *rc, const dib_info *glyph,
                                    const POINT *origin, DWORD text_pixel, const struct intensity_range *ranges);
200
    void    (* draw_subpixel_glyph)(const dib_info *dst, const RECT *rc, const dib_info *glyph,
201
                                    const POINT *origin, DWORD text_pixel, const struct font_gamma_ramp *gamma_ramp);
202
    DWORD             (* get_pixel)(const dib_info *dib, int x, int y);
203
    DWORD     (* colorref_to_pixel)(const dib_info *dib, COLORREF color);
204
    COLORREF  (* pixel_to_colorref)(const dib_info *dib, DWORD pixel);
205
    void             (* convert_to)(dib_info *dst, const dib_info *src, const RECT *src_rect, BOOL dither);
206
    void       (* create_rop_masks)(const dib_info *dib, const BYTE *hatch_ptr,
207
                                    const rop_mask *fg, const rop_mask *bg, rop_mask_bits *bits);
208
    void    (* create_dither_masks)(const dib_info *dib, int rop2, COLORREF color, rop_mask_bits *bits);
209 210 211 212 213 214
    void            (* stretch_row)(const dib_info *dst_dib, const POINT *dst_start,
                                    const dib_info *src_dib, const POINT *src_start,
                                    const struct stretch_params *params, int mode, BOOL keep_dst);
    void             (* shrink_row)(const dib_info *dst_dib, const POINT *dst_start,
                                    const dib_info *src_dib, const POINT *src_start,
                                    const struct stretch_params *params, int mode, BOOL keep_dst);
215 216 217
} primitive_funcs;

extern const primitive_funcs funcs_8888 DECLSPEC_HIDDEN;
218
extern const primitive_funcs funcs_32   DECLSPEC_HIDDEN;
219
extern const primitive_funcs funcs_24   DECLSPEC_HIDDEN;
220 221
extern const primitive_funcs funcs_555  DECLSPEC_HIDDEN;
extern const primitive_funcs funcs_16   DECLSPEC_HIDDEN;
222
extern const primitive_funcs funcs_8    DECLSPEC_HIDDEN;
223
extern const primitive_funcs funcs_4    DECLSPEC_HIDDEN;
224
extern const primitive_funcs funcs_1    DECLSPEC_HIDDEN;
225
extern const primitive_funcs funcs_null DECLSPEC_HIDDEN;
226

227 228 229 230 231
struct rop_codes
{
    DWORD a1, a2, x1, x2;
};

232 233 234 235 236
#define OVERLAP_LEFT  0x01  /* dest starts left of source */
#define OVERLAP_RIGHT 0x02  /* dest starts right of source */
#define OVERLAP_ABOVE 0x04  /* dest starts above source */
#define OVERLAP_BELOW 0x08  /* dest starts below source */

237 238 239 240 241 242 243
typedef struct
{
    unsigned int dx, dy;
    int bias;
    DWORD octant;
} bres_params;

244 245 246 247 248 249 250
struct clipped_rects
{
    RECT *rects;
    int   count;
    RECT  buffer[32];
};

251
extern void get_rop_codes(INT rop, struct rop_codes *codes) DECLSPEC_HIDDEN;
252
extern void reset_dash_origin(dibdrv_physdev *pdev) DECLSPEC_HIDDEN;
253 254
extern void init_dib_info_from_bitmapinfo(dib_info *dib, const BITMAPINFO *info, void *bits) DECLSPEC_HIDDEN;
extern BOOL init_dib_info_from_bitmapobj(dib_info *dib, BITMAPOBJ *bmp) DECLSPEC_HIDDEN;
255
extern void free_dib_info(dib_info *dib) DECLSPEC_HIDDEN;
256
extern void free_pattern_brush(dib_brush *brush) DECLSPEC_HIDDEN;
257 258
extern void copy_dib_color_info(dib_info *dst, const dib_info *src) DECLSPEC_HIDDEN;
extern BOOL convert_dib(dib_info *dst, const dib_info *src) DECLSPEC_HIDDEN;
259
extern DWORD get_pixel_color( DC *dc, const dib_info *dib, COLORREF color, BOOL mono_fixup ) DECLSPEC_HIDDEN;
260
extern int get_dib_rect( const dib_info *dib, RECT *rc ) DECLSPEC_HIDDEN;
261
extern int clip_rect_to_dib( const dib_info *dib, RECT *rc ) DECLSPEC_HIDDEN;
262
extern int get_clipped_rects( const dib_info *dib, const RECT *rc, HRGN clip, struct clipped_rects *clip_rects ) DECLSPEC_HIDDEN;
263
extern void add_clipped_bounds( dibdrv_physdev *dev, const RECT *rect, HRGN clip ) DECLSPEC_HIDDEN;
264 265
extern int clip_line(const POINT *start, const POINT *end, const RECT *clip,
                     const bres_params *params, POINT *pt1, POINT *pt2) DECLSPEC_HIDDEN;
266
extern void release_cached_font( struct cached_font *font ) DECLSPEC_HIDDEN;
267
extern BOOL fill_with_pixel( DC *dc, dib_info *dib, DWORD pixel, int num, const RECT *rects, INT rop ) DECLSPEC_HIDDEN;
268

269 270 271 272 273 274 275 276 277 278 279
static inline void init_clipped_rects( struct clipped_rects *clip_rects )
{
    clip_rects->count = 0;
    clip_rects->rects = clip_rects->buffer;
}

static inline void free_clipped_rects( struct clipped_rects *clip_rects )
{
    if (clip_rects->rects != clip_rects->buffer) HeapFree( GetProcessHeap(), 0, clip_rects->rects );
}

280 281 282 283 284 285 286 287
/* compute the x coordinate corresponding to y on the specified edge */
static inline int edge_coord( int y, int x1, int y1, int x2, int y2 )
{
    if (x2 > x1)  /* always follow the edge from right to left to get correct rounding */
        return x2 + (y - y2) * (x2 - x1) / (y2 - y1);
    else
        return x1 + (y - y1) * (x2 - x1) / (y2 - y1);
}
288 289 290 291 292

static inline const RGBQUAD *get_dib_color_table( const dib_info *dib )
{
    return dib->color_table ? dib->color_table : get_default_color_table( dib->bit_count );
}