FFmpeg
Loading...
Searching...
No Matches
magicyuvenc.c File Reference
#include <stdlib.h>
#include <string.h>
#include "libavutil/cpu.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/qsort.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "encode.h"
#include "put_bits.h"
#include "lossless_videoencdsp.h"

Go to the source code of this file.

Data Structures

struct  HuffEntry
 
struct  PTable
 Used to assign a occurrence count or "probability" to an input value. More...
 
struct  Slice
 
struct  MagicYUVContext
 
struct  PackageMergerList
 Used to store intermediate lists in the package merge algorithm. More...
 

Macros

#define MAGICYUV_EXTRADATA_SIZE   32
 
#define OFFSET(x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Enumerations

enum  Prediction { LEFT = 1 , GRADIENT , MEDIAN }
 

Functions

static void left_predict (MagicYUVContext *s, const uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
 
static void gradient_predict (MagicYUVContext *s, const uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
 
static void median_predict (MagicYUVContext *s, const uint8_t *src, uint8_t *dst, ptrdiff_t stride, int width, int height)
 
static av_cold int magy_encode_init (AVCodecContext *avctx)
 
static void calculate_codes (HuffEntry *he, uint16_t codes_count[33])
 
static void count_usage (const uint8_t *src, int width, int height, int64_t *counts)
 
static int compare_by_prob (const void *a, const void *b)
 
static void magy_huffman_compute_bits (PTable *prob_table, HuffEntry *distincts, uint16_t codes_counts[33], int size, int max_length)
 
static int count_plane_slice (AVCodecContext *avctx, int n, int plane)
 
static void generate_codes (AVCodecContext *avctx, HuffEntry *he, int plane)
 
static void output_codes (PutByteContext *pb, const HuffEntry he[256])
 
static void encode_plane_slice_raw (const uint8_t *src, uint8_t *dst, int width, int height, int prediction)
 
static void encode_plane_slice (const uint8_t *src, uint8_t *dst, unsigned dst_size, int width, int height, HuffEntry *he, int prediction)
 
static int encode_slice (AVCodecContext *avctx, void *tdata, int n, int threadnr)
 
static int predict_slice (AVCodecContext *avctx, void *tdata, int n, int threadnr)
 
static int magy_encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
 
static av_cold int magy_encode_close (AVCodecContext *avctx)
 

Variables

static const AVOption options []
 
static const AVClass magicyuv_class
 
const FFCodec ff_magicyuv_encoder
 

Macro Definition Documentation

◆ MAGICYUV_EXTRADATA_SIZE

#define MAGICYUV_EXTRADATA_SIZE   32

Definition at line 38 of file magicyuvenc.c.

Referenced by magy_encode_init().

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 641 of file magicyuvenc.c.

◆ VE

Definition at line 642 of file magicyuvenc.c.

Enumeration Type Documentation

◆ Prediction

enum Prediction
Enumerator
LEFT 
GRADIENT 
MEDIAN 

Definition at line 40 of file magicyuvenc.c.

Function Documentation

◆ left_predict()

static void left_predict ( MagicYUVContext * s,
const uint8_t * src,
uint8_t * dst,
ptrdiff_t stride,
int width,
int height )
static

Definition at line 85 of file magicyuvenc.c.

Referenced by magy_encode_init().

◆ gradient_predict()

static void gradient_predict ( MagicYUVContext * s,
const uint8_t * src,
uint8_t * dst,
ptrdiff_t stride,
int width,
int height )
static

Definition at line 109 of file magicyuvenc.c.

Referenced by magy_encode_init().

◆ median_predict()

static void median_predict ( MagicYUVContext * s,
const uint8_t * src,
uint8_t * dst,
ptrdiff_t stride,
int width,
int height )
static

Definition at line 137 of file magicyuvenc.c.

Referenced by magy_encode_init().

◆ magy_encode_init()

static av_cold int magy_encode_init ( AVCodecContext * avctx)
static

Definition at line 158 of file magicyuvenc.c.

◆ calculate_codes()

static void calculate_codes ( HuffEntry * he,
uint16_t codes_count[33] )
static

Definition at line 275 of file magicyuvenc.c.

Referenced by generate_codes().

◆ count_usage()

static void count_usage ( const uint8_t * src,
int width,
int height,
int64_t * counts )
static

Definition at line 289 of file magicyuvenc.c.

Referenced by count_plane_slice().

◆ compare_by_prob()

static int compare_by_prob ( const void * a,
const void * b )
static

Definition at line 306 of file magicyuvenc.c.

Referenced by magy_huffman_compute_bits(), and mjpegenc_huffman_compute_bits().

◆ magy_huffman_compute_bits()

static void magy_huffman_compute_bits ( PTable * prob_table,
HuffEntry * distincts,
uint16_t codes_counts[33],
int size,
int max_length )
static

Definition at line 313 of file magicyuvenc.c.

Referenced by generate_codes().

◆ count_plane_slice()

static int count_plane_slice ( AVCodecContext * avctx,
int n,
int plane )
static

Definition at line 375 of file magicyuvenc.c.

Referenced by predict_slice().

◆ generate_codes()

static void generate_codes ( AVCodecContext * avctx,
HuffEntry * he,
int plane )
static

Definition at line 389 of file magicyuvenc.c.

Referenced by magy_encode_frame().

◆ output_codes()

static void output_codes ( PutByteContext * pb,
const HuffEntry he[256] )
static

Definition at line 414 of file magicyuvenc.c.

Referenced by magy_encode_frame().

◆ encode_plane_slice_raw()

static void encode_plane_slice_raw ( const uint8_t * src,
uint8_t * dst,
int width,
int height,
int prediction )
static

Definition at line 423 of file magicyuvenc.c.

Referenced by encode_slice().

◆ encode_plane_slice()

static void encode_plane_slice ( const uint8_t * src,
uint8_t * dst,
unsigned dst_size,
int width,
int height,
HuffEntry * he,
int prediction )
static

Definition at line 434 of file magicyuvenc.c.

Referenced by encode_slice().

◆ encode_slice()

static int encode_slice ( AVCodecContext * avctx,
void * tdata,
int n,
int threadnr )
static

Definition at line 458 of file magicyuvenc.c.

◆ predict_slice()

static int predict_slice ( AVCodecContext * avctx,
void * tdata,
int n,
int threadnr )
static

Definition at line 483 of file magicyuvenc.c.

Referenced by magy_encode_frame().

◆ magy_encode_frame()

static int magy_encode_frame ( AVCodecContext * avctx,
AVPacket * pkt,
const AVFrame * frame,
int * got_packet )
static

Definition at line 542 of file magicyuvenc.c.

◆ magy_encode_close()

static av_cold int magy_encode_close ( AVCodecContext * avctx)
static

Definition at line 624 of file magicyuvenc.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "pred", "Prediction method", OFFSET(frame_pred), AV_OPT_TYPE_INT, {.i64=LEFT}, LEFT, MEDIAN, VE, .unit = "pred" },
{ "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LEFT }, 0, 0, VE, .unit = "pred" },
{ "gradient", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = GRADIENT }, 0, 0, VE, .unit = "pred" },
{ "median", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MEDIAN }, 0, 0, VE, .unit = "pred" },
{ NULL},
}
#define VE
Definition amfenc_av1.c:30
#define LEFT
Definition cdgraphics.c:168
#define NULL
Definition coverity.c:32
#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
@ GRADIENT
Definition magicyuv.c:47
#define MEDIAN(x)

Definition at line 643 of file magicyuvenc.c.

◆ magicyuv_class

const AVClass magicyuv_class
static
Initial value:
= {
.class_name = "magicyuv",
.item_name = av_default_item_name,
.option = options,
}
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 651 of file magicyuvenc.c.

◆ ff_magicyuv_encoder

const FFCodec ff_magicyuv_encoder
Initial value:
= {
.p.name = "magicyuv",
CODEC_LONG_NAME("MagicYUV video"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(MagicYUVContext),
.p.priv_class = &magicyuv_class,
.color_ranges = AVCOL_RANGE_MPEG,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}
#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...
#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_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition codec.h:102
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_MAGICYUV
Definition codec_id.h:265
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static av_cold int magy_encode_init(AVCodecContext *avctx)
static const AVClass magicyuv_class
static int magy_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static av_cold int magy_encode_close(AVCodecContext *avctx)
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition pixfmt.h:212
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165

Definition at line 658 of file magicyuvenc.c.