Avoid some code duplication in xan_unpack

Originally committed as revision 18586 to svn://svn.ffmpeg.org/ffmpeg/trunk
release/0.6
Reimar Döffinger 16 years ago
parent f371abe4a8
commit 948f60fa24
  1. 28
      libavcodec/xan.c

@ -135,16 +135,16 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
while (dest < dest_end) { while (dest < dest_end) {
opcode = *src++; opcode = *src++;
if (opcode < 0xe0) {
int size2, back;
if ( (opcode & 0x80) == 0 ) { if ( (opcode & 0x80) == 0 ) {
offset = *src++; offset = *src++;
size = opcode & 3; size = opcode & 3;
memcpy(dest, src, size); dest += size; src += size;
size = ((opcode & 0x1c) >> 2) + 3; size2 = ((opcode & 0x1c) >> 2) + 3;
av_memcpy_backptr(dest, ((opcode & 0x60) << 3) + offset + 1, size); back = ((opcode & 0x60) << 3) + offset + 1;
dest += size;
} else if ( (opcode & 0x40) == 0 ) { } else if ( (opcode & 0x40) == 0 ) {
@ -152,28 +152,26 @@ static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_l
byte2 = *src++; byte2 = *src++;
size = byte1 >> 6; size = byte1 >> 6;
memcpy(dest, src, size); dest += size; src += size;
size = (opcode & 0x3f) + 4; size2 = (opcode & 0x3f) + 4;
av_memcpy_backptr(dest, ((byte1 & 0x3f) << 8) + byte2 + 1, size); back = ((byte1 & 0x3f) << 8) + byte2 + 1;
dest += size;
} else if ( (opcode & 0x20) == 0 ) { } else {
byte1 = *src++; byte1 = *src++;
byte2 = *src++; byte2 = *src++;
byte3 = *src++; byte3 = *src++;
size = opcode & 3; size = opcode & 3;
memcpy(dest, src, size); dest += size; src += size;
size = byte3 + 5 + ((opcode & 0xc) << 6); size2 = byte3 + 5 + ((opcode & 0xc) << 6);
back = ((opcode & 0x10) << 12) + 1 + (byte1 << 8) + byte2;
if (dest >= dest_end || size > dest_end - dest) if (dest >= dest_end || size > dest_end - dest)
return; return;
av_memcpy_backptr(dest, }
((opcode & 0x10) << 12) + 1 + (byte1 << 8) + byte2, memcpy(dest, src, size); dest += size; src += size;
size); av_memcpy_backptr(dest, back, size2);
dest += size; dest += size2;
} else { } else {
size = ((opcode & 0x1f) << 2) + 4; size = ((opcode & 0x1f) << 2) + 4;

Loading…
Cancel
Save