Pillow

Форк
0
/
RawDecode.c 
92 строки · 2.0 Кб
1
/*
2
 * The Python Imaging Library.
3
 * $Id$
4
 *
5
 * decoder for raw (uncompressed) image data
6
 *
7
 * history:
8
 * 96-03-07 fl rewritten
9
 *
10
 * Copyright (c) Fredrik Lundh 1996.
11
 * Copyright (c) Secret Labs AB 1997.
12
 *
13
 * See the README file for information on usage and redistribution.
14
 */
15

16
#include "Imaging.h"
17

18
#include "Raw.h"
19

20
int
21
ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) {
22
    enum { LINE = 1, SKIP };
23
    RAWSTATE *rawstate = state->context;
24

25
    UINT8 *ptr;
26

27
    if (state->state == 0) {
28
        /* Initialize context variables */
29

30
        /* get size of image data and padding */
31
        state->bytes = (state->xsize * state->bits + 7) / 8;
32
        if (rawstate->stride) {
33
            rawstate->skip = rawstate->stride - state->bytes;
34
            if (rawstate->skip < 0) {
35
                state->errcode = IMAGING_CODEC_CONFIG;
36
                return -1;
37
            }
38
        } else {
39
            rawstate->skip = 0;
40
        }
41

42
        /* check image orientation */
43
        if (state->ystep < 0) {
44
            state->y = state->ysize - 1;
45
            state->ystep = -1;
46
        } else {
47
            state->ystep = 1;
48
        }
49

50
        state->state = LINE;
51
    }
52

53
    ptr = buf;
54

55
    for (;;) {
56
        if (state->state == SKIP) {
57
            /* Skip padding between lines */
58

59
            if (bytes < rawstate->skip) {
60
                return ptr - buf;
61
            }
62

63
            ptr += rawstate->skip;
64
            bytes -= rawstate->skip;
65

66
            state->state = LINE;
67
        }
68

69
        if (bytes < state->bytes) {
70
            return ptr - buf;
71
        }
72

73
        /* Unpack data */
74
        state->shuffle(
75
            (UINT8 *)im->image[state->y + state->yoff] + state->xoff * im->pixelsize,
76
            ptr,
77
            state->xsize
78
        );
79

80
        ptr += state->bytes;
81
        bytes -= state->bytes;
82

83
        state->y += state->ystep;
84

85
        if (state->y < 0 || state->y >= state->ysize) {
86
            /* End of file (errcode = 0) */
87
            return -1;
88
        }
89

90
        state->state = SKIP;
91
    }
92
}
93

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

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

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

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