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
13101310
13111311 sub->num_rects = ctx->display_list_size;
13121312
1313− if (sub->num_rects == 0)
1314− return 0;
1315−
1316− sub->rects = av_mallocz(sizeof(AVSubtitleRect) * sub->num_rects);
1313+ if (sub->num_rects > 0)
1314+ sub->rects = av_mallocz(sizeof(AVSubtitleRect) * sub->num_rects);
13171315
13181316 i = 0;
13191317
@@ -1447,7 +1445,7 @@ static int dvbsub_decode(AVCodecContext *avctx, · 127 unmodified lines
14471445 return -1;
14481446 }
14491447
1450− return 0;
1448+ return buf_size;
14511449 }
14521450
14531451
libavcodec/dvdsub.c+29−20
@@ -107,20 +107,21 @@ static void guess_palette(uint32_t *rgba_palette, · 106 unmodified lines
107107 if (nb_opaque_colors == 0)
108108 return;
109109
110− j = 0;
110+ j = nb_opaque_colors;
111111 memset(color_used, 0, 16);
112112 for(i = 0; i < 4; i++) {
113113 if (alpha[i] != 0) {
114114 if (!color_used[palette[i]]) {
115− level = (0xff * (j + 1)) / nb_opaque_colors;
115+ level = (0xff * j) / nb_opaque_colors;
116116 r = (((subtitle_color >> 16) & 0xff) * level) >> 8;
117117 g = (((subtitle_color >> 8) & 0xff) * level) >> 8;
118118 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);
120120 color_used[palette[i]] = (i + 1);
121− j++;
121+ j--;
122122 } 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);
124125 }
125126 }
126127 }
@@ -133,6 +134,7 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, · 6 unmodified lines
133134 uint8_t palette[4], alpha[4];
134135 int date;
135136 int i;
137+ int is_menu = 0;
136138
137139 if (buf_size < 4)
138140 return -1;
@@ -160,35 +162,39 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, · 21 unmodified lines
160162 #endif
161163 switch(cmd) {
162164 case 0x00:
163− /* force display */
165+ /* menu subpicture */
166+ is_menu = 1;
164167 break;
165168 case 0x01:
166169 /* set start date */
167− sub_header->start_display_time = date * 10;
170+ sub_header->start_display_time = (date << 10) / 90;
168171 break;
169172 case 0x02:
170173 /* set end date */
171− sub_header->end_display_time = date * 10;
174+ sub_header->end_display_time = (date << 10) / 90;
172175 break;
173176 case 0x03:
174177 /* set palette */
175178 if ((buf_size - pos) < 2)
176179 goto fail;
177− palette[0] = buf[pos] >> 4;
178− palette[1] = buf[pos] & 0x0f;
179− palette[2] = buf[pos + 1] >> 4;
180− palette[3] = buf[pos + 1] & 0x0f;
180+ palette[3] = buf[pos] >> 4;
181+ palette[2] = buf[pos] & 0x0f;
182+ palette[1] = buf[pos + 1] >> 4;
183+ palette[0] = buf[pos + 1] & 0x0f;
181184 pos += 2;
182185 break;
183186 case 0x04:
184187 /* set alpha */
185188 if ((buf_size - pos) < 2)
186189 goto fail;
187− alpha[0] = buf[pos] >> 4;
188− alpha[1] = buf[pos] & 0x0f;
189− alpha[2] = buf[pos + 1] >> 4;
190− alpha[3] = buf[pos + 1] & 0x0f;
190+ alpha[3] = buf[pos] >> 4;
191+ alpha[2] = buf[pos] & 0x0f;
192+ alpha[1] = buf[pos + 1] >> 4;
193+ alpha[0] = buf[pos + 1] & 0x0f;
191194 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
192198 break;
193199 case 0x05:
194200 if ((buf_size - pos) < 6)
@@ -264,7 +270,7 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, · 69 unmodified lines
264270 cmd_pos = next_cmd_pos;
265271 }
266272 if (sub_header->num_rects > 0)
267− return 0;
273+ return is_menu;
268274 fail:
269275 return -1;
270276 }
@@ -282,7 +288,7 @@ static int is_transp(const uint8_t *buf, int pitch, int n, · 11 unmodified lines
282288 }
283289
284290 /* return 0 if empty rectangle, 1 if non empty */
285−static int find_smallest_bouding_rectangle(AVSubtitle *s)
291+static int find_smallest_bounding_rectangle(AVSubtitle *s)
286292 {
287293 uint8_t transp_color[256];
288294 int y1, y2, x1, x2, y, w, h, i;
@@ -375,14 +381,17 @@ static int dvdsub_decode(AVCodecContext *avctx, · 86 unmodified lines
375381 uint8_t *buf, int buf_size)
376382 {
377383 AVSubtitle *sub = (void *)data;
384+ int is_menu;
385+
386+ is_menu = decode_dvd_subtitles(sub, buf, buf_size);
378387
379− if (decode_dvd_subtitles(sub, buf, buf_size) < 0) {
388+ if (is_menu < 0) {
380389 no_subtitle:
381390 *data_size = 0;
382391
383392 return buf_size;
384393 }
385− if (find_smallest_bouding_rectangle(sub) == 0)
394+ if (!is_menu && find_smallest_bounding_rectangle(sub) == 0)
386395 goto no_subtitle;
387396
388397 #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