Mercurial > libavcodec.hg
comparison mjpeg.c @ 26:ce751dfbcace libavcodec
added correct component id handling
author | glantau |
---|---|
date | Mon, 06 Aug 2001 01:04:59 +0000 |
parents | 1e131bc21101 |
children | b611fafddf9e |
comparison
equal
deleted
inserted
replaced
25:2f603eb2f23d | 26:ce751dfbcace |
---|---|
440 int buffer_size; | 440 int buffer_size; |
441 int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ | 441 int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ |
442 INT16 quant_matrixes[4][64]; | 442 INT16 quant_matrixes[4][64]; |
443 VLC vlcs[2][4]; | 443 VLC vlcs[2][4]; |
444 int width, height; | 444 int width, height; |
445 int nb_components; | |
446 int component_id[MAX_COMPONENTS]; | |
445 int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */ | 447 int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */ |
446 int v_count[MAX_COMPONENTS]; | 448 int v_count[MAX_COMPONENTS]; |
447 int h_max, v_max; /* maximum h and v counts */ | 449 int h_max, v_max; /* maximum h and v counts */ |
448 int quant_index[4]; /* quant table index for each component */ | 450 int quant_index[4]; /* quant table index for each component */ |
449 int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ | 451 int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ |
550 } | 552 } |
551 | 553 |
552 static int mjpeg_decode_sof0(MJpegDecodeContext *s, | 554 static int mjpeg_decode_sof0(MJpegDecodeContext *s, |
553 UINT8 *buf, int buf_size) | 555 UINT8 *buf, int buf_size) |
554 { | 556 { |
555 int len, nb_components, i, index, width, height; | 557 int len, nb_components, i, width, height; |
556 | 558 |
557 init_get_bits(&s->gb, buf, buf_size); | 559 init_get_bits(&s->gb, buf, buf_size); |
558 | 560 |
559 /* XXX: verify len field validity */ | 561 /* XXX: verify len field validity */ |
560 len = get_bits(&s->gb, 16); | 562 len = get_bits(&s->gb, 16); |
566 | 568 |
567 nb_components = get_bits(&s->gb, 8); | 569 nb_components = get_bits(&s->gb, 8); |
568 if (nb_components <= 0 || | 570 if (nb_components <= 0 || |
569 nb_components > MAX_COMPONENTS) | 571 nb_components > MAX_COMPONENTS) |
570 return -1; | 572 return -1; |
573 s->nb_components = nb_components; | |
571 s->h_max = 1; | 574 s->h_max = 1; |
572 s->v_max = 1; | 575 s->v_max = 1; |
573 for(i=0;i<nb_components;i++) { | 576 for(i=0;i<nb_components;i++) { |
574 /* component id */ | 577 /* component id */ |
575 index = get_bits(&s->gb, 8) - 1; | 578 s->component_id[i] = get_bits(&s->gb, 8) - 1; |
576 /* XXX: avoid this limitation */ | |
577 if (index < 0 || index >= MAX_COMPONENTS) | |
578 return -1; | |
579 s->h_count[i] = get_bits(&s->gb, 4); | 579 s->h_count[i] = get_bits(&s->gb, 4); |
580 s->v_count[i] = get_bits(&s->gb, 4); | 580 s->v_count[i] = get_bits(&s->gb, 4); |
581 /* compute hmax and vmax (only used in interleaved case) */ | 581 /* compute hmax and vmax (only used in interleaved case) */ |
582 if (s->h_count[i] > s->h_max) | 582 if (s->h_count[i] > s->h_max) |
583 s->h_max = s->h_count[i]; | 583 s->h_max = s->h_count[i]; |
584 if (s->v_count[i] > s->v_max) | 584 if (s->v_count[i] > s->v_max) |
585 s->v_max = s->v_count[i]; | 585 s->v_max = s->v_count[i]; |
586 | 586 #if 1 |
587 /* XXX: only 420 is accepted */ | 587 /* XXX: only 420 is accepted */ |
588 if ((i == 0 && (s->h_count[i] != 2 || s->v_count[i] != 2)) || | 588 if ((i == 0 && (s->h_count[i] != 2 || s->v_count[i] != 2)) || |
589 (i != 0 && (s->h_count[i] != 1 || s->v_count[i] != 1))) | 589 (i != 0 && (s->h_count[i] != 1 || s->v_count[i] != 1))) |
590 return -1; | 590 return -1; |
591 #endif | |
591 s->quant_index[i] = get_bits(&s->gb, 8); | 592 s->quant_index[i] = get_bits(&s->gb, 8); |
592 if (s->quant_index[i] >= 4) | 593 if (s->quant_index[i] >= 4) |
593 return -1; | 594 return -1; |
594 dprintf("component %d %d:%d\n", i, s->h_count[i], s->v_count[i]); | 595 dprintf("component %d %d:%d\n", i, s->h_count[i], s->v_count[i]); |
595 } | 596 } |
694 | 695 |
695 static int mjpeg_decode_sos(MJpegDecodeContext *s, | 696 static int mjpeg_decode_sos(MJpegDecodeContext *s, |
696 UINT8 *buf, int buf_size) | 697 UINT8 *buf, int buf_size) |
697 { | 698 { |
698 int len, nb_components, i, j, n, h, v; | 699 int len, nb_components, i, j, n, h, v; |
699 int mb_width, mb_height, mb_x, mb_y, vmax, hmax, index; | 700 int mb_width, mb_height, mb_x, mb_y, vmax, hmax, index, id; |
700 int comp_index[4]; | 701 int comp_index[4]; |
701 int dc_index[4]; | 702 int dc_index[4]; |
702 int ac_index[4]; | 703 int ac_index[4]; |
703 int nb_blocks[4]; | 704 int nb_blocks[4]; |
704 int h_count[4]; | 705 int h_count[4]; |
712 if (nb_components != 3) | 713 if (nb_components != 3) |
713 return -1; | 714 return -1; |
714 vmax = 0; | 715 vmax = 0; |
715 hmax = 0; | 716 hmax = 0; |
716 for(i=0;i<nb_components;i++) { | 717 for(i=0;i<nb_components;i++) { |
717 index = get_bits(&s->gb, 8) - 1; | 718 id = get_bits(&s->gb, 8) - 1; |
718 /* XXX: this limitation is not OK */ | 719 /* find component index */ |
719 if (index < 0 || index >= 4) | 720 for(index=0;index<s->nb_components;index++) |
720 return -1; | 721 if (id == s->component_id[index]) |
722 break; | |
723 if (index == s->nb_components) | |
724 return -1; | |
725 | |
721 comp_index[i] = index; | 726 comp_index[i] = index; |
722 | |
723 nb_blocks[i] = s->h_count[index] * s->v_count[index]; | 727 nb_blocks[i] = s->h_count[index] * s->v_count[index]; |
724 h_count[i] = s->h_count[index]; | 728 h_count[i] = s->h_count[index]; |
725 v_count[i] = s->v_count[index]; | 729 v_count[i] = s->v_count[index]; |
726 | 730 |
727 dc_index[i] = get_bits(&s->gb, 4); | 731 dc_index[i] = get_bits(&s->gb, 4); |