in imageops.c [61:157]
void image_resize(ImageObject* self, int new_height, int new_width, int antialiasing) {
IppStatus ipp_status;
unsigned char* new_buffer = NULL;
IppiSize old_size = { self->width, self->height };
IppiSize new_size = { new_width, new_height };
IppiPoint new_offset = { 0, 0 };
int specification_size = 0, initialization_buffer_size = 0, scratch_buffer_size = 0;
IppiResizeSpec_32f* specification = NULL;
Ipp8u* scratch_buffer = NULL;
Ipp8u* initialization_buffer = NULL;
new_buffer = malloc(new_height * new_width * self->channels);
if (new_buffer == NULL) {
PyErr_NoMemory();
goto cleanup;
}
ipp_status = ippiResizeGetSize_8u(old_size, new_size, ippLinear, antialiasing,
&specification_size, &initialization_buffer_size);
if (ipp_status != ippStsNoErr) {
PyErr_Format(PyExc_SystemError,
"ippiResizeGetSize_8u failed with status %d", ipp_status);
goto cleanup;
}
initialization_buffer = malloc(initialization_buffer_size);
if (initialization_buffer == NULL) {
PyErr_NoMemory();
goto cleanup;
}
specification = malloc(specification_size);
if (specification == NULL) {
PyErr_NoMemory();
goto cleanup;
}
if (antialiasing) {
ipp_status = ippiResizeAntialiasingLinearInit(
old_size, new_size, specification, initialization_buffer);
} else {
ipp_status = ippiResizeLinearInit_8u(old_size, new_size, specification);
}
if (ipp_status != ippStsNoErr) {
PyErr_Format(PyExc_SystemError,
"ippiResizeLinearInit_8u failed with status %d", ipp_status);
goto cleanup;
}
ipp_status = ippiResizeGetBufferSize_8u(specification, new_size, self->channels, &scratch_buffer_size);
if (ipp_status != ippStsNoErr) {
PyErr_Format(PyExc_SystemError,
"ippiResizeGetBufferSize_8u failed with status %d", ipp_status);
goto cleanup;
}
scratch_buffer = malloc(scratch_buffer_size);
if (scratch_buffer == NULL) {
PyErr_NoMemory();
goto cleanup;
}
if (antialiasing) {
ipp_status = ippiResizeAntialiasing_8u_C3R(
self->buffer + (self->y_offset * self->row_stride + self->x_offset) * self->channels,
self->row_stride * self->channels,
new_buffer, new_width * self->channels, new_offset, new_size,
ippBorderRepl, NULL, specification, scratch_buffer);
} else {
ipp_status = ippiResizeLinear_8u_C3R(
self->buffer + (self->y_offset * self->row_stride + self->x_offset) * self->channels,
self->row_stride * self->channels,
new_buffer, new_width * self->channels, new_offset, new_size,
ippBorderRepl, NULL, specification, scratch_buffer);
}
if (ipp_status != ippStsNoErr) {
PyErr_Format(PyExc_SystemError,
"ippiResizeLinear_8u_C3R failed with status %d", ipp_status);
goto cleanup;
}
free(self->buffer);
self->buffer = new_buffer;
new_buffer = NULL;
self->height = new_height;
self->width = new_width;
self->row_stride = new_width;
self->x_offset = 0;
self->y_offset = 0;
cleanup:
free(new_buffer);
free(specification);
free(initialization_buffer);
free(scratch_buffer);
}