comparison mov.c @ 2818:f639238e2936 libavformat

cosmetics
author bcoudurier
date Sun, 16 Dec 2007 18:10:18 +0000
parents b1b21255bbbb
children 5b055288c138
comparison
equal deleted inserted replaced
2817:b1b21255bbbb 2818:f639238e2936
660 color_greyscale = st->codec->bits_per_sample & 0x20; 660 color_greyscale = st->codec->bits_per_sample & 0x20;
661 661
662 /* if the depth is 2, 4, or 8 bpp, file is palettized */ 662 /* if the depth is 2, 4, or 8 bpp, file is palettized */
663 if ((color_depth == 2) || (color_depth == 4) || 663 if ((color_depth == 2) || (color_depth == 4) ||
664 (color_depth == 8)) { 664 (color_depth == 8)) {
665
666 if (color_greyscale) { 665 if (color_greyscale) {
667
668 /* compute the greyscale palette */ 666 /* compute the greyscale palette */
669 color_count = 1 << color_depth; 667 color_count = 1 << color_depth;
670 color_index = 255; 668 color_index = 255;
671 color_dec = 256 / (color_count - 1); 669 color_dec = 256 / (color_count - 1);
672 for (j = 0; j < color_count; j++) { 670 for (j = 0; j < color_count; j++) {
675 (r << 16) | (g << 8) | (b); 673 (r << 16) | (g << 8) | (b);
676 color_index -= color_dec; 674 color_index -= color_dec;
677 if (color_index < 0) 675 if (color_index < 0)
678 color_index = 0; 676 color_index = 0;
679 } 677 }
680
681 } else if (st->codec->color_table_id & 0x08) { 678 } else if (st->codec->color_table_id & 0x08) {
682
683 /* if flag bit 3 is set, use the default palette */ 679 /* if flag bit 3 is set, use the default palette */
684 color_count = 1 << color_depth; 680 color_count = 1 << color_depth;
685 if (color_depth == 2) 681 if (color_depth == 2)
686 color_table = ff_qt_default_palette_4; 682 color_table = ff_qt_default_palette_4;
687 else if (color_depth == 4) 683 else if (color_depth == 4)
694 g = color_table[j * 4 + 1]; 690 g = color_table[j * 4 + 1];
695 b = color_table[j * 4 + 2]; 691 b = color_table[j * 4 + 2];
696 c->palette_control.palette[j] = 692 c->palette_control.palette[j] =
697 (r << 16) | (g << 8) | (b); 693 (r << 16) | (g << 8) | (b);
698 } 694 }
699
700 } else { 695 } else {
701
702 /* load the palette from the file */ 696 /* load the palette from the file */
703 color_start = get_be32(pb); 697 color_start = get_be32(pb);
704 color_count = get_be16(pb); 698 color_count = get_be16(pb);
705 color_end = get_be16(pb); 699 color_end = get_be16(pb);
706 if ((color_start <= 255) && 700 if ((color_start <= 255) &&
720 c->palette_control.palette[j] = 714 c->palette_control.palette[j] =
721 (r << 16) | (g << 8) | (b); 715 (r << 16) | (g << 8) | (b);
722 } 716 }
723 } 717 }
724 } 718 }
725
726 st->codec->palctrl = &c->palette_control; 719 st->codec->palctrl = &c->palette_control;
727 st->codec->palctrl->palette_changed = 1; 720 st->codec->palctrl->palette_changed = 1;
728 } else 721 } else
729 st->codec->palctrl = NULL; 722 st->codec->palctrl = NULL;
730 } else if(st->codec->codec_type==CODEC_TYPE_AUDIO) { 723 } else if(st->codec->codec_type==CODEC_TYPE_AUDIO) {
1362 } 1355 }
1363 } 1356 }
1364 } 1357 }
1365 } else { /* read whole chunk */ 1358 } else { /* read whole chunk */
1366 unsigned int chunk_samples, chunk_size, chunk_duration; 1359 unsigned int chunk_samples, chunk_size, chunk_duration;
1367
1368 for (i = 0; i < sc->chunk_count; i++) { 1360 for (i = 0; i < sc->chunk_count; i++) {
1369 current_offset = sc->chunk_offsets[i]; 1361 current_offset = sc->chunk_offsets[i];
1370 if (stsc_index + 1 < sc->sample_to_chunk_sz && i + 1 == sc->sample_to_chunk[stsc_index + 1].first) 1362 if (stsc_index + 1 < sc->sample_to_chunk_sz && i + 1 == sc->sample_to_chunk[stsc_index + 1].first)
1371 stsc_index++; 1363 stsc_index++;
1372 chunk_samples = sc->sample_to_chunk[stsc_index].count; 1364 chunk_samples = sc->sample_to_chunk[stsc_index].count;
1377 chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame; 1369 chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame;
1378 else { /* workaround to find nearest next chunk offset */ 1370 else { /* workaround to find nearest next chunk offset */
1379 chunk_size = INT_MAX; 1371 chunk_size = INT_MAX;
1380 for (j = 0; j < mov->total_streams; j++) { 1372 for (j = 0; j < mov->total_streams; j++) {
1381 MOVStreamContext *msc = mov->streams[j]; 1373 MOVStreamContext *msc = mov->streams[j];
1382
1383 for (k = msc->next_chunk; k < msc->chunk_count; k++) { 1374 for (k = msc->next_chunk; k < msc->chunk_count; k++) {
1384 if (msc->chunk_offsets[k] > current_offset && msc->chunk_offsets[k] - current_offset < chunk_size) { 1375 if (msc->chunk_offsets[k] > current_offset && msc->chunk_offsets[k] - current_offset < chunk_size) {
1385 chunk_size = msc->chunk_offsets[k] - current_offset; 1376 chunk_size = msc->chunk_offsets[k] - current_offset;
1386 msc->next_chunk = k; 1377 msc->next_chunk = k;
1387 break; 1378 break;
1505 int64_t best_dts = INT64_MAX; 1496 int64_t best_dts = INT64_MAX;
1506 int i; 1497 int i;
1507 1498
1508 for (i = 0; i < mov->total_streams; i++) { 1499 for (i = 0; i < mov->total_streams; i++) {
1509 MOVStreamContext *msc = mov->streams[i]; 1500 MOVStreamContext *msc = mov->streams[i];
1510
1511 if (s->streams[i]->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) { 1501 if (s->streams[i]->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) {
1512 AVIndexEntry *current_sample = &s->streams[i]->index_entries[msc->current_sample]; 1502 AVIndexEntry *current_sample = &s->streams[i]->index_entries[msc->current_sample];
1513 int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale); 1503 int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale);
1514
1515 dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); 1504 dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
1516 if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) || 1505 if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) ||
1517 (!url_is_streamed(s->pb) && 1506 (!url_is_streamed(s->pb) &&
1518 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || 1507 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
1519 (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))) { 1508 (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))) {