FFmpeg
Loading...
Searching...
No Matches
huffyuvenc.c File Reference

huffyuv encoder More...

#include "config_components.h"
#include "avcodec.h"
#include "bswapdsp.h"
#include "codec_internal.h"
#include "encode.h"
#include "huffyuv.h"
#include "huffman.h"
#include "huffyuvencdsp.h"
#include "lossless_videoencdsp.h"
#include "put_bits.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"

Go to the source code of this file.

Data Structures

struct  HYuvEncContext
 

Macros

#define STATS_OUT_SIZE   21*MAX_N*3 + 4
 
#define LOAD4
 
#define LOADEND    int y0 = s->temp[0][width-1];
 
#define LOADEND_14    int y0 = s->temp16[0][width-1] & mask;
 
#define LOADEND_16    int y0 = s->temp16[0][width-1];
 
#define STATEND    s->stats[plane][y0]++;
 
#define STATEND_16    s->stats[plane][y0>>2]++;
 
#define WRITEEND    put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);
 
#define WRITEEND_16
 
#define LOAD2
 
#define LOAD2_14
 
#define LOAD2_16
 
#define STAT2
 
#define STAT2_16
 
#define WRITE2
 
#define WRITE2_16
 
#define ENCODE_PLANE(LOAD, LOADEND, WRITE, WRITEEND, STAT, STATEND)
 
#define LOAD2
 
#define STAT2
 
#define WRITE2
 
#define LOAD_GBRA
 
#define STAT_BGRA
 
#define WRITE_GBRA
 
#define OFFSET(x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void diff_bytes (HYuvEncContext *s, uint8_t *dst, const uint8_t *src0, const uint8_t *src1, int w)
 
static int sub_left_prediction (HYuvEncContext *s, uint8_t *dst, const uint8_t *src, int w, int left)
 
static void sub_left_prediction_bgr32 (HYuvEncContext *s, uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha)
 
static void sub_left_prediction_rgb24 (HYuvEncContext *s, uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue)
 
static void sub_median_prediction (HYuvEncContext *s, uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w, int *left, int *left_top)
 
static int store_table (HYuvEncContext *s, const uint8_t *len, uint8_t *buf)
 
static int store_huffman_tables (HYuvEncContext *s, uint8_t *buf)
 
static av_cold int encode_init (AVCodecContext *avctx)
 
static int encode_422_bitstream (HYuvEncContext *s, int offset, int count)
 
static int encode_plane_bitstream (HYuvEncContext *s, int width, int plane)
 
static int encode_gray_bitstream (HYuvEncContext *s, int count)
 
static int encode_bgra_bitstream (HYuvEncContext *s, int count, int planes)
 
static int encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *p, int *got_packet)
 
static av_cold int encode_end (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass normal_class
 
const FFCodec ff_huffyuv_encoder
 

Detailed Description

huffyuv encoder

Definition in file huffyuvenc.c.

Macro Definition Documentation

◆ STATS_OUT_SIZE

#define STATS_OUT_SIZE   21*MAX_N*3 + 4

◆ LOAD4

#define LOAD4
Value:
int y0 = y[2 * i];\
int y1 = y[2 * i + 1];\
int u0 = u[i];\
int v0 = v[i];
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68

Referenced by encode_422_bitstream().

◆ LOADEND

#define LOADEND    int y0 = s->temp[0][width-1];

Referenced by encode_plane_bitstream().

◆ LOADEND_14

#define LOADEND_14    int y0 = s->temp16[0][width-1] & mask;

Referenced by encode_plane_bitstream().

◆ LOADEND_16

#define LOADEND_16    int y0 = s->temp16[0][width-1];

Referenced by encode_plane_bitstream().

◆ STATEND

#define STATEND    s->stats[plane][y0]++;

Referenced by encode_plane_bitstream().

◆ STATEND_16

#define STATEND_16    s->stats[plane][y0>>2]++;

Referenced by encode_plane_bitstream().

◆ WRITEEND

#define WRITEEND    put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);

Referenced by encode_plane_bitstream().

◆ WRITEEND_16

#define WRITEEND_16
Value:
put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
put_bits(&s->pb, 2, y0&3);
#define s(width, name)
Definition cbs_vp9.c:198
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition j2kenc.c:154

Referenced by encode_plane_bitstream().

◆ LOAD2 [1/2]

#define LOAD2
Value:
int y0 = s->temp[0][2 * i];\
int y1 = s->temp[0][2 * i + 1];

Referenced by encode_gray_bitstream(), and encode_plane_bitstream().

◆ LOAD2_14

#define LOAD2_14
Value:
int y0 = s->temp16[0][2 * i] & mask;\
int y1 = s->temp16[0][2 * i + 1] & mask;
static const uint16_t mask[17]
Definition lzw.c:38

Referenced by encode_plane_bitstream().

◆ LOAD2_16

#define LOAD2_16
Value:
int y0 = s->temp16[0][2 * i];\
int y1 = s->temp16[0][2 * i + 1];

Referenced by encode_plane_bitstream().

◆ STAT2 [1/2]

#define STAT2
Value:
s->stats[plane][y0]++;\
s->stats[plane][y1]++;

Referenced by encode_gray_bitstream(), and encode_plane_bitstream().

◆ STAT2_16

#define STAT2_16
Value:
s->stats[plane][y0>>2]++;\
s->stats[plane][y1>>2]++;

Referenced by encode_plane_bitstream().

◆ WRITE2 [1/2]

#define WRITE2
Value:
put_bits(&s->pb, s->len[plane][y0], s->bits[plane][y0]);\
put_bits(&s->pb, s->len[plane][y1], s->bits[plane][y1]);

Referenced by encode_gray_bitstream(), and encode_plane_bitstream().

◆ WRITE2_16

#define WRITE2_16
Value:
put_bits(&s->pb, s->len[plane][y0>>2], s->bits[plane][y0>>2]);\
put_bits(&s->pb, 2, y0&3);\
put_bits(&s->pb, s->len[plane][y1>>2], s->bits[plane][y1>>2]);\
put_bits(&s->pb, 2, y1&3);

Referenced by encode_plane_bitstream().

◆ ENCODE_PLANE

#define ENCODE_PLANE ( LOAD,
LOADEND,
WRITE,
WRITEEND,
STAT,
STATEND )

Referenced by encode_plane_bitstream().

◆ LOAD2 [2/2]

#define LOAD2
Value:
int y0 = s->temp[0][2 * i];\
int y1 = s->temp[0][2 * i + 1];

◆ STAT2 [2/2]

#define STAT2
Value:
s->stats[0][y0]++;\
s->stats[0][y1]++;

◆ WRITE2 [2/2]

#define WRITE2
Value:
put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\
put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]);

◆ LOAD_GBRA

#define LOAD_GBRA
Value:
int g = s->temp[0][planes == 3 ? 3 * i + 1 : 4 * i + G]; \
int b =(s->temp[0][planes == 3 ? 3 * i + 2 : 4 * i + B] - g) & 0xFF;\
int r =(s->temp[0][planes == 3 ? 3 * i + 0 : 4 * i + R] - g) & 0xFF;\
int a = s->temp[0][planes * i + A];
#define A(x)
Definition vpx_arith.h:28
int a
#define B
Definition huffyuv.h:42
#define R
Definition huffyuv.h:44
#define G
Definition huffyuv.h:43
#define r
Definition input.c:42
#define b
Definition input.c:43
static const struct @257111027162314367033347246032313251342043035002 planes[]
const char * g
Definition vf_curves.c:128

Referenced by encode_bgra_bitstream().

◆ STAT_BGRA

#define STAT_BGRA
Value:
s->stats[0][b]++; \
s->stats[1][g]++; \
s->stats[2][r]++; \
if (planes == 4) \
s->stats[2][a]++;

Referenced by encode_bgra_bitstream().

◆ WRITE_GBRA

#define WRITE_GBRA
Value:
put_bits(&s->pb, s->len[1][g], s->bits[1][g]); \
put_bits(&s->pb, s->len[0][b], s->bits[0][b]); \
put_bits(&s->pb, s->len[2][r], s->bits[2][r]); \
if (planes == 4) \
put_bits(&s->pb, s->len[2][a], s->bits[2][a]);

Referenced by encode_bgra_bitstream().

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 990 of file huffyuvenc.c.

◆ VE

Definition at line 991 of file huffyuvenc.c.

Function Documentation

◆ diff_bytes()

static void diff_bytes ( HYuvEncContext * s,
uint8_t * dst,
const uint8_t * src0,
const uint8_t * src1,
int w )
inlinestatic

Definition at line 81 of file huffyuvenc.c.

Referenced by encode_frame().

◆ sub_left_prediction()

static int sub_left_prediction ( HYuvEncContext * s,
uint8_t * dst,
const uint8_t * src,
int w,
int left )
inlinestatic

Definition at line 91 of file huffyuvenc.c.

Referenced by encode_frame().

◆ sub_left_prediction_bgr32()

static void sub_left_prediction_bgr32 ( HYuvEncContext * s,
uint8_t * dst,
const uint8_t * src,
int w,
int * red,
int * green,
int * blue,
int * alpha )
inlinestatic

Definition at line 122 of file huffyuvenc.c.

Referenced by encode_frame().

◆ sub_left_prediction_rgb24()

static void sub_left_prediction_rgb24 ( HYuvEncContext * s,
uint8_t * dst,
const uint8_t * src,
int w,
int * red,
int * green,
int * blue )
inlinestatic

Definition at line 158 of file huffyuvenc.c.

Referenced by encode_frame().

◆ sub_median_prediction()

static void sub_median_prediction ( HYuvEncContext * s,
uint8_t * dst,
const uint8_t * src1,
const uint8_t * src2,
int w,
int * left,
int * left_top )
static

Definition at line 186 of file huffyuvenc.c.

Referenced by encode_frame().

◆ store_table()

static int store_table ( HYuvEncContext * s,
const uint8_t * len,
uint8_t * buf )
static

Definition at line 198 of file huffyuvenc.c.

Referenced by store_huffman_tables().

◆ store_huffman_tables()

static int store_huffman_tables ( HYuvEncContext * s,
uint8_t * buf )
static

Definition at line 223 of file huffyuvenc.c.

Referenced by encode_frame(), and encode_init().

◆ encode_init()

static av_cold int encode_init ( AVCodecContext * avctx)
static

Definition at line 245 of file huffyuvenc.c.

◆ encode_422_bitstream()

static int encode_422_bitstream ( HYuvEncContext * s,
int offset,
int count )
static

Definition at line 447 of file huffyuvenc.c.

Referenced by encode_frame().

◆ encode_plane_bitstream()

static int encode_plane_bitstream ( HYuvEncContext * s,
int width,
int plane )
static

Definition at line 502 of file huffyuvenc.c.

Referenced by encode_frame().

◆ encode_gray_bitstream()

static int encode_gray_bitstream ( HYuvEncContext * s,
int count )
static

Definition at line 604 of file huffyuvenc.c.

Referenced by encode_frame().

◆ encode_bgra_bitstream()

static int encode_bgra_bitstream ( HYuvEncContext * s,
int count,
int planes )
inlinestatic

Definition at line 649 of file huffyuvenc.c.

Referenced by encode_frame().

◆ encode_frame()

static int encode_frame ( AVCodecContext * avctx,
AVPacket * pkt,
const AVFrame * p,
int * got_packet )
static

Definition at line 699 of file huffyuvenc.c.

◆ encode_end()

static av_cold int encode_end ( AVCodecContext * avctx)
static

Definition at line 978 of file huffyuvenc.c.

Referenced by vulkan_encode_issue().

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "context", "Set per-frame huffman tables", OFFSET(context), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
{ "non_deterministic", "Allow multithreading for e.g. context=1 at the expense of determinism",
OFFSET(non_determ), AV_OPT_TYPE_BOOL, { .i64 = 0 },
0, 1, VE },
{ "pred", "Prediction method", OFFSET(predictor), AV_OPT_TYPE_INT, { .i64 = LEFT }, LEFT, MEDIAN, VE, .unit = "pred" },
{ "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LEFT }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ "plane", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = PLANE }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MEDIAN }, INT_MIN, INT_MAX, VE, .unit = "pred" },
{ NULL },
}
#define VE
Definition amfenc_av1.c:30
#define LEFT
Definition cdgraphics.c:168
#define NULL
Definition coverity.c:32
static void predictor(uint8_t *src, ptrdiff_t size)
Definition exrenc.c:170
#define OFFSET(x)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ PLANE
Definition huffyuv.h:54
#define MEDIAN(x)

Definition at line 993 of file huffyuvenc.c.

◆ normal_class

const AVClass normal_class
static
Initial value:
= {
.class_name = "huffyuv",
.item_name = av_default_item_name,
.option = options + 1,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85

Definition at line 1007 of file huffyuvenc.c.

◆ ff_huffyuv_encoder

const FFCodec ff_huffyuv_encoder
Initial value:
= {
.p.name = "huffyuv",
CODEC_LONG_NAME("Huffyuv / HuffYUV"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(HYuvEncContext),
.close = encode_end,
.p.priv_class = &normal_class,
.color_ranges = AVCOL_RANGE_MPEG,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}
static av_cold int encode_init(AVCodecContext *avctx)
Definition asvenc.c:373
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
Definition ffmpeg_enc.c:694
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_HUFFYUV
Definition codec_id.h:75
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static const AVClass normal_class
static av_cold int encode_end(AVCodecContext *avctx)
Definition huffyuvenc.c:978
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
#define AV_PIX_FMT_RGB32
Definition pixfmt.h:517

Definition at line 1014 of file huffyuvenc.c.