Mercurial > libavcodec.hg
annotate dvbsubdec.c @ 8599:db00335551ca libavcodec
WORDS_BIGENDIAN must be checked with #ifdef
author | aurel |
---|---|
date | Wed, 14 Jan 2009 23:20:43 +0000 |
parents | 315b302fcd1d |
children | 04423b2f6e0b |
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 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
3 * Copyright (c) 2005 Ian Caulfield. |
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" |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
23 #include "bitstream.h" |
5354 | 24 #include "colorspace.h" |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
25 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
26 //#define DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
27 //#define DEBUG_PACKET_CONTENTS |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
28 //#define DEBUG_SAVE_IMAGES |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
29 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
30 #define DVBSUB_PAGE_SEGMENT 0x10 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
31 #define DVBSUB_REGION_SEGMENT 0x11 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
32 #define DVBSUB_CLUT_SEGMENT 0x12 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
33 #define DVBSUB_OBJECT_SEGMENT 0x13 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
34 #define DVBSUB_DISPLAY_SEGMENT 0x80 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
35 |
4659 | 36 #define cm (ff_cropTbl + MAX_NEG_CROP) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
37 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
38 #ifdef DEBUG_SAVE_IMAGES |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
39 #undef fprintf |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
40 #if 0 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
41 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
|
42 uint32_t *rgba_palette) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
43 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
44 int x, y, v; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
45 FILE *f; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
46 char fname[40], fname2[40]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
47 char command[1024]; |
2967 | 48 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
49 snprintf(fname, 40, "%s.ppm", filename); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
50 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
51 f = fopen(fname, "w"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
52 if (!f) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
53 perror(fname); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
54 exit(1); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
55 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
56 fprintf(f, "P6\n" |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
57 "%d %d\n" |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
58 "%d\n", |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
59 w, h, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
60 for(y = 0; y < h; y++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
61 for(x = 0; x < w; x++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
62 v = rgba_palette[bitmap[y * w + x]]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
63 putc((v >> 16) & 0xff, f); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
64 putc((v >> 8) & 0xff, f); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
65 putc((v >> 0) & 0xff, f); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
66 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
67 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
68 fclose(f); |
2967 | 69 |
70 | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
71 snprintf(fname2, 40, "%s-a.pgm", filename); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
72 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
73 f = fopen(fname2, "w"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
74 if (!f) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
75 perror(fname2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
76 exit(1); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
77 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
78 fprintf(f, "P5\n" |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
79 "%d %d\n" |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
80 "%d\n", |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
81 w, h, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
82 for(y = 0; y < h; y++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
83 for(x = 0; x < w; x++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
84 v = rgba_palette[bitmap[y * w + x]]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
85 putc((v >> 24) & 0xff, f); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
86 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
87 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
88 fclose(f); |
2967 | 89 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
90 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
|
91 system(command); |
2967 | 92 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
93 snprintf(command, 1024, "rm %s %s", fname, fname2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
94 system(command); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
95 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
96 #endif |
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 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
|
99 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
100 int x, y, v; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
101 FILE *f; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
102 char fname[40], fname2[40]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
103 char command[1024]; |
2967 | 104 |
5929
aaeed46a74fd
use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents:
5928
diff
changeset
|
105 snprintf(fname, sizeof(fname), "%s.ppm", filename); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
106 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
107 f = fopen(fname, "w"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
108 if (!f) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
109 perror(fname); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
110 exit(1); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
111 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
112 fprintf(f, "P6\n" |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
113 "%d %d\n" |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
114 "%d\n", |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
115 w, h, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
116 for(y = 0; y < h; y++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
117 for(x = 0; x < w; x++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
118 v = bitmap[y * w + x]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
119 putc((v >> 16) & 0xff, f); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
120 putc((v >> 8) & 0xff, f); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
121 putc((v >> 0) & 0xff, f); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
122 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
123 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
124 fclose(f); |
2967 | 125 |
126 | |
5929
aaeed46a74fd
use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents:
5928
diff
changeset
|
127 snprintf(fname2, sizeof(fname2), "%s-a.pgm", filename); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
128 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
129 f = fopen(fname2, "w"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
130 if (!f) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
131 perror(fname2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
132 exit(1); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
133 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
134 fprintf(f, "P5\n" |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
135 "%d %d\n" |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
136 "%d\n", |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
137 w, h, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
138 for(y = 0; y < h; y++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
139 for(x = 0; x < w; x++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
140 v = bitmap[y * w + x]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
141 putc((v >> 24) & 0xff, f); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
142 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
143 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
144 fclose(f); |
2967 | 145 |
5929
aaeed46a74fd
use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents:
5928
diff
changeset
|
146 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
|
147 system(command); |
2967 | 148 |
5929
aaeed46a74fd
use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents:
5928
diff
changeset
|
149 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
|
150 system(command); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
151 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
152 #endif |
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 #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
|
155 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
156 typedef struct DVBSubCLUT { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
157 int id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
158 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
159 uint32_t clut4[4]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
160 uint32_t clut16[16]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
161 uint32_t clut256[256]; |
2967 | 162 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
163 struct DVBSubCLUT *next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
164 } DVBSubCLUT; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
165 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
166 static DVBSubCLUT default_clut; |
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 typedef struct DVBSubObjectDisplay { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
169 int object_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
170 int region_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
171 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
172 int x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
173 int y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
174 |
5982 | 175 int fgcolor; |
176 int bgcolor; | |
2967 | 177 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
178 struct DVBSubObjectDisplay *region_list_next; |
2967 | 179 struct DVBSubObjectDisplay *object_list_next; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
180 } DVBSubObjectDisplay; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
181 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
182 typedef struct DVBSubObject { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
183 int id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
184 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
185 int type; |
2967 | 186 |
187 DVBSubObjectDisplay *display_list; | |
188 | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
189 struct DVBSubObject *next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
190 } DVBSubObject; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
191 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
192 typedef struct DVBSubRegionDisplay { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
193 int region_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
194 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
195 int x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
196 int y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
197 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
198 struct DVBSubRegionDisplay *next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
199 } DVBSubRegionDisplay; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
200 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
201 typedef struct DVBSubRegion { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
202 int id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
203 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
204 int width; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
205 int height; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
206 int depth; |
2967 | 207 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
208 int clut; |
5982 | 209 int bgcolor; |
2967 | 210 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
211 uint8_t *pbuf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
212 int buf_size; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
213 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
214 DVBSubObjectDisplay *display_list; |
2967 | 215 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
216 struct DVBSubRegion *next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
217 } DVBSubRegion; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
218 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
219 typedef struct DVBSubContext { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
220 int composition_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
221 int ancillary_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
222 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
223 int time_out; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
224 DVBSubRegion *region_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
225 DVBSubCLUT *clut_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
226 DVBSubObject *object_list; |
2967 | 227 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
228 int display_list_size; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
229 DVBSubRegionDisplay *display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
230 } DVBSubContext; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
231 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
232 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
233 static DVBSubObject* get_object(DVBSubContext *ctx, int object_id) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
234 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
235 DVBSubObject *ptr = ctx->object_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
236 |
5930 | 237 while (ptr && ptr->id != object_id) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
238 ptr = ptr->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
239 } |
2967 | 240 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
241 return ptr; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
242 } |
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 static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
245 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
246 DVBSubCLUT *ptr = ctx->clut_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
247 |
5930 | 248 while (ptr && ptr->id != clut_id) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
249 ptr = ptr->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
250 } |
2967 | 251 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
252 return ptr; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
253 } |
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 static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
256 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
257 DVBSubRegion *ptr = ctx->region_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
258 |
5930 | 259 while (ptr && ptr->id != region_id) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
260 ptr = ptr->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
261 } |
2967 | 262 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
263 return ptr; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
264 } |
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 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
|
267 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
268 DVBSubObject *object, *obj2, **obj2_ptr; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
269 DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
270 |
5930 | 271 while (region->display_list) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
272 display = region->display_list; |
2967 | 273 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
274 object = get_object(ctx, display->object_id); |
2967 | 275 |
5930 | 276 if (object) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
277 obj_disp_ptr = &object->display_list; |
6916 | 278 obj_disp = *obj_disp_ptr; |
2967 | 279 |
5930 | 280 while (obj_disp && obj_disp != display) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
281 obj_disp_ptr = &obj_disp->object_list_next; |
6916 | 282 obj_disp = *obj_disp_ptr; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
283 } |
2967 | 284 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
285 if (obj_disp) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
286 *obj_disp_ptr = obj_disp->object_list_next; |
2967 | 287 |
5932 | 288 if (!object->display_list) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
289 obj2_ptr = &ctx->object_list; |
6916 | 290 obj2 = *obj2_ptr; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
291 |
6915 | 292 while (obj2 != object) { |
293 assert(obj2); | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
294 obj2_ptr = &obj2->next; |
6916 | 295 obj2 = *obj2_ptr; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
296 } |
2967 | 297 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
298 *obj2_ptr = obj2->next; |
2967 | 299 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
300 av_free(obj2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
301 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
302 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
303 } |
2967 | 304 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
305 region->display_list = display->region_list_next; |
2967 | 306 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
307 av_free(display); |
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 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
311 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
312 static void delete_state(DVBSubContext *ctx) |
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 DVBSubRegion *region; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
315 DVBSubCLUT *clut; |
2967 | 316 |
5931 | 317 while (ctx->region_list) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
318 region = ctx->region_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
319 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
320 ctx->region_list = region->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
321 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
322 delete_region_display_list(ctx, region); |
5930 | 323 if (region->pbuf) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
324 av_free(region->pbuf); |
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 av_free(region); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
327 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
328 |
5931 | 329 while (ctx->clut_list) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
330 clut = ctx->clut_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->clut_list = clut->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 av_free(clut); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
335 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
336 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
337 /* Should already be null */ |
5930 | 338 if (ctx->object_list) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
339 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
|
340 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
341 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6218
diff
changeset
|
342 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
|
343 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
344 int i, r, g, b, a = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
345 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
346 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
347 memset(avctx->priv_data, 0, sizeof(DVBSubContext)); |
2967 | 348 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
349 ctx->composition_id = avctx->sub_id & 0xffff; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
350 ctx->ancillary_id = avctx->sub_id >> 16; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
351 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
352 default_clut.id = -1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
353 default_clut.next = NULL; |
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 default_clut.clut4[0] = RGBA( 0, 0, 0, 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
356 default_clut.clut4[1] = RGBA(255, 255, 255, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
357 default_clut.clut4[2] = RGBA( 0, 0, 0, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
358 default_clut.clut4[3] = RGBA(127, 127, 127, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
359 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
360 default_clut.clut16[0] = RGBA( 0, 0, 0, 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
361 for (i = 1; i < 16; i++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
362 if (i < 8) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
363 r = (i & 1) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
364 g = (i & 2) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
365 b = (i & 4) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
366 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
367 r = (i & 1) ? 127 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
368 g = (i & 2) ? 127 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
369 b = (i & 4) ? 127 : 0; |
2967 | 370 } |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
371 default_clut.clut16[i] = RGBA(r, g, b, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
372 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
373 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
374 default_clut.clut256[0] = RGBA( 0, 0, 0, 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
375 for (i = 1; i < 256; i++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
376 if (i < 8) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
377 r = (i & 1) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
378 g = (i & 2) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
379 b = (i & 4) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
380 a = 63; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
381 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
382 switch (i & 0x88) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
383 case 0x00: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
384 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
385 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
386 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
387 a = 255; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
388 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
389 case 0x08: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
390 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
391 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
392 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
393 a = 127; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
394 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
395 case 0x80: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
396 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
|
397 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
|
398 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
|
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 0x88: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
402 r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
403 g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
404 b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
405 a = 255; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
406 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
407 } |
2967 | 408 } |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
409 default_clut.clut256[i] = RGBA(r, g, b, a); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
410 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
411 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
412 return 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
413 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
414 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6218
diff
changeset
|
415 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
|
416 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
417 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
418 DVBSubRegionDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
419 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
420 delete_state(ctx); |
2967 | 421 |
5931 | 422 while (ctx->display_list) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
423 display = ctx->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
424 ctx->display_list = display->next; |
2967 | 425 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
426 av_free(display); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
427 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
428 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
429 return 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
430 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
431 |
2967 | 432 static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, |
6218 | 433 const uint8_t **srcbuf, int buf_size, |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
434 int non_mod, uint8_t *map_table) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
435 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
436 GetBitContext gb; |
2967 | 437 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
438 int bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
439 int run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
440 int pixels_read = 0; |
2967 | 441 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
442 init_get_bits(&gb, *srcbuf, buf_size << 8); |
2967 | 443 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
444 while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
445 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
446 |
5930 | 447 if (bits) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
448 if (non_mod != 1 || bits != 1) { |
5930 | 449 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
450 *destbuf++ = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
451 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
452 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
453 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
454 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
455 } else { |
5513 | 456 bits = get_bits1(&gb); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
457 if (bits == 1) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
458 run_length = get_bits(&gb, 3) + 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
459 bits = get_bits(&gb, 2); |
2967 | 460 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
461 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
462 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
463 else { |
5930 | 464 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
465 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
466 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
467 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
468 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
469 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
470 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
471 } else { |
5513 | 472 bits = get_bits1(&gb); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
473 if (bits == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
474 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
475 if (bits == 2) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
476 run_length = get_bits(&gb, 4) + 12; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
477 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
478 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
479 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
480 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
481 else { |
5930 | 482 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
483 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
484 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
485 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
486 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
487 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
488 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
489 } else if (bits == 3) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
490 run_length = get_bits(&gb, 8) + 29; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
491 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
492 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
493 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
494 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
495 else { |
5930 | 496 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
497 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
498 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
499 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
500 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
501 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
502 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
503 } else if (bits == 1) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
504 pixels_read += 2; |
5930 | 505 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
506 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
507 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
508 bits = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
509 if (pixels_read <= dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
510 *destbuf++ = bits; |
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 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
513 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
514 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
515 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
516 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
517 } else { |
5930 | 518 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
519 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
520 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
521 bits = 0; |
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 pixels_read++; |
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 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
526 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
527 } |
2967 | 528 |
5930 | 529 if (get_bits(&gb, 6)) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
530 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
|
531 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
532 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
533 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
534 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
535 } |
2967 | 536 |
537 static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, | |
6218 | 538 const uint8_t **srcbuf, int buf_size, |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
539 int non_mod, uint8_t *map_table) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
540 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
541 GetBitContext gb; |
2967 | 542 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
543 int bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
544 int run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
545 int pixels_read = 0; |
2967 | 546 |
547 init_get_bits(&gb, *srcbuf, buf_size << 8); | |
548 | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
549 while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
550 bits = get_bits(&gb, 4); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
551 |
5930 | 552 if (bits) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
553 if (non_mod != 1 || bits != 1) { |
5930 | 554 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
555 *destbuf++ = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
556 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
557 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
558 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
559 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
560 } else { |
5513 | 561 bits = get_bits1(&gb); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
562 if (bits == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
563 run_length = get_bits(&gb, 3); |
2967 | 564 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
565 if (run_length == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
566 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
567 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
568 } |
2967 | 569 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
570 run_length += 2; |
2967 | 571 |
5930 | 572 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
573 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
574 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
575 bits = 0; |
2967 | 576 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
577 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
578 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
579 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
580 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
581 } else { |
5513 | 582 bits = get_bits1(&gb); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
583 if (bits == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
584 run_length = get_bits(&gb, 2) + 4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
585 bits = get_bits(&gb, 4); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
586 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
587 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
588 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
589 else { |
5930 | 590 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
591 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
592 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
593 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
594 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
595 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
596 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
597 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
598 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
599 if (bits == 2) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
600 run_length = get_bits(&gb, 4) + 9; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
601 bits = get_bits(&gb, 4); |
2967 | 602 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
603 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
604 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
605 else { |
5930 | 606 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
607 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
608 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
609 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
610 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
611 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
612 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
613 } else if (bits == 3) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
614 run_length = get_bits(&gb, 8) + 25; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
615 bits = get_bits(&gb, 4); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
616 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
617 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
618 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
619 else { |
5930 | 620 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
621 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
622 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
623 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
624 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
625 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
626 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
627 } else if (bits == 1) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
628 pixels_read += 2; |
5930 | 629 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
630 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
631 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
632 bits = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
633 if (pixels_read <= dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
634 *destbuf++ = bits; |
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 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
637 } else { |
5930 | 638 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
639 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
640 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
641 bits = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
642 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
643 pixels_read ++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
644 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
645 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
646 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
647 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
648 } |
2967 | 649 |
5930 | 650 if (get_bits(&gb, 8)) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
651 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); |
2967 | 652 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
653 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
654 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
655 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
656 } |
2967 | 657 |
658 static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, | |
6218 | 659 const uint8_t **srcbuf, int buf_size, |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
660 int non_mod, uint8_t *map_table) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
661 { |
6218 | 662 const uint8_t *sbuf_end = (*srcbuf) + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
663 int bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
664 int run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
665 int pixels_read = 0; |
2967 | 666 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
667 while (*srcbuf < sbuf_end && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
668 bits = *(*srcbuf)++; |
2967 | 669 |
5930 | 670 if (bits) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
671 if (non_mod != 1 || bits != 1) { |
5930 | 672 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
673 *destbuf++ = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
674 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
675 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
676 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
677 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
678 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
679 bits = *(*srcbuf)++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
680 run_length = bits & 0x7f; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
681 if ((bits & 0x80) == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
682 if (run_length == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
683 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
684 } |
2967 | 685 |
5930 | 686 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
687 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
688 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
689 bits = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
690 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
691 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
692 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
693 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
694 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
695 bits = *(*srcbuf)++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
696 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
697 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
698 pixels_read += run_length; |
5930 | 699 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
700 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
701 else while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
702 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
703 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
704 } |
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 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
707 } |
2967 | 708 |
5930 | 709 if (*(*srcbuf)++) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
710 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); |
2967 | 711 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
712 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
713 } |
2967 | 714 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
715 |
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 static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display, |
6218 | 718 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
|
719 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
720 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
721 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
722 DVBSubRegion *region = get_region(ctx, display->region_id); |
6218 | 723 const uint8_t *buf_end = buf + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
724 uint8_t *pbuf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
725 int x_pos, y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
726 int i; |
2967 | 727 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
728 uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf}; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
729 uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff}; |
2967 | 730 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
|
731 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
732 uint8_t *map_table; |
2967 | 733 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
734 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
735 av_log(avctx, AV_LOG_INFO, "DVB pixel block size %d, %s field:\n", buf_size, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
736 top_bottom ? "bottom" : "top"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
737 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
738 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
739 #ifdef DEBUG_PACKET_CONTENTS |
5931 | 740 for (i = 0; i < buf_size; i++) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
741 if (i % 16 == 0) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
742 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
|
743 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
744 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
745 if (i % 16 == 15) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
746 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
747 } |
2967 | 748 |
5930 | 749 if (i % 16) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
750 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
751 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
752 #endif |
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 if (region == 0) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
755 return; |
2967 | 756 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
757 pbuf = region->pbuf; |
2967 | 758 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
759 x_pos = display->x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
760 y_pos = display->y_pos; |
2967 | 761 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
762 if ((y_pos & 1) != top_bottom) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
763 y_pos++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
764 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
765 while (buf < buf_end) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
766 if (x_pos > region->width || y_pos > region->height) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
767 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
|
768 return; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
769 } |
2967 | 770 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
771 switch (*buf++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
772 case 0x10: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
773 if (region->depth == 8) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
774 map_table = map2to8; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
775 else if (region->depth == 4) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
776 map_table = map2to4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
777 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
778 map_table = NULL; |
2967 | 779 |
780 x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos, | |
781 region->width - x_pos, &buf, buf_size, | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
782 non_mod, map_table); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
783 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
784 case 0x11: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
785 if (region->depth < 4) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
786 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
|
787 return; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
788 } |
2967 | 789 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
790 if (region->depth == 8) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
791 map_table = map4to8; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
792 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
793 map_table = NULL; |
2967 | 794 |
795 x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos, | |
796 region->width - x_pos, &buf, buf_size, | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
797 non_mod, map_table); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
798 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
799 case 0x12: |
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 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
|
802 return; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
803 } |
2967 | 804 |
805 x_pos += dvbsub_read_8bit_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, NULL); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
808 break; |
2967 | 809 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
810 case 0x20: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
811 map2to4[0] = (*buf) >> 4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
812 map2to4[1] = (*buf++) & 0xf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
813 map2to4[2] = (*buf) >> 4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
814 map2to4[3] = (*buf++) & 0xf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
815 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
816 case 0x21: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
817 for (i = 0; i < 4; i++) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
818 map2to8[i] = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
819 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
820 case 0x22: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
821 for (i = 0; i < 16; i++) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
822 map4to8[i] = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
823 break; |
2967 | 824 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
825 case 0xf0: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
826 x_pos = display->x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
827 y_pos += 2; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
828 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
829 default: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
830 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
|
831 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
832 } |
2967 | 833 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
834 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
835 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
836 static void dvbsub_parse_object_segment(AVCodecContext *avctx, |
6218 | 837 const uint8_t *buf, int buf_size) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
838 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
839 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
2967 | 840 |
6218 | 841 const uint8_t *buf_end = buf + buf_size; |
842 const uint8_t *block; | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
843 int object_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
844 DVBSubObject *object; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
845 DVBSubObjectDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
846 int top_field_len, bottom_field_len; |
2967 | 847 |
5982 | 848 int coding_method, non_modifying_color; |
2967 | 849 |
4364 | 850 object_id = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
851 buf += 2; |
2967 | 852 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
853 object = get_object(ctx, object_id); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
854 |
2967 | 855 if (!object) |
856 return; | |
857 | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
858 coding_method = ((*buf) >> 2) & 3; |
5982 | 859 non_modifying_color = ((*buf++) >> 1) & 1; |
2967 | 860 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
861 if (coding_method == 0) { |
4364 | 862 top_field_len = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
863 buf += 2; |
4364 | 864 bottom_field_len = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
865 buf += 2; |
2967 | 866 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
867 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
|
868 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
|
869 return; |
2967 | 870 } |
871 | |
5930 | 872 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
|
873 block = buf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
874 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
875 dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0, |
5982 | 876 non_modifying_color); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
877 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
878 if (bottom_field_len > 0) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
879 block = buf + top_field_len; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
880 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
881 bottom_field_len = top_field_len; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
882 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
883 dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1, |
5982 | 884 non_modifying_color); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
885 } |
2967 | 886 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
887 /* } else if (coding_method == 1) {*/ |
2967 | 888 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
889 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
890 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
|
891 } |
2967 | 892 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
893 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
894 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
895 static void dvbsub_parse_clut_segment(AVCodecContext *avctx, |
6218 | 896 const uint8_t *buf, int buf_size) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
897 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
898 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
2967 | 899 |
6218 | 900 const uint8_t *buf_end = buf + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
901 int clut_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
902 DVBSubCLUT *clut; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
903 int entry_id, depth , full_range; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
904 int y, cr, cb, alpha; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
905 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
|
906 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
907 #ifdef DEBUG_PACKET_CONTENTS |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
908 int i; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
909 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
910 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
|
911 |
5931 | 912 for (i=0; i < buf_size; i++) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
913 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
914 if (i % 16 == 15) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
915 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
916 } |
2967 | 917 |
5930 | 918 if (i % 16) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
919 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
920 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
921 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
922 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
923 clut_id = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
924 buf += 1; |
2967 | 925 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
926 clut = get_clut(ctx, clut_id); |
2967 | 927 |
5932 | 928 if (!clut) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
929 clut = av_malloc(sizeof(DVBSubCLUT)); |
2967 | 930 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
931 memcpy(clut, &default_clut, sizeof(DVBSubCLUT)); |
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 = clut_id; |
2967 | 934 |
935 clut->next = ctx->clut_list; | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
936 ctx->clut_list = clut; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
937 } |
2967 | 938 |
5931 | 939 while (buf + 4 < buf_end) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
940 entry_id = *buf++; |
2967 | 941 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
942 depth = (*buf) & 0xe0; |
2967 | 943 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
944 if (depth == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
945 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
|
946 return; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
947 } |
2967 | 948 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
949 full_range = (*buf++) & 1; |
2967 | 950 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
951 if (full_range) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
952 y = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
953 cr = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
954 cb = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
955 alpha = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
956 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
957 y = buf[0] & 0xfc; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
958 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
|
959 cb = (buf[1] << 2) & 0xf0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
960 alpha = (buf[1] << 6) & 0xc0; |
2967 | 961 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
962 buf += 2; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
963 } |
2967 | 964 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
965 if (y == 0) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
966 alpha = 0xff; |
2967 | 967 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
968 YUV_TO_RGB1_CCIR(cb, cr); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
969 YUV_TO_RGB2_CCIR(r, g, b, y); |
2967 | 970 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
971 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
972 av_log(avctx, AV_LOG_INFO, "clut %d := (%d,%d,%d,%d)\n", entry_id, r, g, b, alpha); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
973 #endif |
2967 | 974 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
975 if (depth & 0x80) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
976 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
|
977 if (depth & 0x40) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
978 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
|
979 if (depth & 0x20) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
980 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
|
981 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
982 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
983 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
984 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
985 static void dvbsub_parse_region_segment(AVCodecContext *avctx, |
6218 | 986 const uint8_t *buf, int buf_size) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
987 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
988 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
2967 | 989 |
6218 | 990 const uint8_t *buf_end = buf + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
991 int region_id, object_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
992 DVBSubRegion *region; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
993 DVBSubObject *object; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
994 DVBSubObjectDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
995 int fill; |
2967 | 996 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
997 if (buf_size < 10) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
998 return; |
2967 | 999 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1000 region_id = *buf++; |
2967 | 1001 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1002 region = get_region(ctx, region_id); |
2967 | 1003 |
5932 | 1004 if (!region) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1005 region = av_mallocz(sizeof(DVBSubRegion)); |
2967 | 1006 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1007 region->id = region_id; |
2967 | 1008 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1009 region->next = ctx->region_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1010 ctx->region_list = region; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1011 } |
2967 | 1012 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1013 fill = ((*buf++) >> 3) & 1; |
2967 | 1014 |
4364 | 1015 region->width = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1016 buf += 2; |
4364 | 1017 region->height = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1018 buf += 2; |
2967 | 1019 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1020 if (region->width * region->height != region->buf_size) { |
5930 | 1021 if (region->pbuf) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1022 av_free(region->pbuf); |
2967 | 1023 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1024 region->buf_size = region->width * region->height; |
2967 | 1025 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1026 region->pbuf = av_malloc(region->buf_size); |
2967 | 1027 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1028 fill = 1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1029 } |
2967 | 1030 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1031 region->depth = 1 << (((*buf++) >> 2) & 7); |
5928 | 1032 if(region->depth<2 || region->depth>8){ |
1033 av_log(avctx, AV_LOG_ERROR, "region depth %d is invalid\n", region->depth); | |
1034 region->depth= 4; | |
1035 } | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1036 region->clut = *buf++; |
2967 | 1037 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1038 if (region->depth == 8) |
5982 | 1039 region->bgcolor = *buf++; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1040 else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1041 buf += 1; |
2967 | 1042 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1043 if (region->depth == 4) |
5982 | 1044 region->bgcolor = (((*buf++) >> 4) & 15); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1045 else |
5982 | 1046 region->bgcolor = (((*buf++) >> 2) & 3); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1047 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1048 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1049 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1050 av_log(avctx, AV_LOG_INFO, "Region %d, (%dx%d)\n", region_id, region->width, region->height); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1051 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1052 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1053 if (fill) { |
5982 | 1054 memset(region->pbuf, region->bgcolor, region->buf_size); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1055 #ifdef DEBUG |
5982 | 1056 av_log(avctx, AV_LOG_INFO, "Fill region (%d)\n", region->bgcolor); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1057 #endif |
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 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1060 delete_region_display_list(ctx, region); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1061 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1062 while (buf + 5 < buf_end) { |
4364 | 1063 object_id = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1064 buf += 2; |
2967 | 1065 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1066 object = get_object(ctx, object_id); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1067 |
5932 | 1068 if (!object) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1069 object = av_mallocz(sizeof(DVBSubObject)); |
2967 | 1070 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1071 object->id = object_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1072 object->next = ctx->object_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1073 ctx->object_list = object; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1074 } |
2967 | 1075 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1076 object->type = (*buf) >> 6; |
2967 | 1077 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1078 display = av_mallocz(sizeof(DVBSubObjectDisplay)); |
2967 | 1079 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1080 display->object_id = object_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1081 display->region_id = region_id; |
2967 | 1082 |
4364 | 1083 display->x_pos = AV_RB16(buf) & 0xfff; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1084 buf += 2; |
4364 | 1085 display->y_pos = AV_RB16(buf) & 0xfff; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1086 buf += 2; |
2967 | 1087 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1088 if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) { |
5982 | 1089 display->fgcolor = *buf++; |
1090 display->bgcolor = *buf++; | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1091 } |
2967 | 1092 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1093 display->region_list_next = region->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1094 region->display_list = display; |
2967 | 1095 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1096 display->object_list_next = object->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1097 object->display_list = display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1098 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1099 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1100 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1101 static void dvbsub_parse_page_segment(AVCodecContext *avctx, |
6218 | 1102 const uint8_t *buf, int buf_size) |
2796
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 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1105 DVBSubRegionDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1106 DVBSubRegionDisplay *tmp_display_list, **tmp_ptr; |
2967 | 1107 |
6218 | 1108 const uint8_t *buf_end = buf + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1109 int region_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1110 int page_state; |
2967 | 1111 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1112 if (buf_size < 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1113 return; |
2967 | 1114 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1115 ctx->time_out = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1116 page_state = ((*buf++) >> 2) & 3; |
2967 | 1117 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1118 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1119 av_log(avctx, AV_LOG_INFO, "Page time out %ds, state %d\n", ctx->time_out, page_state); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1120 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1121 |
5931 | 1122 if (page_state == 2) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1123 delete_state(ctx); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1124 } |
2967 | 1125 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1126 tmp_display_list = ctx->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1127 ctx->display_list = NULL; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1128 ctx->display_list_size = 0; |
2967 | 1129 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1130 while (buf + 5 < buf_end) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1131 region_id = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1132 buf += 1; |
2967 | 1133 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1134 display = tmp_display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1135 tmp_ptr = &tmp_display_list; |
2967 | 1136 |
5930 | 1137 while (display && display->region_id != region_id) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1138 tmp_ptr = &display->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1139 display = display->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1140 } |
2967 | 1141 |
5932 | 1142 if (!display) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1143 display = av_mallocz(sizeof(DVBSubRegionDisplay)); |
2967 | 1144 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1145 display->region_id = region_id; |
2967 | 1146 |
4364 | 1147 display->x_pos = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1148 buf += 2; |
4364 | 1149 display->y_pos = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1150 buf += 2; |
2967 | 1151 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1152 *tmp_ptr = display->next; |
2967 | 1153 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1154 display->next = ctx->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1155 ctx->display_list = display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1156 ctx->display_list_size++; |
2967 | 1157 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1158 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1159 av_log(avctx, AV_LOG_INFO, "Region %d, (%d,%d)\n", region_id, display->x_pos, display->y_pos); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1160 #endif |
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 |
6218 | 1269 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
|
1270 int buf_size, AVSubtitle *sub) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1271 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1272 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1273 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1274 DVBSubRegion *region; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1275 DVBSubRegionDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1276 AVSubtitleRect *rect; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1277 DVBSubCLUT *clut; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1278 uint32_t *clut_table; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1279 int i; |
2967 | 1280 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1281 sub->rects = NULL; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1282 sub->start_display_time = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1283 sub->end_display_time = ctx->time_out * 1000; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1284 sub->format = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1285 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1286 sub->num_rects = ctx->display_list_size; |
2967 | 1287 |
8512
aa45029f5cd7
Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents:
7040
diff
changeset
|
1288 if (sub->num_rects > 0){ |
aa45029f5cd7
Change AVSubtitle.rects to an array of pointers so ABI does not break
michael
parents:
7040
diff
changeset
|
1289 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
|
1290 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
|
1291 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
|
1292 } |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1293 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1294 i = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1295 |
5930 | 1296 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
|
1297 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
|
1298 rect = sub->rects[i]; |
2967 | 1299 |
5932 | 1300 if (!region) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1301 continue; |
2967 | 1302 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1303 rect->x = display->x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1304 rect->y = display->y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1305 rect->w = region->width; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1306 rect->h = region->height; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1307 rect->nb_colors = 16; |
8516
315b302fcd1d
Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents:
8512
diff
changeset
|
1308 rect->pict.linesize[0] = region->width; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1309 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1310 clut = get_clut(ctx, region->clut); |
2967 | 1311 |
5932 | 1312 if (!clut) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1313 clut = &default_clut; |
2967 | 1314 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1315 switch (region->depth) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1316 case 2: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1317 clut_table = clut->clut4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1318 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1319 case 8: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1320 clut_table = clut->clut256; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1321 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1322 case 4: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1323 default: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1324 clut_table = clut->clut16; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1325 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1326 } |
2967 | 1327 |
8516
315b302fcd1d
Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents:
8512
diff
changeset
|
1328 rect->pict.data[1] = av_malloc((1 << region->depth) * sizeof(uint32_t)); |
315b302fcd1d
Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents:
8512
diff
changeset
|
1329 memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t)); |
2967 | 1330 |
8516
315b302fcd1d
Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents:
8512
diff
changeset
|
1331 rect->pict.data[0] = av_malloc(region->buf_size); |
315b302fcd1d
Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
michael
parents:
8512
diff
changeset
|
1332 memcpy(rect->pict.data[0], region->pbuf, region->buf_size); |
2967 | 1333 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1334 i++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1335 } |
2967 | 1336 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1337 sub->num_rects = i; |
2967 | 1338 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1339 #ifdef DEBUG_SAVE_IMAGES |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1340 save_display_set(ctx); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1341 #endif |
2967 | 1342 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1343 return 1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1344 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1345 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1346 static int dvbsub_decode(AVCodecContext *avctx, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1347 void *data, int *data_size, |
6218 | 1348 const uint8_t *buf, int buf_size) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1349 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1350 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1351 AVSubtitle *sub = (AVSubtitle*) data; |
6218 | 1352 const uint8_t *p, *p_end; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1353 int segment_type; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1354 int page_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1355 int segment_length; |
2967 | 1356 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1357 #ifdef DEBUG_PACKET_CONTENTS |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1358 int i; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1359 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1360 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
|
1361 |
5931 | 1362 for (i=0; i < buf_size; i++) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1363 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1364 if (i % 16 == 15) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1365 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1366 } |
2967 | 1367 |
5930 | 1368 if (i % 16) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1369 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1370 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1371 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1372 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1373 if (buf_size <= 2) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1374 return -1; |
2967 | 1375 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1376 p = buf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1377 p_end = buf + buf_size; |
2967 | 1378 |
5931 | 1379 while (p < p_end && *p == 0x0f) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1380 p += 1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1381 segment_type = *p++; |
4364 | 1382 page_id = AV_RB16(p); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1383 p += 2; |
4364 | 1384 segment_length = AV_RB16(p); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1385 p += 2; |
2967 | 1386 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1387 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
|
1388 switch (segment_type) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1389 case DVBSUB_PAGE_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1390 dvbsub_parse_page_segment(avctx, p, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1391 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1392 case DVBSUB_REGION_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1393 dvbsub_parse_region_segment(avctx, p, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1394 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1395 case DVBSUB_CLUT_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1396 dvbsub_parse_clut_segment(avctx, p, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1397 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1398 case DVBSUB_OBJECT_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1399 dvbsub_parse_object_segment(avctx, p, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1400 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1401 case DVBSUB_DISPLAY_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1402 *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
|
1403 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1404 default: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1405 #ifdef DEBUG |
2967 | 1406 av_log(avctx, AV_LOG_INFO, "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
|
1407 segment_type, page_id, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1408 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1409 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1410 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1411 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1412 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1413 p += segment_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1414 } |
2967 | 1415 |
5931 | 1416 if (p != p_end) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1417 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1418 av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1419 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1420 return -1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1421 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1422 |
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
|
1423 return buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1424 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1425 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1426 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1427 AVCodec dvbsub_decoder = { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1428 "dvbsub", |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1429 CODEC_TYPE_SUBTITLE, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1430 CODEC_ID_DVB_SUBTITLE, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1431 sizeof(DVBSubContext), |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1432 dvbsub_init_decoder, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1433 NULL, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1434 dvbsub_close_decoder, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1435 dvbsub_decode, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6916
diff
changeset
|
1436 .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"), |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1437 }; |