FFmpeg
texturedsp_template.c
Go to the documentation of this file.
1 /*
2  * Texture block compression and decompression
3  * Copyright (C) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  *
21  */
22 
23 #include "avcodec.h"
24 
25 static int exec_func(AVCodecContext *avctx, void *arg,
26  int slice, int thread_nb)
27 {
29  uint8_t *d = ctx->tex_data.out;
30  int w_block = ctx->width / TEXTURE_BLOCK_W;
31  int h_block = ctx->height / TEXTURE_BLOCK_H;
32  int x, y;
33  int start_slice, end_slice;
34  int base_blocks_per_slice = h_block / ctx->slice_count;
35  int remainder_blocks = h_block % ctx->slice_count;
36 
37  /* When the frame height (in blocks) doesn't divide evenly between the
38  * number of slices, spread the remaining blocks evenly between the first
39  * operations */
40  start_slice = slice * base_blocks_per_slice;
41  /* Add any extra blocks (one per slice) that have been added before this slice */
42  start_slice += FFMIN(slice, remainder_blocks);
43 
44  end_slice = start_slice + base_blocks_per_slice;
45  /* Add an extra block if there are still remainder blocks to be accounted for */
46  if (slice < remainder_blocks)
47  end_slice++;
48 
49  for (y = start_slice; y < end_slice; y++) {
50  uint8_t *p = ctx->frame_data.out + y * ctx->stride * TEXTURE_BLOCK_H;
51  int off = y * w_block;
52  for (x = 0; x < w_block; x++) {
53  ctx->TEXTUREDSP_TEX_FUNC(p + x * ctx->raw_ratio, ctx->stride,
54  d + (off + x) * ctx->tex_ratio);
55  }
56  }
57 
58  return 0;
59 }
60 
62 {
63  return avctx->execute2(avctx, exec_func, ctx, NULL, ctx->slice_count);
64 }
TEXTURE_BLOCK_H
#define TEXTURE_BLOCK_H
Definition: texturedsp.h:43
TextureDSPThreadContext
Definition: texturedsp.h:69
exec_func
static int exec_func(AVCodecContext *avctx, void *arg, int slice, int thread_nb)
Definition: texturedsp_template.c:25
ctx
AVFormatContext * ctx
Definition: movenc.c:48
arg
const char * arg
Definition: jacosubdec.c:67
NULL
#define NULL
Definition: coverity.c:32
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
TEXTURE_BLOCK_W
#define TEXTURE_BLOCK_W
Definition: texturedsp.h:42
avcodec.h
AVCodecContext
main external API structure.
Definition: avcodec.h:445
TEXTUREDSP_FUNC_NAME
int TEXTUREDSP_FUNC_NAME(AVCodecContext *avctx, TextureDSPThreadContext *ctx)
Definition: texturedsp_template.c:61
d
d
Definition: ffmpeg_filter.c:410
AVCodecContext::execute2
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
Definition: avcodec.h:1631