refactor to different file

This commit is contained in:
wiredfool 2016-06-11 05:14:58 -07:00
parent 857ee63436
commit b152d99d66
4 changed files with 80 additions and 78 deletions

View File

@ -850,7 +850,6 @@ PyImaging_Jpeg2KDecoderNew(PyObject* self, PyObject* args)
int layers = 0;
int fd = -1;
PY_LONG_LONG length = -1;
PyObject * py_fd;
if (!PyArg_ParseTuple(args, "ss|iiiL", &mode, &format,
&reduce, &layers, &fd, &length))
@ -886,60 +885,3 @@ PyImaging_Jpeg2KDecoderNew(PyObject* self, PyObject* args)
}
#endif /* HAVE_OPENJPEG */
Py_ssize_t
_imaging_read_pyFd(PyObject *fd, char* dest, Py_ssize_t bytes)
{
/* dest should be a buffer bytes long, returns length of read
-1 on error */
PyObject *result;
char *buffer;
Py_ssize_t length;
int bytes_result;
result = PyObject_CallMethod(fd, "read", "n", bytes);
bytes_result = PyBytes_AsStringAndSize(result, &buffer, &length);
if (bytes_result == -1) {
goto err;
}
if (length > bytes) {
goto err;
}
memcpy(dest, buffer, length);
Py_DECREF(result);
return length;
err:
Py_DECREF(result);
return -1;
}
int
_imaging_seek_pyFd(PyObject *fd, Py_ssize_t offset, int whence)
{
PyObject *result;
result = PyObject_CallMethod(fd, "seek", "ni", offset, whence);
Py_DECREF(result);
return 0;
}
Py_ssize_t
_imaging_tell_pyFd(PyObject *fd)
{
PyObject *result;
Py_ssize_t location;
result = PyObject_CallMethod(fd, "tell", NULL);
location = PyInt_AsSsize_t(result);
Py_DECREF(result);
return location;
}

View File

@ -1032,25 +1032,6 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args)
#endif
Py_ssize_t
_imaging_write_pyFd(PyObject *fd, char* src, Py_ssize_t bytes)
{
PyObject *result;
PyObject *byteObj;
byteObj = PyBytes_FromStringAndSize(src, bytes);
result = PyObject_CallMethod(fd, "write", "O", byteObj);
Py_DECREF(byteObj);
Py_DECREF(result);
return bytes;
}
/*
* Local Variables:
* c-basic-offset: 4

79
libImaging/codec_fd.c Normal file
View File

@ -0,0 +1,79 @@
#include "Python.h"
#include "Imaging.h"
#include "../py3.h"
Py_ssize_t
_imaging_read_pyFd(PyObject *fd, char* dest, Py_ssize_t bytes)
{
/* dest should be a buffer bytes long, returns length of read
-1 on error */
PyObject *result;
char *buffer;
Py_ssize_t length;
int bytes_result;
result = PyObject_CallMethod(fd, "read", "n", bytes);
bytes_result = PyBytes_AsStringAndSize(result, &buffer, &length);
if (bytes_result == -1) {
goto err;
}
if (length > bytes) {
goto err;
}
memcpy(dest, buffer, length);
Py_DECREF(result);
return length;
err:
Py_DECREF(result);
return -1;
}
Py_ssize_t
_imaging_write_pyFd(PyObject *fd, char* src, Py_ssize_t bytes)
{
PyObject *result;
PyObject *byteObj;
byteObj = PyBytes_FromStringAndSize(src, bytes);
result = PyObject_CallMethod(fd, "write", "O", byteObj);
Py_DECREF(byteObj);
Py_DECREF(result);
return bytes;
}
int
_imaging_seek_pyFd(PyObject *fd, Py_ssize_t offset, int whence)
{
PyObject *result;
result = PyObject_CallMethod(fd, "seek", "ni", offset, whence);
Py_DECREF(result);
return 0;
}
Py_ssize_t
_imaging_tell_pyFd(PyObject *fd)
{
PyObject *result;
Py_ssize_t location;
result = PyObject_CallMethod(fd, "tell", NULL);
location = PyInt_AsSsize_t(result);
Py_DECREF(result);
return location;
}

View File

@ -36,7 +36,7 @@ _LIB_IMAGING = (
"RankFilter", "RawDecode", "RawEncode", "Storage", "SunRleDecode",
"TgaRleDecode", "Unpack", "UnpackYCC", "UnsharpMask", "XbmDecode",
"XbmEncode", "ZipDecode", "ZipEncode", "TiffDecode", "Jpeg2KDecode",
"Jpeg2KEncode", "BoxBlur", "QuantPngQuant")
"Jpeg2KEncode", "BoxBlur", "QuantPngQuant", "codec_fd")
DEBUG = False