Auto-versioning.
[xy_vsfilter.git] / src / filters / transform / vsfilter / csriapi.cpp
blob607e1074f708e9853bed37274fed579ff16fa305
1 /*
2 * Copyright (C) 2007 Niels Martin Hansen
3 * http://aegisub.net/
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.
9 *
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 #include "stdafx.h"
23 #include <afxdlgs.h>
24 #include <atlpath.h>
25 #include "resource.h"
26 #include "..\..\..\subtitles\VobSubFile.h"
27 #include "..\..\..\subtitles\RTS.h"
28 #include "..\..\..\subtitles\SSF.h"
30 #define CSRIAPI extern "C" __declspec(dllexport)
31 #define CSRI_OWN_HANDLES
32 typedef const char *csri_rend;
33 extern "C" struct csri_vsfilter_inst {
34 CRenderedTextSubtitle *rts;
35 CCritSec *cs;
36 CSize script_res;
37 CSize screen_res;
38 CRect video_rect;
39 enum csri_pixfmt pixfmt;
40 size_t readorder;
42 typedef struct csri_vsfilter_inst csri_inst;
43 #include "csri.h"
44 static csri_rend csri_vsfilter = "vsfilter";
47 CSRIAPI csri_inst *csri_open_file(csri_rend *renderer, const char *filename, struct csri_openflag *flags)
49 AMTRACE((TEXT(__FUNCTION__),0));
50 int namesize;
51 wchar_t *namebuf;
53 namesize = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
54 if (!namesize)
55 return 0;
56 namesize++;
57 namebuf = new wchar_t[namesize];
58 MultiByteToWideChar(CP_UTF8, 0, filename, -1, namebuf, namesize);
60 csri_inst *inst = new csri_inst();
61 inst->cs = new CCritSec();
62 inst->rts = new CRenderedTextSubtitle(inst->cs);
63 if (inst->rts->Open(CString(namebuf), DEFAULT_CHARSET)) {
64 delete[] namebuf;
65 inst->readorder = 0;
66 return inst;
67 } else {
68 delete[] namebuf;
69 delete inst->rts;
70 delete inst->cs;
71 delete inst;
72 return 0;
77 CSRIAPI csri_inst *csri_open_mem(csri_rend *renderer, const void *data, size_t length, struct csri_openflag *flags)
79 AMTRACE((TEXT(__FUNCTION__),0));
80 // This is actually less effecient than opening a file, since this first writes the memory data to a temp file,
81 // then opens that file and parses from that.
82 csri_inst *inst = new csri_inst();
83 inst->cs = new CCritSec();
84 inst->rts = new CRenderedTextSubtitle(inst->cs);
85 if (inst->rts->Open((BYTE*)data, (int)length, DEFAULT_CHARSET, _T("CSRI memory subtitles"))) {
86 inst->readorder = 0;
87 return inst;
88 } else {
89 delete inst->rts;
90 delete inst->cs;
91 delete inst;
92 return 0;
97 CSRIAPI void csri_close(csri_inst *inst)
99 if (!inst) return;
101 delete inst->rts;
102 delete inst->cs;
103 delete inst;
107 CSRIAPI int csri_request_fmt(csri_inst *inst, const struct csri_fmt *fmt)
109 if (!inst) return -1;
111 if (!fmt->width || !fmt->height)
112 return -1;
114 // Check if pixel format is supported
115 switch (fmt->pixfmt) {
116 case CSRI_F_BGR_:
117 case CSRI_F_BGR:
118 case CSRI_F_YUY2:
119 case CSRI_F_YV12:
120 inst->pixfmt = fmt->pixfmt;
121 break;
123 default:
124 return -1;
126 inst->screen_res = CSize(fmt->width, fmt->height);
127 inst->video_rect = CRect(0, 0, fmt->width, fmt->height);
128 return 0;
132 CSRIAPI void csri_render(csri_inst *inst, struct csri_frame *frame, double time)
134 const double arbitrary_framerate = 25.0;
135 SubPicDesc spd;
136 spd.w = inst->screen_res.cx;
137 spd.h = inst->screen_res.cy;
138 switch (inst->pixfmt) {
139 case CSRI_F_BGR_:
140 spd.type = MSP_RGB32;
141 spd.bpp = 32;
142 spd.bits = frame->planes[0];
143 spd.pitch = frame->strides[0];
144 break;
146 case CSRI_F_BGR:
147 spd.type = MSP_RGB24;
148 spd.bpp = 24;
149 spd.bits = frame->planes[0];
150 spd.pitch = frame->strides[0];
151 break;
153 case CSRI_F_YUY2:
154 spd.type = MSP_YUY2;
155 spd.bpp = 16;
156 spd.bits = frame->planes[0];
157 spd.pitch = frame->strides[0];
158 break;
160 case CSRI_F_YV12:
161 spd.type = MSP_YV12;
162 spd.bpp = 12;
163 spd.bits = frame->planes[0];
164 spd.bitsU = frame->planes[1];
165 spd.bitsV = frame->planes[2];
166 spd.pitch = frame->strides[0];
167 spd.pitchUV = frame->strides[1];
168 break;
170 default:
171 // eh?
172 return;
174 spd.vidrect = inst->video_rect;
176 inst->rts->Render(spd, (REFERENCE_TIME)(time*10000000), arbitrary_framerate, inst->video_rect);
180 // No extensions supported
181 CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname)
183 return 0;
186 // Get info for renderer
187 static struct csri_info csri_vsfilter_info = {
188 #ifdef _DEBUG
189 "vsfilter_textsub_debug", // name
190 "2.39", // version (assumed version number, svn revision, patchlevel)
191 #else
192 "vsfilter_textsub", // name
193 "2.39", // version (assumed version number, svn revision, patchlevel)
194 #endif
195 // 2.38-0611 is base svn 611
196 // 2.38-0611-1 is with clipfix and fax/fay patch
197 // 2.38-0611-2 adds CSRI
198 // 2.38-0611-3 fixes a bug in CSRI and adds fontcrash-fix and float-pos
199 // 2.38-0611-4 fixes be1-dots and ugly-fade bugs and adds xbord/ybord/xshad/yshad/blur tags and extends be
200 // 2.39 merges with guliverkli2 fork
201 "VSFilter/TextSub (guliverkli2)", // longname
202 "Gabest", // author
203 "Copyright (c) 2003-2008 by Gabest and others" // copyright
205 CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend)
207 return &csri_vsfilter_info;
209 // Only one supported, obviously
210 CSRIAPI csri_rend *csri_renderer_byname(const char *name, const char *specific)
212 if (strcmp(name, csri_vsfilter_info.name))
213 return 0;
214 if (specific && strcmp(specific, csri_vsfilter_info.specific))
215 return 0;
216 return &csri_vsfilter;
218 // Still just one
219 CSRIAPI csri_rend *csri_renderer_default()
221 return &csri_vsfilter;
223 // And no further
224 CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev)
226 return 0;