@@ -258,29 +258,37 @@ ImagingBoxBlur(Imaging imOut, Imaging imIn, float xradius, float yradius, int n)
258258 return ImagingError_ModeError ();
259259 }
260260
261- imTransposed = ImagingNewDirty (imIn -> mode , imIn -> ysize , imIn -> xsize );
262- if (!imTransposed ) {
263- return NULL ;
264- }
265-
266261 /* Apply blur in one dimension.
267262 Use imOut as a destination at first pass,
268263 then use imOut as a source too. */
269- ImagingHorizontalBoxBlur (imOut , imIn , xradius );
270- for (i = 1 ; i < n ; i ++ ) {
271- ImagingHorizontalBoxBlur (imOut , imOut , xradius );
272- }
273- /* Transpose result for blur in another direction. */
274- ImagingTranspose (imTransposed , imOut );
275264
276- /* Reuse imTransposed as a source and destination there. */
277- for (i = 0 ; i < n ; i ++ ) {
278- ImagingHorizontalBoxBlur (imTransposed , imTransposed , yradius );
265+ if (xradius != 0 ) {
266+ ImagingHorizontalBoxBlur (imOut , imIn , xradius );
267+ for (i = 1 ; i < n ; i ++ ) {
268+ ImagingHorizontalBoxBlur (imOut , imOut , xradius );
269+ }
279270 }
280- /* Restore original orientation. */
281- ImagingTranspose (imOut , imTransposed );
271+ if (yradius != 0 ) {
272+ imTransposed = ImagingNewDirty (imIn -> mode , imIn -> ysize , imIn -> xsize );
273+ if (!imTransposed ) {
274+ return NULL ;
275+ }
282276
283- ImagingDelete (imTransposed );
277+ /* Transpose result for blur in another direction. */
278+ ImagingTranspose (imTransposed , xradius == 0 ? imIn : imOut );
279+
280+ /* Reuse imTransposed as a source and destination there. */
281+ for (i = 0 ; i < n ; i ++ ) {
282+ ImagingHorizontalBoxBlur (imTransposed , imTransposed , yradius );
283+ }
284+ /* Restore original orientation. */
285+ ImagingTranspose (imOut , imTransposed );
286+
287+ ImagingDelete (imTransposed );
288+ }
289+ if (xradius == 0 && yradius == 0 ) {
290+ ImagingCopy2 (imOut , imIn );
291+ }
284292
285293 return imOut ;
286294}
0 commit comments