FFmpeg
Macros | Functions | Variables
texturedspenc.c File Reference
#include <stddef.h>
#include <stdint.h>
#include "libavutil/attributes.h"
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "texturedsp.h"

Go to the source code of this file.

Macros

#define mul8(a, b)   (((a) * (b) + 128 + (((a) * (b) + 128) >> 8)) >> 8)
 
#define rgb2rgb565(r, g, b)   ((mul8(r, 31) << 11) | (mul8(g, 63) << 5) | (mul8(b, 31) << 0))
 
#define lerp13(a, b)   ((2 * (a) + (b)) / 3)
 

Functions

static void lerp13rgb (uint8_t *out, uint8_t *p1, uint8_t *p2)
 
static void rgb5652rgb (uint8_t *out, uint16_t v)
 
static unsigned int match_colors (const uint8_t *block, ptrdiff_t stride, uint16_t c0, uint16_t c1)
 
static void optimize_colors (const uint8_t *block, ptrdiff_t stride, uint16_t *pmax16, uint16_t *pmin16)
 
static int refine_colors (const uint8_t *block, ptrdiff_t stride, uint16_t *pmax16, uint16_t *pmin16, uint32_t mask)
 
static int constant_color (const uint8_t *block, ptrdiff_t stride)
 
static void compress_color (uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
 
static void compress_alpha (uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
 
static void rgba2ycocg (uint8_t *dst, const uint8_t *pixel)
 Convert a RGBA buffer to unscaled YCoCg. More...
 
static int dxt1_block (uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
 Compress one block of RGBA pixels in a DXT1 texture and store the resulting bytes in 'dst'. More...
 
static int dxt5_block (uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
 Compress one block of RGBA pixels in a DXT5 texture and store the resulting bytes in 'dst'. More...
 
static int dxt5ys_block (uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
 Compress one block of RGBA pixels in a DXT5-YCoCg texture and store the resulting bytes in 'dst'. More...
 
static int rgtc1u_alpha_block (uint8_t *dst, ptrdiff_t stride, const uint8_t *block)
 Compress one block of RGBA pixels in a RGTC1U texture and store the resulting bytes in 'dst'. More...
 
av_cold void ff_texturedspenc_init (TextureDSPContext *c)
 

Variables

static const uint8_t expand5 [32]
 
static const uint8_t expand6 [64]
 
static const uint8_t match5 [256][2]
 
static const uint8_t match6 [256][2]
 

Macro Definition Documentation

◆ mul8

#define mul8 (   a,
  b 
)    (((a) * (b) + 128 + (((a) * (b) + 128) >> 8)) >> 8)

Definition at line 143 of file texturedspenc.c.

◆ rgb2rgb565

#define rgb2rgb565 (   r,
  g,
  b 
)    ((mul8(r, 31) << 11) | (mul8(g, 63) << 5) | (mul8(b, 31) << 0))

Definition at line 146 of file texturedspenc.c.

◆ lerp13

#define lerp13 (   a,
  b 
)    ((2 * (a) + (b)) / 3)

Definition at line 150 of file texturedspenc.c.

Function Documentation

◆ lerp13rgb()

static void lerp13rgb ( uint8_t *  out,
uint8_t *  p1,
uint8_t *  p2 
)
inlinestatic

Definition at line 153 of file texturedspenc.c.

Referenced by match_colors().

◆ rgb5652rgb()

static void rgb5652rgb ( uint8_t *  out,
uint16_t  v 
)
inlinestatic

Definition at line 161 of file texturedspenc.c.

Referenced by match_colors().

◆ match_colors()

static unsigned int match_colors ( const uint8_t *  block,
ptrdiff_t  stride,
uint16_t  c0,
uint16_t  c1 
)
static

Definition at line 174 of file texturedspenc.c.

Referenced by compress_color().

◆ optimize_colors()

static void optimize_colors ( const uint8_t *  block,
ptrdiff_t  stride,
uint16_t *  pmax16,
uint16_t *  pmin16 
)
static

Definition at line 237 of file texturedspenc.c.

Referenced by compress_color().

◆ refine_colors()

static int refine_colors ( const uint8_t *  block,
ptrdiff_t  stride,
uint16_t *  pmax16,
uint16_t *  pmin16,
uint32_t  mask 
)
static

Definition at line 350 of file texturedspenc.c.

Referenced by compress_color().

◆ constant_color()

static int constant_color ( const uint8_t *  block,
ptrdiff_t  stride 
)
static

Definition at line 440 of file texturedspenc.c.

Referenced by compress_color().

◆ compress_color()

static void compress_color ( uint8_t *  dst,
ptrdiff_t  stride,
const uint8_t *  block 
)
static

Definition at line 453 of file texturedspenc.c.

Referenced by dxt1_block(), dxt5_block(), and dxt5ys_block().

◆ compress_alpha()

static void compress_alpha ( uint8_t *  dst,
ptrdiff_t  stride,
const uint8_t *  block 
)
static

Definition at line 499 of file texturedspenc.c.

Referenced by dxt5_block(), dxt5ys_block(), and rgtc1u_alpha_block().

◆ rgba2ycocg()

static void rgba2ycocg ( uint8_t *  dst,
const uint8_t *  pixel 
)
static

Convert a RGBA buffer to unscaled YCoCg.

Scale is usually introduced to avoid banding over a certain range of colors, but this version of the algorithm does not introduce it as much as other implementations, allowing for a simpler and faster conversion.

Definition at line 579 of file texturedspenc.c.

Referenced by dxt5ys_block().

◆ dxt1_block()

static int dxt1_block ( uint8_t *  dst,
ptrdiff_t  stride,
const uint8_t *  block 
)
static

Compress one block of RGBA pixels in a DXT1 texture and store the resulting bytes in 'dst'.

Alpha is not preserved.

Parameters
dstoutput buffer.
stridescanline in bytes.
blockblock to compress.
Returns
how much texture data has been written.

Definition at line 601 of file texturedspenc.c.

Referenced by ff_texturedspenc_init().

◆ dxt5_block()

static int dxt5_block ( uint8_t *  dst,
ptrdiff_t  stride,
const uint8_t *  block 
)
static

Compress one block of RGBA pixels in a DXT5 texture and store the resulting bytes in 'dst'.

Alpha is preserved.

Parameters
dstoutput buffer.
stridescanline in bytes.
blockblock to compress.
Returns
how much texture data has been written.

Definition at line 617 of file texturedspenc.c.

Referenced by ff_texturedspenc_init().

◆ dxt5ys_block()

static int dxt5ys_block ( uint8_t *  dst,
ptrdiff_t  stride,
const uint8_t *  block 
)
static

Compress one block of RGBA pixels in a DXT5-YCoCg texture and store the resulting bytes in 'dst'.

Alpha is not preserved.

Parameters
dstoutput buffer.
stridescanline in bytes.
blockblock to compress.
Returns
how much texture data has been written.

Definition at line 634 of file texturedspenc.c.

Referenced by ff_texturedspenc_init().

◆ rgtc1u_alpha_block()

static int rgtc1u_alpha_block ( uint8_t *  dst,
ptrdiff_t  stride,
const uint8_t *  block 
)
static

Compress one block of RGBA pixels in a RGTC1U texture and store the resulting bytes in 'dst'.

Use the alpha channel of the input image.

Parameters
dstoutput buffer.
stridescanline in bytes.
blockblock to compress.
Returns
how much texture data has been written.

Definition at line 659 of file texturedspenc.c.

Referenced by ff_texturedspenc_init().

◆ ff_texturedspenc_init()

av_cold void ff_texturedspenc_init ( TextureDSPContext c)

Definition at line 666 of file texturedspenc.c.

Referenced by hap_init().

Variable Documentation

◆ expand5

const uint8_t expand5[32]
static
Initial value:
= {
0, 8, 16, 24, 33, 41, 49, 57, 66, 74, 82, 90,
99, 107, 115, 123, 132, 140, 148, 156, 165, 173, 181, 189,
198, 206, 214, 222, 231, 239, 247, 255,
}

Definition at line 35 of file texturedspenc.c.

Referenced by rgb5652rgb().

◆ expand6

const uint8_t expand6[64]
static
Initial value:
= {
0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44,
48, 52, 56, 60, 65, 69, 73, 77, 81, 85, 89, 93,
97, 101, 105, 109, 113, 117, 121, 125, 130, 134, 138, 142,
146, 150, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190,
195, 199, 203, 207, 211, 215, 219, 223, 227, 231, 235, 239,
243, 247, 251, 255,
}

Definition at line 41 of file texturedspenc.c.

Referenced by rgb5652rgb().

◆ match5

const uint8_t match5[256][2]
static

Definition at line 50 of file texturedspenc.c.

Referenced by compress_color(), and refine_colors().

◆ match6

const uint8_t match6[256][2]
static

Definition at line 96 of file texturedspenc.c.

Referenced by compress_color(), and refine_colors().