44#include " _image_resample.h"
55#include " py_converters_11.h"
66
7+ namespace py = pybind11;
8+ using namespace pybind11 ::literals;
79
810/* *********************************************************************
911 * Free functions
@@ -46,8 +48,8 @@ radius: float, default: 1
4648)""" ;
4749
4850
49- static pybind11 ::array_t <double >
50- _get_transform_mesh (const pybind11 ::object& transform, const pybind11 ::ssize_t *dims)
51+ static py ::array_t <double >
52+ _get_transform_mesh (const py ::object& transform, const py ::ssize_t *dims)
5153{
5254 /* TODO: Could we get away with float, rather than double, arrays here? */
5355
@@ -58,8 +60,8 @@ _get_transform_mesh(const pybind11::object& transform, const pybind11::ssize_t *
5860 // If attribute doesn't exist, raises Python AttributeError
5961 auto inverse = transform.attr (" inverted" )();
6062
61- pybind11 ::ssize_t mesh_dims[2 ] = {dims[0 ]*dims[1 ], 2 };
62- pybind11 ::array_t <double > input_mesh (mesh_dims);
63+ py ::ssize_t mesh_dims[2 ] = {dims[0 ]*dims[1 ], 2 };
64+ py ::array_t <double > input_mesh (mesh_dims);
6365 auto p = input_mesh.mutable_data ();
6466
6567 for (auto y = 0 ; y < dims[0 ]; ++y) {
@@ -72,7 +74,7 @@ _get_transform_mesh(const pybind11::object& transform, const pybind11::ssize_t *
7274 auto output_mesh = inverse.attr (" transform" )(input_mesh);
7375
7476 auto output_mesh_array =
75- pybind11 ::array_t <double , pybind11 ::array::c_style | pybind11 ::array::forcecast>(output_mesh);
77+ py ::array_t <double , py ::array::c_style | py ::array::forcecast>(output_mesh);
7678
7779 if (output_mesh_array.ndim () != 2 ) {
7880 throw std::runtime_error (
@@ -84,12 +86,12 @@ _get_transform_mesh(const pybind11::object& transform, const pybind11::ssize_t *
8486}
8587
8688
87- // Using generic pybind ::array for input and output arrays rather than the more usual
88- // pybind ::array_t<type> as function supports multiple array dtypes.
89+ // Using generic py ::array for input and output arrays rather than the more usual
90+ // py ::array_t<type> as this function supports multiple array dtypes.
8991static void
90- image_resample (pybind11 ::array input_array,
91- pybind11 ::array& output_array,
92- const pybind11 ::object& transform,
92+ image_resample (py ::array input_array,
93+ py ::array& output_array,
94+ const py ::object& transform,
9395 interpolation_e interpolation,
9496 bool resample_, // Avoid name clash with resample() function
9597 float alpha,
@@ -111,7 +113,7 @@ image_resample(pybind11::array input_array,
111113 }
112114
113115 // Ensure input array is contiguous, regardless of dtype
114- input_array = pybind11 ::array::ensure (input_array, pybind11 ::array::c_style);
116+ input_array = py ::array::ensure (input_array, py ::array::c_style);
115117
116118 // Validate output array
117119 auto out_ndim = output_array.ndim ();
@@ -132,7 +134,7 @@ image_resample(pybind11::array input_array,
132134 throw std::invalid_argument (" Input and output arrays have mismatched types" );
133135 }
134136
135- if ((output_array.flags () & pybind11 ::array::c_style) == 0 ) {
137+ if ((output_array.flags () & py ::array::c_style) == 0 ) {
136138 throw std::invalid_argument (" Output array must be C-contiguous" );
137139 }
138140
@@ -150,14 +152,14 @@ image_resample(pybind11::array input_array,
150152
151153 // Only used if transform is not affine.
152154 // Need to keep it in scope for the duration of this function.
153- pybind11 ::array_t <double > transform_mesh;
155+ py ::array_t <double > transform_mesh;
154156
155157 // Validate transform
156158 if (transform.is_none ()) {
157159 params.is_affine = true ;
158160 } else {
159161 // Raises Python AttributeError if no such attribute or TypeError if cast fails
160- bool is_affine = pybind11 ::cast<bool >(transform.attr (" is_affine" ));
162+ bool is_affine = py ::cast<bool >(transform.attr (" is_affine" ));
161163
162164 if (is_affine) {
163165 convert_trans_affine (transform, params.affine );
@@ -171,20 +173,20 @@ image_resample(pybind11::array input_array,
171173
172174 if (auto resampler =
173175 (ndim == 2 ) ? (
174- (dtype.is (pybind11 ::dtype::of<std::uint8_t >())) ? resample<agg::gray8> :
175- (dtype.is (pybind11 ::dtype::of<std::int8_t >())) ? resample<agg::gray8> :
176- (dtype.is (pybind11 ::dtype::of<std::uint16_t >())) ? resample<agg::gray16> :
177- (dtype.is (pybind11 ::dtype::of<std::int16_t >())) ? resample<agg::gray16> :
178- (dtype.is (pybind11 ::dtype::of<float >())) ? resample<agg::gray32> :
179- (dtype.is (pybind11 ::dtype::of<double >())) ? resample<agg::gray64> :
176+ (dtype.is (py ::dtype::of<std::uint8_t >())) ? resample<agg::gray8> :
177+ (dtype.is (py ::dtype::of<std::int8_t >())) ? resample<agg::gray8> :
178+ (dtype.is (py ::dtype::of<std::uint16_t >())) ? resample<agg::gray16> :
179+ (dtype.is (py ::dtype::of<std::int16_t >())) ? resample<agg::gray16> :
180+ (dtype.is (py ::dtype::of<float >())) ? resample<agg::gray32> :
181+ (dtype.is (py ::dtype::of<double >())) ? resample<agg::gray64> :
180182 nullptr ) : (
181183 // ndim == 3
182- (dtype.is (pybind11 ::dtype::of<std::uint8_t >())) ? resample<agg::rgba8> :
183- (dtype.is (pybind11 ::dtype::of<std::int8_t >())) ? resample<agg::rgba8> :
184- (dtype.is (pybind11 ::dtype::of<std::uint16_t >())) ? resample<agg::rgba16> :
185- (dtype.is (pybind11 ::dtype::of<std::int16_t >())) ? resample<agg::rgba16> :
186- (dtype.is (pybind11 ::dtype::of<float >())) ? resample<agg::rgba32> :
187- (dtype.is (pybind11 ::dtype::of<double >())) ? resample<agg::rgba64> :
184+ (dtype.is (py ::dtype::of<std::uint8_t >())) ? resample<agg::rgba8> :
185+ (dtype.is (py ::dtype::of<std::int8_t >())) ? resample<agg::rgba8> :
186+ (dtype.is (py ::dtype::of<std::uint16_t >())) ? resample<agg::rgba16> :
187+ (dtype.is (py ::dtype::of<std::int16_t >())) ? resample<agg::rgba16> :
188+ (dtype.is (py ::dtype::of<float >())) ? resample<agg::rgba32> :
189+ (dtype.is (py ::dtype::of<double >())) ? resample<agg::rgba64> :
188190 nullptr )) {
189191 Py_BEGIN_ALLOW_THREADS
190192 resampler (
@@ -199,7 +201,7 @@ image_resample(pybind11::array input_array,
199201
200202
201203PYBIND11_MODULE (_image, m) {
202- pybind11 ::enum_<interpolation_e>(m, " _InterpolationType" )
204+ py ::enum_<interpolation_e>(m, " _InterpolationType" )
203205 .value (" NEAREST" , NEAREST)
204206 .value (" BILINEAR" , BILINEAR)
205207 .value (" BICUBIC" , BICUBIC)
@@ -220,13 +222,13 @@ PYBIND11_MODULE(_image, m) {
220222 .export_values ();
221223
222224 m.def (" resample" , &image_resample,
223- pybind11::arg ( " input_array" ) ,
224- pybind11::arg ( " output_array" ) ,
225- pybind11::arg ( " transform" ) ,
226- pybind11::arg ( " interpolation" ) = interpolation_e::NEAREST,
227- pybind11::arg ( " resample" ) = false ,
228- pybind11::arg ( " alpha" ) = 1 ,
229- pybind11::arg ( " norm" ) = false ,
230- pybind11::arg ( " radius" ) = 1 ,
225+ " input_array" _a ,
226+ " output_array" _a ,
227+ " transform" _a ,
228+ " interpolation" _a = interpolation_e::NEAREST,
229+ " resample" _a = false ,
230+ " alpha" _a = 1 ,
231+ " norm" _a = false ,
232+ " radius" _a = 1 ,
231233 image_resample__doc__);
232234}
0 commit comments