Mercurial > libavcodec.hg
comparison dvdsubdec.c @ 8516:315b302fcd1d libavcodec
Replace AVSubtitleRect.rgba_palette and bitmap by AVPicture.
author | michael |
---|---|
date | Sat, 03 Jan 2009 19:17:18 +0000 |
parents | b866cb2a5330 |
children | 04423b2f6e0b |
comparison
equal
deleted
inserted
replaced
8515:45506d633cdc | 8516:315b302fcd1d |
---|---|
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_freep(&sub_header->rects[i]->bitmap); | 322 av_freep(&sub_header->rects[i]->pict.data[0]); |
323 av_freep(&sub_header->rects[i]->rgba_palette); | 323 av_freep(&sub_header->rects[i]->pict.data[1]); |
324 av_freep(&sub_header->rects[i]); | 324 av_freep(&sub_header->rects[i]); |
325 } | 325 } |
326 av_freep(&sub_header->rects); | 326 av_freep(&sub_header->rects); |
327 sub_header->num_rects = 0; | 327 sub_header->num_rects = 0; |
328 } | 328 } |
329 | 329 |
330 bitmap = av_malloc(w * h); | 330 bitmap = av_malloc(w * h); |
331 sub_header->rects = av_mallocz(sizeof(*sub_header->rects)); | 331 sub_header->rects = av_mallocz(sizeof(*sub_header->rects)); |
332 sub_header->rects[0] = av_mallocz(sizeof(AVSubtitleRect)); | 332 sub_header->rects[0] = av_mallocz(sizeof(AVSubtitleRect)); |
333 sub_header->num_rects = 1; | 333 sub_header->num_rects = 1; |
334 sub_header->rects[0]->bitmap = bitmap; | 334 sub_header->rects[0]->pict.data[0] = bitmap; |
335 decode_rle(bitmap, w * 2, w, (h + 1) / 2, | 335 decode_rle(bitmap, w * 2, w, (h + 1) / 2, |
336 buf, offset1, buf_size, is_8bit); | 336 buf, offset1, buf_size, is_8bit); |
337 decode_rle(bitmap + w, w * 2, w, h / 2, | 337 decode_rle(bitmap + w, w * 2, w, h / 2, |
338 buf, offset2, buf_size, is_8bit); | 338 buf, offset2, buf_size, is_8bit); |
339 if (is_8bit) { | 339 if (is_8bit) { |
340 if (yuv_palette == 0) | 340 if (yuv_palette == 0) |
341 goto fail; | 341 goto fail; |
342 sub_header->rects[0]->rgba_palette = av_malloc(256 * 4); | 342 sub_header->rects[0]->pict.data[1] = av_malloc(256 * 4); |
343 sub_header->rects[0]->nb_colors = 256; | 343 sub_header->rects[0]->nb_colors = 256; |
344 yuv_a_to_rgba(yuv_palette, alpha, sub_header->rects[0]->rgba_palette, 256); | 344 yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256); |
345 } else { | 345 } else { |
346 sub_header->rects[0]->rgba_palette = av_malloc(4 * 4); | 346 sub_header->rects[0]->pict.data[1] = av_malloc(4 * 4); |
347 sub_header->rects[0]->nb_colors = 4; | 347 sub_header->rects[0]->nb_colors = 4; |
348 guess_palette(sub_header->rects[0]->rgba_palette, | 348 guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1], |
349 colormap, alpha, 0xffff00); | 349 colormap, alpha, 0xffff00); |
350 } | 350 } |
351 sub_header->rects[0]->x = x1; | 351 sub_header->rects[0]->x = x1; |
352 sub_header->rects[0]->y = y1; | 352 sub_header->rects[0]->y = y1; |
353 sub_header->rects[0]->w = w; | 353 sub_header->rects[0]->w = w; |
354 sub_header->rects[0]->h = h; | 354 sub_header->rects[0]->h = h; |
355 sub_header->rects[0]->linesize = w; | 355 sub_header->rects[0]->pict.linesize[0] = w; |
356 } | 356 } |
357 } | 357 } |
358 if (next_cmd_pos == cmd_pos) | 358 if (next_cmd_pos == cmd_pos) |
359 break; | 359 break; |
360 cmd_pos = next_cmd_pos; | 360 cmd_pos = next_cmd_pos; |
362 if (sub_header->num_rects > 0) | 362 if (sub_header->num_rects > 0) |
363 return is_menu; | 363 return is_menu; |
364 fail: | 364 fail: |
365 if (sub_header->rects != NULL) { | 365 if (sub_header->rects != NULL) { |
366 for (i = 0; i < sub_header->num_rects; i++) { | 366 for (i = 0; i < sub_header->num_rects; i++) { |
367 av_freep(&sub_header->rects[i]->bitmap); | 367 av_freep(&sub_header->rects[i]->pict.data[0]); |
368 av_freep(&sub_header->rects[i]->rgba_palette); | 368 av_freep(&sub_header->rects[i]->pict.data[1]); |
369 av_freep(&sub_header->rects[i]); | 369 av_freep(&sub_header->rects[i]); |
370 } | 370 } |
371 av_freep(&sub_header->rects); | 371 av_freep(&sub_header->rects); |
372 sub_header->num_rects = 0; | 372 sub_header->num_rects = 0; |
373 } | 373 } |
396 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) |
397 return 0; | 397 return 0; |
398 | 398 |
399 memset(transp_color, 0, 256); | 399 memset(transp_color, 0, 256); |
400 for(i = 0; i < s->rects[0]->nb_colors; i++) { | 400 for(i = 0; i < s->rects[0]->nb_colors; i++) { |
401 if ((s->rects[0]->rgba_palette[i] >> 24) == 0) | 401 if ((((uint32_t*)s->rects[0]->pict.data[1])[i] >> 24) == 0) |
402 transp_color[i] = 1; | 402 transp_color[i] = 1; |
403 } | 403 } |
404 y1 = 0; | 404 y1 = 0; |
405 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]->pict.data[0] + y1 * s->rects[0]->pict.linesize[0], |
406 1, s->rects[0]->w, transp_color)) | 406 1, s->rects[0]->w, transp_color)) |
407 y1++; | 407 y1++; |
408 if (y1 == s->rects[0]->h) { | 408 if (y1 == s->rects[0]->h) { |
409 av_freep(&s->rects[0]->bitmap); | 409 av_freep(&s->rects[0]->pict.data[0]); |
410 s->rects[0]->w = s->rects[0]->h = 0; | 410 s->rects[0]->w = s->rects[0]->h = 0; |
411 return 0; | 411 return 0; |
412 } | 412 } |
413 | 413 |
414 y2 = s->rects[0]->h - 1; | 414 y2 = s->rects[0]->h - 1; |
415 while (y2 > 0 && is_transp(s->rects[0]->bitmap + y2 * s->rects[0]->linesize, 1, | 415 while (y2 > 0 && is_transp(s->rects[0]->pict.data[0] + y2 * s->rects[0]->pict.linesize[0], 1, |
416 s->rects[0]->w, transp_color)) | 416 s->rects[0]->w, transp_color)) |
417 y2--; | 417 y2--; |
418 x1 = 0; | 418 x1 = 0; |
419 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]->pict.data[0] + x1, s->rects[0]->pict.linesize[0], |
420 s->rects[0]->h, transp_color)) | 420 s->rects[0]->h, transp_color)) |
421 x1++; | 421 x1++; |
422 x2 = s->rects[0]->w - 1; | 422 x2 = s->rects[0]->w - 1; |
423 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]->pict.data[0] + x2, s->rects[0]->pict.linesize[0], s->rects[0]->h, |
424 transp_color)) | 424 transp_color)) |
425 x2--; | 425 x2--; |
426 w = x2 - x1 + 1; | 426 w = x2 - x1 + 1; |
427 h = y2 - y1 + 1; | 427 h = y2 - y1 + 1; |
428 bitmap = av_malloc(w * h); | 428 bitmap = av_malloc(w * h); |
429 if (!bitmap) | 429 if (!bitmap) |
430 return 1; | 430 return 1; |
431 for(y = 0; y < h; y++) { | 431 for(y = 0; y < h; y++) { |
432 memcpy(bitmap + w * y, s->rects[0]->bitmap + x1 + (y1 + y) * s->rects[0]->linesize, w); | 432 memcpy(bitmap + w * y, s->rects[0]->pict.data[0] + x1 + (y1 + y) * s->rects[0]->pict.linesize[0], w); |
433 } | 433 } |
434 av_freep(&s->rects[0]->bitmap); | 434 av_freep(&s->rects[0]->pict.data[0]); |
435 s->rects[0]->bitmap = bitmap; | 435 s->rects[0]->pict.data[0] = bitmap; |
436 s->rects[0]->linesize = w; | 436 s->rects[0]->pict.linesize[0] = w; |
437 s->rects[0]->w = w; | 437 s->rects[0]->w = w; |
438 s->rects[0]->h = h; | 438 s->rects[0]->h = h; |
439 s->rects[0]->x += x1; | 439 s->rects[0]->x += x1; |
440 s->rects[0]->y += y1; | 440 s->rects[0]->y += y1; |
441 return 1; | 441 return 1; |
492 | 492 |
493 #if defined(DEBUG) | 493 #if defined(DEBUG) |
494 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", |
495 sub->start_display_time, | 495 sub->start_display_time, |
496 sub->end_display_time); | 496 sub->end_display_time); |
497 ppm_save("/tmp/a.ppm", sub->rects[0]->bitmap, | 497 ppm_save("/tmp/a.ppm", sub->rects[0]->pict.data[0], |
498 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]->pict.data[1]); |
499 #endif | 499 #endif |
500 | 500 |
501 *data_size = 1; | 501 *data_size = 1; |
502 return buf_size; | 502 return buf_size; |
503 } | 503 } |