• R/O
  • HTTP
  • SSH
  • HTTPS

main: Commit

メインリポジトリ


Commit MetaInfo

Revisiona9a95cfb2081ed82782bdaef39a8467c9dcdcf46 (tree)
Time2009-09-10 16:29:10
AuthorNoumi Akira <noumiakira@user...>
CommiterNoumi Akira

Log Message

optimize DC prediction decoding.

Change Summary

Incremental Difference

--- a/Lib/QTheoraEx/FrameDecoder.c
+++ b/Lib/QTheoraEx/FrameDecoder.c
@@ -363,16 +363,13 @@ static void DecodeDCCoefficients(FrameDecoder_t* t)
363363 if (eob == 0) {
364364 INT8 rr = *(br++);
365365 INT16 cc = *(bc++);
366-
367366 if (rr == 0) {
368367 coeff = cc;
369-
370368 } else if (rr < 0) {
371- eob = cc;
369+ eob = cc - 1;
372370 }
373- }
374371
375- if (eob > 0) {
372+ } else {
376373 eob--;
377374 }
378375
@@ -387,28 +384,6 @@ static void DecodeDCCoefficients(FrameDecoder_t* t)
387384
388385 /* */
389386
390-static const INT32 DCP_W[16][4] = {
391- /* L DL D DR */
392- { 1, 2, 4, 8 },
393-
394- { 128, 0, 0, 0 }, /* 1 */
395- { 0, 128, 0, 0 }, /* 2 */
396- { 128, 0, 0, 0 }, /* 3 */
397- { 0, 0, 128, 0 }, /* 4 */
398- { 64, 0, 64, 0 }, /* 5 */
399- { 0, 0, 128, 0 }, /* 6 */
400- { 116, -104, 116, 0 }, /* 7 */
401- { 0, 0, 0, 128 }, /* 8 */
402- { 75, 0, 0, 53 }, /* 9 */
403- { 0, 64, 0, 64 }, /* 10 */
404- { 75, 0, 0, 53 }, /* 11 */
405- { 0, 0, 128, 0 }, /* 12 */
406- { 75, 0, 0, 53 }, /* 13 */
407- { 0, 24, 80, 24 }, /* 14 */
408- { 116, -104, 116, 0 } /* 15 */
409-
410-};
411-
412387 static const INT32 DCP_T[8] = {
413388 1, 0, 1, 1,
414389 1, 2, 2, 1
@@ -420,7 +395,6 @@ static void UndoDCPrediction(
420395 FrameDecoder_t* t)
421396 {
422397 INT32 i;
423- INT32 x, y;
424398
425399 INT16* DC = t->DC;
426400
@@ -434,78 +408,129 @@ static void UndoDCPrediction(
434408
435409 INT32 v[4] = { 0 };
436410
437- INT32 idx = 0;
411+ INT32 idx = 0, ni;
412+
413+ INT32 y;
414+
415+ for (ni = idx + bx; idx < ni; idx++) {
416+ if (DC[idx] != NOT_CODED) {
417+ INT32 type = DCP_T[mode[idx]];
418+ last[type] = (DC[idx] += last[type]);
419+ }
420+ }
421+
422+ for (y = 1; y < by; y++) {
423+ ni = idx + bx;
424+
425+ if (DC[idx] != NOT_CODED) {
426+ INT32 type = DCP_T[mode[idx]];
427+
428+ INT32 i2 = idx - bx;
429+ INT32 i3 = idx - bx + 1;
430+
431+ if (DC[i2] != NOT_CODED && DCP_T[mode[i2]] == type) {
432+ last[type] = (DC[idx] += DC[i2]);
433+ } else if (DC[i3] != NOT_CODED && DCP_T[mode[i3]] == type) {
434+ last[type] = (DC[idx] += DC[i3]);
435+ } else {
436+ last[type] = (DC[idx] += last[type]);
437+ }
438+ }
438439
439- for (y = 0; y < by; y++) {
440- for (x = 0; x < bx; x++, idx++) {
441- INT32 dc = DC[idx];
442- if (dc != NOT_CODED) {
440+ idx++;
441+
442+ for (; idx < ni; idx++) {
443+ if (DC[idx] != NOT_CODED) {
443444 INT32 pred;
444445
445446 INT32 t0 = 0;
446447 INT32 type = DCP_T[mode[idx]];
447448
448- if (x > 0) {
449- INT32 i0 = idx - 1;
450- v[0] = DC[i0];
451- if (v[0] != NOT_CODED && DCP_T[mode[i0]] == type) {
452- t0 += DCP_W[0][0];
453- }
454- }
449+ INT32 i0 = idx - 1;
450+ INT32 i1 = idx - bx - 1;
451+ INT32 i2 = idx - bx;
455452
456- if (y > 0) {
457- if (x > 0) {
458- INT32 i1 = idx - bx - 1;
459- v[1] = DC[i1];
460- if (v[1] != NOT_CODED && DCP_T[mode[i1]] == type) {
461- t0 += DCP_W[0][1];
462- }
463- }
453+ v[0] = DC[i0];
454+ v[1] = DC[i1];
455+ v[2] = DC[i2];
464456
465- {
466- INT32 i2 = idx - bx;
467- v[2] = DC[i2];
468- if (v[2] != NOT_CODED && DCP_T[mode[i2]] == type) {
469- t0 += DCP_W[0][2];
470- }
471- }
457+ if (v[0] != NOT_CODED && DCP_T[mode[i0]] == type) {
458+ t0 += 1;
459+ }
460+ if (v[1] != NOT_CODED && DCP_T[mode[i1]] == type) {
461+ t0 += 2;
462+ }
463+ if (v[2] != NOT_CODED && DCP_T[mode[i2]] == type) {
464+ t0 += 4;
465+ }
472466
473- if (x < bx - 1) {
474- INT32 i3 = idx - bx + 1;
475- v[3] = DC[i3];
476- if (v[3] != NOT_CODED && DCP_T[mode[i3]] == type) {
477- t0 += DCP_W[0][3];
478- }
467+ if (idx < ni - 1) {
468+ INT32 i3 = idx - bx + 1;
469+ v[3] = DC[i3];
470+ if (v[3] != NOT_CODED && DCP_T[mode[i3]] == type) {
471+ t0 += 8;
479472 }
480473 }
481474
482- if (t0 > 0) {
483- pred =
484- ( v[0] * DCP_W[t0][0]
485- + v[1] * DCP_W[t0][1]
486- + v[2] * DCP_W[t0][2]
487- + v[3] * DCP_W[t0][3] ) / 128;
488-
489- if ((t0 & 0x7) == 7) {
490- INT32 d = pred - v[2]; /* D */
491- if (d < -128 || d > 128) {
492- pred = v[2];
493- } else if (d = pred - v[0], d < -128 || d > 128) { /* L */
494- pred = v[0];
495- } else if (d = pred - v[1], d < -128 || d > 128) { /* DL */
496- pred = v[1];
497- }
475+ switch (t0) {
476+ case 0:
477+ pred = last[type];
478+ break;
479+
480+ case 1:
481+ case 3:
482+ pred = v[0];
483+ break;
484+
485+ case 2:
486+ pred = v[1];
487+ break;
488+
489+ case 4:
490+ case 6:
491+ case 12:
492+ pred = v[2];
493+ break;
494+
495+ case 8:
496+ pred = v[3];
497+ break;
498+
499+ case 5:
500+ pred = (v[0] + v[2]) / 2;
501+ break;
502+
503+ case 9:
504+ case 11:
505+ case 13:
506+ pred = (75 * v[0] + 53 * v[3]) / 128;
507+ break;
508+
509+ case 10:
510+ pred = (v[1] + v[3]) / 2;
511+ break;
512+
513+ case 14:
514+ pred = (3 * (v[1] + v[3]) + 10 * v[2]) / 16;
515+ break;
516+
517+ case 7:
518+ case 15:
519+ pred = (29 * (v[0] + v[2]) - 26 * v[1]) / 32;
520+ if ((UINT32)(pred - v[2] + 128) > 256) { /* D */
521+ pred = v[2];
522+ } else if ((UINT32)(pred - v[0] + 128) > 256) { /* L */
523+ pred = v[0];
524+ } else if ((UINT32)(pred - v[1] + 128) > 256) { /* DL */
525+ pred = v[1];
498526 }
527+ break;
499528
500- } else {
501- pred = last[type];
529+ default:
530+ break;
502531 }
503532
504- dc += pred;
505-
506- DC[idx] = dc;
507-
508- last[type] = dc;
533+ last[type] = (DC[idx] += pred);
509534 }
510535 }
511536 }
Show on old repository browser