Skip to content

Commit 26d1c7d

Browse files
committed
8svx: avoid custom clip, avoid +128 for compressed data.
Based on: commit e371878 Author: Justin Ruggles <justin.ruggles@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
1 parent 6eed92a commit 26d1c7d

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

libavcodec/8svx.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,31 +66,36 @@ static const int8_t exponential[16] = { -128, -64, -32, -16, -8, -4, -2, -1, 0,
6666
* @param table delta sequence table
6767
* @return size in bytes of the decoded data, must be src_size*2
6868
*/
69-
static int delta_decode(int8_t *dst, const uint8_t *src, int src_size,
70-
int8_t val, const int8_t *table)
69+
static int delta_decode(uint8_t *dst, const uint8_t *src, int src_size,
70+
unsigned val, const int8_t *table)
7171
{
72-
int n = src_size;
73-
int8_t *dst0 = dst;
72+
uint8_t *dst0 = dst;
7473

75-
while (n--) {
74+
while (src_size--) {
7675
uint8_t d = *src++;
77-
val = av_clip(val + table[d & 0x0f], -128, 127);
76+
val = av_clip_uint8(val + table[d & 0xF]);
7877
*dst++ = val;
79-
val = av_clip(val + table[d >> 4] , -128, 127);
78+
val = av_clip_uint8(val + table[d >> 4]);
8079
*dst++ = val;
8180
}
8281

8382
return dst-dst0;
8483
}
8584

85+
static void raw_decode(uint8_t *dst, const int8_t *src, int src_size)
86+
{
87+
while (src_size--)
88+
*dst++ = *src++ + 128;
89+
}
90+
8691
/** decode a frame */
8792
static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
8893
int *got_frame_ptr, AVPacket *avpkt)
8994
{
9095
EightSvxContext *esc = avctx->priv_data;
9196
int n, out_data_size;
9297
int ch, ret;
93-
uint8_t *src, *dst;
98+
uint8_t *src;
9499

95100
/* decode and interleave the first packet */
96101
if (!esc->samples && avpkt) {
@@ -122,13 +127,13 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
122127
/* the uncompressed starting value is contained in the first byte */
123128
dst = esc->samples;
124129
for (i = 0; i < avctx->channels; i++) {
125-
*(dst++) = buf[0];
126-
delta_decode(dst, buf + 1, buf_size / avctx->channels - 1, buf[0], esc->table);
130+
*(dst++) = buf[0]+128;
131+
delta_decode(dst, buf + 1, buf_size / avctx->channels - 1, (buf[0]+128)&0xFF, esc->table);
127132
buf += buf_size / avctx->channels;
128133
dst += n / avctx->channels - 1;
129134
}
130135
} else {
131-
memcpy(esc->samples, avpkt->data, esc->samples_size);
136+
raw_decode(esc->samples, avpkt->data, esc->samples_size);
132137
}
133138
}
134139

@@ -145,10 +150,8 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
145150

146151
out_data_size = esc->frame.nb_samples;
147152
for (ch = 0; ch<avctx->channels; ch++) {
148-
dst = esc->frame.data[ch];
149153
src = esc->samples + esc->samples_idx / avctx->channels + ch * esc->samples_size / avctx->channels;
150-
for (n = out_data_size; n > 0; n--)
151-
*dst++ = *src++ + 128;
154+
memcpy(esc->frame.data[ch], src, out_data_size);
152155
}
153156
out_data_size *= avctx->channels;
154157
esc->samples_idx += out_data_size;

0 commit comments

Comments
 (0)