@ -21,26 +21,60 @@
# ifndef SWSCALE_UTILS_H
# define SWSCALE_UTILS_H
# include "libavutil/csp.h"
# include "libavutil/pixdesc.h"
# include "swscale.h"
static inline int ff_q_isnan ( const AVRational a )
{
return ! a . num & & ! a . den ;
}
/* Like av_cmp_q but considers NaN == NaN */
static inline int ff_q_equal ( const AVRational a , const AVRational b )
{
return ( ff_q_isnan ( a ) & & ff_q_isnan ( b ) ) | | ! av_cmp_q ( a , b ) ;
}
static inline int ff_cie_xy_equal ( const AVCIExy a , const AVCIExy b )
{
return ff_q_equal ( a . x , b . x ) & & ff_q_equal ( a . y , b . y ) ;
}
static inline int ff_prim_equal ( const AVPrimaryCoefficients * a ,
const AVPrimaryCoefficients * b )
{
return ff_cie_xy_equal ( a - > r , b - > r ) & &
ff_cie_xy_equal ( a - > g , b - > g ) & &
ff_cie_xy_equal ( a - > b , b - > b ) ;
}
enum {
FIELD_TOP , /* top/even rows, or progressive */
FIELD_BOTTOM , /* bottom/odd rows */
} ;
typedef struct SwsColor {
enum AVColorPrimaries prim ;
enum AVColorTransferCharacteristic trc ;
AVPrimaryCoefficients gamut ; /* mastering display gamut */
AVRational min_luma ; /* minimum luminance in nits */
AVRational max_luma ; /* maximum luminance in nits */
AVRational frame_peak ; /* per-frame/scene peak luminance, or 0 */
AVRational frame_avg ; /* per-frame/scene average luminance, or 0 */
} SwsColor ;
/* Subset of AVFrame parameters that uniquely determine pixel representation */
typedef struct SwsFormat {
int width , height ;
int interlaced ;
enum AVPixelFormat format ;
enum AVColorRange range ;
enum AVColorPrimaries prim ;
enum AVColorTransferCharacteristic trc ;
enum AVColorSpace csp ;
enum AVChromaLocation loc ;
const AVPixFmtDescriptor * desc ; /* convenience */
SwsColor color ;
} SwsFormat ;
/**
@ -49,6 +83,16 @@ typedef struct SwsFormat {
*/
SwsFormat ff_fmt_from_frame ( const AVFrame * frame , int field ) ;
static inline int ff_color_equal ( const SwsColor * c1 , const SwsColor * c2 )
{
return c1 - > prim = = c2 - > prim & &
c1 - > trc = = c2 - > trc & &
ff_q_equal ( c1 - > min_luma , c2 - > min_luma ) & &
ff_q_equal ( c1 - > max_luma , c2 - > max_luma ) & &
ff_prim_equal ( & c1 - > gamut , & c2 - > gamut ) ;
}
/* Tests only the static components of a colorspace, ignoring per-frame data */
static inline int ff_fmt_equal ( const SwsFormat * fmt1 , const SwsFormat * fmt2 )
{
return fmt1 - > width = = fmt2 - > width & &
@ -56,10 +100,9 @@ static inline int ff_fmt_equal(const SwsFormat *fmt1, const SwsFormat *fmt2)
fmt1 - > interlaced = = fmt2 - > interlaced & &
fmt1 - > format = = fmt2 - > format & &
fmt1 - > range = = fmt2 - > range & &
fmt1 - > prim = = fmt2 - > prim & &
fmt1 - > trc = = fmt2 - > trc & &
fmt1 - > csp = = fmt2 - > csp & &
fmt1 - > loc = = fmt2 - > loc ;
fmt1 - > loc = = fmt2 - > loc & &
ff_color_equal ( & fmt1 - > color , & fmt2 - > color ) ;
}
static inline int ff_fmt_align ( enum AVPixelFormat fmt )