static int decompress_texture_thread(AVCodecContext *avctx, void *arg, int block_nb, int thread_nb) { HapContext *ctx = avctx->priv_data; AVFrame *frame = arg; int x = (TEXTURE_BLOCK_W * block_nb) % avctx->coded_width; int y = TEXTURE_BLOCK_H * (TEXTURE_BLOCK_W * block_nb / avctx->coded_width); uint8_t *p = frame->data[0] + x * 4 + y * frame->linesize[0]; const uint8_t *d = ctx->tex_data + block_nb * ctx->tex_rat; ctx->tex_fun(p, frame->linesize[0], d); return 0; }
static void compress_texture(AVCodecContext *avctx, const AVFrame *f) { HapContext *ctx = avctx->priv_data; uint8_t *out = ctx->tex_buf; int i, j; for (j = 0; j < avctx->height; j += 4) { for (i = 0; i < avctx->width; i += 4) { uint8_t *p = f->data[0] + i * 4 + j * f->linesize[0]; const int step = ctx->tex_fun(out, f->linesize[0], p); out += step; } } }
static int compress_texture(AVCodecContext *avctx, uint8_t *out, int out_length, const AVFrame *f) { HapContext *ctx = avctx->priv_data; int i, j; if (ctx->tex_size > out_length) return AVERROR_BUFFER_TOO_SMALL; for (j = 0; j < avctx->height; j += 4) { for (i = 0; i < avctx->width; i += 4) { uint8_t *p = f->data[0] + i * 4 + j * f->linesize[0]; const int step = ctx->tex_fun(out, f->linesize[0], p); out += step; } } return 0; }
static int decompress_texture_thread(AVCodecContext *avctx, void *arg, int slice, int thread_nb) { HapContext *ctx = avctx->priv_data; AVFrame *frame = arg; const uint8_t *d = ctx->tex_data; int w_block = avctx->coded_width / TEXTURE_BLOCK_W; int h_block = avctx->coded_height / TEXTURE_BLOCK_H; int x, y; int start_slice, end_slice; int base_blocks_per_slice = h_block / ctx->slice_count; int remainder_blocks = h_block % ctx->slice_count; /* When the frame height (in blocks) doesn't divide evenly between the * number of slices, spread the remaining blocks evenly between the first * operations */ start_slice = slice * base_blocks_per_slice; /* Add any extra blocks (one per slice) that have been added before this slice */ start_slice += FFMIN(slice, remainder_blocks); end_slice = start_slice + base_blocks_per_slice; /* Add an extra block if there are still remainder blocks to be accounted for */ if (slice < remainder_blocks) end_slice++; for (y = start_slice; y < end_slice; y++) { uint8_t *p = frame->data[0] + y * frame->linesize[0] * TEXTURE_BLOCK_H; int off = y * w_block; for (x = 0; x < w_block; x++) { ctx->tex_fun(p + x * 16, frame->linesize[0], d + (off + x) * ctx->tex_rat); } } return 0; }