1 /*
2 * GPAC - Multimedia Framework C SDK
3 *
4 * Authors: Jean Le Feuvre
5 * Copyright (c) Telecom ParisTech 2000-2012
6 * All rights reserved
7 *
8 * This file is part of GPAC / GDIplus rasterizer module
9 *
10 * GPAC is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * GPAC is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26
27 #ifndef __GDIP_PRIV_H
28 #define __GDIP_PRIV_H
29
30 #include <math.h>
31 #include <gpac/modules/raster2d.h>
32 #include <gpac/modules/font.h>
33 #include <windows.h>
34
35
36 #define SAFEALLOC(__ptr, __struc) __ptr = (__struc*)gf_malloc(sizeof(__struc)); if (__ptr) memset(__ptr, 0, sizeof(__struc));
37
38 /*all GDIPLUS includes for C api*/
39
40 struct IDirectDrawSurface7;
41
42 #include "GdiplusMem.h"
43 #include "GdiplusEnums.h"
44 #include "GdiplusTypes.h"
45 #include "GdiplusInit.h"
46 #include "GdiplusPixelFormats.h"
47 #include "GdiplusColor.h"
48 #include "GdiplusMetaHeader.h"
49 #include "GdiplusImaging.h"
50 #include "GdiplusColorMatrix.h"
51 #include "GdiplusGpStubs.h"
52 #include "GdiplusColor.h"
53 #include "GdiplusFlat.h"
54
55 #include <math.h>
56
57 #define GD_PI 3.1415926536f
58
59 /* default resolution for N-bezier curves*/
60 #define GDIP_DEFAULT_RESOLUTION 64
61
62 struct _gdip_context
63 {
64 ULONG_PTR gdiToken;
65 };
66
67
68 /*struct translators*/
69
mat_gpac_to_gdip(GF_Matrix2D * mat)70 GFINLINE GpMatrix *mat_gpac_to_gdip(GF_Matrix2D *mat)
71 {
72 GpMatrix *ret;
73 if (!mat) return NULL;
74 GdipCreateMatrix(&ret);
75 GdipSetMatrixElements(ret, FIX2FLT(mat->m[0]), FIX2FLT(mat->m[3]), FIX2FLT(mat->m[1]), FIX2FLT(mat->m[4]), FIX2FLT(mat->m[2]), FIX2FLT(mat->m[5]));
76 return ret;
77 }
78
79
cmat_gpac_to_gdip(GF_ColorMatrix * mat,ColorMatrix * matrix)80 GFINLINE void cmat_gpac_to_gdip(GF_ColorMatrix *mat, ColorMatrix *matrix)
81 {
82 memset(matrix->m, 0, sizeof(Float)*5*5);
83 matrix->m[0][0] = FIX2FLT(mat->m[0]);
84 matrix->m[1][0] = FIX2FLT(mat->m[1]);
85 matrix->m[2][0] = FIX2FLT(mat->m[2]);
86 matrix->m[3][0] = FIX2FLT(mat->m[3]);
87 matrix->m[4][0] = FIX2FLT(mat->m[4]);
88 matrix->m[0][1] = FIX2FLT(mat->m[5]);
89 matrix->m[1][1] = FIX2FLT(mat->m[6]);
90 matrix->m[2][1] = FIX2FLT(mat->m[7]);
91 matrix->m[3][1] = FIX2FLT(mat->m[8]);
92 matrix->m[4][1] = FIX2FLT(mat->m[9]);
93 matrix->m[0][2] = FIX2FLT(mat->m[10]);
94 matrix->m[1][2] = FIX2FLT(mat->m[11]);
95 matrix->m[2][2] = FIX2FLT(mat->m[12]);
96 matrix->m[3][2] = FIX2FLT(mat->m[13]);
97 matrix->m[4][2] = FIX2FLT(mat->m[14]);
98 matrix->m[0][3] = FIX2FLT(mat->m[15]);
99 matrix->m[1][3] = FIX2FLT(mat->m[16]);
100 matrix->m[2][3] = FIX2FLT(mat->m[17]);
101 matrix->m[3][3] = FIX2FLT(mat->m[18]);
102 matrix->m[4][3] = FIX2FLT(mat->m[19]);
103 }
104
105
gdip_cmat_reset(ColorMatrix * matrix)106 GFINLINE void gdip_cmat_reset(ColorMatrix *matrix)
107 {
108 memset(matrix->m, 0, sizeof(Float)*5*5);
109 matrix->m[0][0] = matrix->m[1][1] = matrix->m[2][2] = matrix->m[3][3] = matrix->m[4][4] = 1.0;
110 }
111
112 #define GPMATRIX() GpMatrix * _mat = mat_gpac_to_gdip(mat);
113
114 GpPath *gdip_create_path(GF_Path * _this);
115
116 struct _stencil
117 {
118 GF_StencilType type;
119 GF_GradientMode spread;
120 GF_TextureTiling tiling;
121
122 GpSolidFill *pSolid;
123
124 GpMatrix *pMat;
125
126 /*Linear gradient vars*/
127 GpLineGradient *pLinear;
128 GpMatrix *pLinearMat;
129 GpPointF start, end;
130
131 /*Radial gradient vars*/
132 GpPathGradient *pRadial;
133 GpPointF center, radius, focal;
134 GpPath *circle;
135
136 /*interpolation colors storage*/
137 REAL *pos;
138 ARGB *cols;
139 u32 num_pos;
140 Bool needs_rebuild;
141
142 /*texture specific*/
143 GpTexture *pTexture;
144 GpBitmap *pBitmap;
145 u32 width, height;
146 ColorMatrix cmat;
147 Bool has_cmat;
148 PixelFormat format;
149 /*GDIplus is expecting ABGR when creating a bitmap with GdipCreateBitmapFromScan0.
150 Since we don't want to rewrite by hand the full image when loading textures, we
151 force R->B switching */
152 Bool invert_br;
153 GF_TextureFilter tFilter;
154
155 Bool texture_invalid;
156 GF_Rect wnd;
157 u8 alpha;
158
159 unsigned char *conv_buf;
160 u32 conv_size;
161 unsigned char *orig_buf;
162 u32 orig_stride, orig_format;
163 Bool is_converted;
164 /*not used yet, we only convert to RGB or ARGB*/
165 u32 destination_format;
166 };
167 #define GPSTEN() struct _stencil *_sten = (struct _stencil *) _this; assert(_this);
168 #define CHECK(_type) if (_sten->type!=_type) return;
169 #define CHECK_RET(_type) if (_sten->type!=_type) return GF_BAD_PARAM;
170 #define CHECK2(_t1, _t2) if ((_sten->type!=_t1) && (_sten->type!=_t2)) return;
171 #define CHECK2_RET(_t1, _t2) if ((_sten->type!=_t1) && (_sten->type!=_t2)) return GF_BAD_PARAM;
172
173 void gdip_recompute_line_gradient(GF_STENCIL _this);
174 void gdip_recompute_radial_gradient(GF_STENCIL _this);
175
176 void gdip_load_texture(struct _stencil *sten);
177
178 void gdip_init_driver_texture(GF_Raster2D *driver);
179 void gdip_init_driver_common(GF_Raster2D *driver);
180 void gdip_init_driver_grad(GF_Raster2D *driver);
181
182 typedef struct
183 {
184 ULONG_PTR gdiToken;
185
186 /*text stuff*/
187 Float em_size, descent, ascent;
188 s32 font_style;
189 Float whitespace_width;
190 Float underscore_width;
191 GpFontFamily *font;
192
193 char font_serif[1024];
194 char font_sans[1024];
195 char font_fixed[1024];
196 } FontPriv;
197
198 GF_FontReader *gdip_new_font_driver();
199 void gdip_delete_font_driver(GF_FontReader *dr);
200
201
202 GF_Raster2D *gdip_LoadRenderer();
203 void gdip_ShutdownRenderer(GF_Raster2D *driver);
204
205 #endif //__GDIP_PRIV_H