Pillow

Форк
0
63 строки · 1.3 Кб
1
/*
2
 * The Python Imaging Library
3
 * $Id$
4
 *
5
 * cut region from image
6
 *
7
 * history:
8
 * 95-11-27 fl Created
9
 * 98-07-10 fl Fixed "null result" error
10
 * 99-02-05 fl Rewritten to use Paste primitive
11
 *
12
 * Copyright (c) Secret Labs AB 1997-99.
13
 * Copyright (c) Fredrik Lundh 1995.
14
 *
15
 * See the README file for information on usage and redistribution.
16
 */
17

18
#include "Imaging.h"
19

20
Imaging
21
ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1) {
22
    Imaging imOut;
23
    int xsize, ysize;
24
    int dx0, dy0, dx1, dy1;
25
    INT32 zero = 0;
26

27
    if (!imIn) {
28
        return (Imaging)ImagingError_ModeError();
29
    }
30

31
    xsize = sx1 - sx0;
32
    if (xsize < 0) {
33
        xsize = 0;
34
    }
35
    ysize = sy1 - sy0;
36
    if (ysize < 0) {
37
        ysize = 0;
38
    }
39

40
    imOut = ImagingNewDirty(imIn->mode, xsize, ysize);
41
    if (!imOut) {
42
        return NULL;
43
    }
44

45
    ImagingCopyPalette(imOut, imIn);
46

47
    if (sx0 < 0 || sy0 < 0 || sx1 > imIn->xsize || sy1 > imIn->ysize) {
48
        (void)ImagingFill(imOut, &zero);
49
    }
50

51
    dx0 = -sx0;
52
    dy0 = -sy0;
53
    dx1 = imIn->xsize - sx0;
54
    dy1 = imIn->ysize - sy0;
55

56
    /* paste the source image on top of the output image!!! */
57
    if (ImagingPaste(imOut, imIn, NULL, dx0, dy0, dx1, dy1) < 0) {
58
        ImagingDelete(imOut);
59
        return NULL;
60
    }
61

62
    return imOut;
63
}
64

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.