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
&);
51 bool operator==(const PathData
& rhs
)const;
54 bool BeginPath(HDC hdc
);
55 bool EndPath(HDC hdc
);
56 bool PartialBeginPath(HDC hdc
, bool bClearPath
);
57 bool PartialEndPath(HDC hdc
, long dx
, long dy
);
59 void AlignLeftTop(CPoint
*left_top
, CSize
*size
);
66 typedef ::boost::shared_ptr
<const PathData
> SharedPtrConstPathData
;
67 typedef ::boost::shared_ptr
<PathData
> SharedPtrPathData
;
70 typedef std::pair
<unsigned __int64
, unsigned __int64
> tSpan
;
71 typedef std::vector
<tSpan
> tSpanBuffer
;
87 unsigned mEdgeHeapSize
;
90 unsigned int* mpScanBuffer
;
92 typedef unsigned char byte
;
95 void _ReallocEdgeBuffer(int edges
);
96 void _EvaluateBezier(const PathData
& path_data
, int ptbase
, bool fBSpline
);
97 void _EvaluateLine(const PathData
& path_data
, int pt1idx
, int pt2idx
);
98 void _EvaluateLine(int x0
, int y0
, int x1
, int y1
);
102 virtual ~ScanLineData();
104 bool ScanConvert(const PathData
& path_data
, const CSize
& size
);
105 void DeleteOutlines();
107 friend class Rasterizer
;
108 friend class ScanLineData2
;
111 typedef ::boost::shared_ptr
<const ScanLineData
> SharedPtrConstScanLineData
;
112 typedef ::boost::shared_ptr
<ScanLineData
> SharedPtrScanLineData
;
117 ScanLineData2():mPathOffsetX(0),mPathOffsetY(0),mWideBorder(0){}
118 ScanLineData2(const CPoint
& left_top
, const SharedPtrConstScanLineData
& scan_line_data
)
119 :m_scan_line_data(scan_line_data
)
120 ,mPathOffsetX(left_top
.x
)
121 ,mPathOffsetY(left_top
.y
)
124 void SetOffset(const CPoint
& offset
)
126 mPathOffsetX
= offset
.x
;
127 mPathOffsetY
= offset
.y
;
129 bool CreateWidenedRegion(int borderX
, int borderY
);
131 SharedPtrConstScanLineData m_scan_line_data
;
132 int mPathOffsetX
, mPathOffsetY
;
133 tSpanBuffer mWideOutline
;
136 friend class Rasterizer
;
139 typedef ::boost::shared_ptr
<const ScanLineData2
> SharedPtrConstScanLineData2
;
140 typedef ::boost::shared_ptr
<ScanLineData2
> SharedPtrScanLineData2
;
142 typedef ::boost::shared_ptr
<BYTE
> SharedPtrByte
;
149 mOffsetX
=mOffsetY
=mWidth
=mHeight
=0;
150 mOverlayWidth
=mOverlayHeight
=mOverlayPitch
=0;
151 mfWideOutlineEmpty
= false;
160 mBody
.reset((BYTE
*)NULL
);
161 mBorder
.reset((BYTE
*)NULL
);
162 mOffsetX
=mOffsetY
=mWidth
=mHeight
=0;
163 mOverlayWidth
=mOverlayHeight
=mOverlayPitch
=0;
164 mfWideOutlineEmpty
= false;
167 void FillAlphaMash(byte
* outputAlphaMask
, bool fBody
, bool fBorder
,
168 int x
, int y
, int w
, int h
,
169 const byte
* pAlphaMask
, int pitch
, DWORD color_alpha
);
171 Overlay
* GetSubpixelVariance(unsigned int xshift
, unsigned int yshift
);
174 SharedPtrByte mBorder
;
175 int mOffsetX
, mOffsetY
;
178 int mOverlayWidth
, mOverlayHeight
, mOverlayPitch
;
180 bool mfWideOutlineEmpty
;//specially for blur
182 void _DoFillAlphaMash(byte
* outputAlphaMask
, const byte
* pBody
, const byte
* pBorder
,
183 int x
, int y
, int w
, int h
,
184 const byte
* pAlphaMask
, int pitch
, DWORD color_alpha
);
185 void _DoFillAlphaMash_c(byte
* outputAlphaMask
, const byte
* pBody
, const byte
* pBorder
, int x
, int y
, int w
, int h
, const byte
* pAlphaMask
, int pitch
, DWORD color_alpha
);
188 typedef ::boost::shared_ptr
<Overlay
> SharedPtrOverlay
;
199 typedef ::boost::shared_ptr
<GrayImage2
> SharedPtrGrayImage2
;
205 typedef unsigned char byte
;
219 static const float GAUSSIAN_BLUR_THREHOLD
;
222 static bool Rasterize(const ScanLineData2
& scan_line_data2
, int xsub
, int ysub
, SharedPtrOverlay overlay
);
224 static bool IsItReallyBlur(float be_strength
, double gaussian_blur_strength
);
225 static bool OldFixedPointBlur(const Overlay
& input_overlay
, float be_strength
, double gaussian_blur_strength
,
226 double target_scale_x
, double target_scale_y
, SharedPtrOverlay output_overlay
);
228 static bool Blur(const Overlay
& input_overlay
, float be_strength
, double gaussian_blur_strength
,
229 double target_scale_x
, double target_scale_y
, SharedPtrOverlay output_overlay
);
231 static bool BeBlur(const Overlay
& input_overlay
, float be_strength
, float target_scale_x
, float target_scale_y
,
232 SharedPtrOverlay output_overlay
);
234 static bool GaussianBlur( const Overlay
& input_overlay
, double gaussian_blur_strength
,
235 double target_scale_x
, double target_scale_y
,
236 SharedPtrOverlay output_overlay
);
238 static SharedPtrByte
CompositeAlphaMask(const SharedPtrOverlay
& overlay
, const CRect
& clipRect
,
239 const GrayImage2
* alpha_mask
,
240 int xsub
, int ysub
, const DWORD
* switchpts
, bool fBody
, bool fBorder
,
241 CRect
*outputDirtyRect
);
243 static void Draw(XyBitmap
* bitmap
,
244 SharedPtrOverlay overlay
,
245 const CRect
& clipRect
,
248 const DWORD
* switchpts
, bool fBody
, bool fBorder
);
250 static void FillSolidRect(SubPicDesc
& spd
, int x
, int y
, int nWidth
, int nHeight
, DWORD lColor
);