Cleaning up.

Reduced memory limit to 1GB
This commit is contained in:
Josh Ware 2014-08-28 21:33:18 +10:00 committed by wiredfool
parent dd221d9ec0
commit 94194ed248
4 changed files with 28 additions and 28 deletions

View File

@ -135,8 +135,8 @@ class ImageFile(Image.Image):
self.map = None
use_mmap = self.filename and len(self.tile) == 1
# As of pypy 2.1.0, memory mapping was failing here.
use_mmap = use_mmap and not hasattr(sys, 'pypy_version_info')
use_mmap = use_mmap and not hasattr(sys, 'pypy_version_info')
readonly = 0
# look for read/seek overrides

View File

@ -4,7 +4,7 @@ from PIL import Image
from io import BytesIO
# Limits for testing the leak
mem_limit = 2048*1048576
mem_limit = 1024*1048576
stack_size = 8*1048576
iterations = int((mem_limit/stack_size)*2)
codecs = dir(Image.core)

View File

@ -68,7 +68,7 @@ j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data)
typedef void (*j2k_unpacker_t)(opj_image_t *in,
const JPEG2KTILEINFO *tileInfo,
const UINT8 *data,
const UINT8 *data,
Imaging im);
struct j2k_decode_unpacker {
@ -335,7 +335,7 @@ j2ku_srgb_rgb(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4;
for (n = 0; n < 3; ++n)
data[n] = &cdata[n][csiz[n] * y * w];
for (x = 0; x < w; ++x) {
for (n = 0; n < 3; ++n) {
UINT32 word = 0;
@ -388,7 +388,7 @@ j2ku_sycc_rgb(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
UINT8 *row_start = row;
for (n = 0; n < 3; ++n)
data[n] = &cdata[n][csiz[n] * y * w];
for (x = 0; x < w; ++x) {
for (n = 0; n < 3; ++n) {
UINT32 word = 0;
@ -442,7 +442,7 @@ j2ku_srgba_rgba(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4;
for (n = 0; n < 4; ++n)
data[n] = &cdata[n][csiz[n] * y * w];
for (x = 0; x < w; ++x) {
for (n = 0; n < 4; ++n) {
UINT32 word = 0;
@ -494,7 +494,7 @@ j2ku_sycca_rgba(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
UINT8 *row_start = row;
for (n = 0; n < 4; ++n)
data[n] = &cdata[n][csiz[n] * y * w];
for (x = 0; x < w; ++x) {
for (n = 0; n < 4; ++n) {
UINT32 word = 0;
@ -587,13 +587,13 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
/* Setup decompression context */
context->error_msg = NULL;
opj_set_default_decoder_parameters(&params);
params.cp_reduce = context->reduce;
params.cp_layer = context->layers;
codec = opj_create_decompress(context->format);
if (!codec) {
state->errcode = IMAGING_CODEC_BROKEN;
state->state = J2K_STATE_FAILED;
@ -616,7 +616,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
state->state = J2K_STATE_FAILED;
goto quick_exit;
}
for (n = 1; n < image->numcomps; ++n) {
if (image->comps[n].dx != 1 || image->comps[n].dy != 1) {
state->errcode = IMAGING_CODEC_BROKEN;
@ -624,8 +624,8 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
goto quick_exit;
}
}
/*
/*
Colorspace Number of components PIL mode
------------------------------------------------------
sRGB 3 RGB
@ -633,22 +633,22 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
gray 1 L or I
gray 2 LA
YCC 3 YCbCr
If colorspace is unspecified, we assume:
Number of components Colorspace
-----------------------------------------
1 gray
2 gray (+ alpha)
3 sRGB
4 sRGB (+ alpha)
*/
/* Find the correct unpacker */
color_space = image->color_space;
if (color_space == OPJ_CLRSPC_UNSPECIFIED) {
switch (image->numcomps) {
case 1: case 2: color_space = OPJ_CLRSPC_GRAY; break;
@ -668,7 +668,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
if (!unpack) {
state->errcode = IMAGING_CODEC_BROKEN;
state->state = J2K_STATE_FAILED;
goto quick_exit;
goto quick_exit;
}
/* Decode the image tile-by-tile; this means we only need use as much
@ -797,11 +797,11 @@ ImagingJpeg2KDecodeCleanup(ImagingCodecState state) {
if (context->error_msg)
free ((void *)context->error_msg);
context->error_msg = NULL;
if (context->decoder)
ImagingIncrementalCodecDestroy(context->decoder);
context->error_msg = NULL;
/* Prevent multiple calls to ImagingIncrementalCodecDestroy */
context->decoder = NULL;

View File

@ -303,7 +303,7 @@ j2k_encode_entry(Imaging im, ImagingCodecState state,
prec = 16;
bpp = 12;
} else if (strcmp (im->mode, "LA") == 0) {
components = 2;
components = 2;
color_space = OPJ_CLRSPC_GRAY;
pack = j2k_pack_la;
} else if (strcmp (im->mode, "RGB") == 0) {
@ -340,7 +340,7 @@ j2k_encode_entry(Imaging im, ImagingCodecState state,
context->error_msg = NULL;
opj_set_default_encoder_parameters(&params);
params.image_offset_x0 = context->offset_x;
params.image_offset_y0 = context->offset_y;
@ -546,8 +546,8 @@ ImagingJpeg2KEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
return -1;
if (state->state == J2K_STATE_START) {
int seekable = (context->format != OPJ_CODEC_J2K
? INCREMENTAL_CODEC_SEEKABLE
int seekable = (context->format != OPJ_CODEC_J2K
? INCREMENTAL_CODEC_SEEKABLE
: INCREMENTAL_CODEC_NOT_SEEKABLE);
context->encoder = ImagingIncrementalCodecCreate(j2k_encode_entry,
@ -555,6 +555,7 @@ ImagingJpeg2KEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
INCREMENTAL_CODEC_WRITE,
seekable,
context->fd);
if (!context->encoder) {
state->errcode = IMAGING_CODEC_BROKEN;
state->state = J2K_STATE_FAILED;
@ -589,7 +590,6 @@ ImagingJpeg2KEncodeCleanup(ImagingCodecState state) {
/* Prevent multiple calls to ImagingIncrementalCodecDestroy */
context->encoder = NULL;
return -1;
}