Fixed some problems with the reduce option, as well as a number of warnings from GCC.

This commit is contained in:
Alastair Houghton 2014-03-27 08:35:38 +00:00
parent 831216f609
commit 18d6432036
3 changed files with 22 additions and 11 deletions

View File

@ -169,14 +169,14 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
if self.reduce:
power = 1 << self.reduce
adjust = power >> 1
self.size = ((self.size[0] + adjust) / power,
(self.size[1] + adjust) / power)
self.size = (int((self.size[0] + adjust) / power),
int((self.size[1] + adjust) / power))
if self.tile:
# Update the reduce and layers settings
t = self.tile[0]
t3 = (t[3][0], self.reduce, self.layers, t[3][3])
self.tile = [(t[0], t[1], t[2], t3)]
self.tile = [(t[0], (0, 0) + self.size, t[2], t3)]
ImageFile.ImageFile.load(self)

View File

@ -130,6 +130,9 @@ codec_thread(void *ptr)
static void
flush_stream(ImagingIncrementalCodec codec)
{
UINT8 *buffer;
size_t bytes;
/* This is to flush data from the write buffer for a seekable write
codec. */
if (codec->read_or_write != INCREMENTAL_CODEC_WRITE
@ -140,8 +143,8 @@ flush_stream(ImagingIncrementalCodec codec)
DEBUG("flushing data\n");
UINT8 *buffer = codec->stream.buffer;
size_t bytes = codec->stream.ptr - codec->stream.buffer;
buffer = codec->stream.buffer;
bytes = codec->stream.ptr - codec->stream.buffer;
codec->state->errcode = 0;
codec->seekable = INCREMENTAL_CODEC_NOT_SEEKABLE;
@ -645,6 +648,8 @@ off_t
ImagingIncrementalCodecSeek(ImagingIncrementalCodec codec,
off_t bytes)
{
off_t buffered;
DEBUG("seeking (going to %llu bytes)\n", (unsigned long long)bytes);
if (codec->stream.fd >= 0)
@ -660,7 +665,7 @@ ImagingIncrementalCodecSeek(ImagingIncrementalCodec codec,
return -1;
}
off_t buffered = codec->stream.top - codec->stream.buffer;
buffered = codec->stream.top - codec->stream.buffer;
if (bytes <= buffered) {
DEBUG("seek within buffer\n");

View File

@ -230,7 +230,7 @@ j2ku_graya_la(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
const UINT8 *adata = &atiledata[acsiz * y * w];
UINT8 *row = (UINT8 *)im->image[y0 + y] + x0 * 4;
for (x = 0; x < w; ++x) {
UINT32 word = 0, aword = 0;
UINT32 word = 0, aword = 0, byte;
switch (csiz) {
case 1: word = *data++; break;
@ -244,7 +244,7 @@ j2ku_graya_la(opj_image_t *in, const JPEG2KTILEINFO *tileinfo,
case 4: aword = *(const UINT32 *)adata; adata += 4; break;
}
UINT8 byte = j2ku_shift(offset + word, shift);
byte = j2ku_shift(offset + word, shift);
row[0] = row[1] = row[2] = byte;
row[3] = j2ku_shift(aoffset + aword, ashift);
row += 4;
@ -552,9 +552,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
}
for (n = 1; n < image->numcomps; ++n) {
/* Check that the sample frequency is uniform */
if (image->comps[0].dx != image->comps[n].dx
|| image->comps[0].dy != image->comps[n].dy) {
if (image->comps[n].dx != 1 || image->comps[n].dy != 1) {
state->errcode = IMAGING_CODEC_BROKEN;
state->state = J2K_STATE_FAILED;
goto quick_exit;
@ -612,6 +610,7 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
for (;;) {
JPEG2KTILEINFO tile_info;
OPJ_BOOL should_continue;
unsigned correction = (1 << params.cp_reduce) - 1;
if (!opj_read_tile_header(codec,
stream,
@ -629,6 +628,13 @@ j2k_decode_entry(Imaging im, ImagingCodecState state,
if (!should_continue)
break;
/* Adjust the tile co-ordinates based on the reduction (OpenJPEG
doesn't do this for us) */
tile_info.x0 = (tile_info.x0 + correction) >> context->reduce;
tile_info.y0 = (tile_info.y0 + correction) >> context->reduce;
tile_info.x1 = (tile_info.x1 + correction) >> context->reduce;
tile_info.y1 = (tile_info.y1 + correction) >> context->reduce;
if (buffer_size < tile_info.data_size) {
UINT8 *new = realloc (state->buffer, tile_info.data_size);
if (!new) {