Mercurial > libavcodec.hg
annotate dvbsubdec.c @ 6455:6efe6fb35b1a libavcodec
cosmetic: align
author | aurel |
---|---|
date | Wed, 05 Mar 2008 15:15:07 +0000 |
parents | dfdff1ca78a7 |
children | 48759bfbd073 |
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 = object->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
278 obj_disp_ptr = &object->display_list; |
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; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
282 obj_disp = obj_disp->object_list_next; |
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 = ctx->object_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
290 obj2_ptr = &ctx->object_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
291 |
5930 | 292 while (obj2 && obj2 != object) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
293 obj2_ptr = &obj2->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
294 obj2 = obj2->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
295 } |
2967 | 296 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
297 *obj2_ptr = obj2->next; |
2967 | 298 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
299 av_free(obj2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
300 } |
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 } |
2967 | 303 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
304 region->display_list = display->region_list_next; |
2967 | 305 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
306 av_free(display); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
307 } |
2967 | 308 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
309 } |
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 static void delete_state(DVBSubContext *ctx) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
312 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
313 DVBSubRegion *region; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
314 DVBSubCLUT *clut; |
2967 | 315 |
5931 | 316 while (ctx->region_list) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
317 region = ctx->region_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
318 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
319 ctx->region_list = region->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
320 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
321 delete_region_display_list(ctx, region); |
5930 | 322 if (region->pbuf) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
323 av_free(region->pbuf); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
324 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
325 av_free(region); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
326 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
327 |
5931 | 328 while (ctx->clut_list) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
329 clut = ctx->clut_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
330 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
331 ctx->clut_list = clut->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
332 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
333 av_free(clut); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
334 } |
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 /* Should already be null */ |
5930 | 337 if (ctx->object_list) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
338 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
|
339 } |
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 static int dvbsub_init_decoder(AVCodecContext *avctx) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
342 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
343 int i, r, g, b, a = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
344 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
345 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
346 memset(avctx->priv_data, 0, sizeof(DVBSubContext)); |
2967 | 347 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
348 ctx->composition_id = avctx->sub_id & 0xffff; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
349 ctx->ancillary_id = avctx->sub_id >> 16; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
350 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
351 default_clut.id = -1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
352 default_clut.next = NULL; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
353 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
354 default_clut.clut4[0] = RGBA( 0, 0, 0, 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
355 default_clut.clut4[1] = RGBA(255, 255, 255, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
356 default_clut.clut4[2] = RGBA( 0, 0, 0, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
357 default_clut.clut4[3] = RGBA(127, 127, 127, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
358 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
359 default_clut.clut16[0] = RGBA( 0, 0, 0, 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
360 for (i = 1; i < 16; i++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
361 if (i < 8) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
362 r = (i & 1) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
363 g = (i & 2) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
364 b = (i & 4) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
365 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
366 r = (i & 1) ? 127 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
367 g = (i & 2) ? 127 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
368 b = (i & 4) ? 127 : 0; |
2967 | 369 } |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
370 default_clut.clut16[i] = RGBA(r, g, b, 255); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
371 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
372 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
373 default_clut.clut256[0] = RGBA( 0, 0, 0, 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
374 for (i = 1; i < 256; i++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
375 if (i < 8) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
376 r = (i & 1) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
377 g = (i & 2) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
378 b = (i & 4) ? 255 : 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
379 a = 63; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
380 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
381 switch (i & 0x88) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
382 case 0x00: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
383 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
384 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
385 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
386 a = 255; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
387 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
388 case 0x08: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
389 r = ((i & 1) ? 85 : 0) + ((i & 0x10) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
390 g = ((i & 2) ? 85 : 0) + ((i & 0x20) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
391 b = ((i & 4) ? 85 : 0) + ((i & 0x40) ? 170 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
392 a = 127; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
393 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
394 case 0x80: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
395 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
|
396 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
|
397 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
|
398 a = 255; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
399 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
400 case 0x88: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
401 r = ((i & 1) ? 43 : 0) + ((i & 0x10) ? 85 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
402 g = ((i & 2) ? 43 : 0) + ((i & 0x20) ? 85 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
403 b = ((i & 4) ? 43 : 0) + ((i & 0x40) ? 85 : 0); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
404 a = 255; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
405 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
406 } |
2967 | 407 } |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
408 default_clut.clut256[i] = RGBA(r, g, b, a); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
409 } |
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 return 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
412 } |
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 static int dvbsub_close_decoder(AVCodecContext *avctx) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
415 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
416 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
417 DVBSubRegionDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
418 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
419 delete_state(ctx); |
2967 | 420 |
5931 | 421 while (ctx->display_list) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
422 display = ctx->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
423 ctx->display_list = display->next; |
2967 | 424 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
425 av_free(display); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
426 } |
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 return 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
429 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
430 |
2967 | 431 static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, |
6218 | 432 const uint8_t **srcbuf, int buf_size, |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
433 int non_mod, uint8_t *map_table) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
434 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
435 GetBitContext gb; |
2967 | 436 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
437 int bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
438 int run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
439 int pixels_read = 0; |
2967 | 440 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
441 init_get_bits(&gb, *srcbuf, buf_size << 8); |
2967 | 442 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
443 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
|
444 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
445 |
5930 | 446 if (bits) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
447 if (non_mod != 1 || bits != 1) { |
5930 | 448 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
449 *destbuf++ = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
450 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
451 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
452 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
453 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
454 } else { |
5513 | 455 bits = get_bits1(&gb); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
456 if (bits == 1) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
457 run_length = get_bits(&gb, 3) + 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
458 bits = get_bits(&gb, 2); |
2967 | 459 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
460 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
461 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
462 else { |
5930 | 463 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
464 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
465 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
466 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
467 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
468 } |
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 } else { |
5513 | 471 bits = get_bits1(&gb); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
472 if (bits == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
473 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
474 if (bits == 2) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
475 run_length = get_bits(&gb, 4) + 12; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
476 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
477 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
478 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
479 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
480 else { |
5930 | 481 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
482 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
483 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
484 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
485 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
486 } |
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 } else if (bits == 3) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
489 run_length = get_bits(&gb, 8) + 29; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
490 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
491 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
492 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
493 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
494 else { |
5930 | 495 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
496 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
497 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
498 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
499 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
500 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
501 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
502 } else if (bits == 1) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
503 pixels_read += 2; |
5930 | 504 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
505 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
506 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
507 bits = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
508 if (pixels_read <= dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
509 *destbuf++ = bits; |
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 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
512 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
513 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
514 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
515 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
516 } else { |
5930 | 517 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
518 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
519 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
520 bits = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
521 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
522 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
523 } |
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 } |
2967 | 527 |
5930 | 528 if (get_bits(&gb, 6)) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
529 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
|
530 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
531 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
532 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
533 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
534 } |
2967 | 535 |
536 static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, | |
6218 | 537 const uint8_t **srcbuf, int buf_size, |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
538 int non_mod, uint8_t *map_table) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
539 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
540 GetBitContext gb; |
2967 | 541 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
542 int bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
543 int run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
544 int pixels_read = 0; |
2967 | 545 |
546 init_get_bits(&gb, *srcbuf, buf_size << 8); | |
547 | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
548 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
|
549 bits = get_bits(&gb, 4); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
550 |
5930 | 551 if (bits) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
552 if (non_mod != 1 || bits != 1) { |
5930 | 553 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
554 *destbuf++ = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
555 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
556 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
557 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
558 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
559 } else { |
5513 | 560 bits = get_bits1(&gb); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
561 if (bits == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
562 run_length = get_bits(&gb, 3); |
2967 | 563 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
564 if (run_length == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
565 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
566 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
567 } |
2967 | 568 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
569 run_length += 2; |
2967 | 570 |
5930 | 571 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
572 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
573 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
574 bits = 0; |
2967 | 575 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
576 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
577 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
578 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
579 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
580 } else { |
5513 | 581 bits = get_bits1(&gb); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
582 if (bits == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
583 run_length = get_bits(&gb, 2) + 4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
584 bits = get_bits(&gb, 4); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
585 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
586 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
587 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
588 else { |
5930 | 589 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
590 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
591 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
592 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
593 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
594 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
595 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
596 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
597 bits = get_bits(&gb, 2); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
598 if (bits == 2) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
599 run_length = get_bits(&gb, 4) + 9; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
600 bits = get_bits(&gb, 4); |
2967 | 601 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
602 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
603 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
604 else { |
5930 | 605 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
606 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
607 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
608 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
609 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
610 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
611 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
612 } else if (bits == 3) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
613 run_length = get_bits(&gb, 8) + 25; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
614 bits = get_bits(&gb, 4); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
615 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
616 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
617 pixels_read += run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
618 else { |
5930 | 619 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
620 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
621 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
622 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
623 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
624 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
625 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
626 } else if (bits == 1) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
627 pixels_read += 2; |
5930 | 628 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
629 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
630 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
631 bits = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
632 if (pixels_read <= dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
633 *destbuf++ = bits; |
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 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
636 } else { |
5930 | 637 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
638 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
639 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
640 bits = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
641 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
642 pixels_read ++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
643 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
644 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
645 } |
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 } |
2967 | 648 |
5930 | 649 if (get_bits(&gb, 8)) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
650 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); |
2967 | 651 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
652 (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
653 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
654 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
655 } |
2967 | 656 |
657 static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, | |
6218 | 658 const uint8_t **srcbuf, int buf_size, |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
659 int non_mod, uint8_t *map_table) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
660 { |
6218 | 661 const uint8_t *sbuf_end = (*srcbuf) + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
662 int bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
663 int run_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
664 int pixels_read = 0; |
2967 | 665 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
666 while (*srcbuf < sbuf_end && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
667 bits = *(*srcbuf)++; |
2967 | 668 |
5930 | 669 if (bits) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
670 if (non_mod != 1 || bits != 1) { |
5930 | 671 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
672 *destbuf++ = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
673 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
674 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
675 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
676 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
677 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
678 bits = *(*srcbuf)++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
679 run_length = bits & 0x7f; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
680 if ((bits & 0x80) == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
681 if (run_length == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
682 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
683 } |
2967 | 684 |
5930 | 685 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
686 bits = map_table[0]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
687 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
688 bits = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
689 while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
690 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
691 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
692 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
693 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
694 bits = *(*srcbuf)++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
695 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
696 if (non_mod == 1 && bits == 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
697 pixels_read += run_length; |
5930 | 698 if (map_table) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
699 bits = map_table[bits]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
700 else while (run_length-- > 0 && pixels_read < dbuf_len) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
701 *destbuf++ = bits; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
702 pixels_read++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
703 } |
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 } |
2967 | 707 |
5930 | 708 if (*(*srcbuf)++) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
709 av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); |
2967 | 710 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
711 return pixels_read; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
712 } |
2967 | 713 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
714 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
715 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
716 static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display, |
6218 | 717 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
|
718 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
719 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
720 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
721 DVBSubRegion *region = get_region(ctx, display->region_id); |
6218 | 722 const uint8_t *buf_end = buf + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
723 uint8_t *pbuf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
724 int x_pos, y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
725 int i; |
2967 | 726 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
727 uint8_t map2to4[] = { 0x0, 0x7, 0x8, 0xf}; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
728 uint8_t map2to8[] = {0x00, 0x77, 0x88, 0xff}; |
2967 | 729 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
|
730 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
731 uint8_t *map_table; |
2967 | 732 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
733 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
734 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
|
735 top_bottom ? "bottom" : "top"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
736 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
737 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
738 #ifdef DEBUG_PACKET_CONTENTS |
5931 | 739 for (i = 0; i < buf_size; i++) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
740 if (i % 16 == 0) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
741 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
|
742 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
743 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
744 if (i % 16 == 15) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
745 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
746 } |
2967 | 747 |
5930 | 748 if (i % 16) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
749 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
750 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
751 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
752 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
753 if (region == 0) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
754 return; |
2967 | 755 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
756 pbuf = region->pbuf; |
2967 | 757 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
758 x_pos = display->x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
759 y_pos = display->y_pos; |
2967 | 760 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
761 if ((y_pos & 1) != top_bottom) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
762 y_pos++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
763 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
764 while (buf < buf_end) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
765 if (x_pos > region->width || y_pos > region->height) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
766 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
|
767 return; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
768 } |
2967 | 769 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
770 switch (*buf++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
771 case 0x10: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
772 if (region->depth == 8) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
773 map_table = map2to8; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
774 else if (region->depth == 4) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
775 map_table = map2to4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
776 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
777 map_table = NULL; |
2967 | 778 |
779 x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos, | |
780 region->width - x_pos, &buf, buf_size, | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
781 non_mod, map_table); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
782 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
783 case 0x11: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
784 if (region->depth < 4) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
785 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
|
786 return; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
787 } |
2967 | 788 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
789 if (region->depth == 8) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
790 map_table = map4to8; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
791 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
792 map_table = NULL; |
2967 | 793 |
794 x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos, | |
795 region->width - x_pos, &buf, buf_size, | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
796 non_mod, map_table); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
797 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
798 case 0x12: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
799 if (region->depth < 8) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
800 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
|
801 return; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
802 } |
2967 | 803 |
804 x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos, | |
805 region->width - x_pos, &buf, buf_size, | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
806 non_mod, NULL); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
807 break; |
2967 | 808 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
809 case 0x20: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
810 map2to4[0] = (*buf) >> 4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
811 map2to4[1] = (*buf++) & 0xf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
812 map2to4[2] = (*buf) >> 4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
813 map2to4[3] = (*buf++) & 0xf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
814 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
815 case 0x21: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
816 for (i = 0; i < 4; i++) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
817 map2to8[i] = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
818 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
819 case 0x22: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
820 for (i = 0; i < 16; i++) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
821 map4to8[i] = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
822 break; |
2967 | 823 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
824 case 0xf0: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
825 x_pos = display->x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
826 y_pos += 2; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
827 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
828 default: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
829 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
|
830 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
831 } |
2967 | 832 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
833 } |
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 static void dvbsub_parse_object_segment(AVCodecContext *avctx, |
6218 | 836 const uint8_t *buf, int buf_size) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
837 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
838 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
2967 | 839 |
6218 | 840 const uint8_t *buf_end = buf + buf_size; |
841 const uint8_t *block; | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
842 int object_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
843 DVBSubObject *object; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
844 DVBSubObjectDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
845 int top_field_len, bottom_field_len; |
2967 | 846 |
5982 | 847 int coding_method, non_modifying_color; |
2967 | 848 |
4364 | 849 object_id = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
850 buf += 2; |
2967 | 851 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
852 object = get_object(ctx, object_id); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
853 |
2967 | 854 if (!object) |
855 return; | |
856 | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
857 coding_method = ((*buf) >> 2) & 3; |
5982 | 858 non_modifying_color = ((*buf++) >> 1) & 1; |
2967 | 859 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
860 if (coding_method == 0) { |
4364 | 861 top_field_len = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
862 buf += 2; |
4364 | 863 bottom_field_len = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
864 buf += 2; |
2967 | 865 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
866 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
|
867 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
|
868 return; |
2967 | 869 } |
870 | |
5930 | 871 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
|
872 block = buf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
873 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
874 dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0, |
5982 | 875 non_modifying_color); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
876 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
877 if (bottom_field_len > 0) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
878 block = buf + top_field_len; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
879 else |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
880 bottom_field_len = top_field_len; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
881 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
882 dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1, |
5982 | 883 non_modifying_color); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
884 } |
2967 | 885 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
886 /* } else if (coding_method == 1) {*/ |
2967 | 887 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
888 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
889 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
|
890 } |
2967 | 891 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
892 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
893 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
894 static void dvbsub_parse_clut_segment(AVCodecContext *avctx, |
6218 | 895 const uint8_t *buf, int buf_size) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
896 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
897 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
2967 | 898 |
6218 | 899 const uint8_t *buf_end = buf + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
900 int clut_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
901 DVBSubCLUT *clut; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
902 int entry_id, depth , full_range; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
903 int y, cr, cb, alpha; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
904 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
|
905 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
906 #ifdef DEBUG_PACKET_CONTENTS |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
907 int i; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
908 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
909 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
|
910 |
5931 | 911 for (i=0; i < buf_size; i++) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
912 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
913 if (i % 16 == 15) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
914 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
915 } |
2967 | 916 |
5930 | 917 if (i % 16) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
918 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
919 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
920 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
921 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
922 clut_id = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
923 buf += 1; |
2967 | 924 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
925 clut = get_clut(ctx, clut_id); |
2967 | 926 |
5932 | 927 if (!clut) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
928 clut = av_malloc(sizeof(DVBSubCLUT)); |
2967 | 929 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
930 memcpy(clut, &default_clut, sizeof(DVBSubCLUT)); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
931 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
932 clut->id = clut_id; |
2967 | 933 |
934 clut->next = ctx->clut_list; | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
935 ctx->clut_list = clut; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
936 } |
2967 | 937 |
5931 | 938 while (buf + 4 < buf_end) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
939 entry_id = *buf++; |
2967 | 940 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
941 depth = (*buf) & 0xe0; |
2967 | 942 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
943 if (depth == 0) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
944 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
|
945 return; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
946 } |
2967 | 947 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
948 full_range = (*buf++) & 1; |
2967 | 949 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
950 if (full_range) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
951 y = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
952 cr = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
953 cb = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
954 alpha = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
955 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
956 y = buf[0] & 0xfc; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
957 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
|
958 cb = (buf[1] << 2) & 0xf0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
959 alpha = (buf[1] << 6) & 0xc0; |
2967 | 960 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
961 buf += 2; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
962 } |
2967 | 963 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
964 if (y == 0) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
965 alpha = 0xff; |
2967 | 966 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
967 YUV_TO_RGB1_CCIR(cb, cr); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
968 YUV_TO_RGB2_CCIR(r, g, b, y); |
2967 | 969 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
970 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
971 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
|
972 #endif |
2967 | 973 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
974 if (depth & 0x80) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
975 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
|
976 if (depth & 0x40) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
977 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
|
978 if (depth & 0x20) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
979 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
|
980 } |
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 static void dvbsub_parse_region_segment(AVCodecContext *avctx, |
6218 | 985 const uint8_t *buf, int buf_size) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
986 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
987 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
2967 | 988 |
6218 | 989 const uint8_t *buf_end = buf + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
990 int region_id, object_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
991 DVBSubRegion *region; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
992 DVBSubObject *object; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
993 DVBSubObjectDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
994 int fill; |
2967 | 995 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
996 if (buf_size < 10) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
997 return; |
2967 | 998 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
999 region_id = *buf++; |
2967 | 1000 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1001 region = get_region(ctx, region_id); |
2967 | 1002 |
5932 | 1003 if (!region) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1004 region = av_mallocz(sizeof(DVBSubRegion)); |
2967 | 1005 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1006 region->id = region_id; |
2967 | 1007 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1008 region->next = ctx->region_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1009 ctx->region_list = region; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1010 } |
2967 | 1011 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1012 fill = ((*buf++) >> 3) & 1; |
2967 | 1013 |
4364 | 1014 region->width = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1015 buf += 2; |
4364 | 1016 region->height = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1017 buf += 2; |
2967 | 1018 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1019 if (region->width * region->height != region->buf_size) { |
5930 | 1020 if (region->pbuf) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1021 av_free(region->pbuf); |
2967 | 1022 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1023 region->buf_size = region->width * region->height; |
2967 | 1024 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1025 region->pbuf = av_malloc(region->buf_size); |
2967 | 1026 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1027 fill = 1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1028 } |
2967 | 1029 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1030 region->depth = 1 << (((*buf++) >> 2) & 7); |
5928 | 1031 if(region->depth<2 || region->depth>8){ |
1032 av_log(avctx, AV_LOG_ERROR, "region depth %d is invalid\n", region->depth); | |
1033 region->depth= 4; | |
1034 } | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1035 region->clut = *buf++; |
2967 | 1036 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1037 if (region->depth == 8) |
5982 | 1038 region->bgcolor = *buf++; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1039 else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1040 buf += 1; |
2967 | 1041 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1042 if (region->depth == 4) |
5982 | 1043 region->bgcolor = (((*buf++) >> 4) & 15); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1044 else |
5982 | 1045 region->bgcolor = (((*buf++) >> 2) & 3); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1046 } |
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 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1049 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
|
1050 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1051 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1052 if (fill) { |
5982 | 1053 memset(region->pbuf, region->bgcolor, region->buf_size); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1054 #ifdef DEBUG |
5982 | 1055 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
|
1056 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1057 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1058 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1059 delete_region_display_list(ctx, region); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1060 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1061 while (buf + 5 < buf_end) { |
4364 | 1062 object_id = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1063 buf += 2; |
2967 | 1064 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1065 object = get_object(ctx, object_id); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1066 |
5932 | 1067 if (!object) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1068 object = av_mallocz(sizeof(DVBSubObject)); |
2967 | 1069 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1070 object->id = object_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1071 object->next = ctx->object_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1072 ctx->object_list = object; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1073 } |
2967 | 1074 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1075 object->type = (*buf) >> 6; |
2967 | 1076 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1077 display = av_mallocz(sizeof(DVBSubObjectDisplay)); |
2967 | 1078 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1079 display->object_id = object_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1080 display->region_id = region_id; |
2967 | 1081 |
4364 | 1082 display->x_pos = AV_RB16(buf) & 0xfff; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1083 buf += 2; |
4364 | 1084 display->y_pos = AV_RB16(buf) & 0xfff; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1085 buf += 2; |
2967 | 1086 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1087 if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) { |
5982 | 1088 display->fgcolor = *buf++; |
1089 display->bgcolor = *buf++; | |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1090 } |
2967 | 1091 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1092 display->region_list_next = region->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1093 region->display_list = display; |
2967 | 1094 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1095 display->object_list_next = object->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1096 object->display_list = display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1097 } |
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 static void dvbsub_parse_page_segment(AVCodecContext *avctx, |
6218 | 1101 const uint8_t *buf, int buf_size) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1102 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1103 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1104 DVBSubRegionDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1105 DVBSubRegionDisplay *tmp_display_list, **tmp_ptr; |
2967 | 1106 |
6218 | 1107 const uint8_t *buf_end = buf + buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1108 int region_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1109 int page_state; |
2967 | 1110 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1111 if (buf_size < 1) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1112 return; |
2967 | 1113 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1114 ctx->time_out = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1115 page_state = ((*buf++) >> 2) & 3; |
2967 | 1116 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1117 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1118 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
|
1119 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1120 |
5931 | 1121 if (page_state == 2) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1122 delete_state(ctx); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1123 } |
2967 | 1124 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1125 tmp_display_list = ctx->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1126 ctx->display_list = NULL; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1127 ctx->display_list_size = 0; |
2967 | 1128 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1129 while (buf + 5 < buf_end) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1130 region_id = *buf++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1131 buf += 1; |
2967 | 1132 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1133 display = tmp_display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1134 tmp_ptr = &tmp_display_list; |
2967 | 1135 |
5930 | 1136 while (display && display->region_id != region_id) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1137 tmp_ptr = &display->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1138 display = display->next; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1139 } |
2967 | 1140 |
5932 | 1141 if (!display) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1142 display = av_mallocz(sizeof(DVBSubRegionDisplay)); |
2967 | 1143 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1144 display->region_id = region_id; |
2967 | 1145 |
4364 | 1146 display->x_pos = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1147 buf += 2; |
4364 | 1148 display->y_pos = AV_RB16(buf); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1149 buf += 2; |
2967 | 1150 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1151 *tmp_ptr = display->next; |
2967 | 1152 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1153 display->next = ctx->display_list; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1154 ctx->display_list = display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1155 ctx->display_list_size++; |
2967 | 1156 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1157 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1158 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
|
1159 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1160 } |
2967 | 1161 |
5930 | 1162 while (tmp_display_list) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1163 display = tmp_display_list; |
2967 | 1164 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1165 tmp_display_list = display->next; |
2967 | 1166 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1167 av_free(display); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1168 } |
2967 | 1169 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1170 } |
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 #ifdef DEBUG_SAVE_IMAGES |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1174 static void save_display_set(DVBSubContext *ctx) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1175 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1176 DVBSubRegion *region; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1177 DVBSubRegionDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1178 DVBSubCLUT *clut; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1179 uint32_t *clut_table; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1180 int x_pos, y_pos, width, height; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1181 int x, y, y_off, x_off; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1182 uint32_t *pbuf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1183 char filename[32]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1184 static int fileno_index = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1185 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1186 x_pos = -1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1187 y_pos = -1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1188 width = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1189 height = 0; |
2967 | 1190 |
5930 | 1191 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
|
1192 region = get_region(ctx, display->region_id); |
2967 | 1193 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1194 if (x_pos == -1) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1195 x_pos = display->x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1196 y_pos = display->y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1197 width = region->width; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1198 height = region->height; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1199 } else { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1200 if (display->x_pos < x_pos) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1201 width += (x_pos - display->x_pos); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1202 x_pos = display->x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1203 } |
2967 | 1204 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1205 if (display->y_pos < y_pos) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1206 height += (y_pos - display->y_pos); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1207 y_pos = display->y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1208 } |
2967 | 1209 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1210 if (display->x_pos + region->width > x_pos + width) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1211 width = display->x_pos + region->width - x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1212 } |
2967 | 1213 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1214 if (display->y_pos + region->height > y_pos + height) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1215 height = display->y_pos + region->height - y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1216 } |
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 } |
2967 | 1219 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1220 if (x_pos >= 0) { |
2967 | 1221 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1222 pbuf = av_malloc(width * height * 4); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1223 |
5930 | 1224 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
|
1225 region = get_region(ctx, display->region_id); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1226 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1227 x_off = display->x_pos - x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1228 y_off = display->y_pos - y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1229 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1230 clut = get_clut(ctx, region->clut); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1231 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1232 if (clut == 0) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1233 clut = &default_clut; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1234 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1235 switch (region->depth) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1236 case 2: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1237 clut_table = clut->clut4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1238 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1239 case 8: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1240 clut_table = clut->clut256; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1241 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1242 case 4: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1243 default: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1244 clut_table = clut->clut16; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1245 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1246 } |
2967 | 1247 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1248 for (y = 0; y < region->height; y++) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1249 for (x = 0; x < region->width; x++) { |
2967 | 1250 pbuf[((y + y_off) * width) + x_off + x] = |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1251 clut_table[region->pbuf[y * region->width + x]]; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1252 } |
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 |
2967 | 1255 } |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1256 |
5929
aaeed46a74fd
use sizeof in snprintf (note the changed code is all under #if 0)
michael
parents:
5928
diff
changeset
|
1257 snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1258 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1259 png_save2(filename, pbuf, width, height); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1260 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1261 av_free(pbuf); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1262 } |
2967 | 1263 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1264 fileno_index++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1265 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1266 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1267 |
6218 | 1268 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
|
1269 int buf_size, AVSubtitle *sub) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1270 { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1271 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1272 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1273 DVBSubRegion *region; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1274 DVBSubRegionDisplay *display; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1275 AVSubtitleRect *rect; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1276 DVBSubCLUT *clut; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1277 uint32_t *clut_table; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1278 int i; |
2967 | 1279 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1280 sub->rects = NULL; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1281 sub->start_display_time = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1282 sub->end_display_time = ctx->time_out * 1000; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1283 sub->format = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1284 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1285 sub->num_rects = ctx->display_list_size; |
2967 | 1286 |
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
|
1287 if (sub->num_rects > 0) |
1f117208d20f
subs.diff fixes a couple of minor bugs in my DVB subtitle decoder, and also fixes a few
michael
parents:
2796
diff
changeset
|
1288 sub->rects = av_mallocz(sizeof(AVSubtitleRect) * sub->num_rects); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1289 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1290 i = 0; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1291 |
5930 | 1292 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
|
1293 region = get_region(ctx, display->region_id); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1294 rect = &sub->rects[i]; |
2967 | 1295 |
5932 | 1296 if (!region) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1297 continue; |
2967 | 1298 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1299 rect->x = display->x_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1300 rect->y = display->y_pos; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1301 rect->w = region->width; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1302 rect->h = region->height; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1303 rect->nb_colors = 16; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1304 rect->linesize = region->width; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1305 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1306 clut = get_clut(ctx, region->clut); |
2967 | 1307 |
5932 | 1308 if (!clut) |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1309 clut = &default_clut; |
2967 | 1310 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1311 switch (region->depth) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1312 case 2: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1313 clut_table = clut->clut4; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1314 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1315 case 8: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1316 clut_table = clut->clut256; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1317 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1318 case 4: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1319 default: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1320 clut_table = clut->clut16; |
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 } |
2967 | 1323 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1324 rect->rgba_palette = av_malloc((1 << region->depth) * sizeof(uint32_t)); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1325 memcpy(rect->rgba_palette, clut_table, (1 << region->depth) * sizeof(uint32_t)); |
2967 | 1326 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1327 rect->bitmap = av_malloc(region->buf_size); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1328 memcpy(rect->bitmap, region->pbuf, region->buf_size); |
2967 | 1329 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1330 i++; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1331 } |
2967 | 1332 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1333 sub->num_rects = i; |
2967 | 1334 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1335 #ifdef DEBUG_SAVE_IMAGES |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1336 save_display_set(ctx); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1337 #endif |
2967 | 1338 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1339 return 1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1340 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1341 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1342 static int dvbsub_decode(AVCodecContext *avctx, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1343 void *data, int *data_size, |
6218 | 1344 const uint8_t *buf, int buf_size) |
2796
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 DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1347 AVSubtitle *sub = (AVSubtitle*) data; |
6218 | 1348 const uint8_t *p, *p_end; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1349 int segment_type; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1350 int page_id; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1351 int segment_length; |
2967 | 1352 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1353 #ifdef DEBUG_PACKET_CONTENTS |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1354 int i; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1355 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1356 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
|
1357 |
5931 | 1358 for (i=0; i < buf_size; i++) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1359 av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1360 if (i % 16 == 15) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1361 av_log(avctx, AV_LOG_INFO, "\n"); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1362 } |
2967 | 1363 |
5930 | 1364 if (i % 16) |
2796
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 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1367 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1368 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1369 if (buf_size <= 2) |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1370 return -1; |
2967 | 1371 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1372 p = buf; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1373 p_end = buf + buf_size; |
2967 | 1374 |
5931 | 1375 while (p < p_end && *p == 0x0f) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1376 p += 1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1377 segment_type = *p++; |
4364 | 1378 page_id = AV_RB16(p); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1379 p += 2; |
4364 | 1380 segment_length = AV_RB16(p); |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1381 p += 2; |
2967 | 1382 |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1383 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
|
1384 switch (segment_type) { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1385 case DVBSUB_PAGE_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1386 dvbsub_parse_page_segment(avctx, p, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1387 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1388 case DVBSUB_REGION_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1389 dvbsub_parse_region_segment(avctx, p, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1390 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1391 case DVBSUB_CLUT_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1392 dvbsub_parse_clut_segment(avctx, p, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1393 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1394 case DVBSUB_OBJECT_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1395 dvbsub_parse_object_segment(avctx, p, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1396 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1397 case DVBSUB_DISPLAY_SEGMENT: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1398 *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
|
1399 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1400 default: |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1401 #ifdef DEBUG |
2967 | 1402 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
|
1403 segment_type, page_id, segment_length); |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1404 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1405 break; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1406 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1407 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1408 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1409 p += segment_length; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1410 } |
2967 | 1411 |
5931 | 1412 if (p != p_end) { |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1413 #ifdef DEBUG |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1414 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
|
1415 #endif |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1416 return -1; |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1417 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1418 |
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
|
1419 return buf_size; |
2796
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1420 } |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1421 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1422 |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1423 AVCodec dvbsub_decoder = { |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1424 "dvbsub", |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1425 CODEC_TYPE_SUBTITLE, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1426 CODEC_ID_DVB_SUBTITLE, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1427 sizeof(DVBSubContext), |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1428 dvbsub_init_decoder, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1429 NULL, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1430 dvbsub_close_decoder, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1431 dvbsub_decode, |
95c35706acbb
DVB subtitle decoder by (Ian Caulfield: imc25, cam ac uk)
michael
parents:
diff
changeset
|
1432 }; |