• R/O
  • HTTP
  • SSH
  • HTTPS

main: Commit

メインリポジトリ


Commit MetaInfo

Revisionc1c5edae1f1d7a487239a56f1224c996eb31a757 (tree)
Time2009-08-25 17:53:17
AuthorNoumi Akira <noumiakira@user...>
CommiterNoumi Akira

Log Message

add block level qi decoding.

Change Summary

Incremental Difference

--- a/Lib/QTheoraEx/FrameDecoder.c
+++ b/Lib/QTheoraEx/FrameDecoder.c
@@ -132,9 +132,14 @@ static const UINT8 HSHORT[32] = {
132132 static const INT8 HSHORT_BASE[6] = { 1, 3, 5, 7, 11, 15 };
133133 static const INT8 HSHORT_BITS[6] = { 1, 1, 1, 2, 2, 4 };
134134
135+#define RL_LONG_FULL_RUN 4129
136+
137+#define RL_LONG_DECODE_RUN(X) \
138+ { INT32 token; LOAD_BITS token = HLONG[GET_BITS_I(6)]; RETIRE_BITS(token & 0xf); (X) = HLONG_BASE[token >> 4]; \
139+ if (HLONG_BITS[token >> 4] > 0) { INT32 x; FETCH_BITS(x, HLONG_BITS[token >> 4]) (X) += x; } }
140+
135141 #define RL_LONG_DECODE \
136- if (r.Run == 0) { INT32 token; LOAD_BITS token = HLONG[GET_BITS_I(6)]; RETIRE_BITS(token & 0xf); r.Run = HLONG_BASE[token >> 4]; \
137- if (HLONG_BITS[token >> 4] > 0) { INT32 x; FETCH_BITS(x, HLONG_BITS[token >> 4]) r.Run += x; } r.Bit = !(r.Bit); } \
142+ if (r.Run == 0) { RL_LONG_DECODE_RUN(r.Run) r.Bit = !(r.Bit); } \
138143 (r.Run)--;
139144
140145 #define RL_SHORT_DECODE \
@@ -522,6 +527,8 @@ static void UndoDCPrediction(
522527 #define FrameDecoder_DecodeMacroBlockCodingModes FrameDecoder_DecodeMacroBlockCodingModes_C
523528 #define FrameDecoder_DecodeMotionVectors FrameDecoder_DecodeMotionVectors_C
524529
530+#define FrameDecoder_BlockLevelQIDecode FrameDecoder_BlockLevelQIDecode_C
531+
525532 #define FrameDecoder_DecodeBlocks FrameDecoder_DecodeBlocks_C
526533 #define FrameDecoder_DecodeDCTCoefficients FrameDecoder_DecodeDCTCoefficients_C
527534
@@ -543,6 +550,8 @@ static void UndoDCPrediction(
543550 #define FrameDecoder_DecodeMacroBlockCodingModes FrameDecoder_DecodeMacroBlockCodingModes_X86
544551 #define FrameDecoder_DecodeMotionVectors FrameDecoder_DecodeMotionVectors_X86
545552
553+#define FrameDecoder_BlockLevelQIDecode FrameDecoder_BlockLevelQIDecode_X86
554+
546555 #define FrameDecoder_DecodeBlocks FrameDecoder_DecodeBlocks_X86
547556 #define FrameDecoder_DecodeDCTCoefficients FrameDecoder_DecodeDCTCoefficients_X86
548557
@@ -564,6 +573,8 @@ static void UndoDCPrediction(
564573 #define FrameDecoder_DecodeMacroBlockCodingModes FrameDecoder_DecodeMacroBlockCodingModes_MMX
565574 #define FrameDecoder_DecodeMotionVectors FrameDecoder_DecodeMotionVectors_MMX
566575
576+#define FrameDecoder_BlockLevelQIDecode FrameDecoder_BlockLevelQIDecode_MMX
577+
567578 #define FrameDecoder_DecodeBlocks FrameDecoder_DecodeBlocks_MMX
568579 #define FrameDecoder_DecodeDCTCoefficients FrameDecoder_DecodeDCTCoefficients_MMX
569580
@@ -639,7 +650,9 @@ BOOL QT_FrameDecoder_Setup(
639650
640651 /* */
641652
642- t->QIndex = -1;
653+ t->QIndex[0] = -1;
654+ t->QIndex[1] = -1;
655+ t->QIndex[2] = -1;
643656
644657 /* */
645658
@@ -653,6 +666,11 @@ BOOL QT_FrameDecoder_Setup(
653666 return FALSE;
654667 }
655668
669+ t->BQI = (UINT8*)QT_MemoryPool_Allocate(pool, sizeof(UINT8) * index->Blocks);
670+ if (t->BQI == NULL) {
671+ return FALSE;
672+ }
673+
656674 t->MBMode = (UINT8*)QT_MemoryPool_Allocate(pool, sizeof(UINT8) * index->MC);
657675 if (t->MBMode == NULL) {
658676 return FALSE;
--- a/Lib/QTheoraEx/FrameDecoder.h
+++ b/Lib/QTheoraEx/FrameDecoder.h
@@ -101,18 +101,20 @@ struct QT_FrameDecoder {
101101
102102 FrameHeader_t Header;
103103
104- DequantizeMatrix_t Dequantize;
104+ DequantizeMatrix_t Dequantize[3];
105105
106106 FrameReconstructor_SSE2_t* Reconstructor;
107107
108108 LoopFilter_t Filter;
109109
110- INT32 QIndex;
110+ INT32 QIndex[3];
111111
112112 INT8* SBCoded;
113113
114114 UINT8* BCoded;
115115
116+ UINT8* BQI;
117+
116118 UINT8* MBMode;
117119
118120 UINT8* BMode;
--- a/Lib/QTheoraEx/FrameDecoder_Impl.h
+++ b/Lib/QTheoraEx/FrameDecoder_Impl.h
@@ -365,6 +365,110 @@ static BOOL FrameDecoder_DecodeMotionVectors(
365365
366366 /* */
367367
368+static BOOL FrameDecoder_BlockLevelQIDecode(
369+ FrameDecoder_t* t,
370+ BitReader_t* d)
371+{
372+ INITIATE_BITS
373+
374+ INT32 nqi = 0;
375+
376+ UINT8* qi = t->BQI;
377+
378+ const UINT8* c = t->BCoded;
379+ const UINT8* end = c + t->Index->Blocks;
380+
381+ INT32 bit, run, full;
382+
383+ FETCH_BITS_I(bit, 1)
384+ run = 0;
385+
386+ while (c < end) {
387+ RL_LONG_DECODE_RUN(run)
388+ full = (run >= RL_LONG_FULL_RUN);
389+
390+#if 0
391+ printf("RUN: %d, %d\n", run, bit);
392+#endif
393+
394+ while (run > 0 && c < end) {
395+ if (*(c++) == 0) {
396+ qi++;
397+ } else {
398+ run--;
399+ nqi += bit;
400+ *(qi++) = bit;
401+ }
402+ }
403+
404+ for (; *c == 0 && c < end; c++)
405+ ;
406+
407+ if (full != 0 && c < end) {
408+ FETCH_BITS_I(bit, 1)
409+ } else {
410+ bit = !bit;
411+ }
412+ }
413+
414+ if (run > 0) {
415+ return FALSE;
416+ }
417+
418+#if 0
419+ printf("nqi: %d\n", nqi);
420+#endif
421+
422+ if (t->Header.NQIS == 3 && nqi > 0) {
423+ UINT8* eqi = t->BQI + t->Index->Blocks;
424+ qi = t->BQI;
425+
426+ FETCH_BITS_I(bit, 1)
427+ run = 0;
428+
429+ while (qi < eqi) {
430+ RL_LONG_DECODE_RUN(run)
431+ full = (run >= RL_LONG_FULL_RUN);
432+
433+#if 0
434+ printf("RUN: %d, %d\n", run, bit);
435+#endif
436+
437+ while (run > 0 && qi < eqi) {
438+ if (*qi == 0) {
439+ qi++;
440+ } else {
441+ run--;
442+ *(qi++) += bit;
443+ }
444+ }
445+
446+ for (; *qi == 0 && qi < eqi; qi++)
447+ ;
448+
449+ if (full != 0 && qi < eqi) {
450+ FETCH_BITS_I(bit, 1)
451+ } else {
452+ bit = !bit;
453+ }
454+ }
455+
456+ if (run > 0) {
457+ return FALSE;
458+ }
459+ }
460+
461+ FINALIZE_BITS
462+
463+#if 0
464+ puts("E");
465+#endif
466+
467+ return TRUE;
468+}
469+
470+/* */
471+
368472 static BOOL FrameDecoder_DecodeBlocks(
369473 FrameDecoder_t* t,
370474 BitReader_t* d,
@@ -677,29 +781,45 @@ static BOOL FrameDecoder_Decode(
677781 {
678782 BitReader_t d;
679783
784+ INT32 i, qup = 0;
785+
680786 QT_BitReader_Initialize(&d, p, size);
681787
682788 if (!FrameHeader_Decode(&(t->Header), &d)) {
683789 return FALSE;
684790 }
685791
686- if (t->QIndex != t->Header.QIS[0]) {
687- t->QIndex = t->Header.QIS[0];
792+ if (t->QIndex[0] != t->Header.QIS[0]) {
793+ t->QIndex[0] = t->Header.QIS[0];
688794 Dequantize_MakeMatrix(
689- &(t->Dequantize),
795+ &(t->Dequantize[0]),
690796 &(t->Setup->Dequantize),
691- t->QIndex);
797+ t->QIndex[0]);
692798
693799 Filter_Setup(
694800 &(t->Filter),
695801 &(t->Setup->Filter),
696- t->QIndex);
802+ t->QIndex[0]);
803+
804+ qup = 1;
805+ }
806+
807+ for (i = 1; i < t->Header.NQIS; i++) {
808+ if (t->QIndex[i] != t->Header.QIS[i]) {
809+ t->QIndex[i] = t->Header.QIS[i];
810+ Dequantize_MakeMatrix(
811+ &(t->Dequantize[i]),
812+ &(t->Setup->Dequantize),
813+ t->QIndex[i]);
697814
698- if (t->UpdateDequantizeMatrix != NULL) {
699- t->UpdateDequantizeMatrix(t);
815+ qup = 1;
700816 }
701817 }
702818
819+ if (qup && t->UpdateDequantizeMatrix != NULL) {
820+ t->UpdateDequantizeMatrix(t);
821+ }
822+
703823 /* */
704824
705825 if (t->Header.Type == 0) { /* Intra */
@@ -741,6 +861,14 @@ static BOOL FrameDecoder_Decode(
741861 }
742862 }
743863
864+ memset(t->BQI, 0, sizeof(UINT8) * t->Index->Blocks);
865+
866+ if (t->Header.NQIS > 1) {
867+ if (!FrameDecoder_BlockLevelQIDecode(t, &d)) {
868+ return FALSE;
869+ }
870+ }
871+
744872 if (!FrameDecoder_DecodeDCTCoefficients(t, &d)) {
745873 return FALSE;
746874 }
@@ -770,6 +898,8 @@ static BOOL FrameDecoder_Decode(
770898 #undef FrameDecoder_DecodeMacroBlockCodingModes
771899 #undef FrameDecoder_DecodeMotionVectors
772900
901+#undef FrameDecoder_BlockLevelQIDecode
902+
773903 #undef FrameDecoder_DecodeBlocks
774904 #undef FrameDecoder_DecodeDCTCoefficients
775905
--- a/Lib/QTheoraEx/FrameReconstructor.c
+++ b/Lib/QTheoraEx/FrameReconstructor.c
@@ -705,7 +705,7 @@ static void Reconstruct_IntraBlock(
705705 block[0] = dc;
706706
707707 Dequantize_DoDequantize(
708- &(t->Dequantize),
708+ &(t->Dequantize[0]),
709709 0,
710710 plane,
711711 coeff,
@@ -743,7 +743,7 @@ static void Reconstruct_InterBlock(
743743 block[0] = dc;
744744
745745 Dequantize_DoDequantize(
746- &(t->Dequantize),
746+ &(t->Dequantize[0]),
747747 1,
748748 plane,
749749 coeff,
--- a/Lib/QTheoraEx/FrameReconstructor_MMX.c
+++ b/Lib/QTheoraEx/FrameReconstructor_MMX.c
@@ -101,7 +101,7 @@ void QT_UpdateDequantizeMatrix_MMX(
101101
102102 for (i = 0; i < 2; i++) {
103103 for (p = 0; p < 3; p++) {
104- const INT16* x = t->Dequantize.Matrix[i][p];
104+ const INT16* x = t->Dequantize[0].Matrix[i][p];
105105 INT16* y = r->Matrix[i][p];
106106 Transpose_MMX(x, y);
107107 }
--- a/Lib/QTheoraEx/FrameReconstructor_SSE2.c
+++ b/Lib/QTheoraEx/FrameReconstructor_SSE2.c
@@ -69,7 +69,7 @@ void QT_UpdateDequantizeMatrix_SSE2(
6969
7070 for (i = 0; i < 2; i++) {
7171 for (p = 0; p < 3; p++) {
72- const INT16* x = t->Dequantize.Matrix[i][p];
72+ const INT16* x = t->Dequantize[0].Matrix[i][p];
7373 INT16* y = r->Matrix[i][p];
7474 Transpose_SSE2(x, y);
7575 }
Show on old repository browser