openjpeg-20070719svn-mqc-more-optimize.patch 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. diff -urN -x '*.orig' -x '*.rej' -x '*~' -x '.*' OpenJPEG.orig/libopenjpeg/mqc.c OpenJPEG.patched/libopenjpeg/mqc.c
  2. --- OpenJPEG.orig/libopenjpeg/mqc.c 2007-08-06 16:16:00.000000000 -0500
  3. +++ OpenJPEG.patched/libopenjpeg/mqc.c 2007-08-06 19:07:28.000000000 -0500
  4. @@ -68,13 +68,13 @@
  5. @param mqc MQC handle
  6. @return
  7. */
  8. -static int mqc_mpsexchange(opj_mqc_t *mqc);
  9. +//static int mqc_mpsexchange(opj_mqc_t *mqc);
  10. /**
  11. FIXME: documentation ???
  12. @param mqc MQC handle
  13. @return
  14. */
  15. -static int mqc_lpsexchange(opj_mqc_t *mqc);
  16. +//static int mqc_lpsexchange(opj_mqc_t *mqc);
  17. /**
  18. Input a byte
  19. @param mqc MQC handle
  20. @@ -271,33 +271,22 @@
  21. }
  22. }
  23. +/*
  24. static int mqc_mpsexchange(opj_mqc_t *mqc) {
  25. - int d;
  26. - if (mqc->a < (*mqc->curctx)->qeval) {
  27. - d = 1 - (*mqc->curctx)->mps;
  28. - *mqc->curctx = (*mqc->curctx)->nlps;
  29. - } else {
  30. - d = (*mqc->curctx)->mps;
  31. - *mqc->curctx = (*mqc->curctx)->nmps;
  32. - }
  33. -
  34. - return d;
  35. + int d = (*mqc->curctx)->mps;
  36. + int tmp = (mqc->a < (*mqc->curctx)->qeval);
  37. + *mqc->curctx = tmp ? (*mqc->curctx)->nlps : (*mqc->curctx)->nmps;
  38. + return tmp ^ d;
  39. }
  40. static int mqc_lpsexchange(opj_mqc_t *mqc) {
  41. - int d;
  42. - if (mqc->a < (*mqc->curctx)->qeval) {
  43. - mqc->a = (*mqc->curctx)->qeval;
  44. - d = (*mqc->curctx)->mps;
  45. - *mqc->curctx = (*mqc->curctx)->nmps;
  46. - } else {
  47. - mqc->a = (*mqc->curctx)->qeval;
  48. - d = 1 - (*mqc->curctx)->mps;
  49. - *mqc->curctx = (*mqc->curctx)->nlps;
  50. - }
  51. -
  52. - return d;
  53. + int d = (*mqc->curctx)->mps;
  54. + int tmp = !(mqc->a < (*mqc->curctx)->qeval);
  55. + mqc->a = (*mqc->curctx)->qeval;
  56. + *mqc->curctx = tmp ? (*mqc->curctx)->nlps : (*mqc->curctx)->nmps;
  57. + return tmp ^ d;
  58. }
  59. +*/
  60. static void mqc_bytein(opj_mqc_t *mqc) {
  61. if (mqc->bp != mqc->end) {
  62. @@ -506,22 +495,27 @@
  63. }
  64. int mqc_decode(opj_mqc_t *mqc) {
  65. - int d;
  66. unsigned int qeval = (*mqc->curctx)->qeval;
  67. mqc->a -= qeval;
  68. + bool tmp = (mqc->a < qeval);
  69. qeval <<= 16;
  70. - if (mqc->c < qeval) {
  71. - d = mqc_lpsexchange(mqc);
  72. - } else {
  73. + if (mqc->c >= qeval) {
  74. mqc->c -= qeval;
  75. - if ((mqc->a & 0x8000) == 0) {
  76. - d = mqc_mpsexchange(mqc);
  77. - } else {
  78. + if (mqc->a & 0x8000) {
  79. return (*mqc->curctx)->mps;
  80. }
  81. + }else{
  82. + tmp = !tmp;
  83. + mqc->a = (*mqc->curctx)->qeval;
  84. }
  85. +
  86. + opj_mqc_state_t* nmps = (*mqc->curctx)->nmps;
  87. + opj_mqc_state_t* nlps = (*mqc->curctx)->nlps;
  88. + int mps = (*mqc->curctx)->mps ^ tmp;
  89. + *mqc->curctx = tmp ? nlps : nmps;
  90. +
  91. mqc_renormd(mqc);
  92. - return d;
  93. + return mps;
  94. }
  95. void mqc_resetstates(opj_mqc_t *mqc) {