Pillow/src/libImaging/Copy.c

58 lines
1.2 KiB
C
Raw Normal View History

/*
2010-07-31 06:52:47 +04:00
* The Python Imaging Library
* $Id$
*
* copy image
*
* history:
* 95-11-26 fl Moved from Imaging.c
* 97-05-12 fl Added ImagingCopy2
* 97-08-28 fl Allow imOut == NULL in ImagingCopy2
*
* Copyright (c) Fredrik Lundh 1995-97.
* Copyright (c) Secret Labs AB 1997.
*
* See the README file for details on usage and redistribution.
*/
#include "Imaging.h"
static Imaging
2021-01-03 06:17:51 +03:00
_copy(Imaging imOut, Imaging imIn) {
2010-07-31 06:52:47 +04:00
ImagingSectionCookie cookie;
int y;
2020-05-10 12:56:36 +03:00
if (!imIn) {
2021-01-03 06:17:51 +03:00
return (Imaging)ImagingError_ValueError(NULL);
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
2017-08-06 20:08:07 +03:00
imOut = ImagingNew2Dirty(imIn->mode, imOut, imIn);
2020-05-10 12:56:36 +03:00
if (!imOut) {
2010-07-31 06:52:47 +04:00
return NULL;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
ImagingCopyPalette(imOut, imIn);
2010-07-31 06:52:47 +04:00
ImagingSectionEnter(&cookie);
2020-05-10 12:56:36 +03:00
if (imIn->block != NULL && imOut->block != NULL) {
2020-05-01 15:08:57 +03:00
memcpy(imOut->block, imIn->block, imIn->ysize * imIn->linesize);
2020-05-10 12:56:36 +03:00
} else {
for (y = 0; y < imIn->ysize; y++) {
2010-07-31 06:52:47 +04:00
memcpy(imOut->image[y], imIn->image[y], imIn->linesize);
2020-05-10 12:56:36 +03:00
}
}
2010-07-31 06:52:47 +04:00
ImagingSectionLeave(&cookie);
return imOut;
}
Imaging
2021-01-03 06:17:51 +03:00
ImagingCopy(Imaging imIn) {
2010-07-31 06:52:47 +04:00
return _copy(NULL, imIn);
}
Imaging
2021-01-03 06:17:51 +03:00
ImagingCopy2(Imaging imOut, Imaging imIn) {
2010-07-31 06:52:47 +04:00
return _copy(imOut, imIn);
}