1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* Copyright (C) 2007 Niels Martin Hansen
* http://aegisub.net/
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "stdafx.h"
#include <afxdlgs.h>
#include <atlpath.h>
#include "resource.h"
#include "../../../Subtitles/VobSubFile.h"
#include "../../../Subtitles/RTS.h"
#include "../../../Subtitles/SSF.h"
#include "../../../SubPic/MemSubPic.h"
#define CSRIAPI extern "C" __declspec(dllexport)
#define CSRI_OWN_HANDLES
typedef const char *csri_rend;
extern "C" struct csri_vsfilter_inst {
CRenderedTextSubtitle *rts;
CCritSec *cs;
CSize script_res;
CSize screen_res;
CRect video_rect;
enum csri_pixfmt pixfmt;
size_t readorder;
};
typedef struct csri_vsfilter_inst csri_inst;
#include "csri.h"
#ifdef _VSMOD
static csri_rend csri_vsfilter = "vsfiltermod";
#else
static csri_rend csri_vsfilter = "vsfilter";
#endif
CSRIAPI csri_inst *csri_open_file(csri_rend *renderer, const char *filename, struct csri_openflag *flags)
{
int namesize;
wchar_t *namebuf;
namesize = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
if (!namesize)
return 0;
namesize++;
namebuf = new wchar_t[namesize];
MultiByteToWideChar(CP_UTF8, 0, filename, -1, namebuf, namesize);
csri_inst *inst = new csri_inst();
inst->cs = new CCritSec();
inst->rts = new CRenderedTextSubtitle(inst->cs);
if (inst->rts->Open(CString(namebuf), DEFAULT_CHARSET)) {
delete[] namebuf;
inst->readorder = 0;
return inst;
} else {
delete[] namebuf;
delete inst->rts;
delete inst->cs;
delete inst;
return 0;
}
}
CSRIAPI csri_inst *csri_open_mem(csri_rend *renderer, const void *data, size_t length, struct csri_openflag *flags)
{
// This is actually less effecient than opening a file, since this first writes the memory data to a temp file,
// then opens that file and parses from that.
csri_inst *inst = new csri_inst();
inst->cs = new CCritSec();
inst->rts = new CRenderedTextSubtitle(inst->cs);
if (inst->rts->Open((BYTE*)data, (int)length, DEFAULT_CHARSET, _T("CSRI memory subtitles"))) {
inst->readorder = 0;
return inst;
} else {
delete inst->rts;
delete inst->cs;
delete inst;
return 0;
}
}
CSRIAPI void csri_close(csri_inst *inst)
{
if (!inst) return;
delete inst->rts;
delete inst->cs;
delete inst;
}
CSRIAPI int csri_request_fmt(csri_inst *inst, const struct csri_fmt *fmt)
{
if (!inst) return -1;
if (!fmt->width || !fmt->height)
return -1;
// Check if pixel format is supported
switch (fmt->pixfmt) {
case CSRI_F_BGR_:
case CSRI_F_BGR:
case CSRI_F_YUY2:
case CSRI_F_YV12:
inst->pixfmt = fmt->pixfmt;
break;
default:
return -1;
}
inst->screen_res = CSize(fmt->width, fmt->height);
inst->video_rect = CRect(0, 0, fmt->width, fmt->height);
return 0;
}
CSRIAPI void csri_render(csri_inst *inst, struct csri_frame *frame, double time)
{
const double arbitrary_framerate = 25.0;
SubPicDesc spd;
spd.w = inst->screen_res.cx;
spd.h = inst->screen_res.cy;
switch (inst->pixfmt) {
case CSRI_F_BGR_:
spd.type = MSP_RGB32;
spd.bpp = 32;
spd.bits = frame->planes[0];
spd.pitch = frame->strides[0];
break;
case CSRI_F_BGR:
spd.type = MSP_RGB24;
spd.bpp = 24;
spd.bits = frame->planes[0];
spd.pitch = frame->strides[0];
break;
case CSRI_F_YUY2:
spd.type = MSP_YUY2;
spd.bpp = 16;
spd.bits = frame->planes[0];
spd.pitch = frame->strides[0];
break;
case CSRI_F_YV12:
spd.type = MSP_YV12;
spd.bpp = 12;
spd.bits = frame->planes[0];
spd.bitsU = frame->planes[1];
spd.bitsV = frame->planes[2];
spd.pitch = frame->strides[0];
spd.pitchUV = frame->strides[1];
break;
default:
// eh?
return;
}
spd.vidrect = inst->video_rect;
inst->rts->Render(spd, (REFERENCE_TIME)(time*10000000), arbitrary_framerate, inst->video_rect);
}
// No extensions supported
CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname)
{
return 0;
}
// Get info for renderer
static struct csri_info csri_vsfilter_info = {
#ifdef _DEBUG
#ifdef _VSMOD
"vsfiltermod_textsub_debug", // name
#else
"vsfilter_textsub_debug", // name
#endif
"2.40", // version (assumed version number, svn revision, patchlevel)
#else
#ifdef _VSMOD
"vsfiltermod_textsub", // name
#else
"vsfilter_textsub", // name
#endif
"2.40", // version (assumed version number, svn revision, patchlevel)
#endif
// 2.38-0611 is base svn 611
// 2.38-0611-1 is with clipfix and fax/fay patch
// 2.38-0611-2 adds CSRI
// 2.38-0611-3 fixes a bug in CSRI and adds fontcrash-fix and float-pos
// 2.38-0611-4 fixes be1-dots and ugly-fade bugs and adds xbord/ybord/xshad/yshad/blur tags and extends be
// 2.39 merges with guliverkli2 fork
#ifdef _VSMOD
"VSFilterMod/TextSub (guliverkli2)", // longname
#else
"VSFilter/TextSub (MPC-HC)", // longname
#endif
"Gabest", // author
"Copyright (c) 2003-2010 by Gabest and others" // copyright
};
CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend)
{
return &csri_vsfilter_info;
}
// Only one supported, obviously
CSRIAPI csri_rend *csri_renderer_byname(const char *name, const char *specific)
{
if (strcmp(name, csri_vsfilter_info.name))
return 0;
if (specific && strcmp(specific, csri_vsfilter_info.specific))
return 0;
return &csri_vsfilter;
}
// Still just one
CSRIAPI csri_rend *csri_renderer_default()
{
return &csri_vsfilter;
}
// And no further
CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev)
{
return 0;
}
|