1
/***************************************************************************
2
ADM_vidSRT.cpp - description
4
begin : Thu Dec 12 2002
5
copyright : (C) 2002 by mean
6
email : fixounet@free.fr
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
34
#include "ADM_toolkit/toolkit.hxx"
37
#include "ADM_editor/ADM_edit.hxx"
38
#include "ADM_video/ADM_genvideo.hxx"
40
#include "ADM_video/ADM_vidFont.h"
41
#include "ADM_video/ADM_vidSRT.h"
43
#include <ADM_assert.h>
45
#include "ADM_toolkit/ADM_debugID.h"
46
#define MODULE_NAME MODULE_FILTER
47
#include "ADM_toolkit/ADM_debug.h"
48
#include "ADM_filter/video_filters.h"
52
static FILTER_PARAM subParam={15,{"_fontsize","_subname","_fontname","_charset",
53
"_baseLine","_Y_percent","_U_percent","_V_percent",
54
"_selfAdjustable","_delay","_useBackgroundColor","_bg_Y_percent",
55
"_bg_U_percent","_bg_V_percent","_blend"}};
57
SCRIPT_CREATE(subtitle_script,ADMVideoSubtitle,subParam);
59
BUILD_CREATE(subtitle_create,ADMVideoSubtitle);
61
//__________________________________________________________________
63
//_______________________________________________________________
65
//__________________________________________________________________
67
char *ADMVideoSubtitle::printConf(void)
71
sprintf((char *)buf,"Subtitle ");
75
//--------------------------------------------------------
76
ADMVideoSubtitle::ADMVideoSubtitle(AVDMGenericVideoStream *in,CONFcouple *couples)
87
memcpy(&_info,_in->getInfo(),sizeof(_info));
89
frame=3*_in->getInfo()->width*_in->getInfo()->height;
96
_font = new ADMfont();
104
_param=_conf; // keep macro happy
114
GET(_selfAdjustable);
116
GET(_useBackgroundColor);
121
couples->getCouple("_blend",&b);
122
_param->_blend=(BlendMode)b;
123
if(_conf->_baseLine>_info.height-_conf->_fontsize*SRT_MAX_LINE)
125
printf("Base exceeded : base :%lu height :%lu bottom:%lu\n",
126
_conf->_baseLine,_info.height,_info.height-_conf->_fontsize*SRT_MAX_LINE);
127
_conf->_baseLine=_conf->_fontsize*SRT_MAX_LINE;
131
ft=(char *)ADM_alloc(500);
132
sub=(char *)ADM_alloc(500);
133
strcpy(ft,(char *)_conf->_subname);
134
_conf->_subname=(ADM_filename *)ft;
135
strcpy(sub,(char *)_conf->_fontname);
136
_conf->_fontname=(ADM_filename *)sub;
138
sub=(char *)ADM_alloc(500);
139
strcpy(sub,_conf->_charset);
149
_conf->_fontname=(ADM_filename *)ADM_alloc(500);
150
_conf->_subname=(ADM_filename *)ADM_alloc(500);
151
_conf->_charset=(char *)ADM_alloc(500);
152
_conf->_fontname[0]=0;
153
_conf->_subname[0]=0;
154
_conf->_charset[0]=0;
157
_conf->_baseLine=_info.height-24*SRT_MAX_LINE;
158
_conf->_Y_percent=255;
162
_conf->_selfAdjustable=0;
164
_conf->_useBackgroundColor=0;
166
_conf->_bg_Y_percent=0;
167
_conf->_bg_U_percent=0;
168
_conf->_bg_V_percent=0;
169
_conf->_blend=BLEND_SOLID;
171
prefs->get(FILTERS_SUBTITLE_FONTSIZE,&(_conf->_fontsize));
172
prefs->get(FILTERS_SUBTITLE_YPERCENT,&(_conf->_Y_percent));
173
prefs->get(FILTERS_SUBTITLE_UPERCENT,&(_conf->_U_percent));
174
prefs->get(FILTERS_SUBTITLE_VPERCENT,&(_conf->_V_percent));
175
prefs->get(FILTERS_SUBTITLE_SELFADJUSTABLE,&(_conf->_selfAdjustable));
176
prefs->get(FILTERS_SUBTITLE_USEBACKGROUNDCOLOR,&(_conf->_useBackgroundColor));
178
// _conf->_fontname, ... are used as memory for a dialog
179
// later. we can't used the length of the current string
181
prefs->get(FILTERS_SUBTITLE_FONTNAME,&tmp);
182
strcpy((char *)_conf->_fontname,tmp);
185
prefs->get(FILTERS_SUBTITLE_CHARSET,&tmp);
186
strcpy(_conf->_charset,tmp);
197
#define BITMAP_SIZE _info.width*_conf->_fontsize*SRT_MAX_LINE
198
_bitmapBuffer=new uint8_t[_info.width*_info.height];
199
_maskBuffer=new uint8_t[_info.width*_info.height];
200
_bgBitmapBuffer=new uint8_t[(_info.width*_info.height)>>1];
201
_bgMaskBuffer=new uint8_t[_info.width*_info.height];
202
_dirty=new uint8_t[_info.height];
203
ADM_assert(_bitmapBuffer);
204
ADM_assert(_maskBuffer);
205
ADM_assert(_bgBitmapBuffer);
206
ADM_assert(_bgMaskBuffer);
209
uint8_t ADMVideoSubtitle::loadSubtitle( void )
212
_fd=fopen((char *)_conf->_subname,"rt");
215
GUI_Error_HIG(_("Could not open subtitle file"), NULL);
218
// Try to detect utf16 files
220
// Skip utf identifier if any
238
GUI_Error_HIG(_("Cannot identify subtitle format"), NULL);
241
// Apply delay to subtitles
243
aprintf("[debug] DELAY %d\n", _conf->_delay);
246
int32_t newStartTime;
248
for(uint32_t i=0;i<_line;i++)
250
aprintf("[debug] BEFORE DELAY (%d) %d %d\n",i, _subs[i].startTime,_subs[i].endTime);
251
newStartTime=_subs[i].startTime;
252
newStartTime+=_conf->_delay;
253
_subs[i].startTime=(newStartTime);
254
newEndTime=_subs[i].endTime;
255
newEndTime+=_conf->_delay;
256
_subs[i].endTime=(newEndTime);
257
// put them at infinit display time
258
// should get rid of them
259
if(newEndTime<0 || newStartTime<0)
261
_subs[i].startTime=_subs[i].endTime=0;
263
aprintf("[debug] AFTER DELAY (%d) %d %d\n",i, _subs[i].startTime,_subs[i].endTime);
271
if(_line) // that way we will have the first sub
275
uint8_t ADMVideoSubtitle::getCoupledConf( CONFcouple **couples)
279
_param=_conf; // keep macro happy
281
*couples=new CONFcouple(15);
291
CSET(_selfAdjustable);
293
CSET(_useBackgroundColor);
297
(*couples)->setCouple("_blend",(uint32_t)_param->_blend);
302
//__________________________________________________________________
304
ADMVideoSubtitle::~ADMVideoSubtitle()
309
delete [] _bitmapBuffer;
314
delete [] _maskBuffer;
320
delete [] _bgBitmapBuffer;
326
delete [] _bgMaskBuffer;
342
for(uint32_t i=0;i<_line;i++)
346
for(uint32_t k=0;k<_subs[i].nbLine;k++)
348
if(_subs[i].string[k])
350
delete [] _subs[i].string[k];
351
_subs[i].string[k]=NULL;
355
delete _subs[i].string;
356
_subs[i].string=NULL;
357
delete _subs[i].lineSize;
358
_subs[i].lineSize=NULL;
366
ADM_dealloc(_conf->_subname);
367
ADM_dealloc(_conf->_fontname);
368
ADM_dealloc(_conf->_charset);