[PATCH] Simplf decode_format80
Adam Iglewski
adam.iglewski
Thu May 7 00:09:49 CEST 2009
---
libavcodec/vqavideo.c | 118 ++++++++++++++++---------------------------------
1 files changed, 38 insertions(+), 80 deletions(-)
diff --git a/libavcodec/vqavideo.c b/libavcodec/vqavideo.c
index da2ff8f..3de8d88 100644
--- a/libavcodec/vqavideo.c
+++ b/libavcodec/vqavideo.c
@@ -199,103 +199,62 @@ static av_cold int vqa_decode_init(AVCodecContext *avctx)
return 0;
}
-#define CHECK_COUNT() \
- if (dest_index + count > dest_size) { \
- av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: next op would overflow dest_index\n"); \
- av_log(NULL, AV_LOG_ERROR, " VQA video: current dest_index = %d, count = %d, dest_size = %d\n", \
- dest_index, count, dest_size); \
+#define CHECK_PTR() \
+ if (dest + count > dest_end) { \
+ av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: next op would overflow dest buffer\n"); \
return; \
}
static void decode_format80(const unsigned char *src, int src_size,
unsigned char *dest, int dest_size, int check_size) {
- int src_index = 0;
- int dest_index = 0;
int new_format = 0;
int count;
int src_pos;
- unsigned char color;
- int i;
+ unsigned char code;
+ const unsigned char *from,*src_end = src+src_size;
+ unsigned char *dest_end = dest+dest_size;
- if (!src[src_index] || src_size > 0xffff) {
+ if (!*src || src_size > 0xffff) {
new_format = 1;
- src_index++;
+ src++;
}
- while (src_index < src_size) {
-
- vqa_debug(" opcode %02X: ", src[src_index]);
+ while (src < src_end) {
+ code = *src++;
/* 0x80 means that frame is finished */
- if (src[src_index] == 0x80)
+ if (code == 0x80)
return;
- if (dest_index >= dest_size) {
- av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: dest_index (%d) exceeded dest_size (%d)\n",
- dest_index, dest_size);
- return;
- }
-
- if (src[src_index] == 0xFF) {
-
- src_index++;
- count = AV_RL16(&src[src_index]);
- src_index += 2;
- src_pos = AV_RL16(&src[src_index]);
- if(new_format)
- src_pos = dest_index-src_pos;
- src_index += 2;
- vqa_debug("(1) copy %X bytes from absolute pos %X\n", count, src_pos);
- CHECK_COUNT();
- for (i = 0; i < count; i++)
- dest[dest_index + i] = dest[src_pos + i];
- dest_index += count;
-
- } else if (src[src_index] == 0xFE) {
-
- src_index++;
- count = AV_RL16(&src[src_index]);
- src_index += 2;
- color = src[src_index++];
- vqa_debug("(2) set %X bytes to %02X\n", count, color);
- CHECK_COUNT();
- memset(&dest[dest_index], color, count);
- dest_index += count;
-
- } else if ((src[src_index] & 0xC0) == 0xC0) {
-
- count = (src[src_index++] & 0x3F) + 3;
- src_pos = AV_RL16(&src[src_index]);
+ if(code == 0xFE) {
+ count = bytestream_get_le16(&src);
+ CHECK_PTR()
+ memset(dest, *src++, count);
+ dest += count;
+ continue;
+ } else if((code == 0xFF) || ((code & 0xC0) == 0xC0)) {
+ if(code == 0xFF)
+ count = bytestream_get_le16(&src);
+ else
+ count = (code & 0x3F) + 3;
+ src_pos = bytestream_get_le16(&src);
if(new_format)
- src_pos = dest_index-src_pos;
- src_index += 2;
- vqa_debug("(3) copy %X bytes from absolute pos %X\n", count, src_pos);
- CHECK_COUNT();
- for (i = 0; i < count; i++)
- dest[dest_index + i] = dest[src_pos + i];
- dest_index += count;
-
- } else if (src[src_index] > 0x80) {
-
- count = src[src_index++] & 0x3F;
- vqa_debug("(4) copy %X bytes from source to dest\n", count);
- CHECK_COUNT();
- memcpy(&dest[dest_index], &src[src_index], count);
- src_index += count;
- dest_index += count;
-
+ from = dest-src_pos;
+ else
+ from = dest_end-dest_size+src_pos;
+ } else if (code > 0x80) {
+ count = (code & 0x3F);
+ from = src;
+ src += count;
} else {
-
- count = ((src[src_index] & 0x70) >> 4) + 3;
- src_pos = AV_RB16(&src[src_index]) & 0x0FFF;
- src_index += 2;
- vqa_debug("(5) copy %X bytes from relpos %X\n", count, src_pos);
- CHECK_COUNT();
- for (i = 0; i < count; i++)
- dest[dest_index + i] = dest[dest_index - src_pos + i];
- dest_index += count;
+ count = ((code & 0x70) >> 4) + 3;
+ src_pos = ((code & 0x0F) << 8) | *src++;
+ from = dest-src_pos;
}
+ CHECK_PTR()
+ while(count--)
+ *dest++ = *from++;
}
/* validate that the entire destination buffer was filled; this is
@@ -303,9 +262,8 @@ static void decode_format80(const unsigned char *src, int src_size,
* codebook entry; it is not important for compressed codebooks because
* not every entry needs to be filled */
if (check_size)
- if (dest_index < dest_size)
- av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: decode finished with dest_index (%d) < dest_size (%d)\n",
- dest_index, dest_size);
+ if (dest < dest_end)
+ av_log(NULL, AV_LOG_ERROR, " VQA video: decode_format80 problem: decode finished with dest < dest_end\n");
}
static inline void vqa_copy_hc_block(uint16_t *pixels,int stride,const uint16_t *codebook,
--
1.6.0.4
--------------010706080102070000040602
Content-Type: text/x-diff;
name="0006-Simplify-vqa_decode_chunk.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="0006-Simplify-vqa_decode_chunk.patch"
More information about the ffmpeg-devel
mailing list