Skip to content

Commit

Permalink
Added the Vapoursynth API header files to 'fix' AppVouyer building
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypoulter committed Jul 15, 2016
1 parent 935abfa commit 734fa45
Show file tree
Hide file tree
Showing 3 changed files with 572 additions and 0 deletions.
168 changes: 168 additions & 0 deletions QRCodeSource/VSHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*****************************************************************************
* Copyright (c) 2012-2015 Fredrik Mellbin
* --- Legal stuff ---
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*****************************************************************************/

#ifndef VSHELPER_H
#define VSHELPER_H

#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifdef _WIN32
#include <malloc.h>
#endif
#include "VapourSynth.h"

/* Visual Studio doesn't recognize inline in c mode */
#if defined(_MSC_VER) && !defined(__cplusplus)
#define inline _inline
#endif

/* A kinda portable definition of the C99 restrict keyword (or its inofficial C++ equivalent) */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* Available in C99 */
#define VS_RESTRICT restrict
#elif defined(__cplusplus) || defined(_MSC_VER) /* Almost all relevant C++ compilers support it so just assume it works */
#define VS_RESTRICT __restrict
#else /* Not supported */
#define VS_RESTRICT
#endif

#ifdef _WIN32
#define VS_ALIGNED_MALLOC(pptr, size, alignment) do { *(pptr) = _aligned_malloc((size), (alignment)); } while (0)
#define VS_ALIGNED_FREE(ptr) do { _aligned_free((ptr)); } while (0)
#else
#define VS_ALIGNED_MALLOC(pptr, size, alignment) do { if(posix_memalign((void**)(pptr), (alignment), (size))) *((void**)pptr) = NULL; } while (0)
#define VS_ALIGNED_FREE(ptr) do { free((ptr)); } while (0)
#endif

#define VSMAX(a,b) ((a) > (b) ? (a) : (b))
#define VSMIN(a,b) ((a) > (b) ? (b) : (a))

#ifdef __cplusplus
/* A nicer templated malloc for all the C++ users out there */
#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
template<typename T=void>
#else
template<typename T>
#endif
static inline T* vs_aligned_malloc(size_t size, size_t alignment) {
#ifdef _WIN32
return (T*)_aligned_malloc(size, alignment);
#else
void *tmp = NULL;
if (posix_memalign(&tmp, alignment, size))
tmp = 0;
return (T*)tmp;
#endif
}

static inline void vs_aligned_free(void *ptr) {
VS_ALIGNED_FREE(ptr);
}
#endif /* __cplusplus */

/* convenience function for checking if the format never changes between frames */
static inline int isConstantFormat(const VSVideoInfo *vi) {
return vi->height > 0 && vi->width > 0 && vi->format;
}

/* convenience function to check for if two clips have the same format (unknown/changeable will be considered the same too) */
static inline int isSameFormat(const VSVideoInfo *v1, const VSVideoInfo *v2) {
return v1->height == v2->height && v1->width == v2->width && v1->format == v2->format;
}

/* multiplies and divides a rational number, such as a frame duration, in place and reduces the result */
static inline void muldivRational(int64_t *num, int64_t *den, int64_t mul, int64_t div) {
/* do nothing if the rational number is invalid */
if (!*den)
return;

/* nobody wants to accidentally divide by zero */
assert(div);

int64_t a, b;
*num *= mul;
*den *= div;
a = *num;
b = *den;
while (b != 0) {
int64_t t = a;
a = b;
b = t % b;
}
if (a < 0)
a = -a;
*num /= a;
*den /= a;
}

/* reduces a rational number */
static inline void vs_normalizeRational(int64_t *num, int64_t *den) {
muldivRational(num, den, 1, 1);
}

/* add two rational numbers and reduces the result */
static inline void vs_addRational(int64_t *num, int64_t *den, int64_t addnum, int64_t addden) {
/* do nothing if the rational number is invalid */
if (!*den)
return;

/* nobody wants to accidentally add an invalid rational number */
assert(addden);

if (*den == addden) {
*num += addnum;
} else {
int64_t temp = addden;
addnum *= *den;
addden *= *den;
*num *= temp;
*den *= temp;

*num += addnum;

vs_normalizeRational(num, den);
}
}

/* converts an int64 to int with saturation, useful to silence warnings when reading int properties among other things */
static inline int int64ToIntS(int64_t i) {
if (i > INT_MAX)
return INT_MAX;
else if (i < INT_MIN)
return INT_MIN;
else return (int)i;
}

static inline void vs_bitblt(void *dstp, int dst_stride, const void *srcp, int src_stride, size_t row_size, size_t height) {
if (height) {
if (src_stride == dst_stride && src_stride == (int)row_size) {
memcpy(dstp, srcp, row_size * height);
} else {
const uint8_t *srcp8 = (const uint8_t *)srcp;
uint8_t *dstp8 = (uint8_t *)dstp;
size_t i;
for (i = 0; i < height; i++) {
memcpy(dstp8, srcp8, row_size);
srcp8 += src_stride;
dstp8 += dst_stride;
}
}
}
}

/* check if the frame dimensions are valid for a given format */
/* returns non-zero for valid width and height */
static inline int areValidDimensions(const VSFormat *fi, int width, int height) {
return !(width % (1 << fi->subSamplingW) || height % (1 << fi->subSamplingH));
}

#endif
70 changes: 70 additions & 0 deletions QRCodeSource/VSScript.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2013-2015 Fredrik Mellbin
*
* This file is part of VapourSynth.
*
* VapourSynth is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* VapourSynth is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with VapourSynth; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef VSSCRIPT_H
#define VSSCRIPT_H

#include "VapourSynth.h"

typedef struct VSScript VSScript;

typedef enum VSEvalFlags {
efSetWorkingDir = 1,
} VSEvalFlags;

/* Initialize the available scripting runtimes, returns zero on failure */
VS_API(int) vsscript_init(void);

/* Free all scripting runtimes */
VS_API(int) vsscript_finalize(void);

/*
* Pass a pointer to a null handle to create a new one
* The values returned by the query functions are only valid during the lifetime of the VSScript
* scriptFilename is if the error message should reference a certain file, NULL allowed in vsscript_evaluateScript()
* core is to pass in an already created instance so that mixed environments can be used,
* NULL creates a new core that can be fetched with vsscript_getCore() later OR implicitly uses the one associated with an already existing handle when passed
* If efSetWorkingDir is passed to flags the current working directory will be changed to the path of the script
* note that if scriptFilename is NULL in vsscript_evaluateScript() then __file__ won't be set and the working directory won't be changed
* Set efSetWorkingDir to get the default and recommended behavior
*/
VS_API(int) vsscript_evaluateScript(VSScript **handle, const char *script, const char *scriptFilename, int flags);
/* Convenience version of the above function that loads the script from a file */
VS_API(int) vsscript_evaluateFile(VSScript **handle, const char *scriptFilename, int flags);
/* Create an empty environment for use in later invocations, mostly useful to set script variables before execution */
VS_API(int) vsscript_createScript(VSScript **handle);

VS_API(void) vsscript_freeScript(VSScript *handle);
VS_API(const char *) vsscript_getError(VSScript *handle);
/* The node returned must be freed using freeNode() before calling vsscript_freeScript() */
VS_API(VSNodeRef *) vsscript_getOutput(VSScript *handle, int index);
VS_API(int) vsscript_clearOutput(VSScript *handle, int index);
/* The core is valid as long as the environment exists */
VS_API(VSCore *) vsscript_getCore(VSScript *handle);
VS_API(const VSAPI *) vsscript_getVSApi(void);

/* Variables names that are not set or not of a convertible type will return an error */
VS_API(int) vsscript_getVariable(VSScript *handle, const char *name, VSMap *dst);
VS_API(int) vsscript_setVariable(VSScript *handle, const VSMap *vars);
VS_API(int) vsscript_clearVariable(VSScript *handle, const char *name);
/* Tries to clear everything set in an environment, normally it is better to simply free an environment completely and create a new one */
VS_API(void) vsscript_clearEnvironment(VSScript *handle);

#endif /* VSSCRIPT_H */

0 comments on commit 734fa45

Please sign in to comment.