* unpack simple compression * * @param dest destination buffer of dest_len, must be padded with at least 130 bytes */
| 151 | * @param dest destination buffer of dest_len, must be padded with at least 130 bytes |
| 152 | */ |
| 153 | static 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 | |
| 207 | static inline void xan_wc3_output_pixel_run(XanContext *s, AVFrame *frame, |
| 208 | const uint8_t *pixel_buffer, int x, int y, int pixel_count) |
no test coverage detected