WinGui: Fix another instance of the Caliburn vs Json.net sillyness where objects...
[HandBrake.git] / libhb / decutf8sub.c
blob5a278c786240237d13bd84d45531747b64e316ef
1 /* decutf8sub.c
3 Copyright (c) 2003-2015 HandBrake Team
4 This file is part of the HandBrake source code
5 Homepage: <http://handbrake.fr/>.
6 It may be used under the terms of the GNU General Public License v2.
7 For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
8 */
11 * Decoder for UTF-8 subtitles obtained from file input-sources.
13 * Input and output packet format is UTF-8 encoded text,
14 * with limited HTML-style markup (only <b>, <i>, and <u>).
16 * @author David Foster (davidfstr)
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include "hb.h"
22 #include "decsrtsub.h"
24 struct hb_work_private_s
26 int line; // SSA line number
29 static int decutf8Init(hb_work_object_t *w, hb_job_t *job)
31 hb_work_private_t * pv;
32 pv = calloc( 1, sizeof( hb_work_private_t ) );
33 if (pv == NULL)
34 return 1;
35 w->private_data = pv;
37 // Generate generic SSA Script Info.
38 int height = job->title->geometry.height - job->crop[0] - job->crop[1];
39 int width = job->title->geometry.width - job->crop[2] - job->crop[3];
40 hb_subtitle_add_ssa_header(w->subtitle, "Arial",
41 .066 * job->title->geometry.height,
42 width, height);
44 return 0;
47 static int decutf8Work(hb_work_object_t * w,
48 hb_buffer_t **buf_in, hb_buffer_t **buf_out)
50 hb_work_private_t * pv = w->private_data;
51 hb_buffer_t * in = *buf_in;
52 hb_buffer_t *out = *buf_in;
54 *buf_in = NULL;
55 if (in->s.flags & HB_BUF_FLAG_EOF)
57 *buf_out = in;
58 return HB_WORK_DONE;
61 // Warn if the subtitle's duration has not been passed through by the
62 // demuxer, which will prevent the subtitle from displaying at all
63 if (out->s.stop == 0)
65 hb_log("decutf8sub: subtitle packet lacks duration");
68 hb_srt_to_ssa(out, ++pv->line);
69 out->s.frametype = HB_FRAME_SUBTITLE;
70 *buf_out = out;
72 return HB_WORK_OK;
75 static void decutf8Close(hb_work_object_t *w)
77 free(w->private_data);
80 hb_work_object_t hb_decutf8sub =
82 WORK_DECUTF8SUB,
83 "UTF-8 Subtitle Decoder",
84 decutf8Init,
85 decutf8Work,
86 decutf8Close