MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / xan_unpack

Function xan_unpack

libavcodec/xan.c:153–205  ·  view source on GitHub ↗

* unpack simple compression * * @param dest destination buffer of dest_len, must be padded with at least 130 bytes */

Source from the content-addressed store, hash-verified

151 * @param dest destination buffer of dest_len, must be padded with at least 130 bytes
152 */
153static void xan_unpack(uint8_t *dest, int dest_len,
154 const uint8_t *src, int src_len)
155{
156 uint8_t opcode;
157 int size;
158 uint8_t *dest_org = dest;
159 uint8_t *dest_end = dest + dest_len;
160 GetByteContext ctx;
161
162 bytestream2_init(&ctx, src, src_len);
163 while (dest < dest_end && bytestream2_get_bytes_left(&ctx)) {
164 opcode = bytestream2_get_byte(&ctx);
165
166 if (opcode < 0xe0) {
167 int size2, back;
168 if ((opcode & 0x80) == 0) {
169 size = opcode & 3;
170
171 back = ((opcode & 0x60) << 3) + bytestream2_get_byte(&ctx) + 1;
172 size2 = ((opcode & 0x1c) >> 2) + 3;
173 } else if ((opcode & 0x40) == 0) {
174 size = bytestream2_peek_byte(&ctx) >> 6;
175
176 back = (bytestream2_get_be16(&ctx) & 0x3fff) + 1;
177 size2 = (opcode & 0x3f) + 4;
178 } else {
179 size = opcode & 3;
180
181 back = ((opcode & 0x10) << 12) + bytestream2_get_be16(&ctx) + 1;
182 size2 = ((opcode & 0x0c) << 6) + bytestream2_get_byte(&ctx) + 5;
183 }
184
185 if (dest_end - dest < size + size2 ||
186 dest + size - dest_org < back ||
187 bytestream2_get_bytes_left(&ctx) < size)
188 return;
189 bytestream2_get_buffer(&ctx, dest, size);
190 dest += size;
191 av_memcpy_backptr(dest, back, size2);
192 dest += size2;
193 } else {
194 int finish = opcode >= 0xfc;
195 size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4;
196
197 if (dest_end - dest < size || bytestream2_get_bytes_left(&ctx) < size)
198 return;
199 bytestream2_get_buffer(&ctx, dest, size);
200 dest += size;
201 if (finish)
202 return;
203 }
204 }
205}
206
207static inline void xan_wc3_output_pixel_run(XanContext *s, AVFrame *frame,
208 const uint8_t *pixel_buffer, int x, int y, int pixel_count)

Callers 1

xan_wc3_decode_frameFunction · 0.70

Calls 4

bytestream2_initFunction · 0.85
bytestream2_get_bufferFunction · 0.85
av_memcpy_backptrFunction · 0.85

Tested by

no test coverage detected