[FFmpeg-devel] [PATCH 02/13] lavc/ass: add support for configuring default style via AVOptions

rcombs rcombs at rcombs.me
Wed Jan 29 06:42:33 EET 2020



> On Jan 27, 2020, at 08:28, Moritz Barsnick <barsnick at gmx.net> wrote:
> 
> On Fri, Jan 24, 2020 at 20:01:49 -0600, rcombs wrote:
>> +static int invert_ass_alpha(uint32_t c)
>> +{
>> +    uint32_t a = c >> 24;
>> +    return ((255 - a) << 24) | (c & 0xffffff);
>> +}
> 
> You're inverting the "leftmost" 8 bits of c? Can't you just make this
> 
> return (c ^ 0xff000000);
> 
> ? Even inline, or just a macro? (Or perhaps I'm missing something, and
> (255 - a) is not always the same as (a ^ 0xff).

These are indeed equivalent, but I thought this more clearly conveyed the intent here ("convert between 0=transparent and 0=opaque by inverting the 0-255 alpha field").

> 
>> +#define ASS_HEADER_AVOPTIONS(cls, obj) \
>> +    { "res",  "script resolution", offsetof(cls, obj.res_x), AV_OPT_TYPE_IMAGE_SIZE, { .str = ASS_DEFAULT_PLAYRES_STR }, 1, INT_MAX, ASS_DS }, \
>> +    { "font", "default font name", offsetof(cls, obj.style.font), AV_OPT_TYPE_STRING,  { .str = NULL }, 0, 0, ASS_DS }, \
>> +    { "font_size", "default font name", offsetof(cls, obj.style.font_size), AV_OPT_TYPE_DOUBLE,  { .dbl = ASS_DEFAULT_FONT_SIZE }, 0, INT_MAX, ASS_DS }, \
>> +    { "color", "default text color", offsetof(cls, obj.style.color), AV_OPT_TYPE_COLOR, { .str = ASS_DEFAULT_COLOR_STR }, 0, 0, ASS_DS }, \
>> +    { "color2", "default secondary text color", offsetof(cls, obj.style.color2), AV_OPT_TYPE_COLOR, { .str = ASS_DEFAULT_COLOR_STR }, 0, 0, ASS_DS }, \
>> +    { "outline_color", "default text outline color", offsetof(cls, obj.style.outline_color), AV_OPT_TYPE_COLOR, { .str = ASS_DEFAULT_BCOLOR_STR }, 0, 0, ASS_DS }, \
>> +    { "back_color", "default text background/shadow color", offsetof(cls, obj.style.back_color), AV_OPT_TYPE_COLOR, { .str = ASS_DEFAULT_BCOLOR_STR }, 0, 0, ASS_DS }, \
>> +    { "bold", "default text boldness (0/1/weight value)", offsetof(cls, obj.style.bold), AV_OPT_TYPE_INT, { .i64 = ASS_DEFAULT_BOLD }, 0, INT_MAX, ASS_DS }, \
>> +    { "italic", "default text italics", offsetof(cls, obj.style.bold), AV_OPT_TYPE_BOOL, { .i64 = ASS_DEFAULT_ITALIC }, 0, 1, ASS_DS }, \
>> +    { "underline", "default text italics", offsetof(cls, obj.style.underline), AV_OPT_TYPE_BOOL, { .i64 = ASS_DEFAULT_UNDERLINE }, 0, 1, ASS_DS }, \
>> +    { "strikeout", "default text strikeout", offsetof(cls, obj.style.strikeout), AV_OPT_TYPE_BOOL, { .i64 = ASS_DEFAULT_STRIKEOUT }, 0, 1, ASS_DS }, \
>> +    { "scale_x", "default horizontal text scale", offsetof(cls, obj.style.scale_x), AV_OPT_TYPE_DOUBLE, { .dbl = ASS_DEFAULT_SCALE_X }, 0, INT_MAX, ASS_DS }, \
>> +    { "scale_y", "default vertical text scale", offsetof(cls, obj.style.scale_y), AV_OPT_TYPE_DOUBLE, { .dbl = ASS_DEFAULT_SCALE_Y }, 0, INT_MAX, ASS_DS }, \
>> +    { "border_style", "default text border style", offsetof(cls, obj.style.border_style), AV_OPT_TYPE_INT, { .i64 = ASS_DEFAULT_BORDERSTYLE }, 1, 4, ASS_DS }, \
>> +    { "outline", "default text outline width", offsetof(cls, obj.style.outline), AV_OPT_TYPE_DOUBLE, { .dbl = ASS_DEFAULT_OUTLINE }, 0, INT_MAX, ASS_DS }, \
>> +    { "shadow", "default text shadow drop", offsetof(cls, obj.style.shadow), AV_OPT_TYPE_DOUBLE, { .dbl = ASS_DEFAULT_SHADOW }, 0, INT_MAX, ASS_DS }, \
>> +    { "alignment", "default text alignment", offsetof(cls, obj.style.alignment), AV_OPT_TYPE_INT, { .i64 = ASS_DEFAULT_ALIGNMENT }, 1, 9, ASS_DS }, \
>> +    { "margin_l", "default left margin", offsetof(cls, obj.style.margin_l), AV_OPT_TYPE_INT, { .i64 = ASS_DEFAULT_MARGINL }, 0, INT_MAX, ASS_DS }, \
>> +    { "margin_r", "default right margin", offsetof(cls, obj.style.margin_r), AV_OPT_TYPE_INT, { .i64 = ASS_DEFAULT_MARGINR }, 0, INT_MAX, ASS_DS }, \
>> +    { "margin_v", "default vertical margin", offsetof(cls, obj.style.margin_v), AV_OPT_TYPE_INT, { .i64 = ASS_DEFAULT_MARGINV }, 0, INT_MAX, ASS_DS }, \
> 
> To make this more readable, you should also MACROify the "offsetof(cls,
> obj.X)", as many other options sections do it, and perhaps align the
> entries' columns.

I shied away from this to avoid polluting the global macro space (since this is in a header); I can do it anyway if you prefer (it's not like it's a public header, at least).

> 
> Moritz
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-devel mailing list