VSHelper4.h — VapourSynth R72 documentation

# VSHelper4.h

## Table of contents

Introduction

Macros

  VSH_STD_PLUGIN_ID

  VSH_RESIZE_PLUGIN_ID

  VSH_TEXT_PLUGIN_ID

  VS_RESTRICT

  VSH_ALIGNED_MALLOC

  VSH_ALIGNED_FREE

  VSMIN

  VSMAX

Functions

  vsh_aligned_malloc

  vsh_aligned_free

  isConstantVideoFormat

  isSameVideoFormat

  isSameVideoPresetFormat

  isSameVideoInfo

  isSameAudioFormat

  isSameAudioInfo

  muldivRational

  addRational

  reduceRational

  int64ToIntS

  doubleToFloatS

  bitblt

  areValidDimensions

## Introduction

This is a collection of helpful macros and functions. Note that all functions (not macros) are either prefixed with vsh_ in C mode or placed in the vsh namespace for C++. This documentation will use the C++ names for these function.

## Macros

### VSH_STD_PLUGIN_ID

Macro defined to the internal std plugin id provided for convenience.

### VSH_RESIZE_PLUGIN_ID

Macro defined to the internal resizer plugin id provided for convenience.

### VSH_TEXT_PLUGIN_ID

Macro defined to the internal std plugin id provided for convenience.

### VS_RESTRICT

Attempts to provide a portable definition of the C99 `restrict` keyword, or its C++ counterpart.

### VSH_ALIGNED_MALLOC

VSH_ALIGNED_MALLOC(pptr, size, alignment)

Expands to _aligned_malloc() in Windows, and posix_memalign() elsewhere. Note that the arguments are in the style of posix_memalign().

pptr is a pointer to a pointer.

### VSH_ALIGNED_FREE

VSH_ALIGNED_FREE(ptr)

Expands to _aligned_free() in Windows, and free() elsewhere.

ptr is a pointer.

### VSMIN

VSMIN(a, b)

Returns the minimum of the two numbers.

### VSMAX

VSMAX(a, b)

Returns the maximum of the two numbers.

## Functions

### vsh_aligned_malloc

T *vsh::vsh_aligned_malloc(size_t size, size_t alignment)

  A templated aligned malloc for C++. It uses the same functions as the VSH_ALIGNED_MALLOC macro but is easier to use.

### vsh_aligned_free

void vsh::vsh_aligned_free(void *ptr)

  This simply uses the VSH_ALIGNED_FREE macro.

### isConstantVideoFormat

static inline bool vsh::isConstantVideoFormat(const VSVideoInfo *vi)

  Checks if a clip’s format and dimensions are known (and therefore constant).

### isSameVideoFormat

static inline bool vsh::isSameVideoFormat(const VSVideoInfo *v1, const VSVideoInfo *v2)

  Checks if two clips have the same video format. If the format is unknown in both, it will be considered the same.

### isSameVideoPresetFormat

static inline bool vsh::isSameVideoPresetFormat(unsigned presetFormat, const VSVideoFormat *v, VSCore *core, const VSAPI *vsapi)

  Checks if a clip has the same video format as the preset.

### isSameVideoInfo

static inline bool vsh::isSameVideoInfo(const VSVideoInfo *v1, const VSVideoInfo *v2)

  Checks if two clips have the same video format and dimensions. If the format is unknown in both, it will be considered the same. This is also true for the dimensions. Framerate is not taken into consideration when comparing.

### isSameAudioFormat

static inline bool vsh::isSameAudioFormat(const VSAudioInfo *v1, const VSAudioInfo *v2)

  Checks if two clips have the same audio format.

### isSameAudioInfo

static inline bool vsh::isSameAudioInfo(const VSAudioInfo *v1, const VSAudioInfo *v2)

  Checks if two clips have the same audio format and samplerate.

### muldivRational

static inline void vsh::muldivRational(int64_t *num, int64_t *den, int64_t mul, int64_t div)

  Multiplies two rational numbers and reduces the result, i.e. num/den * mul/div. The result is stored in num and den.

  The caller must ensure that div is not 0.

### reduceRational

static inline void vsh::reduceRational(int64_t *num, int64_t *den)

  Reduces a rational number.

### addRational

static inline void vsh::addRational(int64_t *num, int64_t *den, int64_t addnum, int64_t addden)

  Adds two rational numbers and reduces the result, i.e. num/den + addnum/addden. The result is stored in num and den.

### int64ToIntS

static inline int vsh::int64ToIntS(int64_t i)

  Converts an int64_t to int with signed saturation. It’s useful to silence warnings when reading integer properties from a VSMap and to avoid unexpected behavior on int overflow.

### doubleToFloatS

static inline int vsh::doubleToFloatS(double d)

  Converts a double to float. It’s useful to silence warnings when reading double properties from a VSMap and mostly exists to mirror int64ToIntS.

### bitblt

static inline void vsh::bitblt(void *dstp, int dst_stride, const void *srcp, int src_stride, size_t row_size, size_t height)

  Copies bytes from one plane to another. Basically, it is memcpy in a loop.

  row_size is in bytes.

### areValidDimensions

static inline bool vsh::areValidDimensions(const VSFormat *fi, int width, int height)

  Checks if the given dimensions are valid for a particular format, with regards to chroma subsampling.