~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_video/ADM_vidSRT.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                          ADM_vidSRT.cpp  -  description
3
 
                             -------------------
4
 
    begin                : Thu Dec 12 2002
5
 
    copyright            : (C) 2002 by mean
6
 
    email                : fixounet@free.fr
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
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.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
#include "config.h"
18
 
 
19
 
#include <stdio.h>
20
 
#include <stdlib.h>
21
 
#include <string.h>
22
 
#include <math.h>
23
 
#include <math.h>
24
 
#include <iconv.h>
25
 
 
26
 
 
27
 
#ifdef USE_FREETYPE
28
 
 
29
 
#include "fourcc.h"
30
 
#include "avio.hxx"
31
 
 
32
 
#include "avi_vars.h"
33
 
 
34
 
#include "ADM_toolkit/toolkit.hxx"
35
 
 
36
 
 
37
 
#include "ADM_editor/ADM_edit.hxx"
38
 
#include "ADM_video/ADM_genvideo.hxx"
39
 
 
40
 
#include "ADM_video/ADM_vidFont.h"
41
 
#include "ADM_video/ADM_vidSRT.h"
42
 
 
43
 
#include <ADM_assert.h>
44
 
 
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"
49
 
 
50
 
#include <prefs.h>
51
 
 
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"}};
56
 
 
57
 
SCRIPT_CREATE(subtitle_script,ADMVideoSubtitle,subParam);
58
 
 
59
 
BUILD_CREATE(subtitle_create,ADMVideoSubtitle);
60
 
 
61
 
//__________________________________________________________________
62
 
 
63
 
//_______________________________________________________________
64
 
 
65
 
//__________________________________________________________________
66
 
 
67
 
char                                                            *ADMVideoSubtitle::printConf(void)
68
 
 {
69
 
                static char buf[50];
70
 
        
71
 
                                sprintf((char *)buf,"Subtitle ");
72
 
        return buf;
73
 
        }
74
 
 
75
 
//--------------------------------------------------------      
76
 
ADMVideoSubtitle::ADMVideoSubtitle(AVDMGenericVideoStream *in,CONFcouple *couples)
77
 
{
78
 
 
79
 
  uint32_t frame;
80
 
//  char c;
81
 
 
82
 
  _uncompressed=NULL;
83
 
  _font=NULL;
84
 
 
85
 
 
86
 
  _in=in;
87
 
  memcpy(&_info,_in->getInfo(),sizeof(_info));
88
 
 
89
 
        frame=3*_in->getInfo()->width*_in->getInfo()->height;
90
 
 
91
 
        _subs=NULL;
92
 
        _fd=NULL;
93
 
        _line=0;
94
 
        _oldframe=0;
95
 
        _oldline=0;
96
 
        _font = new ADMfont();  
97
 
        if(couples)
98
 
        {
99
 
                int32_t b;
100
 
                        SUBCONF *_param;
101
 
                        _conf=NEW( SUBCONF);
102
 
 
103
 
 
104
 
                        _param=_conf; // keep macro happy
105
 
 
106
 
                        GET(_fontsize);
107
 
                        GET(_subname);
108
 
                        GET(_fontname);
109
 
                        GET(_charset);
110
 
                        GET(_baseLine);
111
 
                        GET(_Y_percent);
112
 
                        GET(_U_percent);
113
 
                        GET(_V_percent);
114
 
                        GET(_selfAdjustable);
115
 
                        GET(_delay);
116
 
                        GET(_useBackgroundColor);
117
 
                        GET(_bg_Y_percent);
118
 
                        GET(_bg_U_percent);
119
 
                        GET(_bg_V_percent);
120
 
//                        GET(_blend);
121
 
                        couples->getCouple("_blend",&b);
122
 
                        _param->_blend=(BlendMode)b;
123
 
                        if(_conf->_baseLine>_info.height-_conf->_fontsize*SRT_MAX_LINE)
124
 
                        {
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;
128
 
                        }
129
 
 
130
 
                    char *ft,*sub;
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;
137
 
 
138
 
                        sub=(char *)ADM_alloc(500);
139
 
                        strcpy(sub,_conf->_charset);
140
 
                        _conf->_charset=sub;
141
 
                        loadSubtitle();
142
 
                        loadFont();
143
 
 
144
 
        }
145
 
        else
146
 
        {
147
 
                        _conf=NEW( SUBCONF);
148
 
 
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;
155
 
                        
156
 
                        
157
 
                        _conf->_baseLine=_info.height-24*SRT_MAX_LINE;
158
 
                        _conf->_Y_percent=255;
159
 
                        _conf->_U_percent=0;
160
 
                        _conf->_V_percent=0;
161
 
                        _conf->_fontsize=24; 
162
 
                        _conf->_selfAdjustable=0;
163
 
                        _conf->_delay=0;
164
 
                        _conf->_useBackgroundColor=0;
165
 
                        
166
 
                        _conf->_bg_Y_percent=0;
167
 
                        _conf->_bg_U_percent=0;
168
 
                        _conf->_bg_V_percent=0;
169
 
                        _conf->_blend=BLEND_SOLID;
170
 
 
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));
177
 
                        
178
 
                        // _conf->_fontname, ... are used as memory for a dialog
179
 
                        // later. we can't used the length of the current string
180
 
                        { char *tmp;
181
 
                           prefs->get(FILTERS_SUBTITLE_FONTNAME,&tmp);
182
 
                           strcpy((char *)_conf->_fontname,tmp);
183
 
                           ADM_dealloc(tmp);
184
 
                           
185
 
                           prefs->get(FILTERS_SUBTITLE_CHARSET,&tmp);
186
 
                           strcpy(_conf->_charset,tmp); 
187
 
                           ADM_dealloc(tmp);
188
 
                        }
189
 
                        
190
 
        }
191
 
 
192
 
  
193
 
        _info.encoding=1;
194
 
 
195
 
 
196
 
        _bitmap=0xffffffff;
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);
207
 
        ADM_assert(_dirty);
208
 
}
209
 
uint8_t ADMVideoSubtitle::loadSubtitle( void )
210
 
{
211
 
unsigned char c,d;
212
 
                        _fd=fopen((char *)_conf->_subname,"rt");
213
 
                        if(!_fd)
214
 
                        {
215
 
                          GUI_Error_HIG(_("Could not open subtitle file"), NULL);
216
 
                                return 0;
217
 
                        }
218
 
                        // Try to detect utf16 files                    
219
 
                        c=fgetc(_fd);
220
 
                        // Skip utf identifier if any
221
 
                        if(c==0xff)
222
 
                        {
223
 
                                c=fgetc(_fd);
224
 
                                if(c==0xfe)
225
 
                                {
226
 
                                        c=fgetc(_fd);
227
 
                                }
228
 
                        }
229
 
                        switch(c)
230
 
                        {
231
 
                        case '{' :
232
 
                                                loadSubTitle();
233
 
                                                break;
234
 
                        case '1' :
235
 
                                                loadSRT();
236
 
                                                break;
237
 
                        default:
238
 
                          GUI_Error_HIG(_("Cannot identify subtitle format"), NULL);
239
 
                        }
240
 
 
241
 
  // Apply delay to subtitles
242
 
  
243
 
  aprintf("[debug] DELAY %d\n", _conf->_delay);
244
 
  if(_conf->_delay)
245
 
  {
246
 
        int32_t newStartTime;
247
 
        int32_t newEndTime;
248
 
        for(uint32_t i=0;i<_line;i++) 
249
 
        {
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)
260
 
                {
261
 
                        _subs[i].startTime=_subs[i].endTime=0;
262
 
                }
263
 
                aprintf("[debug] AFTER DELAY (%d) %d %d\n",i, _subs[i].startTime,_subs[i].endTime);
264
 
        }
265
 
  }
266
 
 
267
 
 
268
 
        fclose(_fd);
269
 
        _fd=NULL;
270
 
        _bitmap=0xffffffff;
271
 
        if(_line)       // that way we will have the first sub
272
 
                _oldline=_line-1;
273
 
        return 1;
274
 
}
275
 
uint8_t ADMVideoSubtitle::getCoupledConf( CONFcouple **couples)
276
 
{
277
 
SUBCONF *_param;
278
 
 
279
 
                        _param=_conf; // keep macro happy
280
 
                        ADM_assert(_param);
281
 
                        *couples=new CONFcouple(15);
282
 
 
283
 
                        CSET(_fontsize);
284
 
                        CSET(_subname);
285
 
                        CSET(_fontname);
286
 
                        CSET(_charset);
287
 
                        CSET(_baseLine);
288
 
                        CSET(_Y_percent);
289
 
                        CSET(_U_percent);
290
 
                        CSET(_V_percent);
291
 
                        CSET(_selfAdjustable);
292
 
                        CSET(_delay);
293
 
                        CSET(_useBackgroundColor);
294
 
                        CSET(_bg_Y_percent);
295
 
                        CSET(_bg_U_percent);
296
 
                        CSET(_bg_V_percent);
297
 
                        (*couples)->setCouple("_blend",(uint32_t)_param->_blend);
298
 
 
299
 
                return 1;
300
 
 
301
 
}
302
 
//__________________________________________________________________
303
 
 
304
 
ADMVideoSubtitle::~ADMVideoSubtitle()
305
 
{
306
 
 
307
 
                if(_bitmapBuffer)
308
 
                        {
309
 
                                delete [] _bitmapBuffer;
310
 
                                _bitmapBuffer=0;
311
 
                        }
312
 
                if(_maskBuffer)
313
 
                        {
314
 
                                delete [] _maskBuffer;
315
 
                                _maskBuffer=0;
316
 
                        }
317
 
 
318
 
                if(_bgBitmapBuffer) 
319
 
                        {
320
 
                                delete [] _bgBitmapBuffer;
321
 
                                _bgBitmapBuffer=0;
322
 
                        }
323
 
 
324
 
                if(_bgMaskBuffer) 
325
 
                        {
326
 
                                delete [] _bgMaskBuffer;
327
 
                                _bgMaskBuffer=0;
328
 
                        }
329
 
                if(_dirty)
330
 
                {
331
 
                                delete [] _dirty;
332
 
                                _dirty=0;
333
 
                }
334
 
 
335
 
                if(_fd)
336
 
                {
337
 
                                fclose(_fd);
338
 
                                _fd=NULL;
339
 
                }
340
 
                if(_subs)
341
 
                {
342
 
                                for(uint32_t i=0;i<_line;i++)
343
 
                                {
344
 
                                        if(_subs[i].nbLine)
345
 
                                        {
346
 
                                        for(uint32_t k=0;k<_subs[i].nbLine;k++)
347
 
                                        {                                       
348
 
                                                if(_subs[i].string[k])
349
 
                                                {
350
 
                                                        delete [] _subs[i].string[k];
351
 
                                                        _subs[i].string[k]=NULL;
352
 
                                                }
353
 
                                        }                                       
354
 
                                        
355
 
                                        delete _subs[i].string;
356
 
                                        _subs[i].string=NULL;
357
 
                                        delete _subs[i].lineSize;
358
 
                                        _subs[i].lineSize=NULL;
359
 
                                        }
360
 
                                }
361
 
                                delete [] _subs;
362
 
                                _subs=NULL;
363
 
                }
364
 
        if(_conf)
365
 
        {
366
 
                        ADM_dealloc(_conf->_subname);
367
 
                        ADM_dealloc(_conf->_fontname);
368
 
                        ADM_dealloc(_conf->_charset);
369
 
 
370
 
                        DELETE(_conf);
371
 
        }
372
 
        if(_font)
373
 
        {
374
 
                delete _font;
375
 
                _font=NULL;
376
 
        }
377
 
}
378
 
#endif
379