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.
Unified · Split
| @@ -57,6 +57,7 @@ typedef struct AviSynthLibrary { · 56 unmodified lines | ||
| 57 | 57 | AVSC_DECLARE_FUNC(avs_get_version); |
| 58 | 58 | AVSC_DECLARE_FUNC(avs_get_video_info); |
| 59 | 59 | AVSC_DECLARE_FUNC(avs_invoke); |
| 60 | + AVSC_DECLARE_FUNC(avs_is_color_space); | |
| 60 | 61 | AVSC_DECLARE_FUNC(avs_release_clip); |
| 61 | 62 | AVSC_DECLARE_FUNC(avs_release_value); |
| 62 | 63 | AVSC_DECLARE_FUNC(avs_release_video_frame); |
| @@ -133,6 +134,7 @@ static av_cold int avisynth_load_library(void) · 70 unmodified lines | ||
| 133 | 134 | LOAD_AVS_FUNC(avs_get_version, 0); |
| 134 | 135 | LOAD_AVS_FUNC(avs_get_video_info, 0); |
| 135 | 136 | LOAD_AVS_FUNC(avs_invoke, 0); |
| 137 | + LOAD_AVS_FUNC(avs_is_color_space, 1); | |
| 136 | 138 | LOAD_AVS_FUNC(avs_release_clip, 0); |
| 137 | 139 | LOAD_AVS_FUNC(avs_release_value, 0); |
| 138 | 140 | LOAD_AVS_FUNC(avs_release_video_frame, 0); |
| @@ -628,7 +630,6 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, · 489 unmodified lines | ||
| 628 | 630 | const unsigned char *src_p; |
| 629 | 631 | int n, i, plane, rowsize, planeheight, pitch, bits, ret; |
| 630 | 632 | const char *error; |
| 631 | − int avsplus av_unused; | |
| 632 | 633 | |
| 633 | 634 | if (avs->curr_frame >= avs->vi->num_frames) |
| 634 | 635 | return AVERROR_EOF; |
| @@ -638,19 +639,6 @@ static int avisynth_read_packet_video(AVFormatContext *s, AVPacket *pkt, · 3 unmodified lines | ||
| 638 | 639 | if (discard) |
| 639 | 640 | return 0; |
| 640 | 641 | |
| 641 | −#ifdef _WIN32 | |
| 642 | − /* Detect whether we're using AviSynth 2.6 or AviSynth+ by | |
| 643 | − * looking for whether avs_is_planar_rgb exists. */ | |
| 644 | − if (GetProcAddress(avs_library.library, "avs_is_planar_rgb") == NULL) | |
| 645 | − avsplus = 0; | |
| 646 | − else | |
| 647 | − avsplus = 1; | |
| 648 | −#else | |
| 649 | − /* AviSynth+ is now the only variant of AviSynth we support | |
| 650 | − * on Linux and macOS. */ | |
| 651 | − avsplus = 1; | |
| 652 | −#endif | |
| 653 | − | |
| 654 | 642 | bits = avs_library.avs_bits_per_pixel(avs->vi); |
| 655 | 643 | |
| 656 | 644 | /* 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, · 30 unmodified lines | ||
| 687 | 675 | planeheight = avs_library.avs_get_height_p(frame, plane); |
| 688 | 676 | |
| 689 | 677 | /* Flip RGB video. */ |
| 690 | − if (avs_is_rgb24(avs->vi) || avs_is_rgb(avs->vi)) { | |
| 691 | − src_p = src_p + (planeheight - 1) * pitch; | |
| 692 | − pitch = -pitch; | |
| 693 | − } | |
| 694 | − | |
| 695 | − /* Flip Planar RGB video */ | |
| 696 | − if (avsplus && (avs_library.avs_is_planar_rgb(avs->vi) || | |
| 697 | − avs_library.avs_is_planar_rgba(avs->vi))) { | |
| 678 | + if (avs_library.avs_is_color_space(avs->vi, AVS_CS_BGR) || | |
| 679 | + avs_library.avs_is_color_space(avs->vi, AVS_CS_BGR48) || | |
| 680 | + avs_library.avs_is_color_space(avs->vi, AVS_CS_BGR64)) { | |
| 698 | 681 | src_p = src_p + (planeheight - 1) * pitch; |
| 699 | 682 | pitch = -pitch; |
| 700 | 683 | } |