@@ -65,12 +65,12 @@ void CpuDeviceInterface::initialize(
6565 // choose color conversion library publicly; we only use this ability
6666 // internally.
6767
68- // If any transforms are not swscale compatible, then we can't use swscale.
69- bool areTransformsSwScaleCompatible = true ;
70- for ( const auto & transform : transforms) {
71- areTransformsSwScaleCompatible =
72- areTransformsSwScaleCompatible && transform-> isSwScaleCompatible ();
73- }
68+ // We can only use swscale when we have a single resize transform. Note that
69+ // this means swscale will not support the case of having several,
70+ // back-to-base resizes. There's no strong reason to even do that, but if
71+ // someone does, it's more correct to implement that with filtergraph.
72+ bool areTransformsSwScaleCompatible = transforms. empty () ||
73+ (transforms. size () == 1 && transforms[ 0 ]-> isResize ());
7474
7575 // swscale requires widths to be multiples of 32:
7676 // https://stackoverflow.com/questions/74351955/turn-off-sw-scale-conversion-to-planar-yuv-32-byte-alignment-requirements
@@ -95,8 +95,14 @@ void CpuDeviceInterface::initialize(
9595 (userRequestedSwScale || isWidthSwScaleCompatible)) {
9696 colorConversionLibrary_ = ColorConversionLibrary::SWSCALE;
9797
98- // SCOTT NEXT TODO: set swsFlags_
99-
98+ // We established above that if the transforms are swscale compatible and
99+ // non-empty, then they must have only one transforms, and that transform is
100+ // ResizeTransform.
101+ if (!transforms.empty ()) {
102+ auto resize = dynamic_cast <ResizeTransform*>(transforms[0 ].get ());
103+ TORCH_CHECK (resize != nullptr , " ResizeTransform expected but not found!" )
104+ swsFlags_ = resize->getSwsFlags ();
105+ }
100106 } else {
101107 colorConversionLibrary_ = ColorConversionLibrary::FILTERGRAPH;
102108
0 commit comments