FFmpeg
Macros | Functions | Variables
swscale.c File Reference
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/bswap.h"
#include "libavutil/common.h"
#include "libavutil/cpu.h"
#include "libavutil/emms.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavutil/pixdesc.h"
#include "config.h"
#include "swscale_internal.h"
#include "swscale.h"

Go to the source code of this file.

Macros

#define DEBUG_SWSCALE_BUFFERS   0
 
#define DEBUG_BUFFERS(...)
 
#define RGB2YUV_SHIFT   15
 
#define BY   ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
#define BV   (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
#define BU   ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
#define GY   ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
#define GV   (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
#define GU   (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
#define RY   ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
#define RV   ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
#define RU   (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
 
#define VALIDATE(field, min, max)
 

Functions

static av_always_inline void fillPlane (uint8_t *plane, int stride, int width, int height, int y, uint8_t val)
 
static void hScale16To19_c (SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
 
static void hScale16To15_c (SwsInternal *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
 
static void hScale8To15_c (SwsInternal *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
 
static void hScale8To19_c (SwsInternal *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
 
static void chrRangeToJpeg_c (int16_t *dstU, int16_t *dstV, int width, uint32_t _coeff, int64_t _offset)
 
static void chrRangeFromJpeg_c (int16_t *dstU, int16_t *dstV, int width, uint32_t _coeff, int64_t _offset)
 
static void lumRangeToJpeg_c (int16_t *dst, int width, uint32_t _coeff, int64_t _offset)
 
static void lumRangeFromJpeg_c (int16_t *dst, int width, uint32_t _coeff, int64_t _offset)
 
static void chrRangeToJpeg16_c (int16_t *_dstU, int16_t *_dstV, int width, uint32_t coeff, int64_t offset)
 
static void chrRangeFromJpeg16_c (int16_t *_dstU, int16_t *_dstV, int width, uint32_t coeff, int64_t offset)
 
static void lumRangeToJpeg16_c (int16_t *_dst, int width, uint32_t coeff, int64_t offset)
 
static void lumRangeFromJpeg16_c (int16_t *_dst, int width, uint32_t coeff, int64_t offset)
 
int ff_swscale (SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[], int dstSliceY, int dstSliceH)
 
static void solve_range_convert (uint16_t src_min, uint16_t src_max, uint16_t dst_min, uint16_t dst_max, int src_bits, int src_shift, int mult_shift, uint32_t *coeff, int64_t *offset)
 
static void init_range_convert_constants (SwsInternal *c)
 
av_cold void ff_sws_init_range_convert (SwsInternal *c)
 
static av_cold void sws_init_swscale (SwsInternal *c)
 
void ff_sws_init_scale (SwsInternal *c)
 
static void reset_ptr (const uint8_t *src[], enum AVPixelFormat format)
 
static int check_image_pointers (const uint8_t *const data[4], enum AVPixelFormat pix_fmt, const int linesizes[4])
 
void ff_xyz12Torgb48 (const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h)
 
void ff_rgb48Toxyz12 (const SwsInternal *c, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int w, int h)
 
void ff_update_palette (SwsInternal *c, const uint32_t *pal)
 
static int scale_internal (SwsContext *sws, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH)
 
static int scale_gamma (SwsInternal *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH)
 
static int scale_cascaded (SwsInternal *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstSlice[], const int dstStride[], int dstSliceY, int dstSliceH)
 
void sws_frame_end (SwsContext *sws)
 Finish the scaling process for a pair of source/destination frames previously submitted with sws_frame_start(). More...
 
int sws_frame_start (SwsContext *sws, AVFrame *dst, const AVFrame *src)
 Initialize the scaling process for a given pair of source/destination frames. More...
 
int sws_send_slice (SwsContext *sws, unsigned int slice_start, unsigned int slice_height)
 Indicate that a horizontal slice of input data is available in the source frame previously provided to sws_frame_start(). More...
 
unsigned int sws_receive_slice_alignment (const SwsContext *sws)
 Get the alignment required for slices. More...
 
int sws_receive_slice (SwsContext *sws, unsigned int slice_start, unsigned int slice_height)
 Request a horizontal slice of the output data to be written into the frame previously provided to sws_frame_start(). More...
 
static void get_frame_pointers (const AVFrame *frame, uint8_t *data[4], int linesize[4], int field)
 
static int frame_ref (AVFrame *dst, const AVFrame *src)
 
int sws_scale_frame (SwsContext *sws, AVFrame *dst, const AVFrame *src)
 Scale source data from src and write the output to dst. More...
 
static int validate_params (SwsContext *ctx)
 
int sws_frame_setup (SwsContext *ctx, const AVFrame *dst, const AVFrame *src)
 Like sws_scale_frame, but without actually scaling. More...
 
int attribute_align_arg sws_scale (SwsContext *sws, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
 swscale wrapper, so we don't need to export the SwsContext. More...
 
void ff_sws_slice_worker (void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
 

Variables

const uint8_t ff_dither_8x8_128 [9][8]
 
static const uint8_t sws_pb_64 [8]
 

Macro Definition Documentation

◆ DEBUG_SWSCALE_BUFFERS

#define DEBUG_SWSCALE_BUFFERS   0

Definition at line 254 of file swscale.c.

◆ DEBUG_BUFFERS

#define DEBUG_BUFFERS (   ...)
Value:
av_log(c, AV_LOG_DEBUG, __VA_ARGS__)

Definition at line 255 of file swscale.c.

◆ RGB2YUV_SHIFT

#define RGB2YUV_SHIFT   15

◆ BY

#define BY   ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))

◆ BV

#define BV   (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))

◆ BU

#define BU   ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))

◆ GY

#define GY   ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))

◆ GV

#define GV   (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))

◆ GU

#define GU   (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))

◆ RY

#define RY   ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))

◆ RV

#define RV   ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))

◆ RU

#define RU   (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))

◆ VALIDATE

#define VALIDATE (   field,
  min,
  max 
)
Value:
if (ctx->field < min || ctx->field > max) { \
av_log(ctx, AV_LOG_ERROR, "'%s' (%d) out of range [%d, %d]\n", \
#field, (int) ctx->field, min, max); \
return AVERROR(EINVAL); \
}

Function Documentation

◆ fillPlane()

static av_always_inline void fillPlane ( uint8_t *  plane,
int  stride,
int  width,
int  height,
int  y,
uint8_t  val 
)
static

Definition at line 54 of file swscale.c.

Referenced by ff_swscale().

◆ hScale16To19_c()

static void hScale16To19_c ( SwsInternal c,
int16_t *  _dst,
int  dstW,
const uint8_t *  _src,
const int16_t *  filter,
const int32_t filterPos,
int  filterSize 
)
static

Definition at line 65 of file swscale.c.

Referenced by sws_init_swscale().

◆ hScale16To15_c()

static void hScale16To15_c ( SwsInternal c,
int16_t *  dst,
int  dstW,
const uint8_t *  _src,
const int16_t *  filter,
const int32_t filterPos,
int  filterSize 
)
static

Definition at line 95 of file swscale.c.

Referenced by sws_init_swscale().

◆ hScale8To15_c()

static void hScale8To15_c ( SwsInternal c,
int16_t *  dst,
int  dstW,
const uint8_t *  src,
const int16_t *  filter,
const int32_t filterPos,
int  filterSize 
)
static

Definition at line 124 of file swscale.c.

Referenced by sws_init_swscale().

◆ hScale8To19_c()

static void hScale8To19_c ( SwsInternal c,
int16_t *  _dst,
int  dstW,
const uint8_t *  src,
const int16_t *  filter,
const int32_t filterPos,
int  filterSize 
)
static

Definition at line 140 of file swscale.c.

Referenced by sws_init_swscale().

◆ chrRangeToJpeg_c()

static void chrRangeToJpeg_c ( int16_t *  dstU,
int16_t *  dstV,
int  width,
uint32_t  _coeff,
int64_t  _offset 
)
static

Definition at line 159 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ chrRangeFromJpeg_c()

static void chrRangeFromJpeg_c ( int16_t *  dstU,
int16_t *  dstV,
int  width,
uint32_t  _coeff,
int64_t  _offset 
)
static

Definition at line 173 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ lumRangeToJpeg_c()

static void lumRangeToJpeg_c ( int16_t *  dst,
int  width,
uint32_t  _coeff,
int64_t  _offset 
)
static

Definition at line 185 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ lumRangeFromJpeg_c()

static void lumRangeFromJpeg_c ( int16_t *  dst,
int  width,
uint32_t  _coeff,
int64_t  _offset 
)
static

Definition at line 197 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ chrRangeToJpeg16_c()

static void chrRangeToJpeg16_c ( int16_t *  _dstU,
int16_t *  _dstV,
int  width,
uint32_t  coeff,
int64_t  offset 
)
static

Definition at line 207 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ chrRangeFromJpeg16_c()

static void chrRangeFromJpeg16_c ( int16_t *  _dstU,
int16_t *  _dstV,
int  width,
uint32_t  coeff,
int64_t  offset 
)
static

Definition at line 221 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ lumRangeToJpeg16_c()

static void lumRangeToJpeg16_c ( int16_t *  _dst,
int  width,
uint32_t  coeff,
int64_t  offset 
)
static

Definition at line 233 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ lumRangeFromJpeg16_c()

static void lumRangeFromJpeg16_c ( int16_t *  _dst,
int  width,
uint32_t  coeff,
int64_t  offset 
)
static

Definition at line 244 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ ff_swscale()

int ff_swscale ( SwsInternal c,
const uint8_t *const  src[],
const int  srcStride[],
int  srcSliceY,
int  srcSliceH,
uint8_t *const  dst[],
const int  dstStride[],
int  dstSliceY,
int  dstSliceH 
)

Definition at line 259 of file swscale.c.

Referenced by run_legacy_swscale(), and scale_internal().

◆ solve_range_convert()

static void solve_range_convert ( uint16_t  src_min,
uint16_t  src_max,
uint16_t  dst_min,
uint16_t  dst_max,
int  src_bits,
int  src_shift,
int  mult_shift,
uint32_t *  coeff,
int64_t offset 
)
static

Definition at line 574 of file swscale.c.

Referenced by init_range_convert_constants().

◆ init_range_convert_constants()

static void init_range_convert_constants ( SwsInternal c)
static

Definition at line 587 of file swscale.c.

Referenced by ff_sws_init_range_convert().

◆ ff_sws_init_range_convert()

av_cold void ff_sws_init_range_convert ( SwsInternal c)

Definition at line 622 of file swscale.c.

Referenced by sws_init_swscale(), and sws_setColorspaceDetails().

◆ sws_init_swscale()

static av_cold void sws_init_swscale ( SwsInternal c)
static

Definition at line 658 of file swscale.c.

Referenced by ff_sws_init_scale().

◆ ff_sws_init_scale()

void ff_sws_init_scale ( SwsInternal c)

◆ reset_ptr()

static void reset_ptr ( const uint8_t *  src[],
enum AVPixelFormat  format 
)
static

Definition at line 710 of file swscale.c.

Referenced by scale_internal().

◆ check_image_pointers()

static int check_image_pointers ( const uint8_t *const  data[4],
enum AVPixelFormat  pix_fmt,
const int  linesizes[4] 
)
static

Definition at line 722 of file swscale.c.

Referenced by scale_internal().

◆ ff_xyz12Torgb48()

void ff_xyz12Torgb48 ( const SwsInternal c,
uint8_t *  dst,
int  dst_stride,
const uint8_t *  src,
int  src_stride,
int  w,
int  h 
)

Definition at line 739 of file swscale.c.

Referenced by run_xyz2rgb(), and scale_internal().

◆ ff_rgb48Toxyz12()

void ff_rgb48Toxyz12 ( const SwsInternal c,
uint8_t *  dst,
int  dst_stride,
const uint8_t *  src,
int  src_stride,
int  w,
int  h 
)

Definition at line 798 of file swscale.c.

Referenced by run_rgb2xyz(), and scale_internal().

◆ ff_update_palette()

void ff_update_palette ( SwsInternal c,
const uint32_t *  pal 
)

Definition at line 857 of file swscale.c.

Referenced by scale_internal(), and setup_legacy_swscale().

◆ scale_internal()

static int scale_internal ( SwsContext sws,
const uint8_t *const  srcSlice[],
const int  srcStride[],
int  srcSliceY,
int  srcSliceH,
uint8_t *const  dstSlice[],
const int  dstStride[],
int  dstSliceY,
int  dstSliceH 
)
static

◆ scale_gamma()

static int scale_gamma ( SwsInternal c,
const uint8_t *const  srcSlice[],
const int  srcStride[],
int  srcSliceY,
int  srcSliceH,
uint8_t *const  dstSlice[],
const int  dstStride[],
int  dstSliceY,
int  dstSliceH 
)
static

Definition at line 938 of file swscale.c.

Referenced by scale_internal().

◆ scale_cascaded()

static int scale_cascaded ( SwsInternal c,
const uint8_t *const  srcSlice[],
const int  srcStride[],
int  srcSliceY,
int  srcSliceH,
uint8_t *const  dstSlice[],
const int  dstStride[],
int  dstSliceY,
int  dstSliceH 
)
static

Definition at line 972 of file swscale.c.

Referenced by scale_internal().

◆ get_frame_pointers()

static void get_frame_pointers ( const AVFrame frame,
uint8_t *  data[4],
int  linesize[4],
int  field 
)
static

Definition at line 1302 of file swscale.c.

Referenced by sws_scale_frame().

◆ frame_ref()

static int frame_ref ( AVFrame dst,
const AVFrame src 
)
static

Definition at line 1331 of file swscale.c.

Referenced by sws_scale_frame().

◆ validate_params()

static int validate_params ( SwsContext ctx)
static

Definition at line 1408 of file swscale.c.

Referenced by sws_frame_setup().

◆ ff_sws_slice_worker()

void ff_sws_slice_worker ( void *  priv,
int  jobnr,
int  threadnr,
int  nb_jobs,
int  nb_threads 
)

Definition at line 1523 of file swscale.c.

Referenced by context_init_threaded().

Variable Documentation

◆ ff_dither_8x8_128

const uint8_t ff_dither_8x8_128[9][8]
Initial value:
= {
{ 36, 68, 60, 92, 34, 66, 58, 90, },
{ 100, 4, 124, 28, 98, 2, 122, 26, },
{ 52, 84, 44, 76, 50, 82, 42, 74, },
{ 116, 20, 108, 12, 114, 18, 106, 10, },
{ 32, 64, 56, 88, 38, 70, 62, 94, },
{ 96, 0, 120, 24, 102, 6, 126, 30, },
{ 48, 80, 40, 72, 54, 86, 46, 78, },
{ 112, 16, 104, 8, 118, 22, 110, 14, },
{ 36, 68, 60, 92, 34, 66, 58, 90, },
}

Definition at line 38 of file swscale.c.

Referenced by ff_swscale().

◆ sws_pb_64

const uint8_t sws_pb_64[8]
static
Initial value:
= {
64, 64, 64, 64, 64, 64, 64, 64
}

Definition at line 50 of file swscale.c.

Referenced by ff_swscale().

AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
max
#define max(a, b)
Definition: cuda_runtime.h:33
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
ctx
AVFormatContext * ctx
Definition: movenc.c:49
field
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
Definition: writing_filters.txt:78
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
DEBUG_SWSCALE_BUFFERS
#define DEBUG_SWSCALE_BUFFERS
Definition: swscale.c:254
min
float min
Definition: vorbis_enc_data.h:429