avisynth: more intelligent RGB flipping

avs_is_color_space provides a generic way of checking whether the
video is RGB, and has been available through AVSC_API since 2.6.
This means that GetProcAddress doesn't have to run on every frame.

Signed-off-by: Stephen Hutchinson <qyot27@gmail.com>
This commit is contained in:
Stephen Hutchinson
2020-04-07 19:47:43 -04:00
parent 9f1b808bde
commit 4c40686ee2

View File

@@ -57,6 +57,7 @@ typedef struct AviSynthLibrary {
AVSC_DECLARE_FUNC(avs_get_version); AVSC_DECLARE_FUNC(avs_get_version);
AVSC_DECLARE_FUNC(avs_get_video_info); AVSC_DECLARE_FUNC(avs_get_video_info);
AVSC_DECLARE_FUNC(avs_invoke); AVSC_DECLARE_FUNC(avs_invoke);
AVSC_DECLARE_FUNC(avs_is_color_space);
AVSC_DECLARE_FUNC(avs_release_clip); AVSC_DECLARE_FUNC(avs_release_clip);
AVSC_DECLARE_FUNC(avs_release_value); AVSC_DECLARE_FUNC(avs_release_value);
AVSC_DECLARE_FUNC(avs_release_video_frame); AVSC_DECLARE_FUNC(avs_release_video_frame);
@@ -133,6 +134,7 @@ static av_cold int avisynth_load_library(void)
LOAD_AVS_FUNC(avs_get_version, 0); LOAD_AVS_FUNC(avs_get_version, 0);
LOAD_AVS_FUNC(avs_get_video_info, 0); LOAD_AVS_FUNC(avs_get_video_info, 0);
LOAD_AVS_FUNC(avs_invoke, 0); LOAD_AVS_FUNC(avs_invoke, 0);
LOAD_AVS_FUNC(avs_is_color_space, 1);
LOAD_AVS_FUNC(avs_release_clip, 0); LOAD_AVS_FUNC(avs_release_clip, 0);
LOAD_AVS_FUNC(avs_release_value, 0); LOAD_AVS_FUNC(avs_release_value, 0);
LOAD_AVS_FUNC(avs_release_video_frame, 0); LOAD_AVS_FUNC(avs_release_video_frame, 0);
@@ -628,7 +630,6 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
const unsigned char *src_p; const unsigned char *src_p;
int n, i, plane, rowsize, planeheight, pitch, bits, ret; int n, i, plane, rowsize, planeheight, pitch, bits, ret;
const char *error; const char *error;
int avsplus av_unused;
if (avs->curr_frame >= avs->vi->num_frames) if (avs->curr_frame >= avs->vi->num_frames)
return AVERROR_EOF; return AVERROR_EOF;
@@ -638,19 +639,6 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
if (discard) if (discard)
return 0; return 0;
#ifdef _WIN32
/* Detect whether we're using AviSynth 2.6 or AviSynth+ by
* looking for whether avs_is_planar_rgb exists. */
if (GetProcAddress(avs_library.library, "avs_is_planar_rgb") == NULL)
avsplus = 0;
else
avsplus = 1;
#else
/* AviSynth+ is now the only variant of AviSynth we support
* on Linux and macOS. */
avsplus = 1;
#endif
bits = avs_library.avs_bits_per_pixel(avs->vi); bits = avs_library.avs_bits_per_pixel(avs->vi);
/* Without the cast to int64_t, calculation overflows at about 9k x 9k /* Without the cast to int64_t, calculation overflows at about 9k x 9k
@@ -687,14 +675,9 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt,
planeheight = avs_library.avs_get_height_p(frame, plane); planeheight = avs_library.avs_get_height_p(frame, plane);
/* Flip RGB video. */ /* Flip RGB video. */
if (avs_is_rgb24(avs->vi) || avs_is_rgb(avs->vi)) { if (avs_library.avs_is_color_space(avs->vi, AVS_CS_BGR) ||
src_p = src_p + (planeheight - 1) * pitch; avs_library.avs_is_color_space(avs->vi, AVS_CS_BGR48) ||
pitch = -pitch; avs_library.avs_is_color_space(avs->vi, AVS_CS_BGR64)) {
}
/* Flip Planar RGB video */
if (avsplus && (avs_library.avs_is_planar_rgb(avs->vi) ||
avs_library.avs_is_planar_rgba(avs->vi))) {
src_p = src_p + (planeheight - 1) * pitch; src_p = src_p + (planeheight - 1) * pitch;
pitch = -pitch; pitch = -pitch;
} }