2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 #include <boost/smart_ptr.hpp>
26 #include "../SubPic/ISubPic.h"
27 #include "xy_malloc.h"
33 #define PT_MOVETONC 0xfe
34 #define PT_BSPLINETO 0xfc
35 #define PT_BSPLINEPATCHTO 0xfa
39 int w
, h
; // width, height
40 unsigned char *buffer
; // w x h buffer
49 PathData(const PathData
&);//important! disable default copy constructor
50 const PathData
& operator=(const PathData
&);
52 bool BeginPath(HDC hdc
);
53 bool EndPath(HDC hdc
);
54 bool PartialBeginPath(HDC hdc
, bool bClearPath
);
55 bool PartialEndPath(HDC hdc
, long dx
, long dy
);
57 void AlignLeftTop(CPoint
*left_top
, CSize
*size
);
64 typedef ::boost::shared_ptr
<const PathData
> SharedPtrConstPathData
;
65 typedef ::boost::shared_ptr
<PathData
> SharedPtrPathData
;
75 typedef std::pair
<unsigned __int64
, unsigned __int64
> tSpan
;
76 typedef std::vector
<tSpan
> tSpanBuffer
;
79 tSpanBuffer mWideOutline
;
86 unsigned mEdgeHeapSize
;
89 unsigned int* mpScanBuffer
;
91 typedef unsigned char byte
;
94 void _ReallocEdgeBuffer(int edges
);
95 void _EvaluateBezier(const PathData
& path_data
, int ptbase
, bool fBSpline
);
96 void _EvaluateLine(const PathData
& path_data
, int pt1idx
, int pt2idx
);
97 void _EvaluateLine(int x0
, int y0
, int x1
, int y1
);
98 static void _OverlapRegion(tSpanBuffer
& dst
, tSpanBuffer
& src
, int dx
, int dy
);
102 virtual ~ScanLineData();
104 bool ScanConvert(const PathData
& path_data
, const CSize
& size
);
105 bool CreateWidenedRegion(int borderX
, int borderY
);
106 void DeleteOutlines();
108 friend class Rasterizer
;
111 class ScanLineData2
:public ScanLineData
114 ScanLineData2():mPathOffsetX(0),mPathOffsetY(0){}
116 void SetOffset(const CPoint
& offset
)
118 mPathOffsetX
= offset
.x
;
119 mPathOffsetY
= offset
.y
;
122 int mPathOffsetX
, mPathOffsetY
;
124 friend class Rasterizer
;
127 typedef ::boost::shared_ptr
<const ScanLineData2
> SharedPtrConstScanLineData2
;
128 typedef ::boost::shared_ptr
<ScanLineData2
> SharedPtrScanLineData2
;
130 typedef ::boost::shared_ptr
<BYTE
> SharedPtrByte
;
137 memset(this, 0, sizeof(*this));//todo: fix me. not safe.
146 xy_free(mpOverlayBuffer
.base
);
147 memset(&mpOverlayBuffer
, 0, sizeof(mpOverlayBuffer
));
148 mOverlayWidth
=mOverlayHeight
=mOverlayPitch
=0;
149 mfWideOutlineEmpty
= false;
152 void FillAlphaMash(byte
* outputAlphaMask
, bool fBody
, bool fBorder
,
153 int x
, int y
, int w
, int h
,
154 const byte
* pAlphaMask
, int pitch
, DWORD color_alpha
);
156 Overlay
* GetSubpixelVariance(unsigned int xshift
, unsigned int yshift
);
163 int mOffsetX
, mOffsetY
;
166 int mOverlayWidth
, mOverlayHeight
, mOverlayPitch
;
168 bool mfWideOutlineEmpty
;//specially for blur
170 void _DoFillAlphaMash(byte
* outputAlphaMask
, const byte
* pBody
, const byte
* pBorder
,
171 int x
, int y
, int w
, int h
,
172 const byte
* pAlphaMask
, int pitch
, DWORD color_alpha
);
175 typedef ::boost::shared_ptr
<Overlay
> SharedPtrOverlay
;
177 typedef ::boost::shared_array
<BYTE
> SharedArrayByte
;
181 SharedPtrOverlay overlay
;
183 SharedArrayByte alpha_mask
;
191 typedef ::boost::shared_ptr
<DrawItem
> SharedPtrDrawItem
;
196 typedef unsigned char byte
;
210 static bool Rasterize(const ScanLineData2
& scan_line_data2
, int xsub
, int ysub
, SharedPtrOverlay overlay
);
211 static bool Blur(const Overlay
& input_overlay
, int fBlur
, double fGaussianBlur
, SharedPtrOverlay output_overlay
);
213 static DrawItem
* CreateDrawItem(SubPicDesc
& spd
,
214 SharedPtrOverlay overlay
,
215 const CRect
& clipRect
,
216 SharedArrayByte pAlphaMask
,
218 const DWORD
* switchpts
, bool fBody
, bool fBorder
);
220 static SharedPtrByte
CompositeAlphaMask(SubPicDesc
& spd
, SharedPtrOverlay overlay
, const CRect
& clipRect
, byte
* pAlphaMask
,
221 int xsub
, int ysub
, const DWORD
* switchpts
, bool fBody
, bool fBorder
,
222 CRect
*outputDirtyRect
);
223 static CRect
Draw(SubPicDesc
& spd
, DrawItem
& draw_item
);
225 static CRect
DryDraw(SubPicDesc
& spd
, DrawItem
& draw_item
);
227 static CRect
DryDraw(SubPicDesc
& spd
,
228 SharedPtrOverlay overlay
,
229 const CRect
& clipRect
,
232 const DWORD
* switchpts
, bool fBody
, bool fBorder
);
234 static CRect
Draw(SubPicDesc
& spd
,
235 SharedPtrOverlay overlay
,
236 const CRect
& clipRect
,
239 const DWORD
* switchpts
, bool fBody
, bool fBorder
);
241 static void FillSolidRect(SubPicDesc
& spd
, int x
, int y
, int nWidth
, int nHeight
, DWORD lColor
);