Split scan convert operation for a new cache. [Part 2]
[xy_vsfilter.git] / src / subtitles / Rasterizer.h
blob95b60be6230b88c58add65a13e89eae42ea3bb53
1 /*
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)
8 * any later version.
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
22 #pragma once
24 #include <boost/smart_ptr.hpp>
25 #include <vector>
26 #include "../SubPic/ISubPic.h"
27 #include "xy_malloc.h"
29 #ifdef _OPENMP
30 #include <omp.h>
31 #endif
33 #define PT_MOVETONC 0xfe
34 #define PT_BSPLINETO 0xfc
35 #define PT_BSPLINEPATCHTO 0xfa
37 typedef struct {
38 int left, top;
39 int w, h; // width, height
40 unsigned char *buffer; // w x h buffer
41 } Bitmap;
43 struct PathData
45 public:
46 PathData();
47 ~PathData();
49 PathData(const PathData&);//important! disable default copy constructor
50 const PathData& operator=(const PathData&);
51 void _TrashPath();
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);
59 BYTE* mpPathTypes;
60 POINT* mpPathPoints;
61 int mPathPoints;
64 typedef ::boost::shared_ptr<const PathData> SharedPtrConstPathData;
65 typedef ::boost::shared_ptr<PathData> SharedPtrPathData;
67 class ScanLineData
69 bool fFirstSet;
70 CPoint firstp, lastp;
72 private:
73 int mWidth, mHeight;
75 typedef std::pair<unsigned __int64, unsigned __int64> tSpan;
76 typedef std::vector<tSpan> tSpanBuffer;
78 tSpanBuffer mOutline;
79 tSpanBuffer mWideOutline;
80 int mWideBorder;
82 struct Edge {
83 int next;
84 int posandflag;
85 } *mpEdgeBuffer;
86 unsigned mEdgeHeapSize;
87 unsigned mEdgeNext;
89 unsigned int* mpScanBuffer;
91 typedef unsigned char byte;
93 private:
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);
100 public:
101 ScanLineData();
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
113 public:
114 ScanLineData2():mPathOffsetX(0),mPathOffsetY(0){}
116 void SetOffset(const CPoint& offset)
118 mPathOffsetX = offset.x;
119 mPathOffsetY = offset.y;
121 protected:
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;
132 struct Overlay
134 public:
135 Overlay()
137 memset(this, 0, sizeof(*this));//todo: fix me. not safe.
139 ~Overlay()
141 CleanUp();
144 void CleanUp()
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);
158 struct {
159 byte *base;
160 byte *body;
161 byte *border;
162 } mpOverlayBuffer;
163 int mOffsetX, mOffsetY;
164 int mWidth, mHeight;
166 int mOverlayWidth, mOverlayHeight, mOverlayPitch;
168 bool mfWideOutlineEmpty;//specially for blur
169 private:
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;
179 struct DrawItem
181 SharedPtrOverlay overlay;
182 CRect clip_rect;
183 SharedArrayByte alpha_mask;
184 int xsub;
185 int ysub;
186 DWORD switchpts[6];
187 bool fBody;
188 bool fBorder;
191 typedef ::boost::shared_ptr<DrawItem> SharedPtrDrawItem;
193 class Rasterizer
195 private:
196 typedef unsigned char byte;
198 struct DM
200 enum
202 SSE2 = 1,
203 ALPHA_MASK = 1<<1,
204 SINGLE_COLOR = 1<<2,
205 BODY = 1<<3,
206 AYUV_PLANAR = 1<<4
209 public:
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,
217 int xsub, int ysub,
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,
230 byte* pAlphaMask,
231 int xsub, int ysub,
232 const DWORD* switchpts, bool fBody, bool fBorder);
234 static CRect Draw(SubPicDesc& spd,
235 SharedPtrOverlay overlay,
236 const CRect& clipRect,
237 byte* pAlphaMask,
238 int xsub, int ysub,
239 const DWORD* switchpts, bool fBody, bool fBorder);
241 static void FillSolidRect(SubPicDesc& spd, int x, int y, int nWidth, int nHeight, DWORD lColor);