mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2026-03-13 09:00:40 +08:00
avcodec/codec_internal: Use bitfield for alpha_modes
Right now, FFCodec contains a dedicated pointer for alpha_mode; this is wasteful, as there is only a very limited range of options for this value, namely four. So store it as a two-bit bitfield like color_ranges. This reduces sizeof(FFCodec) by 16 here (the placement of alpha_mode entailed unnecessary padding) and saves 11328B of .data.rel.ro here (on a standard build with no external libraries). (If it were not for effective-type violations, one could share the code and the table with AV_CODEC_CONFIG_COLOR_RANGE.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
committed by
James Almer
parent
df1b6f9cfd
commit
ab70751c8a
@@ -23,6 +23,8 @@
|
||||
* AVCodecContext functions for libavcodec
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "libavutil/avassert.h"
|
||||
#include "libavutil/avstring.h"
|
||||
@@ -30,7 +32,6 @@
|
||||
#include "libavutil/channel_layout.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/emms.h"
|
||||
#include "libavutil/fifo.h"
|
||||
#include "libavutil/imgutils.h"
|
||||
#include "libavutil/mem.h"
|
||||
#include "libavutil/opt.h"
|
||||
@@ -41,12 +42,10 @@
|
||||
#include "codec_desc.h"
|
||||
#include "codec_internal.h"
|
||||
#include "decode.h"
|
||||
#include "encode.h"
|
||||
#include "frame_thread_encoder.h"
|
||||
#include "hwconfig.h"
|
||||
#include "internal.h"
|
||||
#include "libavutil/refstruct.h"
|
||||
#include "thread.h"
|
||||
|
||||
/**
|
||||
* Maximum size in bytes of extradata.
|
||||
@@ -737,7 +736,17 @@ static const enum AVColorRange color_range_tab[] = {
|
||||
AVCOL_RANGE_MPEG, AVCOL_RANGE_UNSPECIFIED,
|
||||
};
|
||||
|
||||
static const uint8_t color_range_offsets[] = {
|
||||
static const enum AVAlphaMode alpha_mode_tab[] = {
|
||||
AVALPHA_MODE_PREMULTIPLIED, AVALPHA_MODE_STRAIGHT, AVALPHA_MODE_UNSPECIFIED,
|
||||
AVALPHA_MODE_PREMULTIPLIED, AVALPHA_MODE_UNSPECIFIED
|
||||
};
|
||||
|
||||
static_assert((int)AVCOL_RANGE_MPEG == (int)AVALPHA_MODE_PREMULTIPLIED, "unexpected enum values");
|
||||
static_assert((int)AVCOL_RANGE_JPEG == (int)AVALPHA_MODE_STRAIGHT, "unexpected enum values");
|
||||
static_assert(AVCOL_RANGE_UNSPECIFIED == 0 && AVALPHA_MODE_UNSPECIFIED == 0, "unexpected enum values");
|
||||
static_assert(AVCOL_RANGE_NB == 3 && AVALPHA_MODE_NB == 3, "unexpected enum values");
|
||||
|
||||
static const uint8_t offset_tab[] = {
|
||||
[AVCOL_RANGE_MPEG] = 3,
|
||||
[AVCOL_RANGE_JPEG] = 1,
|
||||
[AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG] = 0,
|
||||
@@ -771,7 +780,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||
return AVERROR(EINVAL);
|
||||
unsigned color_ranges = codec2->color_ranges;
|
||||
if (color_ranges)
|
||||
*out_configs = color_range_tab + color_range_offsets[color_ranges];
|
||||
*out_configs = color_range_tab + offset_tab[color_ranges];
|
||||
else
|
||||
*out_configs = NULL;
|
||||
*out_num_configs = av_popcount(color_ranges);
|
||||
@@ -783,7 +792,15 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||
return 0;
|
||||
|
||||
case AV_CODEC_CONFIG_ALPHA_MODE:
|
||||
WRAP_CONFIG(AVMEDIA_TYPE_VIDEO, codec2->alpha_modes, enum AVAlphaMode, AVALPHA_MODE_UNSPECIFIED);
|
||||
if (codec->type != AVMEDIA_TYPE_VIDEO)
|
||||
return AVERROR(EINVAL);
|
||||
unsigned alpha_modes = codec2->alpha_modes;
|
||||
if (alpha_modes)
|
||||
*out_configs = alpha_mode_tab + offset_tab[alpha_modes];
|
||||
else
|
||||
*out_configs = NULL;
|
||||
*out_num_configs = av_popcount(alpha_modes);
|
||||
return 0;
|
||||
|
||||
default:
|
||||
return AVERROR(EINVAL);
|
||||
|
||||
@@ -133,7 +133,7 @@ typedef struct FFCodec {
|
||||
/**
|
||||
* Internal codec capabilities FF_CODEC_CAP_*.
|
||||
*/
|
||||
unsigned caps_internal:26;
|
||||
unsigned caps_internal:24;
|
||||
|
||||
/**
|
||||
* Is this a decoder?
|
||||
@@ -146,6 +146,12 @@ typedef struct FFCodec {
|
||||
*/
|
||||
unsigned color_ranges:2;
|
||||
|
||||
/**
|
||||
* This field determines the alpha modes supported by an encoder.
|
||||
* Should be set to a bitmask of AVALPHA_MODE_PREMULTIPLIED and AVALPHA_MODE_STRAIGHT.
|
||||
*/
|
||||
unsigned alpha_modes:2;
|
||||
|
||||
/**
|
||||
* This field determines the type of the codec (decoder/encoder)
|
||||
* and also the exact callback cb implemented by the codec.
|
||||
@@ -153,11 +159,6 @@ typedef struct FFCodec {
|
||||
*/
|
||||
unsigned cb_type:3;
|
||||
|
||||
/**
|
||||
* This field determines the alpha modes supported by an encoder.
|
||||
*/
|
||||
const enum AVAlphaMode *alpha_modes;
|
||||
|
||||
int priv_data_size;
|
||||
/**
|
||||
* @name Frame-level threading support functions
|
||||
|
||||
@@ -553,7 +553,5 @@ const FFCodec ff_exr_encoder = {
|
||||
FF_CODEC_ENCODE_CB(encode_frame),
|
||||
.close = encode_close,
|
||||
CODEC_PIXFMTS(AV_PIX_FMT_GRAYF32, AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32),
|
||||
.alpha_modes = (const enum AVAlphaMode[]) {
|
||||
AVALPHA_MODE_PREMULTIPLIED, AVALPHA_MODE_UNSPECIFIED
|
||||
},
|
||||
.alpha_modes = AVALPHA_MODE_PREMULTIPLIED,
|
||||
};
|
||||
|
||||
@@ -793,9 +793,7 @@ const FFCodec ff_libjxl_encoder = {
|
||||
FF_CODEC_CAP_AUTO_THREADS | FF_CODEC_CAP_INIT_CLEANUP |
|
||||
FF_CODEC_CAP_ICC_PROFILES,
|
||||
CODEC_PIXFMTS_ARRAY(libjxl_supported_pixfmts),
|
||||
.alpha_modes = (const enum AVAlphaMode[]) {
|
||||
AVALPHA_MODE_STRAIGHT, AVALPHA_MODE_PREMULTIPLIED, AVALPHA_MODE_UNSPECIFIED
|
||||
},
|
||||
.alpha_modes = AVALPHA_MODE_STRAIGHT | AVALPHA_MODE_PREMULTIPLIED,
|
||||
.p.priv_class = &libjxl_encode_class,
|
||||
.p.wrapper_name = "libjxl",
|
||||
};
|
||||
@@ -816,9 +814,7 @@ const FFCodec ff_libjxl_anim_encoder = {
|
||||
FF_CODEC_CAP_AUTO_THREADS | FF_CODEC_CAP_INIT_CLEANUP |
|
||||
FF_CODEC_CAP_ICC_PROFILES,
|
||||
CODEC_PIXFMTS_ARRAY(libjxl_supported_pixfmts),
|
||||
.alpha_modes = (const enum AVAlphaMode[]) {
|
||||
AVALPHA_MODE_STRAIGHT, AVALPHA_MODE_PREMULTIPLIED, AVALPHA_MODE_UNSPECIFIED
|
||||
},
|
||||
.alpha_modes = AVALPHA_MODE_STRAIGHT | AVALPHA_MODE_PREMULTIPLIED,
|
||||
.p.priv_class = &libjxl_encode_class,
|
||||
.p.wrapper_name = "libjxl",
|
||||
};
|
||||
|
||||
@@ -1299,9 +1299,7 @@ const FFCodec ff_png_encoder = {
|
||||
AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A,
|
||||
AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE,
|
||||
AV_PIX_FMT_MONOBLACK),
|
||||
.alpha_modes = (const enum AVAlphaMode[]) {
|
||||
AVALPHA_MODE_STRAIGHT, AVALPHA_MODE_UNSPECIFIED
|
||||
},
|
||||
.alpha_modes = AVALPHA_MODE_STRAIGHT,
|
||||
.p.priv_class = &pngenc_class,
|
||||
.caps_internal = FF_CODEC_CAP_ICC_PROFILES,
|
||||
};
|
||||
@@ -1322,9 +1320,7 @@ const FFCodec ff_apng_encoder = {
|
||||
AV_PIX_FMT_PAL8,
|
||||
AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A,
|
||||
AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_YA16BE),
|
||||
.alpha_modes = (const enum AVAlphaMode[]) {
|
||||
AVALPHA_MODE_STRAIGHT, AVALPHA_MODE_UNSPECIFIED
|
||||
},
|
||||
.alpha_modes = AVALPHA_MODE_STRAIGHT,
|
||||
.p.priv_class = &pngenc_class,
|
||||
.caps_internal = FF_CODEC_CAP_ICC_PROFILES,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user