OSDN Git Service

cook: use a table for xor key rotation
authorMans Rullgard <mans@mansr.com>
Fri, 25 Nov 2011 20:43:05 +0000 (20:43 +0000)
committerMans Rullgard <mans@mansr.com>
Sat, 26 Nov 2011 11:38:41 +0000 (11:38 +0000)
This is simpler and avoids an invalid shift by 32 in the
aligned case.

Signed-off-by: Mans Rullgard <mans@mansr.com>
libavcodec/cook.c

index 186c3e7..8b0a351 100644 (file)
@@ -273,6 +273,10 @@ static av_cold void init_cplscales_table (COOKContext *q) {
  */
 
 static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){
+    static const uint32_t tab[4] = {
+        AV_BE2NE32C(0x37c511f2), AV_BE2NE32C(0xf237c511),
+        AV_BE2NE32C(0x11f237c5), AV_BE2NE32C(0xc511f237),
+    };
     int i, off;
     uint32_t c;
     const uint32_t* buf;
@@ -285,7 +289,7 @@ static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes)
 
     off = (intptr_t)inbuffer & 3;
     buf = (const uint32_t*) (inbuffer - off);
-    c = av_be2ne32((0x37c511f2 >> (off*8)) | (0x37c511f2 << (32-(off*8))));
+    c = tab[off];
     bytes += 3 + off;
     for (i = 0; i < bytes/4; i++)
         obuf[i] = c ^ buf[i];