FFmpeg
texturedsp.h
Go to the documentation of this file.
1 /*
2  * Texture block module
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  * @file
24  * Texture block (4x4) module
25  *
26  * References:
27  * https://www.opengl.org/wiki/S3_Texture_Compression
28  * https://www.opengl.org/wiki/Red_Green_Texture_Compression
29  * https://msdn.microsoft.com/en-us/library/bb694531%28v=vs.85%29.aspx
30  *
31  * All functions return how much data has been written or read.
32  *
33  * Pixel input or output format is always AV_PIX_FMT_RGBA.
34  */
35 
36 #ifndef AVCODEC_TEXTUREDSP_H
37 #define AVCODEC_TEXTUREDSP_H
38 
39 #include <stddef.h>
40 #include <stdint.h>
41 
42 #define TEXTURE_BLOCK_W 4
43 #define TEXTURE_BLOCK_H 4
44 
45 typedef struct TextureDSPContext {
46  int (*dxt1_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
47  int (*dxt1a_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
48  int (*dxt2_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
49  int (*dxt3_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
50  int (*dxt4_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
51  int (*dxt5_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
52  int (*dxt5y_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
53  int (*dxt5ys_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
54  int (*rgtc1s_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
55  int (*rgtc1u_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
56  int (*rgtc1u_gray_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
57  int (*rgtc1u_alpha_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
58  int (*rgtc2s_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
59  int (*rgtc2u_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
60  int (*dxn3dc_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
62 
63 typedef struct TextureDSPEncContext {
64  int (*dxt1_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
65  int (*dxt5_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
66  int (*dxt5ys_block) (uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
68 
69 typedef struct TextureDSPThreadContext {
70  union {
71  const uint8_t *in; // Input frame data
72  uint8_t *out; // Output frame data
73  } frame_data;
74  ptrdiff_t stride; // Frame linesize
75  int width, height; // Frame width / height
76  union {
77  const uint8_t *in; // Compressed texture for decompression
78  uint8_t *out; // Compressed texture of compression
79  } tex_data;
80  int tex_ratio; // Number of compressed bytes in a texture block
81  int raw_ratio; // Number bytes in a line of a raw block
82  int slice_count; // Number of slices for threaded operations
83 
84  /* Pointer to the selected compress or decompress function. */
85  int (*tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
87 
90 
91 struct AVCodecContext;
96 
97 #endif /* AVCODEC_TEXTUREDSP_H */
TextureDSPContext::dxt1_block
int(* dxt1_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:46
TextureDSPContext::rgtc1u_alpha_block
int(* rgtc1u_alpha_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:57
TextureDSPContext::rgtc1u_gray_block
int(* rgtc1u_gray_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:56
TextureDSPContext::rgtc2s_block
int(* rgtc2s_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:58
TextureDSPThreadContext::tex_data
union TextureDSPThreadContext::@234 tex_data
TextureDSPContext::dxt2_block
int(* dxt2_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:48
TextureDSPContext::dxt5ys_block
int(* dxt5ys_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:53
TextureDSPEncContext
Definition: texturedsp.h:63
TextureDSPThreadContext::tex_ratio
int tex_ratio
Definition: texturedsp.h:80
TextureDSPContext
Definition: texturedsp.h:45
ff_texturedspenc_init
void ff_texturedspenc_init(TextureDSPEncContext *c)
Definition: texturedspenc.c:650
TextureDSPContext::rgtc1u_block
int(* rgtc1u_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:55
TextureDSPThreadContext::width
int width
Definition: texturedsp.h:75
TextureDSPThreadContext
Definition: texturedsp.h:69
TextureDSPContext::dxt5_block
int(* dxt5_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:51
TextureDSPContext::dxt1a_block
int(* dxt1a_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:47
TextureDSPThreadContext::out
uint8_t * out
Definition: texturedsp.h:72
ctx
AVFormatContext * ctx
Definition: movenc.c:49
TextureDSPContext::dxn3dc_block
int(* dxn3dc_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:60
TextureDSPThreadContext::stride
ptrdiff_t stride
Definition: texturedsp.h:74
TextureDSPContext::rgtc2u_block
int(* rgtc2u_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:59
TextureDSPContext::dxt4_block
int(* dxt4_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:50
TextureDSPThreadContext::height
int height
Definition: texturedsp.h:75
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ff_texturedsp_exec_decompress_threads
int ff_texturedsp_exec_decompress_threads(struct AVCodecContext *avctx, TextureDSPThreadContext *ctx)
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
ff_texturedsp_exec_compress_threads
int ff_texturedsp_exec_compress_threads(struct AVCodecContext *avctx, TextureDSPThreadContext *ctx)
TextureDSPContext::dxt5y_block
int(* dxt5y_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:52
TextureDSPThreadContext::slice_count
int slice_count
Definition: texturedsp.h:82
TextureDSPEncContext::dxt5ys_block
int(* dxt5ys_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:66
stride
#define stride
Definition: h264pred_template.c:537
AVCodecContext
main external API structure.
Definition: avcodec.h:451
TextureDSPEncContext::dxt1_block
int(* dxt1_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:64
TextureDSPContext::dxt3_block
int(* dxt3_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:49
TextureDSPThreadContext::tex_funct
int(* tex_funct)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:85
TextureDSPThreadContext::raw_ratio
int raw_ratio
Definition: texturedsp.h:81
ff_texturedsp_init
void ff_texturedsp_init(TextureDSPContext *c)
Definition: texturedsp.c:640
TextureDSPThreadContext::in
const uint8_t * in
Definition: texturedsp.h:71
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
TextureDSPEncContext::dxt5_block
int(* dxt5_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:65
TextureDSPContext::rgtc1s_block
int(* rgtc1s_block)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
Definition: texturedsp.h:54
TextureDSPThreadContext::frame_data
union TextureDSPThreadContext::@233 frame_data