annotate dvbsubdec.c @ 11979:59f399926c12 libavcodec

tableprint: use the type name as-is for the functions' names. This drops one parameter from the functions' macros, and require structures to be typedeffed, but ensures that it is possible to map 1-to-1 the type to the function name.
author flameeyes
date Sun, 27 Jun 2010 12:20:39 +0000
parents c591e96c03ab
children d5705b52b76e
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"
5354
dfa6e7fa2bac create colorspace.h and use it where appropriate
benoit
parents: 4920
diff changeset
24 #include "colorspace.h"
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
25 #include "bytestream.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;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
359 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
360
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
361 memset(avctx->priv_data, 0, sizeof(DVBSubContext));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
362
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
363 ctx->composition_id = avctx->sub_id & 0xffff;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
364 ctx->ancillary_id = avctx->sub_id >> 16;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
365
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
366 default_clut.id = -1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
367 default_clut.next = NULL;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
368
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
369 default_clut.clut4[0] = RGBA( 0, 0, 0, 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
370 default_clut.clut4[1] = RGBA(255, 255, 255, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
371 default_clut.clut4[2] = RGBA( 0, 0, 0, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
372 default_clut.clut4[3] = RGBA(127, 127, 127, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
373
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
374 default_clut.clut16[0] = RGBA( 0, 0, 0, 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
375 for (i = 1; i < 16; i++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
376 if (i < 8) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
377 r = (i & 1) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
378 g = (i & 2) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
379 b = (i & 4) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
380 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
381 r = (i & 1) ? 127 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
382 g = (i & 2) ? 127 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
383 b = (i & 4) ? 127 : 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
384 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
385 default_clut.clut16[i] = RGBA(r, g, b, 255);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
386 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
387
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
388 default_clut.clut256[0] = RGBA( 0, 0, 0, 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
389 for (i = 1; i < 256; i++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
390 if (i < 8) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
391 r = (i & 1) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
392 g = (i & 2) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
393 b = (i & 4) ? 255 : 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
394 a = 63;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
395 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
396 switch (i & 0x88) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
397 case 0x00:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
398 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
399 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
400 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
401 a = 255;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
402 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
403 case 0x08:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
404 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
405 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
406 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
407 a = 127;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
408 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
409 case 0x80:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
410 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
411 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
412 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
413 a = 255;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
414 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
415 case 0x88:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
416 r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
417 g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
418 b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
419 a = 255;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
420 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
421 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
422 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
423 default_clut.clut256[i] = RGBA(r, g, b, a);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
424 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
425
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
426 return 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
427 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
428
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6218
diff changeset
429 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
430 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
431 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
432 DVBSubRegionDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
433
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
434 delete_state(ctx);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
435
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
436 while (ctx->display_list) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
437 display = ctx->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
438 ctx->display_list = display->next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
439
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
440 av_free(display);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
441 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
442
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
443 return 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
444 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
445
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
446 static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len,
6218
michael
parents: 5982
diff changeset
447 const uint8_t **srcbuf, int buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
448 int non_mod, uint8_t *map_table)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
449 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
450 GetBitContext gb;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
451
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
452 int bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
453 int run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
454 int pixels_read = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
455
9422
997f587c3db8 Fix wrong size computation for buffer. Patch is part of
reynaldo
parents: 9355
diff changeset
456 init_get_bits(&gb, *srcbuf, buf_size << 3);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
457
9422
997f587c3db8 Fix wrong size computation for buffer. Patch is part of
reynaldo
parents: 9355
diff changeset
458 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
459 bits = get_bits(&gb, 2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
460
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
461 if (bits) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
462 if (non_mod != 1 || bits != 1) {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
463 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
464 *destbuf++ = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
465 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
466 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
467 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
468 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
469 } else {
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5354
diff changeset
470 bits = get_bits1(&gb);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
471 if (bits == 1) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
472 run_length = get_bits(&gb, 3) + 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
473 bits = get_bits(&gb, 2);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
474
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
475 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
476 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
477 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
478 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
479 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
480 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
481 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
482 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
483 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
484 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
485 } else {
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5354
diff changeset
486 bits = get_bits1(&gb);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
487 if (bits == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
488 bits = get_bits(&gb, 2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
489 if (bits == 2) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
490 run_length = get_bits(&gb, 4) + 12;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
491 bits = get_bits(&gb, 2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
492
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
493 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
494 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
495 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
496 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
497 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
498 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
499 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
500 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
501 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
502 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
503 } else if (bits == 3) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
504 run_length = get_bits(&gb, 8) + 29;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
505 bits = get_bits(&gb, 2);
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 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
508 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
509 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
510 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
511 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
512 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
513 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
514 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
515 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
516 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
517 } else if (bits == 1) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
518 pixels_read += 2;
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
519 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
520 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
521 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
522 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
523 if (pixels_read <= dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
524 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
525 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
526 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
527 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
528 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
529 return pixels_read;
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 {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
532 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
533 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
534 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
535 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
536 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
537 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
538 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
539 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
540 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
541 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
542
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
543 if (get_bits(&gb, 6))
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
544 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
545
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
546 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
547
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
548 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
549 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
550
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
551 static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len,
6218
michael
parents: 5982
diff changeset
552 const uint8_t **srcbuf, int buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
553 int non_mod, uint8_t *map_table)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
554 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
555 GetBitContext gb;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
556
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
557 int bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
558 int run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
559 int pixels_read = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
560
9422
997f587c3db8 Fix wrong size computation for buffer. Patch is part of
reynaldo
parents: 9355
diff changeset
561 init_get_bits(&gb, *srcbuf, buf_size << 3);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
562
9422
997f587c3db8 Fix wrong size computation for buffer. Patch is part of
reynaldo
parents: 9355
diff changeset
563 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
564 bits = get_bits(&gb, 4);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
565
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
566 if (bits) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
567 if (non_mod != 1 || bits != 1) {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
568 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
569 *destbuf++ = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
570 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
571 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
572 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
573 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
574 } else {
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5354
diff changeset
575 bits = get_bits1(&gb);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
576 if (bits == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
577 run_length = get_bits(&gb, 3);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
578
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
579 if (run_length == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
580 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
581 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
582 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
583
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
584 run_length += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
585
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
586 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
587 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
588 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
589 bits = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
590
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
591 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
592 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
593 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
594 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
595 } else {
5513
9f8219a3b86f use get_bits1(..) instead get_bits(.., 1)
alex
parents: 5354
diff changeset
596 bits = get_bits1(&gb);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
597 if (bits == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
598 run_length = get_bits(&gb, 2) + 4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
599 bits = get_bits(&gb, 4);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
600
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
601 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
602 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
603 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
604 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
605 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
606 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
607 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
608 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
609 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
610 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
611 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
612 bits = get_bits(&gb, 2);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
613 if (bits == 2) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
614 run_length = get_bits(&gb, 4) + 9;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
615 bits = get_bits(&gb, 4);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
616
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
617 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
618 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
619 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
620 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
621 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
622 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
623 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
624 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
625 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
626 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
627 } else if (bits == 3) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
628 run_length = get_bits(&gb, 8) + 25;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
629 bits = get_bits(&gb, 4);
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 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
632 pixels_read += run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
633 else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
634 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
635 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
636 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
637 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
638 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
639 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
640 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
641 } else if (bits == 1) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
642 pixels_read += 2;
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
643 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
644 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
645 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
646 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
647 if (pixels_read <= dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
648 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
649 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
650 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
651 } else {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
652 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
653 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
654 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
655 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
656 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
657 pixels_read ++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
658 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
659 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
660 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
661 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
662 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
663
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
664 if (get_bits(&gb, 8))
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
665 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
666
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
667 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
668
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
669 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
670 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
671
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
672 static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len,
6218
michael
parents: 5982
diff changeset
673 const uint8_t **srcbuf, int buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
674 int non_mod, uint8_t *map_table)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
675 {
6218
michael
parents: 5982
diff changeset
676 const uint8_t *sbuf_end = (*srcbuf) + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
677 int bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
678 int run_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
679 int pixels_read = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
680
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
681 while (*srcbuf < sbuf_end && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
682 bits = *(*srcbuf)++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
683
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
684 if (bits) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
685 if (non_mod != 1 || bits != 1) {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
686 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
687 *destbuf++ = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
688 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
689 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
690 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
691 pixels_read++;
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 bits = *(*srcbuf)++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
694 run_length = bits & 0x7f;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
695 if ((bits & 0x80) == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
696 if (run_length == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
697 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
698 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
699
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
700 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
701 bits = map_table[0];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
702 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
703 bits = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
704 while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
705 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
706 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
707 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
708 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
709 bits = *(*srcbuf)++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
710
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
711 if (non_mod == 1 && bits == 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
712 pixels_read += run_length;
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
713 if (map_table)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
714 bits = map_table[bits];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
715 else while (run_length-- > 0 && pixels_read < dbuf_len) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
716 *destbuf++ = bits;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
717 pixels_read++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
718 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
719 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
720 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
721 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
722
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
723 if (*(*srcbuf)++)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
724 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n");
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
725
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
726 return pixels_read;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
727 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
728
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
729
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
730
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
731 static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display,
6218
michael
parents: 5982
diff changeset
732 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
733 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
734 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
735
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
736 DVBSubRegion *region = get_region(ctx, display->region_id);
6218
michael
parents: 5982
diff changeset
737 const uint8_t *buf_end = buf + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
738 uint8_t *pbuf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
739 int x_pos, y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
740 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
741
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
742 uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf};
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
743 uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff};
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
744 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
745 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
746 uint8_t *map_table;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
747
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
748 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
749 top_bottom ? "bottom" : "top");
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
750
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
751 #ifdef DEBUG_PACKET_CONTENTS
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
752 for (i = 0; i < buf_size; i++) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
753 if (i % 16 == 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
754 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
755
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
756 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
757 if (i % 16 == 15)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
758 av_log(avctx, AV_LOG_INFO, "\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
759 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
760
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
761 if (i % 16)
2796
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
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
764 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
765
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
766 if (region == 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
767 return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
768
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
769 pbuf = region->pbuf;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
770
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
771 x_pos = display->x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
772 y_pos = display->y_pos;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
773
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
774 if ((y_pos & 1) != top_bottom)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
775 y_pos++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
776
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
777 while (buf < buf_end) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
778 if (x_pos > region->width || y_pos > region->height) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
779 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
780 return;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
781 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
782
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
783 switch (*buf++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
784 case 0x10:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
785 if (region->depth == 8)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
786 map_table = map2to8;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
787 else if (region->depth == 4)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
788 map_table = map2to4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
789 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
790 map_table = NULL;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
791
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
792 x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
793 region->width - x_pos, &buf, buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
794 non_mod, map_table);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
795 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
796 case 0x11:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
797 if (region->depth < 4) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
798 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
799 return;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
800 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
801
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
802 if (region->depth == 8)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
803 map_table = map4to8;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
804 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
805 map_table = NULL;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
806
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
807 x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
808 region->width - x_pos, &buf, buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
809 non_mod, map_table);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
810 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
811 case 0x12:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
812 if (region->depth < 8) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
813 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
814 return;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
815 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
816
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
817 x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos,
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
818 region->width - x_pos, &buf, buf_size,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
819 non_mod, NULL);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
820 break;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
821
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
822 case 0x20:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
823 map2to4[0] = (*buf) >> 4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
824 map2to4[1] = (*buf++) & 0xf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
825 map2to4[2] = (*buf) >> 4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
826 map2to4[3] = (*buf++) & 0xf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
827 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
828 case 0x21:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
829 for (i = 0; i < 4; i++)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
830 map2to8[i] = *buf++;
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 0x22:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
833 for (i = 0; i < 16; i++)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
834 map4to8[i] = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
835 break;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
836
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
837 case 0xf0:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
838 x_pos = display->x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
839 y_pos += 2;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
840 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
841 default:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
842 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
843 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
844 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
845
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
846 }
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 static void dvbsub_parse_object_segment(AVCodecContext *avctx,
6218
michael
parents: 5982
diff changeset
849 const uint8_t *buf, int buf_size)
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 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
852
6218
michael
parents: 5982
diff changeset
853 const uint8_t *buf_end = buf + buf_size;
michael
parents: 5982
diff changeset
854 const uint8_t *block;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
855 int object_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
856 DVBSubObject *object;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
857 DVBSubObjectDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
858 int top_field_len, bottom_field_len;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
859
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
860 int coding_method, non_modifying_color;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
861
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
862 object_id = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
863 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
864
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
865 object = get_object(ctx, object_id);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
866
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
867 if (!object)
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
868 return;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
869
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
870 coding_method = ((*buf) >> 2) & 3;
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
871 non_modifying_color = ((*buf++) >> 1) & 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
872
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
873 if (coding_method == 0) {
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
874 top_field_len = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
875 buf += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
876 bottom_field_len = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
877 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
878
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
879 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
880 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
881 return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
882 }
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
883
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
884 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
885 block = buf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
886
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
887 dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0,
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
888 non_modifying_color);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
889
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
890 if (bottom_field_len > 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
891 block = buf + top_field_len;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
892 else
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
893 bottom_field_len = top_field_len;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
894
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
895 dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1,
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
896 non_modifying_color);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
897 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
898
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
899 /* } else if (coding_method == 1) {*/
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
900
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
901 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
902 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
903 }
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 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
906
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
907 static void dvbsub_parse_clut_segment(AVCodecContext *avctx,
6218
michael
parents: 5982
diff changeset
908 const uint8_t *buf, int buf_size)
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 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
911
6218
michael
parents: 5982
diff changeset
912 const uint8_t *buf_end = buf + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
913 int clut_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
914 DVBSubCLUT *clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
915 int entry_id, depth , full_range;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
916 int y, cr, cb, alpha;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
917 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
918
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
919 #ifdef DEBUG_PACKET_CONTENTS
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
920 int i;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
921
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
922 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
923
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
924 for (i=0; i < buf_size; i++) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
925 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
926 if (i % 16 == 15)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
927 av_log(avctx, AV_LOG_INFO, "\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
928 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
929
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
930 if (i % 16)
2796
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
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
933 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
934
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
935 clut_id = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
936 buf += 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
937
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
938 clut = get_clut(ctx, clut_id);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
939
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
940 if (!clut) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
941 clut = av_malloc(sizeof(DVBSubCLUT));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
942
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
943 memcpy(clut, &default_clut, sizeof(DVBSubCLUT));
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
944
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
945 clut->id = clut_id;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
946
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
947 clut->next = ctx->clut_list;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
948 ctx->clut_list = clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
949 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
950
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
951 while (buf + 4 < buf_end) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
952 entry_id = *buf++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
953
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
954 depth = (*buf) & 0xe0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
955
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
956 if (depth == 0) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
957 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
958 return;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
959 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
960
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
961 full_range = (*buf++) & 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
962
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
963 if (full_range) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
964 y = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
965 cr = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
966 cb = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
967 alpha = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
968 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
969 y = buf[0] & 0xfc;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
970 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
971 cb = (buf[1] << 2) & 0xf0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
972 alpha = (buf[1] << 6) & 0xc0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
973
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
974 buf += 2;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
975 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
976
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
977 if (y == 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
978 alpha = 0xff;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
979
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
980 YUV_TO_RGB1_CCIR(cb, cr);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
981 YUV_TO_RGB2_CCIR(r, g, b, y);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
982
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
983 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
984
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
985 if (depth & 0x80)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
986 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
987 if (depth & 0x40)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
988 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
989 if (depth & 0x20)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
990 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
991 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
992 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
993
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
994
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
995 static void dvbsub_parse_region_segment(AVCodecContext *avctx,
6218
michael
parents: 5982
diff changeset
996 const uint8_t *buf, int buf_size)
2796
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 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
999
6218
michael
parents: 5982
diff changeset
1000 const uint8_t *buf_end = buf + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1001 int region_id, object_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1002 DVBSubRegion *region;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1003 DVBSubObject *object;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1004 DVBSubObjectDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1005 int fill;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1006
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1007 if (buf_size < 10)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1008 return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1009
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1010 region_id = *buf++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1011
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1012 region = get_region(ctx, region_id);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1013
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1014 if (!region) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1015 region = av_mallocz(sizeof(DVBSubRegion));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1016
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1017 region->id = region_id;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1018
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1019 region->next = ctx->region_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1020 ctx->region_list = region;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1021 }
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 fill = ((*buf++) >> 3) & 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1024
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1025 region->width = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1026 buf += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1027 region->height = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1028 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1029
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1030 if (region->width * region->height != region->buf_size) {
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1031 if (region->pbuf)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1032 av_free(region->pbuf);
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 region->buf_size = region->width * region->height;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1035
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1036 region->pbuf = av_malloc(region->buf_size);
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 fill = 1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1039 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1040
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1041 region->depth = 1 << (((*buf++) >> 2) & 7);
5928
de81a7e065fc check region depth for validity
michael
parents: 5513
diff changeset
1042 if(region->depth<2 || region->depth>8){
de81a7e065fc check region depth for validity
michael
parents: 5513
diff changeset
1043 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
1044 region->depth= 4;
de81a7e065fc check region depth for validity
michael
parents: 5513
diff changeset
1045 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1046 region->clut = *buf++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1047
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1048 if (region->depth == 8)
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1049 region->bgcolor = *buf++;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1050 else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1051 buf += 1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1052
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1053 if (region->depth == 4)
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1054 region->bgcolor = (((*buf++) >> 4) & 15);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1055 else
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1056 region->bgcolor = (((*buf++) >> 2) & 3);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1057 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1058
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1059 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
1060
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1061 if (fill) {
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1062 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
1063 dprintf(avctx, "Fill region (%d)\n", region->bgcolor);
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
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1066 delete_region_display_list(ctx, region);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1067
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1068 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
1069 object_id = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1070 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1071
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1072 object = get_object(ctx, object_id);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1073
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1074 if (!object) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1075 object = av_mallocz(sizeof(DVBSubObject));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1076
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1077 object->id = object_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1078 object->next = ctx->object_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1079 ctx->object_list = object;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1080 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1081
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1082 object->type = (*buf) >> 6;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1083
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1084 display = av_mallocz(sizeof(DVBSubObjectDisplay));
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 display->object_id = object_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1087 display->region_id = region_id;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1088
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1089 display->x_pos = AV_RB16(buf) & 0xfff;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1090 buf += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1091 display->y_pos = AV_RB16(buf) & 0xfff;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1092 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1093
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1094 if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) {
5982
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1095 display->fgcolor = *buf++;
1900b70712ab colour --> color in variable names
diego
parents: 5932
diff changeset
1096 display->bgcolor = *buf++;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1097 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1098
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1099 display->region_list_next = region->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1100 region->display_list = display;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1101
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1102 display->object_list_next = object->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1103 object->display_list = display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1104 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1105 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1106
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1107 static void dvbsub_parse_page_segment(AVCodecContext *avctx,
6218
michael
parents: 5982
diff changeset
1108 const uint8_t *buf, int buf_size)
2796
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 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1111 DVBSubRegionDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1112 DVBSubRegionDisplay *tmp_display_list, **tmp_ptr;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1113
6218
michael
parents: 5982
diff changeset
1114 const uint8_t *buf_end = buf + buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1115 int region_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1116 int page_state;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1117
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1118 if (buf_size < 1)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1119 return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1120
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1121 ctx->time_out = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1122 page_state = ((*buf++) >> 2) & 3;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1123
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1124 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
1125
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
1126 if (page_state == 2) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1127 delete_state(ctx);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1128 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1129
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1130 tmp_display_list = ctx->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1131 ctx->display_list = NULL;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1132 ctx->display_list_size = 0;
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 while (buf + 5 < buf_end) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1135 region_id = *buf++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1136 buf += 1;
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 display = tmp_display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1139 tmp_ptr = &tmp_display_list;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1140
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1141 while (display && display->region_id != region_id) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1142 tmp_ptr = &display->next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1143 display = display->next;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1144 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1145
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1146 if (!display)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1147 display = av_mallocz(sizeof(DVBSubRegionDisplay));
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1148
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1149 display->region_id = region_id;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1150
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1151 display->x_pos = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1152 buf += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1153 display->y_pos = AV_RB16(buf);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1154 buf += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1155
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1156 *tmp_ptr = display->next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1157
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1158 display->next = ctx->display_list;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1159 ctx->display_list = display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1160 ctx->display_list_size++;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1161
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1162 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
1163 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1164
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1165 while (tmp_display_list) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1166 display = tmp_display_list;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1167
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1168 tmp_display_list = display->next;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1169
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1170 av_free(display);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1171 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1172
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1173 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1174
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1175
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1176 #ifdef DEBUG_SAVE_IMAGES
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1177 static void save_display_set(DVBSubContext *ctx)
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 DVBSubRegion *region;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1180 DVBSubRegionDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1181 DVBSubCLUT *clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1182 uint32_t *clut_table;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1183 int x_pos, y_pos, width, height;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1184 int x, y, y_off, x_off;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1185 uint32_t *pbuf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1186 char filename[32];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1187 static int fileno_index = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1188
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1189 x_pos = -1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1190 y_pos = -1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1191 width = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1192 height = 0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1193
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1194 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
1195 region = get_region(ctx, display->region_id);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1196
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1197 if (x_pos == -1) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1198 x_pos = display->x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1199 y_pos = display->y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1200 width = region->width;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1201 height = region->height;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1202 } else {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1203 if (display->x_pos < x_pos) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1204 width += (x_pos - display->x_pos);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1205 x_pos = display->x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1206 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1207
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1208 if (display->y_pos < y_pos) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1209 height += (y_pos - display->y_pos);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1210 y_pos = display->y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1211 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1212
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1213 if (display->x_pos + region->width > x_pos + width) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1214 width = display->x_pos + region->width - x_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->y_pos + region->height > y_pos + height) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1218 height = display->y_pos + region->height - y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1219 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1220 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1221 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1222
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1223 if (x_pos >= 0) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1224
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1225 pbuf = av_malloc(width * height * 4);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1226
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1227 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
1228 region = get_region(ctx, display->region_id);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1229
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1230 x_off = display->x_pos - x_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1231 y_off = display->y_pos - y_pos;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1232
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1233 clut = get_clut(ctx, region->clut);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1234
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1235 if (clut == 0)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1236 clut = &default_clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1237
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1238 switch (region->depth) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1239 case 2:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1240 clut_table = clut->clut4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1241 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1242 case 8:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1243 clut_table = clut->clut256;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1244 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1245 case 4:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1246 default:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1247 clut_table = clut->clut16;
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 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1250
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1251 for (y = 0; y < region->height; y++) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1252 for (x = 0; x < region->width; x++) {
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1253 pbuf[((y + y_off) * width) + x_off + x] =
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1254 clut_table[region->pbuf[y * region->width + x]];
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1255 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1256 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1257
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1258 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1259
5929
aaeed46a74fd use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents: 5928
diff changeset
1260 snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1261
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1262 png_save2(filename, pbuf, width, height);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1263
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1264 av_free(pbuf);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1265 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1266
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1267 fileno_index++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1268 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1269 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1270
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1271 static void dvbsub_parse_display_definition_segment(AVCodecContext *avctx,
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1272 const uint8_t *buf,
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1273 int buf_size)
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1274 {
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1275 DVBSubContext *ctx = avctx->priv_data;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1276 DVBSubDisplayDefinition *display_def = ctx->display_definition;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1277 int dds_version, info_byte;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1278
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1279 if (buf_size < 5)
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1280 return;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1281
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1282 info_byte = bytestream_get_byte(&buf);
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1283 dds_version = info_byte >> 4;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1284 if (display_def && display_def->version == dds_version)
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1285 return; // already have this display definition version
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1286
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1287 if (!display_def) {
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1288 display_def = av_mallocz(sizeof(*display_def));
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1289 ctx->display_definition = display_def;
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 return;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1293
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1294 display_def->version = dds_version;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1295 display_def->x = 0;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1296 display_def->y = 0;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1297 display_def->width = bytestream_get_be16(&buf) + 1;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1298 display_def->height = bytestream_get_be16(&buf) + 1;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1299
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1300 if (buf_size < 13)
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1301 return;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1302
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1303 if (info_byte & 1<<3) { // display_window_flag
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1304 display_def->x = bytestream_get_be16(&buf);
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1305 display_def->y = bytestream_get_be16(&buf);
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1306 display_def->width = bytestream_get_be16(&buf) - display_def->x + 1;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1307 display_def->height = bytestream_get_be16(&buf) - display_def->y + 1;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1308 }
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1309 }
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1310
6218
michael
parents: 5982
diff changeset
1311 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
1312 int buf_size, AVSubtitle *sub)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1313 {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1314 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1315 DVBSubDisplayDefinition *display_def = ctx->display_definition;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1316
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1317 DVBSubRegion *region;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1318 DVBSubRegionDisplay *display;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1319 AVSubtitleRect *rect;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1320 DVBSubCLUT *clut;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1321 uint32_t *clut_table;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1322 int i;
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1323 int offset_x=0, offset_y=0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1324
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1325 sub->rects = NULL;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1326 sub->start_display_time = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1327 sub->end_display_time = ctx->time_out * 1000;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1328 sub->format = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1329
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1330 if (display_def) {
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1331 offset_x = display_def->x;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1332 offset_y = display_def->y;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1333 }
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1334
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1335 sub->num_rects = ctx->display_list_size;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1336
8512
aa45029f5cd7 Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents: 7040
diff changeset
1337 if (sub->num_rects > 0){
aa45029f5cd7 Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents: 7040
diff changeset
1338 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
1339 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
1340 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
1341 }
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1342
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1343 i = 0;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1344
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1345 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
1346 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
1347 rect = sub->rects[i];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1348
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1349 if (!region)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1350 continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1351
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1352 rect->x = display->x_pos + offset_x;
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1353 rect->y = display->y_pos + offset_y;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1354 rect->w = region->width;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1355 rect->h = region->height;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1356 rect->nb_colors = 16;
9954
50327500e065 Set subtitle type in DVB subtitle decoder.
stefano
parents: 9428
diff changeset
1357 rect->type = SUBTITLE_BITMAP;
8516
315b302fcd1d Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents: 8512
diff changeset
1358 rect->pict.linesize[0] = region->width;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1359
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1360 clut = get_clut(ctx, region->clut);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1361
5932
d457f0c01ec5 cosmetic (x==NULL -> !x)
michael
parents: 5931
diff changeset
1362 if (!clut)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1363 clut = &default_clut;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1364
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1365 switch (region->depth) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1366 case 2:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1367 clut_table = clut->clut4;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1368 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1369 case 8:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1370 clut_table = clut->clut256;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1371 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1372 case 4:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1373 default:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1374 clut_table = clut->clut16;
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 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1377
10069
8ac9bc10b485 Always allocate a buffer of AVPALETTE_SIZE for palette in the subtitle
reimar
parents: 9999
diff changeset
1378 rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
8516
315b302fcd1d Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents: 8512
diff changeset
1379 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
1380
8516
315b302fcd1d Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents: 8512
diff changeset
1381 rect->pict.data[0] = av_malloc(region->buf_size);
315b302fcd1d Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents: 8512
diff changeset
1382 memcpy(rect->pict.data[0], region->pbuf, region->buf_size);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1383
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1384 i++;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1385 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1386
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1387 sub->num_rects = i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1388
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1389 #ifdef DEBUG_SAVE_IMAGES
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1390 save_display_set(ctx);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1391 #endif
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 return 1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1394 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1395
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1396 static int dvbsub_decode(AVCodecContext *avctx,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1397 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8629
diff changeset
1398 AVPacket *avpkt)
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1399 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8629
diff changeset
1400 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8629
diff changeset
1401 int buf_size = avpkt->size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1402 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1403 AVSubtitle *sub = (AVSubtitle*) data;
6218
michael
parents: 5982
diff changeset
1404 const uint8_t *p, *p_end;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1405 int segment_type;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1406 int page_id;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1407 int segment_length;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1408
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1409 #ifdef DEBUG_PACKET_CONTENTS
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1410 int i;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1411
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1412 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
1413
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
1414 for (i=0; i < buf_size; i++) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1415 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1416 if (i % 16 == 15)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1417 av_log(avctx, AV_LOG_INFO, "\n");
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1418 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1419
5930
8a9716d0ccff cosmetic (remove != 0 / != NULL)
michael
parents: 5929
diff changeset
1420 if (i % 16)
2796
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
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1423 #endif
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1424
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1425 if (buf_size <= 2)
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1426 return -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1427
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1428 p = buf;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1429 p_end = buf + buf_size;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1430
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
1431 while (p < p_end && *p == 0x0f) {
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1432 p += 1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1433 segment_type = *p++;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1434 page_id = AV_RB16(p);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1435 p += 2;
4364
05e932ddaaa9 rename BE/LE_8/16/32 to AV_RL/B_8/16/32
alex
parents: 4176
diff changeset
1436 segment_length = AV_RB16(p);
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1437 p += 2;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1438
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1439 if (page_id == ctx->composition_id || page_id == ctx->ancillary_id) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1440 switch (segment_type) {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1441 case DVBSUB_PAGE_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1442 dvbsub_parse_page_segment(avctx, p, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1443 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1444 case DVBSUB_REGION_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1445 dvbsub_parse_region_segment(avctx, p, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1446 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1447 case DVBSUB_CLUT_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1448 dvbsub_parse_clut_segment(avctx, p, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1449 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1450 case DVBSUB_OBJECT_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1451 dvbsub_parse_object_segment(avctx, p, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1452 break;
11882
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1453 case DVBSUB_DISPLAYDEFINITION_SEGMENT:
c591e96c03ab dvbsub: parse display definition segment
janne
parents: 11560
diff changeset
1454 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
1455 case DVBSUB_DISPLAY_SEGMENT:
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1456 *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
1457 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1458 default:
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1459 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
1460 segment_type, page_id, segment_length);
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1461 break;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1462 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1463 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1464
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1465 p += segment_length;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1466 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2833
diff changeset
1467
5931
3bb292a4ae12 cosmetic (place { consistently)
michael
parents: 5930
diff changeset
1468 if (p != p_end) {
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9954
diff changeset
1469 dprintf(avctx, "Junk at end of packet\n");
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1470 return -1;
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1471 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1472
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
1473 return buf_size;
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1474 }
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1475
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 AVCodec dvbsub_decoder = {
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1478 "dvbsub",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 10069
diff changeset
1479 AVMEDIA_TYPE_SUBTITLE,
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1480 CODEC_ID_DVB_SUBTITLE,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1481 sizeof(DVBSubContext),
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1482 dvbsub_init_decoder,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1483 NULL,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1484 dvbsub_close_decoder,
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1485 dvbsub_decode,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6916
diff changeset
1486 .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"),
2796
95c35706acbb DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff changeset
1487 };