comparison mjpeg.c @ 1280:8623c2e29555 libavcodec

optimize
author michaelni
date Fri, 23 May 2003 16:04:24 +0000
parents 61317ffc64d5
children 26bed13dd48d
comparison
equal deleted inserted replaced
1279:77aafc141a39 1280:8623c2e29555
555 if (val < 0) { 555 if (val < 0) {
556 val = -val; 556 val = -val;
557 mant--; 557 mant--;
558 } 558 }
559 559
560 /* compute the log (XXX: optimize) */ 560 nbits= av_log2(val) + 1;
561 nbits = 0;
562 while (val != 0) {
563 val = val >> 1;
564 nbits++;
565 }
566 561
567 put_bits(&s->pb, huff_size[nbits], huff_code[nbits]); 562 put_bits(&s->pb, huff_size[nbits], huff_code[nbits]);
568 563
569 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); 564 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
570 } 565 }
611 if (val < 0) { 606 if (val < 0) {
612 val = -val; 607 val = -val;
613 mant--; 608 mant--;
614 } 609 }
615 610
616 /* compute the log (XXX: optimize) */ 611 nbits= av_log2(val) + 1;
617 nbits = 0;
618 while (val != 0) {
619 val = val >> 1;
620 nbits++;
621 }
622 code = (run << 4) | nbits; 612 code = (run << 4) | nbits;
623 613
624 put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); 614 put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]);
625 615
626 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); 616 put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1));
900 return 0; 890 return 0;
901 } 891 }
902 892
903 static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index) 893 static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
904 { 894 {
905 int code, diff; 895 int code;
906 code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2); 896 code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2);
907 if (code < 0) 897 if (code < 0)
908 { 898 {
909 dprintf("mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", 0, dc_index, 899 dprintf("mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", 0, dc_index,
910 &s->vlcs[0][dc_index]); 900 &s->vlcs[0][dc_index]);
911 return 0xffff; 901 return 0xffff;
912 } 902 }
913 if (code == 0) { 903
914 diff = 0; 904 if(code)
915 } else { 905 return get_xbits(&s->gb, code);
916 diff = get_xbits(&s->gb, code); 906 else
917 } 907 return 0;
918 return diff;
919 } 908 }
920 909
921 /* decode block and dequantize */ 910 /* decode block and dequantize */
922 static int decode_block(MJpegDecodeContext *s, DCTELEM *block, 911 static int decode_block(MJpegDecodeContext *s, DCTELEM *block,
923 int component, int dc_index, int ac_index, int quant_index) 912 int component, int dc_index, int ac_index, int quant_index)
924 { 913 {
925 int nbits, code, i, j, level; 914 int code, i, j, level, val;
926 int run, val;
927 VLC *ac_vlc; 915 VLC *ac_vlc;
928 int16_t *quant_matrix; 916 int16_t *quant_matrix;
929 917
930 /* DC coef */ 918 /* DC coef */
931 val = mjpeg_decode_dc(s, dc_index); 919 val = mjpeg_decode_dc(s, dc_index);
951 if (code == 0) 939 if (code == 0)
952 break; 940 break;
953 if (code == 0xf0) { 941 if (code == 0xf0) {
954 i += 16; 942 i += 16;
955 } else { 943 } else {
956 run = code >> 4; 944 level = get_xbits(&s->gb, code & 0xf);
957 nbits = code & 0xf; 945 i += code >> 4;
958 level = get_xbits(&s->gb, nbits);
959 i += run;
960 if (i >= 64) { 946 if (i >= 64) {
961 dprintf("error count: %d\n", i); 947 dprintf("error count: %d\n", i);
962 return -1; 948 return -1;
963 } 949 }
964 j = s->scantable.permutated[i]; 950 j = s->scantable.permutated[i];