1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Texture block compression and decompression
3cabdff1aSopenharmony_ci * Copyright (C) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
4cabdff1aSopenharmony_ci *
5cabdff1aSopenharmony_ci * This file is part of FFmpeg.
6cabdff1aSopenharmony_ci *
7cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
8cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
9cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
10cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
11cabdff1aSopenharmony_ci *
12cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
13cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
14cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15cabdff1aSopenharmony_ci * Lesser General Public License for more details.
16cabdff1aSopenharmony_ci *
17cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
18cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
19cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20cabdff1aSopenharmony_ci *
21cabdff1aSopenharmony_ci */
22cabdff1aSopenharmony_ci
23cabdff1aSopenharmony_ciint TEXTUREDSP_FUNC_NAME(AVCodecContext *avctx, void *arg,
24cabdff1aSopenharmony_ci                         int slice, int thread_nb)
25cabdff1aSopenharmony_ci{
26cabdff1aSopenharmony_ci    TextureDSPThreadContext *ctx = arg;
27cabdff1aSopenharmony_ci    uint8_t *d = ctx->tex_data.out;
28cabdff1aSopenharmony_ci    int w_block = avctx->coded_width / TEXTURE_BLOCK_W;
29cabdff1aSopenharmony_ci    int h_block = avctx->coded_height / TEXTURE_BLOCK_H;
30cabdff1aSopenharmony_ci    int x, y;
31cabdff1aSopenharmony_ci    int start_slice, end_slice;
32cabdff1aSopenharmony_ci    int base_blocks_per_slice = h_block / ctx->slice_count;
33cabdff1aSopenharmony_ci    int remainder_blocks = h_block % ctx->slice_count;
34cabdff1aSopenharmony_ci
35cabdff1aSopenharmony_ci    /* When the frame height (in blocks) doesn't divide evenly between the
36cabdff1aSopenharmony_ci     * number of slices, spread the remaining blocks evenly between the first
37cabdff1aSopenharmony_ci     * operations */
38cabdff1aSopenharmony_ci    start_slice = slice * base_blocks_per_slice;
39cabdff1aSopenharmony_ci    /* Add any extra blocks (one per slice) that have been added before this slice */
40cabdff1aSopenharmony_ci    start_slice += FFMIN(slice, remainder_blocks);
41cabdff1aSopenharmony_ci
42cabdff1aSopenharmony_ci    end_slice = start_slice + base_blocks_per_slice;
43cabdff1aSopenharmony_ci    /* Add an extra block if there are still remainder blocks to be accounted for */
44cabdff1aSopenharmony_ci    if (slice < remainder_blocks)
45cabdff1aSopenharmony_ci        end_slice++;
46cabdff1aSopenharmony_ci
47cabdff1aSopenharmony_ci    for (y = start_slice; y < end_slice; y++) {
48cabdff1aSopenharmony_ci        uint8_t *p = ctx->frame_data.out + y * ctx->stride * TEXTURE_BLOCK_H;
49cabdff1aSopenharmony_ci        int off = y * w_block;
50cabdff1aSopenharmony_ci        for (x = 0; x < w_block; x++) {
51cabdff1aSopenharmony_ci            ctx->TEXTUREDSP_TEX_FUNC(p + x * ctx->raw_ratio, ctx->stride,
52cabdff1aSopenharmony_ci                                     d + (off + x) * ctx->tex_ratio);
53cabdff1aSopenharmony_ci        }
54cabdff1aSopenharmony_ci    }
55cabdff1aSopenharmony_ci
56cabdff1aSopenharmony_ci    return 0;
57cabdff1aSopenharmony_ci}
58