History

subs.diff fixes a couple of minor bugs in my DVB subtitle decoder, and also fixes a few problems in the DVD decoder (the palette entries were being read back-to-front, and the timing conversions were slighly off) patch by (Ian Caulfield: imc25, cam ac uk)

Originally committed as revision 4520 to svn://svn.ffmpeg.org/ffmpeg/trunk

Ian Caulfield committed 21 years ago

Commit bf01fb61 parent 8341e4e2 files · +32 −25Browse files

Unified · Split

2 files
  1. libavcodec/dvbsubdec.c +3 −5
  2. libavcodec/dvdsub.c +29 −20
libavcodec/dvbsubdec.c+3−5
@@ -1310,10 +1310,8 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, uint8_t *buf, · 1309 unmodified lines
1310 1310
1311 sub->num_rects = ctx->display_list_size;1311 sub->num_rects = ctx->display_list_size;
1312 1312
1313 if (sub->num_rects == 0)1313 if (sub->num_rects > 0)
1314 return 0;1314 sub->rects = av_mallocz(sizeof(AVSubtitleRect) * sub->num_rects);
1315
1316 sub->rects = av_mallocz(sizeof(AVSubtitleRect) * sub->num_rects);
1317 1315
1318 i = 0;1316 i = 0;
1319 1317
@@ -1447,7 +1445,7 @@ static int dvbsub_decode(AVCodecContext *avctx, · 127 unmodified lines
1447 return -1;1445 return -1;
1448 }1446 }
1449 1447
1450 return 0;1448 return buf_size;
1451}1449}
1452 1450
1453 1451
libavcodec/dvdsub.c+29−20
@@ -107,20 +107,21 @@ static void guess_palette(uint32_t *rgba_palette, · 106 unmodified lines
107 if (nb_opaque_colors == 0)107 if (nb_opaque_colors == 0)
108 return;108 return;
109 109
110 j = 0;110 j = nb_opaque_colors;
111 memset(color_used, 0, 16);111 memset(color_used, 0, 16);
112 for(i = 0; i < 4; i++) {112 for(i = 0; i < 4; i++) {
113 if (alpha[i] != 0) {113 if (alpha[i] != 0) {
114 if (!color_used[palette[i]]) {114 if (!color_used[palette[i]]) {
115 level = (0xff * (j + 1)) / nb_opaque_colors;115 level = (0xff * j) / nb_opaque_colors;
116 r = (((subtitle_color >> 16) & 0xff) * level) >> 8;116 r = (((subtitle_color >> 16) & 0xff) * level) >> 8;
117 g = (((subtitle_color >> 8) & 0xff) * level) >> 8;117 g = (((subtitle_color >> 8) & 0xff) * level) >> 8;
118 b = (((subtitle_color >> 0) & 0xff) * level) >> 8;118 b = (((subtitle_color >> 0) & 0xff) * level) >> 8;
119 rgba_palette[i] = b | (g << 8) | (r << 16) | (0xff << 24);119 rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24);
120 color_used[palette[i]] = (i + 1);120 color_used[palette[i]] = (i + 1);
121 j++;121 j--;
122 } else {122 } else {
123 rgba_palette[i] = rgba_palette[color_used[palette[i]] - 1];123 rgba_palette[i] = (rgba_palette[color_used[palette[i]] - 1] & 0x00ffffff) |
124 ((alpha[i] * 17) << 24);
124 }125 }
125 }126 }
126 }127 }
@@ -133,6 +134,7 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, · 6 unmodified lines
133 uint8_t palette[4], alpha[4];134 uint8_t palette[4], alpha[4];
134 int date;135 int date;
135 int i;136 int i;
137 int is_menu = 0;
136 138
137 if (buf_size < 4)139 if (buf_size < 4)
138 return -1;140 return -1;
@@ -160,35 +162,39 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, · 21 unmodified lines
160#endif162#endif
161 switch(cmd) {163 switch(cmd) {
162 case 0x00:164 case 0x00:
163 /* force display */165 /* menu subpicture */
166 is_menu = 1;
164 break;167 break;
165 case 0x01:168 case 0x01:
166 /* set start date */169 /* set start date */
167 sub_header->start_display_time = date * 10;170 sub_header->start_display_time = (date << 10) / 90;
168 break;171 break;
169 case 0x02:172 case 0x02:
170 /* set end date */173 /* set end date */
171 sub_header->end_display_time = date * 10;174 sub_header->end_display_time = (date << 10) / 90;
172 break;175 break;
173 case 0x03:176 case 0x03:
174 /* set palette */177 /* set palette */
175 if ((buf_size - pos) < 2)178 if ((buf_size - pos) < 2)
176 goto fail;179 goto fail;
177 palette[0] = buf[pos] >> 4;180 palette[3] = buf[pos] >> 4;
178 palette[1] = buf[pos] & 0x0f;181 palette[2] = buf[pos] & 0x0f;
179 palette[2] = buf[pos + 1] >> 4;182 palette[1] = buf[pos + 1] >> 4;
180 palette[3] = buf[pos + 1] & 0x0f;183 palette[0] = buf[pos + 1] & 0x0f;
181 pos += 2;184 pos += 2;
182 break;185 break;
183 case 0x04:186 case 0x04:
184 /* set alpha */187 /* set alpha */
185 if ((buf_size - pos) < 2)188 if ((buf_size - pos) < 2)
186 goto fail;189 goto fail;
187 alpha[0] = buf[pos] >> 4;190 alpha[3] = buf[pos] >> 4;
188 alpha[1] = buf[pos] & 0x0f;191 alpha[2] = buf[pos] & 0x0f;
189 alpha[2] = buf[pos + 1] >> 4;192 alpha[1] = buf[pos + 1] >> 4;
190 alpha[3] = buf[pos + 1] & 0x0f;193 alpha[0] = buf[pos + 1] & 0x0f;
191 pos += 2;194 pos += 2;
195#ifdef DEBUG
196 av_log(NULL, AV_LOG_INFO, "alpha=%x%x%x%x\n", alpha[0],alpha[1],alpha[2],alpha[3]);
197#endif
192 break;198 break;
193 case 0x05:199 case 0x05:
194 if ((buf_size - pos) < 6)200 if ((buf_size - pos) < 6)
@@ -264,7 +270,7 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, · 69 unmodified lines
264 cmd_pos = next_cmd_pos;270 cmd_pos = next_cmd_pos;
265 }271 }
266 if (sub_header->num_rects > 0)272 if (sub_header->num_rects > 0)
267 return 0;273 return is_menu;
268 fail:274 fail:
269 return -1;275 return -1;
270}276}
@@ -282,7 +288,7 @@ static int is_transp(const uint8_t *buf, int pitch, int n, · 11 unmodified lines
282}288}
283 289
284/* return 0 if empty rectangle, 1 if non empty */290/* return 0 if empty rectangle, 1 if non empty */
285static int find_smallest_bouding_rectangle(AVSubtitle *s)291static int find_smallest_bounding_rectangle(AVSubtitle *s)
286{292{
287 uint8_t transp_color[256];293 uint8_t transp_color[256];
288 int y1, y2, x1, x2, y, w, h, i;294 int y1, y2, x1, x2, y, w, h, i;
@@ -375,14 +381,17 @@ static int dvdsub_decode(AVCodecContext *avctx, · 86 unmodified lines
375 uint8_t *buf, int buf_size)381 uint8_t *buf, int buf_size)
376{382{
377 AVSubtitle *sub = (void *)data;383 AVSubtitle *sub = (void *)data;
384 int is_menu;
385
386 is_menu = decode_dvd_subtitles(sub, buf, buf_size);
378 387
379 if (decode_dvd_subtitles(sub, buf, buf_size) < 0) {388 if (is_menu < 0) {
380 no_subtitle:389 no_subtitle:
381 *data_size = 0;390 *data_size = 0;
382 391
383 return buf_size;392 return buf_size;
384 }393 }
385 if (find_smallest_bouding_rectangle(sub) == 0)394 if (!is_menu && find_smallest_bounding_rectangle(sub) == 0)
386 goto no_subtitle;395 goto no_subtitle;
387 396
388#if defined(DEBUG)397#if defined(DEBUG)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t