Commits

Anonymous committed 198ad9e

some texcrc changes, don't know if they work

  • Participants
  • Parent commits 7f1ae43

Comments (0)

Files changed (2)

   ~TxDbg();
   void output(const int level, const wchar_t *format, ...);
 };
-
+#define DEBUG 1
 #ifdef DEBUG
 #define DBG_INFO TxDbg::getInstance()->output
 #define INFO DBG_INFO

GlideHQ/TxUtil.cpp

 #include "TxDbg.h"
 #include <zlib.h>
 #include <stdlib.h>
-//#include <malloc.h>
+#include <math.h>
+//#include <malloc.h>
 
 /*
  * External libraries
 uint32
 TxUtil::RiceCRC32(const uint8* src, int width, int height, int size, int rowStride)
 {
-  /* NOTE: bytes_per_width must be equal or larger than 4 */
+    /* NOTE: bytes_per_width must be equal or larger than 4 */
+    const uint32 bytes_per_width = ((width << size) + 1) >> 1;
 
-  uint32 crc32Ret = 0;
-  const uint32 bytes_per_width = ((width << size) + 1) >> 1;
-
-  /*if (bytes_per_width < 4) return 0;*/
-
-  try {
-#ifdef __MSC__
-    __asm {
-      push ebx;
-      push esi;
-      push edi;
-
-      mov ecx, dword ptr [src];
-      mov eax, dword ptr [height];
-      mov edx, 0;
-      dec eax;
-
-    loop2:
-      mov ebx, dword ptr [bytes_per_width];
-      sub ebx, 4;
-
-    loop1:
-      mov esi, dword ptr [ecx+ebx];
-      xor esi, ebx;
-      rol edx, 4;
-      add edx, esi;
-      sub ebx, 4;
-      jge loop1;
-
-      xor esi, eax;
-      add edx, esi;
-      add ecx, dword ptr [rowStride];
-      dec eax;
-      jge loop2;
-
-      mov dword ptr [crc32Ret], edx;
-
-      pop edi;
-      pop esi;
-      pop ebx;
+    unsigned int bogusCRC = 0;
+    for (int y = height - 1; y >= 0; y--)
+    {
+        unsigned int curW;
+        for (int x = bytes_per_width - 4; x >= 0; x -= 4)
+        {
+            curW = *((unsigned int *) (src + x));
+            curW = curW ^ x;
+            bogusCRC = (bogusCRC << 4) | (bogusCRC >> 28);
+            bogusCRC += curW;
+        }
+        curW = curW ^ y;
+        bogusCRC += curW;
+        src += rowStride;
     }
-#else
-    asm volatile(
-      "pushl %%ebx \n"
-      "pushl %%esi \n"
-      "pushl %%edi \n"
-
-      "movl %0, %%ecx \n"
-      "movl %1, %%eax \n"
-      "movl $0, %%edx \n"
-      "decl %%eax \n"
-
-      "0: \n"
-      "movl %2, %%ebx \n"
-      "subl $4, %%ebx \n"
-
-      "1: \n"
-      "movl (%%ecx,%%ebx), %%esi \n"
-      "xorl %%ebx, %%esi \n"
-      "roll $4, %%edx \n"
-      "addl %%esi, %%edx \n"
-      "subl $4, %%ebx \n"
-      "jge  1b \n"
-
-      "xorl %%eax, %%esi \n"
-      "addl %%esi, %%edx \n"
-      "addl %3, %%ecx \n"
-      "decl %%eax \n"
-      "jge  0b \n"
-
-      "movl %%edx, %4 \n"
-
-      "popl %%edi \n"
-      "popl %%esi \n"
-      "popl %%ebx \n"
-      :
-      : "m"(src), "m"(height), "m"(bytes_per_width), "m"(rowStride), "m"(crc32Ret)
-      : "memory", "cc"
-      );
-#endif
-  } catch(...) {
-    DBG_INFO(80, L"Error: RiceCRC32 exception!\n");
-  }
-
-  return crc32Ret;
+    return bogusCRC;
 }
 
-boolean
-TxUtil::RiceCRC32_CI4(const uint8* src, int width, int height, int size, int rowStride,
+
+boolean TxUtil::RiceCRC32_CI4(const uint8* src, int width, int height, int size, int rowStride,
                         uint32* crc32, uint32* cimax)
 {
-  /* NOTE: bytes_per_width must be equal or larger than 4 */
+    /* NOTE: bytes_per_width must be equal or larger than 4 */
 
-  uint32 crc32Ret = 0;
-  uint32 cimaxRet = 0;
-  const uint32 bytes_per_width = ((width << size) + 1) >> 1;
+    uint32 cimaxRet = 0;
+    const uint32 bytes_per_width = ((width << size) + 1) >> 1;
 
-  /*if (bytes_per_width < 4) return 0;*/
+    uint32 bogusCRC = 0;
+    for (int y = height - 1; y >= 0; y--)
+    {
+        uint32 curW;
+        for (int x = bytes_per_width - 4; x >= 0; x -= 4)
+        {
+            curW = *((unsigned int *) (src + x));
+            uint32 curW2 = curW;
+            for (int z = 0; z < 8; z++)
+            {
+                int curN = (curW2 & 0x0f);
+                curW2 >>= 4;
+                int mask = (int) (curN - cimaxRet) >> 4;
+                cimaxRet = (cimaxRet & mask) | (curN & (~mask));
+            }
+            curW = curW ^ x;
+            bogusCRC = (bogusCRC << 4) | (bogusCRC >> 28);
+            bogusCRC += curW;
+        }
+        curW = curW ^ y;
+        bogusCRC += curW;
+        src += rowStride;
+    }
 
-  /* 4bit CI */
-  try {
-#ifdef __MSC__
-    __asm {
-      push ebx;
-      push esi;
-      push edi;
-
-      mov ecx, dword ptr [src];
-      mov eax, dword ptr [height];
-      mov edx, 0;
-      mov edi, 0;
-      dec eax;
-
-    loop2:
-      mov ebx, dword ptr [bytes_per_width];
-      sub ebx, 4;
-
-    loop1:
-      mov esi, dword ptr [ecx+ebx];
-
-      cmp edi, 0x0000000f;
-      je findmax0;
-
-      push ecx;
-      mov ecx, esi;
-      and ecx, 0x0000000f;
-      cmp ecx, edi;
-      jb  findmax8;
-      mov edi, ecx;
-
-    findmax8:
-      mov ecx, esi;
-      shr ecx, 4;
-      and ecx, 0x0000000f;
-      cmp ecx, edi;
-      jb  findmax7;
-      mov edi, ecx;
-
-    findmax7:
-      mov ecx, esi;
-      shr ecx, 8;
-      and ecx, 0x0000000f;
-      cmp ecx, edi;
-      jb  findmax6;
-      mov edi, ecx;
-
-    findmax6:
-      mov ecx, esi;
-      shr ecx, 12;
-      and ecx, 0x0000000f;
-      cmp ecx, edi;
-      jb  findmax5;
-      mov edi, ecx;
-
-    findmax5:
-      mov ecx, esi;
-      shr ecx, 16;
-      and ecx, 0x0000000f;
-      cmp ecx, edi;
-      jb  findmax4;
-      mov edi, ecx;
-
-    findmax4:
-      mov ecx, esi;
-      shr ecx, 20;
-      and ecx, 0x0000000f;
-      cmp ecx, edi;
-      jb  findmax3;
-      mov edi, ecx;
-
-    findmax3:
-      mov ecx, esi;
-      shr ecx, 24;
-      and ecx, 0x0000000f;
-      cmp ecx, edi;
-      jb  findmax2;
-      mov edi, ecx;
-
-    findmax2:
-      mov ecx, esi;
-      shr ecx, 28;
-      and ecx, 0x0000000f;
-      cmp ecx, edi;
-      jb  findmax1;
-      mov edi, ecx;
-
-    findmax1:
-      pop ecx;
-
-    findmax0:
-      xor esi, ebx;
-      rol edx, 4;
-      add edx, esi;
-      sub ebx, 4;
-      jge loop1;
-
-      xor esi, eax;
-      add edx, esi;
-      add ecx, dword ptr [rowStride];
-      dec eax;
-      jge loop2;
-
-      mov dword ptr [crc32Ret], edx;
-      mov dword ptr [cimaxRet], edi;
-
-      pop edi;
-      pop esi;
-      pop ebx;
-    }
-#else
-    asm volatile(
-      "pushl %%ebx \n"
-      "pushl %%esi \n"
-      "pushl %%edi \n"
-
-      "movl %0, %%ecx \n"
-      "movl %1, %%eax \n"
-      "movl $0, %%edx \n"
-      "movl $0, %%edi \n"
-      "decl %%eax \n"
-
-      "0: \n"
-      "movl %2, %%ebx \n"
-      "subl $4, %%ebx \n"
-
-      "1: \n"
-      "movl (%%ecx,%%ebx), %%esi \n"
-
-      "cmpl $0x0000000f, %%edi \n"
-      "je  10f \n"
-
-      "pushl %%ecx \n"
-      "movl %%esi, %%ecx \n"
-      "andl $0x0000000f, %%ecx \n"
-      "cmpl %%edi, %%ecx \n"
-      "jb   2f \n"
-      "movl %%ecx, %%edi \n"
-
-      "2: \n"
-      "movl %%esi, %%ecx \n"
-      "shrl $4, %%ecx \n"
-      "andl $0x0000000f, %%ecx \n"
-      "cmpl %%edi, %%ecx \n"
-      "jb   3f \n"
-      "movl %%ecx, %%edi \n"
-
-      "3: \n"
-      "movl %%esi, %%ecx \n"
-      "shrl $8, %%ecx \n"
-      "andl $0x0000000f, %%ecx \n"
-      "cmpl %%edi, %%ecx \n"
-      "jb   4f \n"
-      "movl %%ecx, %%edi \n"
-
-      "4: \n"
-      "movl %%esi, %%ecx \n"
-      "shrl $12, %%ecx \n"
-      "andl $0x0000000f, %%ecx \n"
-      "cmpl %%edi, %%ecx \n"
-      "jb   5f \n"
-      "movl %%ecx, %%edi \n"
-
-      "5: \n"
-      "movl %%esi, %%ecx \n"
-      "shrl $16, %%ecx \n"
-      "andl $0x0000000f, %%ecx \n"
-      "cmpl %%edi, %%ecx \n"
-      "jb   6f \n"
-      "movl %%ecx, %%edi \n"
-
-      "6: \n"
-      "movl %%esi, %%ecx \n"
-      "shrl $20, %%ecx \n"
-      "andl $0x0000000f, %%ecx \n"
-      "cmpl %%edi, %%ecx \n"
-      "jb   7f \n"
-      "movl %%ecx, %%edi \n"
-
-      "7: \n"
-      "movl %%esi, %%ecx \n"
-      "shrl $24, %%ecx \n"
-      "andl $0x0000000f, %%ecx \n"
-      "cmpl %%edi, %%ecx \n"
-      "jb   8f \n"
-      "movl %%ecx, %%edi \n"
-
-      "8: \n"
-      "movl %%esi, %%ecx \n"
-      "shrl $28, %%ecx \n"
-      "andl $0x0000000f, %%ecx \n"
-      "cmpl %%edi, %%ecx \n"
-      "jb   9f \n"
-      "movl %%ecx, %%edi \n"
-
-      "9: \n"
-      "popl %%ecx \n"
-
-      "10: \n"
-      "xorl %%ebx, %%esi \n"
-      "roll $4, %%edx \n"
-      "addl %%esi, %%edx \n"
-      "subl $4, %%ebx \n"
-      "jge  1b \n"
-
-      "xorl %%eax, %%esi \n"
-      "addl %%esi, %%edx \n"
-      "addl %3, %%ecx \n"
-      "decl %%eax \n"
-      "jge  0b \n"
-
-      "movl %%edx, %4 \n"
-      "movl %%edi, %5 \n"
-
-      "popl %%edi \n"
-      "popl %%esi \n"
-      "popl %%ebx \n"
-      :
-      : "m"(src), "m"(height), "m"(bytes_per_width), "m"(rowStride), "m"(crc32Ret), "m"(cimaxRet)
-      : "memory", "cc"
-      );
-#endif
-  } catch(...) {
-    DBG_INFO(80, L"Error: RiceCRC32 exception!\n");
-  }
-
-  *crc32 = crc32Ret;
-  *cimax = cimaxRet;
-
-  return 1;
+    *crc32 = bogusCRC;
+    *cimax = cimaxRet;
+    return 1;
 }
-
 boolean
 TxUtil::RiceCRC32_CI8(const uint8* src, int width, int height, int size, int rowStride,
                       uint32* crc32, uint32* cimax)
 {
   int i = 0;
 
-#if 1
+#if 0
   if (!num) return 0;
 #ifdef __MSC__
   __asm {
 #endif
 #else
   switch (num) {
-    case 1:    return 0;
-    case 2:    return 1;
-    case 4:    return 2;
-    case 8:    return 3;
-    case 16:   return 4;
-    case 32:   return 5;
-    case 64:   return 6;
-    case 128:  return 7;
-    case 256:  return 8;
-    case 512:  return 9;
-    case 1024:  return 10;
-    case 2048:  return 11;
+    case 1:    return 0;   break;
+    case 2:    return 1;   break;
+    case 4:    return 2;   break;
+    case 8:    return 3;   break;
+    case 16:   return 4;   break;
+    case 32:   return 5;   break;
+    case 64:   return 6;   break;
+    case 128:  return 7;   break;
+    case 256:  return 8;   break;
+    case 512:  return 9;   break;
+    case 1024:  return 10; break; 
+    case 2048:  return 11; break; 
+    default: return (int)(log2((double)(num)));
   }
 #endif