annotate dvbsubdec.c @ 12472:9c9be94124f8 libavcodec

Only draw the actually visible area in vp3_draw_horiz_band. Fixes a black line in non-swapped, non-mod-16-height Theora videos when vp3_draw_horiz_band is used.
author reimar
date Wed, 08 Sep 2010 05:51:31 +0000
parents 59ba77fe9922
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1 /*
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
2 * DVB subtitle decoding for ffmpeg
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 8516
diff changeset
3 * Copyright (c) 2005 Ian Caulfield
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
16 *
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2967
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
20 */
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
21 #include "avcodec.h"
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
22 #include "dsputil.h"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9422
diff changeset
23 #include "get_bits.h"
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
24 #include "bytestream.h"
12039
d5705b52b76e Move colorspace.h from libavcodec to libavutil.
stefano
parents: 11882
diff changeset
25 #include "libavutil/colorspace.h"
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
26
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
27 //#define DEBUG
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
28 //#define DEBUG_PACKET_CONTENTS
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
29 //#define DEBUG_SAVE_IMAGES
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
30
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
31 #define DVBSUB_PAGE_SEGMENT 0x10
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
32 #define DVBSUB_REGION_SEGMENT 0x11
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
33 #define DVBSUB_CLUT_SEGMENT 0x12
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
34 #define DVBSUB_OBJECT_SEGMENT 0x13
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
35 #define DVBSUB_DISPLAYDEFINITION_SEGMENT 0x14
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
36 #define DVBSUB_DISPLAY_SEGMENT 0x80
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
37
4659
83dad4f266a6 remove useless static cm variable
michael
parents: 4364
diff changeset
38 #define cm (ff_cropTbl + MAX_NEG_CROP)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
39
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
40 #ifdef DEBUG_SAVE_IMAGES
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
41 #undef fprintf
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
42 #if 0
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
43 static void png_save(const char *filename, uint8_t *bitmap, int w, int h,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
44 uint32_t *rgba_palette)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
45 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
46 int x, y, v;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
47 FILE *f;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
48 char fname[40], fname2[40];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
49 char command[1024];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
50
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
51 snprintf(fname, 40, "%s.ppm", filename);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
52
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
53 f = fopen(fname, "w");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
54 if (!f) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
55 perror(fname);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
56 exit(1);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
57 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
58 fprintf(f, "P6\n"
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
59 "%d %d\n"
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
60 "%d\n",
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
61 w, h, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
62 for(y = 0; y < h; y++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
63 for(x = 0; x < w; x++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
64 v = rgba_palette[bitmap[y * w + x]];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
65 putc((v >> 16) & 0xff, f);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
66 putc((v >> 8) & 0xff, f);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
67 putc((v >> 0) & 0xff, f);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
68 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
69 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
70 fclose(f);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
71
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
72
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
73 snprintf(fname2, 40, "%s-a.pgm", filename);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
74
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
75 f = fopen(fname2, "w");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
76 if (!f) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
77 perror(fname2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
78 exit(1);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
79 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
80 fprintf(f, "P5\n"
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
81 "%d %d\n"
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
82 "%d\n",
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
83 w, h, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
84 for(y = 0; y < h; y++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
85 for(x = 0; x < w; x++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
86 v = rgba_palette[bitmap[y * w + x]];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
87 putc((v >> 24) & 0xff, f);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
88 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
89 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
90 fclose(f);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
91
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
92 snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
93 system(command);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
94
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
95 snprintf(command, 1024, "rm %s %s", fname, fname2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
96 system(command);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
97 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
98 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
99
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
100 static void png_save2(const char *filename, uint32_t *bitmap, int w, int h)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
101 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
102 int x, y, v;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
103 FILE *f;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
104 char fname[40], fname2[40];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
105 char command[1024];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
106
5929
aaeed46a74fd use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents: 5928
diff changeset
107 snprintf(fname, sizeof(fname), "%s.ppm", filename);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
108
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
109 f = fopen(fname, "w");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
110 if (!f) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
111 perror(fname);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
112 exit(1);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
113 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
114 fprintf(f, "P6\n"
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
115 "%d %d\n"
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
116 "%d\n",
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
117 w, h, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
118 for(y = 0; y < h; y++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
119 for(x = 0; x < w; x++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
120 v = bitmap[y * w + x];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
121 putc((v >> 16) & 0xff, f);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
122 putc((v >> 8) & 0xff, f);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
123 putc((v >> 0) & 0xff, f);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
124 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
125 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
126 fclose(f);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
127
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
128
5929
aaeed46a74fd use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents: 5928
diff changeset
129 snprintf(fname2, sizeof(fname2), "%s-a.pgm", filename);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
130
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
131 f = fopen(fname2, "w");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
132 if (!f) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
133 perror(fname2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
134 exit(1);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
135 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
136 fprintf(f, "P5\n"
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
137 "%d %d\n"
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
138 "%d\n",
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
139 w, h, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
140 for(y = 0; y < h; y++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
141 for(x = 0; x < w; x++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
142 v = bitmap[y * w + x];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
143 putc((v >> 24) & 0xff, f);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
144 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
145 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
146 fclose(f);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
147
5929
aaeed46a74fd use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents: 5928
diff changeset
148 snprintf(command, sizeof(command), "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
149 system(command);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
150
5929
aaeed46a74fd use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents: 5928
diff changeset
151 snprintf(command, sizeof(command), "rm %s %s", fname, fname2);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
152 system(command);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
153 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
154 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
155
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
156 #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
157
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
158 typedef struct DVBSubCLUT {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
159 int id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
160
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
161 uint32_t clut4[4];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
162 uint32_t clut16[16];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
163 uint32_t clut256[256];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
164
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
165 struct DVBSubCLUT *next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
166 } DVBSubCLUT;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
167
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
168 static DVBSubCLUT default_clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
169
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
170 typedef struct DVBSubObjectDisplay {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
171 int object_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
172 int region_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
173
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
174 int x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
175 int y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
176
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
177 int fgcolor;
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
178 int bgcolor;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
179
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
180 struct DVBSubObjectDisplay *region_list_next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
181 struct DVBSubObjectDisplay *object_list_next;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
182 } DVBSubObjectDisplay;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
183
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
184 typedef struct DVBSubObject {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
185 int id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
186
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
187 int type;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
188
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
189 DVBSubObjectDisplay *display_list;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
190
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
191 struct DVBSubObject *next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
192 } DVBSubObject;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
193
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
194 typedef struct DVBSubRegionDisplay {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
195 int region_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
196
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
197 int x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
198 int y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
199
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
200 struct DVBSubRegionDisplay *next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
201 } DVBSubRegionDisplay;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
202
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
203 typedef struct DVBSubRegion {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
204 int id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
205
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
206 int width;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
207 int height;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
208 int depth;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
209
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
210 int clut;
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
211 int bgcolor;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
212
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
213 uint8_t *pbuf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
214 int buf_size;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
215
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
216 DVBSubObjectDisplay *display_list;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
217
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
218 struct DVBSubRegion *next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
219 } DVBSubRegion;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
220
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
221 typedef struct DVBSubDisplayDefinition {
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
222 int version;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
223
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
224 int x;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
225 int y;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
226 int width;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
227 int height;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
228 } DVBSubDisplayDefinition;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
229
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
230 typedef struct DVBSubContext {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
231 int composition_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
232 int ancillary_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
233
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
234 int time_out;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
235 DVBSubRegion *region_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
236 DVBSubCLUT *clut_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
237 DVBSubObject *object_list;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
238
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
239 int display_list_size;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
240 DVBSubRegionDisplay *display_list;
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
241 DVBSubDisplayDefinition *display_definition;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
242 } DVBSubContext;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
243
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
244
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
245 static DVBSubObject* get_object(DVBSubContext *ctx, int object_id)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
246 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
247 DVBSubObject *ptr = ctx->object_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
248
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
249 while (ptr && ptr->id != object_id) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
250 ptr = ptr->next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
251 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
252
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
253 return ptr;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
254 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
255
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
256 static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
257 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
258 DVBSubCLUT *ptr = ctx->clut_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
259
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
260 while (ptr && ptr->id != clut_id) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
261 ptr = ptr->next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
262 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
263
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
264 return ptr;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
265 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
266
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
267 static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
268 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
269 DVBSubRegion *ptr = ctx->region_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
270
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
271 while (ptr && ptr->id != region_id) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
272 ptr = ptr->next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
273 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
274
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
275 return ptr;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
276 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
277
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
278 static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
279 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
280 DVBSubObject *object, *obj2, **obj2_ptr;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
281 DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
282
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
283 while (region->display_list) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
284 display = region->display_list;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
285
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
286 object = get_object(ctx, display->object_id);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
287
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
288 if (object) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
289 obj_disp_ptr = &object->display_list;
6916
603bdc5d8493 minor simplification
michael
parents: 6915
diff changeset
290 obj_disp = *obj_disp_ptr;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
291
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
292 while (obj_disp && obj_disp != display) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
293 obj_disp_ptr = &obj_disp->object_list_next;
6916
603bdc5d8493 minor simplification
michael
parents: 6915
diff changeset
294 obj_disp = *obj_disp_ptr;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
295 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
296
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
297 if (obj_disp) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
298 *obj_disp_ptr = obj_disp->object_list_next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
299
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
300 if (!object->display_list) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
301 obj2_ptr = &ctx->object_list;
6916
603bdc5d8493 minor simplification
michael
parents: 6915
diff changeset
302 obj2 = *obj2_ptr;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
303
6915
77ce2329f620 redundant
michael
parents: 6712
diff changeset
304 while (obj2 != object) {
77ce2329f620 redundant
michael
parents: 6712
diff changeset
305 assert(obj2);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
306 obj2_ptr = &obj2->next;
6916
603bdc5d8493 minor simplification
michael
parents: 6915
diff changeset
307 obj2 = *obj2_ptr;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
308 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
309
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
310 *obj2_ptr = obj2->next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
311
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
312 av_free(obj2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
313 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
314 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
315 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
316
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
317 region->display_list = display->region_list_next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
318
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
319 av_free(display);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
320 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
321
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
322 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
323
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
324 static void delete_state(DVBSubContext *ctx)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
325 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
326 DVBSubRegion *region;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
327 DVBSubCLUT *clut;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
328
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
329 while (ctx->region_list) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
330 region = ctx->region_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
331
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
332 ctx->region_list = region->next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
333
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
334 delete_region_display_list(ctx, region);
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
335 if (region->pbuf)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
336 av_free(region->pbuf);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
337
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
338 av_free(region);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
339 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
340
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
341 while (ctx->clut_list) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
342 clut = ctx->clut_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
343
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
344 ctx->clut_list = clut->next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
345
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
346 av_free(clut);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
347 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
348
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
349 av_freep(&ctx->display_definition);
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
350
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
351 /* Should already be null */
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
352 if (ctx->object_list)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
353 av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
354 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
355
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
356 static av_cold int dvbsub_init_decoder(AVCodecContext *avctx)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
357 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
358 int i, r, g, b, a = 0;
12135
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
359 DVBSubContext *ctx = avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
360
12164
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
361 if (!avctx->extradata || avctx->extradata_size != 4) {
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
362 av_log(avctx, AV_LOG_WARNING, "Invalid extradata, subtitle streams may be combined!\n");
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
363 ctx->composition_id = -1;
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
364 ctx->ancillary_id = -1;
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
365 } else {
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
366 ctx->composition_id = AV_RB16(avctx->extradata);
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
367 ctx->ancillary_id = AV_RB16(avctx->extradata + 2);
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
368 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
369
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
370 default_clut.id = -1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
371 default_clut.next = NULL;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
372
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
373 default_clut.clut4[0] = RGBA( 0, 0, 0, 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
374 default_clut.clut4[1] = RGBA(255, 255, 255, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
375 default_clut.clut4[2] = RGBA( 0, 0, 0, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
376 default_clut.clut4[3] = RGBA(127, 127, 127, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
377
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
378 default_clut.clut16[0] = RGBA( 0, 0, 0, 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
379 for (i = 1; i < 16; i++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
380 if (i < 8) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
381 r = (i & 1) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
382 g = (i & 2) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
383 b = (i & 4) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
384 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
385 r = (i & 1) ? 127 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
386 g = (i & 2) ? 127 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
387 b = (i & 4) ? 127 : 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
388 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
389 default_clut.clut16[i] = RGBA(r, g, b, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
390 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
391
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
392 default_clut.clut256[0] = RGBA( 0, 0, 0, 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
393 for (i = 1; i < 256; i++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
394 if (i < 8) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
395 r = (i & 1) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
396 g = (i & 2) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
397 b = (i & 4) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
398 a = 63;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
399 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
400 switch (i & 0x88) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
401 case 0x00:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
402 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
403 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
404 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
405 a = 255;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
406 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
407 case 0x08:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
408 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
409 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
410 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
411 a = 127;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
412 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
413 case 0x80:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
414 r = 127 + ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
415 g = 127 + ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
416 b = 127 + ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
417 a = 255;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
418 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
419 case 0x88:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
420 r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
421 g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
422 b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
423 a = 255;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
424 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
425 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
426 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
427 default_clut.clut256[i] = RGBA(r, g, b, a);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
428 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
429
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
430 return 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
431 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
432
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
433 static av_cold int dvbsub_close_decoder(AVCodecContext *avctx)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
434 {
12135
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
435 DVBSubContext *ctx = avctx->priv_data;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
436 DVBSubRegionDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
437
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
438 delete_state(ctx);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
439
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
440 while (ctx->display_list) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
441 display = ctx->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
442 ctx->display_list = display->next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
443
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
444 av_free(display);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
445 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
446
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
447 return 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
448 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
449
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
450 static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,
6218
michael
parents: 5982
diff changeset
451 const uint8_t **srcbuf, int buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
452 int non_mod, uint8_t *map_table)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
453 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
454 GetBitContext gb;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
455
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
456 int bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
457 int run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
458 int pixels_read = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
459
9422
997f587c3db8 Fix wrong size computation for buffer. Patch is part of
reynaldo
parents: 9355
diff changeset
460 init_get_bits(&gb, *srcbuf, buf_size << 3);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
461
9422
997f587c3db8 Fix wrong size computation for buffer. Patch is part of
reynaldo
parents: 9355
diff changeset
462 while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
463 bits = get_bits(&gb, 2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
464
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
465 if (bits) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
466 if (non_mod != 1 || bits != 1) {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
467 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
468 *destbuf++ = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
469 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
470 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
471 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
472 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
473 } else {
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5354
diff changeset
474 bits = get_bits1(&gb);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
475 if (bits == 1) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
476 run_length = get_bits(&gb, 3) + 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
477 bits = get_bits(&gb, 2);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
478
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
479 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
480 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
481 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
482 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
483 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
484 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
485 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
486 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
487 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
488 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
489 } else {
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5354
diff changeset
490 bits = get_bits1(&gb);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
491 if (bits == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
492 bits = get_bits(&gb, 2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
493 if (bits == 2) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
494 run_length = get_bits(&gb, 4) + 12;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
495 bits = get_bits(&gb, 2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
496
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
497 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
498 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
499 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
500 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
501 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
502 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
503 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
504 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
505 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
506 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
507 } else if (bits == 3) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
508 run_length = get_bits(&gb, 8) + 29;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
509 bits = get_bits(&gb, 2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
510
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
511 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
512 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
513 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
514 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
515 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
516 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
517 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
518 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
519 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
520 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
521 } else if (bits == 1) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
522 pixels_read += 2;
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
523 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
524 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
525 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
526 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
527 if (pixels_read <= dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
528 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
529 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
530 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
531 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
532 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
533 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
534 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
535 } else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
536 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
537 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
538 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
539 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
540 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
541 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
542 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
543 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
544 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
545 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
546
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
547 if (get_bits(&gb, 6))
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
548 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
549
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
550 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
551
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
552 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
553 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
554
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
555 static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len,
6218
michael
parents: 5982
diff changeset
556 const uint8_t **srcbuf, int buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
557 int non_mod, uint8_t *map_table)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
558 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
559 GetBitContext gb;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
560
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
561 int bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
562 int run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
563 int pixels_read = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
564
9422
997f587c3db8 Fix wrong size computation for buffer. Patch is part of
reynaldo
parents: 9355
diff changeset
565 init_get_bits(&gb, *srcbuf, buf_size << 3);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
566
9422
997f587c3db8 Fix wrong size computation for buffer. Patch is part of
reynaldo
parents: 9355
diff changeset
567 while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
568 bits = get_bits(&gb, 4);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
569
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
570 if (bits) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
571 if (non_mod != 1 || bits != 1) {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
572 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
573 *destbuf++ = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
574 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
575 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
576 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
577 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
578 } else {
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5354
diff changeset
579 bits = get_bits1(&gb);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
580 if (bits == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
581 run_length = get_bits(&gb, 3);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
582
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
583 if (run_length == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
584 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
585 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
586 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
587
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
588 run_length += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
589
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
590 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
591 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
592 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
593 bits = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
594
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
595 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
596 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
597 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
598 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
599 } else {
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5354
diff changeset
600 bits = get_bits1(&gb);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
601 if (bits == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
602 run_length = get_bits(&gb, 2) + 4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
603 bits = get_bits(&gb, 4);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
604
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
605 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
606 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
607 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
608 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
609 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
610 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
611 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
612 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
613 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
614 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
615 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
616 bits = get_bits(&gb, 2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
617 if (bits == 2) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
618 run_length = get_bits(&gb, 4) + 9;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
619 bits = get_bits(&gb, 4);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
620
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
621 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
622 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
623 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
624 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
625 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
626 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
627 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
628 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
629 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
630 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
631 } else if (bits == 3) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
632 run_length = get_bits(&gb, 8) + 25;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
633 bits = get_bits(&gb, 4);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
634
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
635 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
636 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
637 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
638 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
639 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
640 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
641 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
642 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
643 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
644 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
645 } else if (bits == 1) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
646 pixels_read += 2;
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
647 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
648 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
649 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
650 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
651 if (pixels_read <= dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
652 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
653 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
654 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
655 } else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
656 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
657 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
658 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
659 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
660 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
661 pixels_read ++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
662 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
663 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
664 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
665 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
666 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
667
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
668 if (get_bits(&gb, 8))
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
669 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
670
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
671 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
672
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
673 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
674 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
675
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
676 static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len,
6218
michael
parents: 5982
diff changeset
677 const uint8_t **srcbuf, int buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
678 int non_mod, uint8_t *map_table)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
679 {
6218
michael
parents: 5982
diff changeset
680 const uint8_t *sbuf_end = (*srcbuf) + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
681 int bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
682 int run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
683 int pixels_read = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
684
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
685 while (*srcbuf < sbuf_end && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
686 bits = *(*srcbuf)++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
687
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
688 if (bits) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
689 if (non_mod != 1 || bits != 1) {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
690 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
691 *destbuf++ = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
692 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
693 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
694 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
695 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
696 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
697 bits = *(*srcbuf)++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
698 run_length = bits & 0x7f;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
699 if ((bits & 0x80) == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
700 if (run_length == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
701 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
702 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
703
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
704 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
705 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
706 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
707 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
708 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
709 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
710 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
711 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
712 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
713 bits = *(*srcbuf)++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
714
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
715 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
716 pixels_read += run_length;
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
717 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
718 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
719 else while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
720 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
721 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
722 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
723 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
724 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
725 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
726
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
727 if (*(*srcbuf)++)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
728 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
729
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
730 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
731 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
732
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
733
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
734
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
735 static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display,
6218
michael
parents: 5982
diff changeset
736 const uint8_t *buf, int buf_size, int top_bottom, int non_mod)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
737 {
12135
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
738 DVBSubContext *ctx = avctx->priv_data;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
739
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
740 DVBSubRegion *region = get_region(ctx, display->region_id);
6218
michael
parents: 5982
diff changeset
741 const uint8_t *buf_end = buf + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
742 uint8_t *pbuf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
743 int x_pos, y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
744 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
745
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
746 uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf};
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
747 uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
748 uint8_t map4to8[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
749 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
750 uint8_t *map_table;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
751
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
752 dprintf(avctx, "DVB pixel block size %d, %s field:\n", buf_size,
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
753 top_bottom ? "bottom" : "top");
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
754
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
755 #ifdef DEBUG_PACKET_CONTENTS
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
756 for (i = 0; i < buf_size; i++) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
757 if (i % 16 == 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
758 av_log(avctx, AV_LOG_INFO, "0x%08p: ", buf+i);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
759
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
760 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
761 if (i % 16 == 15)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
762 av_log(avctx, AV_LOG_INFO, "\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
763 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
764
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
765 if (i % 16)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
766 av_log(avctx, AV_LOG_INFO, "\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
767
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
768 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
769
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
770 if (region == 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
771 return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
772
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
773 pbuf = region->pbuf;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
774
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
775 x_pos = display->x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
776 y_pos = display->y_pos;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
777
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
778 if ((y_pos & 1) != top_bottom)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
779 y_pos++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
780
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
781 while (buf < buf_end) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
782 if (x_pos > region->width || y_pos > region->height) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
783 av_log(avctx, AV_LOG_ERROR, "Invalid object location!\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
784 return;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
785 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
786
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
787 switch (*buf++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
788 case 0x10:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
789 if (region->depth == 8)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
790 map_table = map2to8;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
791 else if (region->depth == 4)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
792 map_table = map2to4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
793 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
794 map_table = NULL;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
795
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
796 x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
797 region->width - x_pos, &buf, buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
798 non_mod, map_table);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
799 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
800 case 0x11:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
801 if (region->depth < 4) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
802 av_log(avctx, AV_LOG_ERROR, "4-bit pixel string in %d-bit region!\n", region->depth);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
803 return;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
804 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
805
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
806 if (region->depth == 8)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
807 map_table = map4to8;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
808 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
809 map_table = NULL;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
810
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
811 x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
812 region->width - x_pos, &buf, buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
813 non_mod, map_table);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
814 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
815 case 0x12:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
816 if (region->depth < 8) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
817 av_log(avctx, AV_LOG_ERROR, "8-bit pixel string in %d-bit region!\n", region->depth);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
818 return;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
819 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
820
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
821 x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
822 region->width - x_pos, &buf, buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
823 non_mod, NULL);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
824 break;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
825
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
826 case 0x20:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
827 map2to4[0] = (*buf) >> 4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
828 map2to4[1] = (*buf++) & 0xf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
829 map2to4[2] = (*buf) >> 4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
830 map2to4[3] = (*buf++) & 0xf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
831 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
832 case 0x21:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
833 for (i = 0; i < 4; i++)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
834 map2to8[i] = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
835 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
836 case 0x22:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
837 for (i = 0; i < 16; i++)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
838 map4to8[i] = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
839 break;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
840
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
841 case 0xf0:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
842 x_pos = display->x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
843 y_pos += 2;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
844 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
845 default:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
846 av_log(avctx, AV_LOG_INFO, "Unknown/unsupported pixel block 0x%x\n", *(buf-1));
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
847 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
848 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
849
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
850 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
851
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
852 static void dvbsub_parse_object_segment(AVCodecContext *avctx,
6218
michael
parents: 5982
diff changeset
853 const uint8_t *buf, int buf_size)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
854 {
12135
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
855 DVBSubContext *ctx = avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
856
6218
michael
parents: 5982
diff changeset
857 const uint8_t *buf_end = buf + buf_size;
michael
parents: 5982
diff changeset
858 const uint8_t *block;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
859 int object_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
860 DVBSubObject *object;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
861 DVBSubObjectDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
862 int top_field_len, bottom_field_len;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
863
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
864 int coding_method, non_modifying_color;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
865
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
866 object_id = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
867 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
868
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
869 object = get_object(ctx, object_id);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
870
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
871 if (!object)
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
872 return;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
873
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
874 coding_method = ((*buf) >> 2) & 3;
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
875 non_modifying_color = ((*buf++) >> 1) & 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
876
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
877 if (coding_method == 0) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
878 top_field_len = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
879 buf += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
880 bottom_field_len = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
881 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
882
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
883 if (buf + top_field_len + bottom_field_len > buf_end) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
884 av_log(avctx, AV_LOG_ERROR, "Field data size too large\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
885 return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
886 }
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
887
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
888 for (display = object->display_list; display; display = display->object_list_next) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
889 block = buf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
890
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
891 dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0,
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
892 non_modifying_color);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
893
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
894 if (bottom_field_len > 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
895 block = buf + top_field_len;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
896 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
897 bottom_field_len = top_field_len;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
898
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
899 dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1,
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
900 non_modifying_color);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
901 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
902
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
903 /* } else if (coding_method == 1) {*/
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
904
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
905 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
906 av_log(avctx, AV_LOG_ERROR, "Unknown object coding %d\n", coding_method);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
907 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
908
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
909 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
910
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
911 static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
6218
michael
parents: 5982
diff changeset
912 const uint8_t *buf, int buf_size)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
913 {
12135
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
914 DVBSubContext *ctx = avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
915
6218
michael
parents: 5982
diff changeset
916 const uint8_t *buf_end = buf + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
917 int clut_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
918 DVBSubCLUT *clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
919 int entry_id, depth , full_range;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
920 int y, cr, cb, alpha;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
921 int r, g, b, r_add, g_add, b_add;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
922
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
923 #ifdef DEBUG_PACKET_CONTENTS
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
924 int i;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
925
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
926 av_log(avctx, AV_LOG_INFO, "DVB clut packet:\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
927
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
928 for (i=0; i < buf_size; i++) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
929 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
930 if (i % 16 == 15)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
931 av_log(avctx, AV_LOG_INFO, "\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
932 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
933
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
934 if (i % 16)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
935 av_log(avctx, AV_LOG_INFO, "\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
936
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
937 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
938
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
939 clut_id = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
940 buf += 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
941
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
942 clut = get_clut(ctx, clut_id);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
943
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
944 if (!clut) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
945 clut = av_malloc(sizeof(DVBSubCLUT));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
946
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
947 memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
948
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
949 clut->id = clut_id;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
950
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
951 clut->next = ctx->clut_list;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
952 ctx->clut_list = clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
953 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
954
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
955 while (buf + 4 < buf_end) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
956 entry_id = *buf++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
957
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
958 depth = (*buf) & 0xe0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
959
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
960 if (depth == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
961 av_log(avctx, AV_LOG_ERROR, "Invalid clut depth 0x%x!\n", *buf);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
962 return;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
963 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
964
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
965 full_range = (*buf++) & 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
966
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
967 if (full_range) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
968 y = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
969 cr = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
970 cb = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
971 alpha = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
972 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
973 y = buf[0] & 0xfc;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
974 cr = (((buf[0] & 3) << 2) | ((buf[1] >> 6) & 3)) << 4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
975 cb = (buf[1] << 2) & 0xf0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
976 alpha = (buf[1] << 6) & 0xc0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
977
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
978 buf += 2;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
979 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
980
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
981 if (y == 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
982 alpha = 0xff;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
983
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
984 YUV_TO_RGB1_CCIR(cb, cr);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
985 YUV_TO_RGB2_CCIR(r, g, b, y);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
986
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
987 dprintf(avctx, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
988
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
989 if (depth & 0x80)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
990 clut->clut4[entry_id] = RGBA(r,g,b,255 - alpha);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
991 if (depth & 0x40)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
992 clut->clut16[entry_id] = RGBA(r,g,b,255 - alpha);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
993 if (depth & 0x20)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
994 clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
995 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
996 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
997
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
998
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
999 static void dvbsub_parse_region_segment(AVCodecContext *avctx,
6218
michael
parents: 5982
diff changeset
1000 const uint8_t *buf, int buf_size)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1001 {
12135
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
1002 DVBSubContext *ctx = avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1003
6218
michael
parents: 5982
diff changeset
1004 const uint8_t *buf_end = buf + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1005 int region_id, object_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1006 DVBSubRegion *region;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1007 DVBSubObject *object;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1008 DVBSubObjectDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1009 int fill;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1010
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1011 if (buf_size < 10)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1012 return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1013
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1014 region_id = *buf++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1015
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1016 region = get_region(ctx, region_id);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1017
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1018 if (!region) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1019 region = av_mallocz(sizeof(DVBSubRegion));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1020
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1021 region->id = region_id;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1022
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1023 region->next = ctx->region_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1024 ctx->region_list = region;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1025 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1026
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1027 fill = ((*buf++) >> 3) & 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1028
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1029 region->width = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1030 buf += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1031 region->height = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1032 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1033
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1034 if (region->width * region->height != region->buf_size) {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1035 if (region->pbuf)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1036 av_free(region->pbuf);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1037
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1038 region->buf_size = region->width * region->height;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1039
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1040 region->pbuf = av_malloc(region->buf_size);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1041
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1042 fill = 1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1043 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1044
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1045 region->depth = 1 << (((*buf++) >> 2) & 7);
5928
de81a7e065fc check region depth for validity
michael
parents: 5513
diff changeset
1046 if(region->depth<2 || region->depth>8){
de81a7e065fc check region depth for validity
michael
parents: 5513
diff changeset
1047 av_log(avctx, AV_LOG_ERROR, "region depth %d is invalid\n", region->depth);
de81a7e065fc check region depth for validity
michael
parents: 5513
diff changeset
1048 region->depth= 4;
de81a7e065fc check region depth for validity
michael
parents: 5513
diff changeset
1049 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1050 region->clut = *buf++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1051
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1052 if (region->depth == 8)
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1053 region->bgcolor = *buf++;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1054 else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1055 buf += 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1056
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1057 if (region->depth == 4)
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1058 region->bgcolor = (((*buf++) >> 4) & 15);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1059 else
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1060 region->bgcolor = (((*buf++) >> 2) & 3);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1061 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1062
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1063 dprintf(avctx, "Region %d, (%dx%d)\n", region_id, region->width, region->height);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1064
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1065 if (fill) {
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1066 memset(region->pbuf, region->bgcolor, region->buf_size);
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1067 dprintf(avctx, "Fill region (%d)\n", region->bgcolor);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1068 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1069
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1070 delete_region_display_list(ctx, region);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1071
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1072 while (buf + 5 < buf_end) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1073 object_id = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1074 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1075
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1076 object = get_object(ctx, object_id);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1077
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1078 if (!object) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1079 object = av_mallocz(sizeof(DVBSubObject));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1080
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1081 object->id = object_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1082 object->next = ctx->object_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1083 ctx->object_list = object;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1084 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1085
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1086 object->type = (*buf) >> 6;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1087
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1088 display = av_mallocz(sizeof(DVBSubObjectDisplay));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1089
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1090 display->object_id = object_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1091 display->region_id = region_id;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1092
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1093 display->x_pos = AV_RB16(buf) & 0xfff;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1094 buf += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1095 display->y_pos = AV_RB16(buf) & 0xfff;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1096 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1097
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1098 if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) {
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1099 display->fgcolor = *buf++;
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1100 display->bgcolor = *buf++;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1101 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1102
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1103 display->region_list_next = region->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1104 region->display_list = display;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1105
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1106 display->object_list_next = object->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1107 object->display_list = display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1108 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1109 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1110
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1111 static void dvbsub_parse_page_segment(AVCodecContext *avctx,
6218
michael
parents: 5982
diff changeset
1112 const uint8_t *buf, int buf_size)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1113 {
12135
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
1114 DVBSubContext *ctx = avctx->priv_data;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1115 DVBSubRegionDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1116 DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1117
6218
michael
parents: 5982
diff changeset
1118 const uint8_t *buf_end = buf + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1119 int region_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1120 int page_state;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1121
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1122 if (buf_size < 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1123 return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1124
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1125 ctx->time_out = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1126 page_state = ((*buf++) >> 2) & 3;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1127
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1128 dprintf(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1129
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
1130 if (page_state == 2) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1131 delete_state(ctx);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1132 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1133
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1134 tmp_display_list = ctx->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1135 ctx->display_list = NULL;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1136 ctx->display_list_size = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1137
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1138 while (buf + 5 < buf_end) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1139 region_id = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1140 buf += 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1141
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1142 display = tmp_display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1143 tmp_ptr = &tmp_display_list;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1144
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1145 while (display && display->region_id != region_id) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1146 tmp_ptr = &display->next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1147 display = display->next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1148 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1149
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1150 if (!display)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1151 display = av_mallocz(sizeof(DVBSubRegionDisplay));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1152
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1153 display->region_id = region_id;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1154
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1155 display->x_pos = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1156 buf += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1157 display->y_pos = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1158 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1159
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1160 *tmp_ptr = display->next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1161
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1162 display->next = ctx->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1163 ctx->display_list = display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1164 ctx->display_list_size++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1165
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1166 dprintf(avctx, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1167 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1168
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1169 while (tmp_display_list) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1170 display = tmp_display_list;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1171
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1172 tmp_display_list = display->next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1173
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1174 av_free(display);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1175 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1176
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1177 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1178
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1179
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1180 #ifdef DEBUG_SAVE_IMAGES
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1181 static void save_display_set(DVBSubContext *ctx)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1182 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1183 DVBSubRegion *region;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1184 DVBSubRegionDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1185 DVBSubCLUT *clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1186 uint32_t *clut_table;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1187 int x_pos, y_pos, width, height;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1188 int x, y, y_off, x_off;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1189 uint32_t *pbuf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1190 char filename[32];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1191 static int fileno_index = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1192
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1193 x_pos = -1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1194 y_pos = -1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1195 width = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1196 height = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1197
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1198 for (display = ctx->display_list; display; display = display->next) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1199 region = get_region(ctx, display->region_id);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1200
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1201 if (x_pos == -1) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1202 x_pos = display->x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1203 y_pos = display->y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1204 width = region->width;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1205 height = region->height;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1206 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1207 if (display->x_pos < x_pos) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1208 width += (x_pos - display->x_pos);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1209 x_pos = display->x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1210 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1211
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1212 if (display->y_pos < y_pos) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1213 height += (y_pos - display->y_pos);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1214 y_pos = display->y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1215 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1216
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1217 if (display->x_pos + region->width > x_pos + width) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1218 width = display->x_pos + region->width - x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1219 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1220
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1221 if (display->y_pos + region->height > y_pos + height) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1222 height = display->y_pos + region->height - y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1223 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1224 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1225 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1226
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1227 if (x_pos >= 0) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1228
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1229 pbuf = av_malloc(width * height * 4);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1230
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1231 for (display = ctx->display_list; display; display = display->next) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1232 region = get_region(ctx, display->region_id);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1233
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1234 x_off = display->x_pos - x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1235 y_off = display->y_pos - y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1236
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1237 clut = get_clut(ctx, region->clut);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1238
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1239 if (clut == 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1240 clut = &default_clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1241
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1242 switch (region->depth) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1243 case 2:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1244 clut_table = clut->clut4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1245 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1246 case 8:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1247 clut_table = clut->clut256;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1248 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1249 case 4:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1250 default:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1251 clut_table = clut->clut16;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1252 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1253 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1254
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1255 for (y = 0; y < region->height; y++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1256 for (x = 0; x < region->width; x++) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1257 pbuf[((y + y_off) * width) + x_off + x] =
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1258 clut_table[region->pbuf[y * region->width + x]];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1259 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1260 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1261
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1262 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1263
5929
aaeed46a74fd use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents: 5928
diff changeset
1264 snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1265
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1266 png_save2(filename, pbuf, width, height);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1267
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1268 av_free(pbuf);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1269 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1270
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1271 fileno_index++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1272 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1273 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1274
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1275 static void dvbsub_parse_display_definition_segment(AVCodecContext *avctx,
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1276 const uint8_t *buf,
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1277 int buf_size)
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1278 {
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1279 DVBSubContext *ctx = avctx->priv_data;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1280 DVBSubDisplayDefinition *display_def = ctx->display_definition;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1281 int dds_version, info_byte;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1282
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1283 if (buf_size < 5)
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1284 return;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1285
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1286 info_byte = bytestream_get_byte(&buf);
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1287 dds_version = info_byte >> 4;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1288 if (display_def && display_def->version == dds_version)
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1289 return; // already have this display definition version
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1290
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1291 if (!display_def) {
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1292 display_def = av_mallocz(sizeof(*display_def));
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1293 ctx->display_definition = display_def;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1294 }
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1295 if (!display_def)
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1296 return;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1297
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1298 display_def->version = dds_version;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1299 display_def->x = 0;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1300 display_def->y = 0;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1301 display_def->width = bytestream_get_be16(&buf) + 1;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1302 display_def->height = bytestream_get_be16(&buf) + 1;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1303
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1304 if (buf_size < 13)
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1305 return;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1306
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1307 if (info_byte & 1<<3) { // display_window_flag
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1308 display_def->x = bytestream_get_be16(&buf);
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1309 display_def->y = bytestream_get_be16(&buf);
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1310 display_def->width = bytestream_get_be16(&buf) - display_def->x + 1;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1311 display_def->height = bytestream_get_be16(&buf) - display_def->y + 1;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1312 }
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1313 }
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1314
6218
michael
parents: 5982
diff changeset
1315 static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1316 int buf_size, AVSubtitle *sub)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1317 {
12135
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
1318 DVBSubContext *ctx = avctx->priv_data;
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1319 DVBSubDisplayDefinition *display_def = ctx->display_definition;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1320
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1321 DVBSubRegion *region;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1322 DVBSubRegionDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1323 AVSubtitleRect *rect;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1324 DVBSubCLUT *clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1325 uint32_t *clut_table;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1326 int i;
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1327 int offset_x=0, offset_y=0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1328
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1329 sub->rects = NULL;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1330 sub->start_display_time = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1331 sub->end_display_time = ctx->time_out * 1000;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1332 sub->format = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1333
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1334 if (display_def) {
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1335 offset_x = display_def->x;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1336 offset_y = display_def->y;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1337 }
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1338
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1339 sub->num_rects = ctx->display_list_size;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1340
8512
aa45029f5cd7 Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents: 7040
diff changeset
1341 if (sub->num_rects > 0){
aa45029f5cd7 Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents: 7040
diff changeset
1342 sub->rects = av_mallocz(sizeof(*sub->rects) * sub->num_rects);
aa45029f5cd7 Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents: 7040
diff changeset
1343 for(i=0; i<sub->num_rects; i++)
aa45029f5cd7 Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents: 7040
diff changeset
1344 sub->rects[i] = av_mallocz(sizeof(*sub->rects[i]));
aa45029f5cd7 Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents: 7040
diff changeset
1345 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1346
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1347 i = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1348
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1349 for (display = ctx->display_list; display; display = display->next) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1350 region = get_region(ctx, display->region_id);
8512
aa45029f5cd7 Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents: 7040
diff changeset
1351 rect = sub->rects[i];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1352
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1353 if (!region)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1354 continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1355
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1356 rect->x = display->x_pos + offset_x;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1357 rect->y = display->y_pos + offset_y;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1358 rect->w = region->width;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1359 rect->h = region->height;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1360 rect->nb_colors = 16;
9954
50327500e065 Set subtitle type in DVB subtitle decoder.
stefano
parents: 9428
diff changeset
1361 rect->type = SUBTITLE_BITMAP;
8516
315b302fcd1d Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents: 8512
diff changeset
1362 rect->pict.linesize[0] = region->width;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1363
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1364 clut = get_clut(ctx, region->clut);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1365
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1366 if (!clut)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1367 clut = &default_clut;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1368
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1369 switch (region->depth) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1370 case 2:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1371 clut_table = clut->clut4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1372 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1373 case 8:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1374 clut_table = clut->clut256;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1375 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1376 case 4:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1377 default:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1378 clut_table = clut->clut16;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1379 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1380 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1381
10069
8ac9bc10b485 Always allocate a buffer of AVPALETTE_SIZE for palette in the subtitle
reimar
parents: 9999
diff changeset
1382 rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
8516
315b302fcd1d Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents: 8512
diff changeset
1383 memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1384
8516
315b302fcd1d Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents: 8512
diff changeset
1385 rect->pict.data[0] = av_malloc(region->buf_size);
315b302fcd1d Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents: 8512
diff changeset
1386 memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1387
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1388 i++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1389 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1390
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1391 sub->num_rects = i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1392
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1393 #ifdef DEBUG_SAVE_IMAGES
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1394 save_display_set(ctx);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1395 #endif
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1396
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1397 return 1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1398 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1399
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1400 static int dvbsub_decode(AVCodecContext *avctx,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1401 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8629
diff changeset
1402 AVPacket *avpkt)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1403 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8629
diff changeset
1404 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8629
diff changeset
1405 int buf_size = avpkt->size;
12135
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
1406 DVBSubContext *ctx = avctx->priv_data;
0f987eea1349 Remove useless casts and memset.
reimar
parents: 12039
diff changeset
1407 AVSubtitle *sub = data;
6218
michael
parents: 5982
diff changeset
1408 const uint8_t *p, *p_end;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1409 int segment_type;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1410 int page_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1411 int segment_length;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1412
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1413 #ifdef DEBUG_PACKET_CONTENTS
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1414 int i;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1415
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1416 av_log(avctx, AV_LOG_INFO, "DVB sub packet:\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1417
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
1418 for (i=0; i < buf_size; i++) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1419 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1420 if (i % 16 == 15)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1421 av_log(avctx, AV_LOG_INFO, "\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1422 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1423
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1424 if (i % 16)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1425 av_log(avctx, AV_LOG_INFO, "\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1426
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1427 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1428
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1429 if (buf_size <= 2)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1430 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1431
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1432 p = buf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1433 p_end = buf + buf_size;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1434
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
1435 while (p < p_end && *p == 0x0f) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1436 p += 1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1437 segment_type = *p++;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1438 page_id = AV_RB16(p);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1439 p += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1440 segment_length = AV_RB16(p);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1441 p += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1442
12164
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
1443 if (page_id == ctx->composition_id || page_id == ctx->ancillary_id ||
59ba77fe9922 Pass the composition and ancillary ID for DVB subtitles via extradata instead
reimar
parents: 12135
diff changeset
1444 ctx->composition_id == -1 || ctx->ancillary_id == -1) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1445 switch (segment_type) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1446 case DVBSUB_PAGE_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1447 dvbsub_parse_page_segment(avctx, p, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1448 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1449 case DVBSUB_REGION_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1450 dvbsub_parse_region_segment(avctx, p, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1451 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1452 case DVBSUB_CLUT_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1453 dvbsub_parse_clut_segment(avctx, p, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1454 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1455 case DVBSUB_OBJECT_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1456 dvbsub_parse_object_segment(avctx, p, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1457 break;
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1458 case DVBSUB_DISPLAYDEFINITION_SEGMENT:
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1459 dvbsub_parse_display_definition_segment(avctx, p, segment_length);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1460 case DVBSUB_DISPLAY_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1461 *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1462 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1463 default:
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1464 dprintf(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n",
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1465 segment_type, page_id, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1466 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1467 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1468 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1469
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1470 p += segment_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1471 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1472
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
1473 if (p != p_end) {
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1474 dprintf(avctx, "Junk at end of packet\n");
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1475 return -1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1476 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1477
2833
1f117208d20f subs.diff fixes a couple of minor bugs in my DVB subtitle decoder, and also fixes a few
michael
parents: 2796
diff changeset
1478 return buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1479 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1480
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1481
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1482 AVCodec dvbsub_decoder = {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1483 "dvbsub",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 10069
diff changeset
1484 AVMEDIA_TYPE_SUBTITLE,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1485 CODEC_ID_DVB_SUBTITLE,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1486 sizeof(DVBSubContext),
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1487 dvbsub_init_decoder,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1488 NULL,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1489 dvbsub_close_decoder,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1490 dvbsub_decode,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6916
diff changeset
1491 .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"),
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1492 };