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