Commit bf93e32d authored by Julien Muchembled's avatar Julien Muchembled

Initial revision

parents
*.pyc
*.pyo
*.c
*.so
/build/
/dist/
This diff is collapsed.
include *.pyx
from setuptools import setup, Extension
import os
kw = dict(name="zopfli", libraries=["zopfli"])
try:
if int(os.getenv("WITHOUT_CYTHON") or 0):
raise ImportError
from Cython.Build import cythonize
except ImportError:
ext_modules = [Extension(sources=["zopfli.c"], **kw)]
else:
ext_modules = cythonize([Extension(sources=["zopfli.pyx"], **kw)])
classifiers = """\
License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)
Programming Language :: Cython
Programming Language :: Python :: 2
Programming Language :: Python :: 3
"""
setup(
name = 'cython-zopfli',
version = '0.1',
description = 'Zopfli bindings for Python',
author = 'Nexedi',
author_email = 'jm@nexedi.com',
url = 'https://lab.nexedi.com/nexedi/cython-zopfli',
license = 'GPL 2+',
classifiers=classifiers.splitlines(),
ext_modules = ext_modules,
)
from libc.stdlib cimport free
cdef extern from "zopfli/zopfli.h":
ctypedef enum ZopfliFormat:
ZOPFLI_FORMAT_GZIP
ZOPFLI_FORMAT_ZLIB
ZOPFLI_FORMAT_DEFLATE
ctypedef struct ZopfliOptions:
bint verbose
bint verbose_more
int numiterations
bint blocksplitting
int blocksplittingmax
void ZopfliInitOptions(ZopfliOptions* options)
void ZopfliCompress(const ZopfliOptions* options, ZopfliFormat output_type,
const unsigned char* in_, size_t insize,
unsigned char** out, size_t* outsize) nogil
FORMAT_GZIP = ZOPFLI_FORMAT_GZIP
FORMAT_ZLIB = ZOPFLI_FORMAT_ZLIB
FORMAT_DEFLATE = ZOPFLI_FORMAT_DEFLATE
cdef class Compress:
cdef ZopfliOptions options
cdef public ZopfliFormat output_type
def __init__(self, output_type, **kw):
ZopfliInitOptions(&self.options)
self.output_type = output_type
for x in kw.items():
setattr(self, *x)
property verbose:
def __get__(self): return self.options.verbose
def __set__(self, bint value): self.options.verbose = value
property verbose_more:
def __get__(self): return self.options.verbose_more
def __set__(self, bint value): self.options.verbose_more = value
property numiterations:
def __get__(self):
return self.options.numiterations
def __set__(self, int value):
if value <= 0:
raise ValueError('numiterations <= 0')
self.options.numiterations = value
property blocksplitting:
def __get__(self): return self.options.blocksplitting
def __set__(self, bint value): self.options.blocksplitting = value
property blocksplittingmax:
def __get__(self):
return self.options.blocksplittingmax
def __set__(self, int value):
if value < 0:
raise ValueError('blocksplittingmax < 0')
self.options.blocksplittingmax = value
def __call__(self, data):
cdef:
const unsigned char *in_ = data
unsigned char *out
size_t insize = len(data), outsize = 0
with nogil:
ZopfliCompress(&self.options, self.output_type,
in_, insize, &out, &outsize)
try:
return out[:outsize]
finally:
free(out)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment