Skip to content

Commit 48ca8c5

Browse files
committed
transform.pixelate: Removed unused variables, single decref, reorder error check
1 parent 3b79bb4 commit 48ca8c5

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src_c/transform.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4243,38 +4243,34 @@ surf_pixelate(PyObject *self, PyObject *args, PyObject *kwargs)
42434243
return NULL;
42444244
}
42454245

4246-
double testWidth = round((double)src->surf->w / pixel_size);
4247-
double testHeight = round((double)src->surf->h / pixel_size);
4248-
42494246
if (pixel_size < 1) {
42504247
PyErr_SetString(PyExc_ValueError,
42514248
"Pixel size must be a nonnegative integer");
42524249
return NULL;
42534250
}
42544251

4255-
int width = (int)testWidth;
4256-
int height = (int)testHeight;
4252+
int width = (int)round((double)src->surf->w / pixel_size);
4253+
int height = (int)round((double)src->surf->h / pixel_size);
42574254

42584255
SDL_Surface *temp = scale_to(src, NULL, width, height);
42594256
intermediate = pgSurface_New(temp);
42604257
if (intermediate == NULL) {
42614258
SDL_FreeSurface(temp);
42624259
return NULL; /* Exception already set in scale_to */
42634260
}
4261+
42644262
new_surf = scale_to(intermediate, dst, src->surf->w, src->surf->h);
4263+
Py_DECREF(intermediate);
4264+
42654265
if (new_surf == NULL) {
4266-
Py_DECREF(intermediate);
42674266
return NULL; /* Exception already set in scale_to */
42684267
}
42694268

42704269
if (dst) {
42714270
Py_INCREF(dst);
4272-
Py_DECREF(intermediate);
42734271
return (PyObject *)dst;
42744272
}
42754273

4276-
Py_DECREF(intermediate);
4277-
42784274
return (PyObject *)pgSurface_New(new_surf);
42794275
}
42804276

0 commit comments

Comments
 (0)