Mercurial > libavcodec.hg
comparison dvdsubdec.c @ 8514:b866cb2a5330 libavcodec
Forgot to update (I likely missed it due to its similar name to dvb...)
author | michael |
---|---|
date | Sat, 03 Jan 2009 18:26:07 +0000 |
parents | a9ca5a1b8a1e |
children | 315b302fcd1d |
comparison
equal
deleted
inserted
replaced
8513:1d2c018a7ac7 | 8514:b866cb2a5330 |
---|---|
317 if (h < 0) | 317 if (h < 0) |
318 h = 0; | 318 h = 0; |
319 if (w > 0 && h > 0) { | 319 if (w > 0 && h > 0) { |
320 if (sub_header->rects != NULL) { | 320 if (sub_header->rects != NULL) { |
321 for (i = 0; i < sub_header->num_rects; i++) { | 321 for (i = 0; i < sub_header->num_rects; i++) { |
322 av_free(sub_header->rects[i].bitmap); | 322 av_freep(&sub_header->rects[i]->bitmap); |
323 av_free(sub_header->rects[i].rgba_palette); | 323 av_freep(&sub_header->rects[i]->rgba_palette); |
324 av_freep(&sub_header->rects[i]); | |
324 } | 325 } |
325 av_freep(&sub_header->rects); | 326 av_freep(&sub_header->rects); |
326 sub_header->num_rects = 0; | 327 sub_header->num_rects = 0; |
327 } | 328 } |
328 | 329 |
329 bitmap = av_malloc(w * h); | 330 bitmap = av_malloc(w * h); |
330 sub_header->rects = av_mallocz(sizeof(AVSubtitleRect)); | 331 sub_header->rects = av_mallocz(sizeof(*sub_header->rects)); |
332 sub_header->rects[0] = av_mallocz(sizeof(AVSubtitleRect)); | |
331 sub_header->num_rects = 1; | 333 sub_header->num_rects = 1; |
332 sub_header->rects[0].bitmap = bitmap; | 334 sub_header->rects[0]->bitmap = bitmap; |
333 decode_rle(bitmap, w * 2, w, (h + 1) / 2, | 335 decode_rle(bitmap, w * 2, w, (h + 1) / 2, |
334 buf, offset1, buf_size, is_8bit); | 336 buf, offset1, buf_size, is_8bit); |
335 decode_rle(bitmap + w, w * 2, w, h / 2, | 337 decode_rle(bitmap + w, w * 2, w, h / 2, |
336 buf, offset2, buf_size, is_8bit); | 338 buf, offset2, buf_size, is_8bit); |
337 if (is_8bit) { | 339 if (is_8bit) { |
338 if (yuv_palette == 0) | 340 if (yuv_palette == 0) |
339 goto fail; | 341 goto fail; |
340 sub_header->rects[0].rgba_palette = av_malloc(256 * 4); | 342 sub_header->rects[0]->rgba_palette = av_malloc(256 * 4); |
341 sub_header->rects[0].nb_colors = 256; | 343 sub_header->rects[0]->nb_colors = 256; |
342 yuv_a_to_rgba(yuv_palette, alpha, sub_header->rects[0].rgba_palette, 256); | 344 yuv_a_to_rgba(yuv_palette, alpha, sub_header->rects[0]->rgba_palette, 256); |
343 } else { | 345 } else { |
344 sub_header->rects[0].rgba_palette = av_malloc(4 * 4); | 346 sub_header->rects[0]->rgba_palette = av_malloc(4 * 4); |
345 sub_header->rects[0].nb_colors = 4; | 347 sub_header->rects[0]->nb_colors = 4; |
346 guess_palette(sub_header->rects[0].rgba_palette, | 348 guess_palette(sub_header->rects[0]->rgba_palette, |
347 colormap, alpha, 0xffff00); | 349 colormap, alpha, 0xffff00); |
348 } | 350 } |
349 sub_header->rects[0].x = x1; | 351 sub_header->rects[0]->x = x1; |
350 sub_header->rects[0].y = y1; | 352 sub_header->rects[0]->y = y1; |
351 sub_header->rects[0].w = w; | 353 sub_header->rects[0]->w = w; |
352 sub_header->rects[0].h = h; | 354 sub_header->rects[0]->h = h; |
353 sub_header->rects[0].linesize = w; | 355 sub_header->rects[0]->linesize = w; |
354 } | 356 } |
355 } | 357 } |
356 if (next_cmd_pos == cmd_pos) | 358 if (next_cmd_pos == cmd_pos) |
357 break; | 359 break; |
358 cmd_pos = next_cmd_pos; | 360 cmd_pos = next_cmd_pos; |
360 if (sub_header->num_rects > 0) | 362 if (sub_header->num_rects > 0) |
361 return is_menu; | 363 return is_menu; |
362 fail: | 364 fail: |
363 if (sub_header->rects != NULL) { | 365 if (sub_header->rects != NULL) { |
364 for (i = 0; i < sub_header->num_rects; i++) { | 366 for (i = 0; i < sub_header->num_rects; i++) { |
365 av_free(sub_header->rects[i].bitmap); | 367 av_freep(&sub_header->rects[i]->bitmap); |
366 av_free(sub_header->rects[i].rgba_palette); | 368 av_freep(&sub_header->rects[i]->rgba_palette); |
369 av_freep(&sub_header->rects[i]); | |
367 } | 370 } |
368 av_freep(&sub_header->rects); | 371 av_freep(&sub_header->rects); |
369 sub_header->num_rects = 0; | 372 sub_header->num_rects = 0; |
370 } | 373 } |
371 return -1; | 374 return -1; |
388 { | 391 { |
389 uint8_t transp_color[256]; | 392 uint8_t transp_color[256]; |
390 int y1, y2, x1, x2, y, w, h, i; | 393 int y1, y2, x1, x2, y, w, h, i; |
391 uint8_t *bitmap; | 394 uint8_t *bitmap; |
392 | 395 |
393 if (s->num_rects == 0 || s->rects == NULL || s->rects[0].w <= 0 || s->rects[0].h <= 0) | 396 if (s->num_rects == 0 || s->rects == NULL || s->rects[0]->w <= 0 || s->rects[0]->h <= 0) |
394 return 0; | 397 return 0; |
395 | 398 |
396 memset(transp_color, 0, 256); | 399 memset(transp_color, 0, 256); |
397 for(i = 0; i < s->rects[0].nb_colors; i++) { | 400 for(i = 0; i < s->rects[0]->nb_colors; i++) { |
398 if ((s->rects[0].rgba_palette[i] >> 24) == 0) | 401 if ((s->rects[0]->rgba_palette[i] >> 24) == 0) |
399 transp_color[i] = 1; | 402 transp_color[i] = 1; |
400 } | 403 } |
401 y1 = 0; | 404 y1 = 0; |
402 while (y1 < s->rects[0].h && is_transp(s->rects[0].bitmap + y1 * s->rects[0].linesize, | 405 while (y1 < s->rects[0]->h && is_transp(s->rects[0]->bitmap + y1 * s->rects[0]->linesize, |
403 1, s->rects[0].w, transp_color)) | 406 1, s->rects[0]->w, transp_color)) |
404 y1++; | 407 y1++; |
405 if (y1 == s->rects[0].h) { | 408 if (y1 == s->rects[0]->h) { |
406 av_freep(&s->rects[0].bitmap); | 409 av_freep(&s->rects[0]->bitmap); |
407 s->rects[0].w = s->rects[0].h = 0; | 410 s->rects[0]->w = s->rects[0]->h = 0; |
408 return 0; | 411 return 0; |
409 } | 412 } |
410 | 413 |
411 y2 = s->rects[0].h - 1; | 414 y2 = s->rects[0]->h - 1; |
412 while (y2 > 0 && is_transp(s->rects[0].bitmap + y2 * s->rects[0].linesize, 1, | 415 while (y2 > 0 && is_transp(s->rects[0]->bitmap + y2 * s->rects[0]->linesize, 1, |
413 s->rects[0].w, transp_color)) | 416 s->rects[0]->w, transp_color)) |
414 y2--; | 417 y2--; |
415 x1 = 0; | 418 x1 = 0; |
416 while (x1 < (s->rects[0].w - 1) && is_transp(s->rects[0].bitmap + x1, s->rects[0].linesize, | 419 while (x1 < (s->rects[0]->w - 1) && is_transp(s->rects[0]->bitmap + x1, s->rects[0]->linesize, |
417 s->rects[0].h, transp_color)) | 420 s->rects[0]->h, transp_color)) |
418 x1++; | 421 x1++; |
419 x2 = s->rects[0].w - 1; | 422 x2 = s->rects[0]->w - 1; |
420 while (x2 > 0 && is_transp(s->rects[0].bitmap + x2, s->rects[0].linesize, s->rects[0].h, | 423 while (x2 > 0 && is_transp(s->rects[0]->bitmap + x2, s->rects[0]->linesize, s->rects[0]->h, |
421 transp_color)) | 424 transp_color)) |
422 x2--; | 425 x2--; |
423 w = x2 - x1 + 1; | 426 w = x2 - x1 + 1; |
424 h = y2 - y1 + 1; | 427 h = y2 - y1 + 1; |
425 bitmap = av_malloc(w * h); | 428 bitmap = av_malloc(w * h); |
426 if (!bitmap) | 429 if (!bitmap) |
427 return 1; | 430 return 1; |
428 for(y = 0; y < h; y++) { | 431 for(y = 0; y < h; y++) { |
429 memcpy(bitmap + w * y, s->rects[0].bitmap + x1 + (y1 + y) * s->rects[0].linesize, w); | 432 memcpy(bitmap + w * y, s->rects[0]->bitmap + x1 + (y1 + y) * s->rects[0]->linesize, w); |
430 } | 433 } |
431 av_freep(&s->rects[0].bitmap); | 434 av_freep(&s->rects[0]->bitmap); |
432 s->rects[0].bitmap = bitmap; | 435 s->rects[0]->bitmap = bitmap; |
433 s->rects[0].linesize = w; | 436 s->rects[0]->linesize = w; |
434 s->rects[0].w = w; | 437 s->rects[0]->w = w; |
435 s->rects[0].h = h; | 438 s->rects[0]->h = h; |
436 s->rects[0].x += x1; | 439 s->rects[0]->x += x1; |
437 s->rects[0].y += y1; | 440 s->rects[0]->y += y1; |
438 return 1; | 441 return 1; |
439 } | 442 } |
440 | 443 |
441 #ifdef DEBUG | 444 #ifdef DEBUG |
442 #undef fprintf | 445 #undef fprintf |
489 | 492 |
490 #if defined(DEBUG) | 493 #if defined(DEBUG) |
491 av_log(NULL, AV_LOG_INFO, "start=%d ms end =%d ms\n", | 494 av_log(NULL, AV_LOG_INFO, "start=%d ms end =%d ms\n", |
492 sub->start_display_time, | 495 sub->start_display_time, |
493 sub->end_display_time); | 496 sub->end_display_time); |
494 ppm_save("/tmp/a.ppm", sub->rects[0].bitmap, | 497 ppm_save("/tmp/a.ppm", sub->rects[0]->bitmap, |
495 sub->rects[0].w, sub->rects[0].h, sub->rects[0].rgba_palette); | 498 sub->rects[0]->w, sub->rects[0]->h, sub->rects[0]->rgba_palette); |
496 #endif | 499 #endif |
497 | 500 |
498 *data_size = 1; | 501 *data_size = 1; |
499 return buf_size; | 502 return buf_size; |
500 } | 503 } |