comparison pytouhou/utils/lzss.pyx @ 490:1b532e7dd521

Decrease PBG3 loading time by improving lzss and bitstream integration.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 04 Oct 2013 14:28:49 +0200
parents 71cd4461bb7f
children 53fa73932e9a
comparison
equal deleted inserted replaced
489:59bd29568753 490:1b532e7dd521
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 cimport cython
15 from libc.stdlib cimport calloc, malloc, free 16 from libc.stdlib cimport calloc, malloc, free
16 17
18 from .bitstream cimport BitStream
17 19
18 cpdef bytes decompress(object bitstream, 20
21 @cython.cdivision(True)
22 cpdef bytes decompress(BitStream bitstream,
19 Py_ssize_t size, 23 Py_ssize_t size,
20 unsigned int dictionary_size=0x2000, 24 unsigned int dictionary_size=0x2000,
21 unsigned int offset_size=13, 25 unsigned int offset_size=13,
22 unsigned int length_size=4, 26 unsigned int length_size=4,
23 unsigned int minimum_match_length=3): 27 unsigned int minimum_match_length=3):
24 cdef unsigned int i, ptr, dictionary_head, offset, length 28 cdef Py_ssize_t ptr, length
29 cdef unsigned int dictionary_head
25 cdef unsigned char byte 30 cdef unsigned char byte
26 cdef char *out_data, *dictionary 31 cdef char *out_data, *dictionary
27 cdef bytes _out_data
28 32
29 out_data = <char*> malloc(size) 33 out_data = <char*> malloc(size)
30 dictionary = <char*> calloc(dictionary_size, 1) 34 dictionary = <char*> calloc(dictionary_size, 1)
31 dictionary_head, ptr = 1, 0 35 dictionary_head, ptr = 1, 0
32 36