Variable renaming. #130

This commit is contained in:
jevans 2014-04-03 22:52:11 -04:00
commit 4e19e688a0

View file

@ -1922,13 +1922,11 @@ class PaletteBox(Jp2kBox):
------- -------
PaletteBox instance PaletteBox instance
""" """
num_bytes = offset + length - fptr.tell() read_buffer = fptr.read(3)
read_buffer = fptr.read(num_bytes) (nrows, ncols) = struct.unpack('>HB', read_buffer)
(nrows, ncols) = struct.unpack_from('>HB', read_buffer, offset=0)
# Need to determine bps and signed or not read_buffer = fptr.read(ncols)
read_buffer = fptr.read(num_columns) bps_signed = struct.unpack('>' + 'B' * ncols, read_buffer)
bps_signed = struct.unpack('>' + 'B' * num_columns, read_buffer)
bps = [((x & 0x7f) + 1) for x in bps_signed] bps = [((x & 0x7f) + 1) for x in bps_signed]
signed = [((x & 0x80) > 1) for x in bps_signed] signed = [((x & 0x80) > 1) for x in bps_signed]
@ -1936,18 +1934,18 @@ class PaletteBox(Jp2kBox):
# Ok the palette has the same datatype for all columns. We should # Ok the palette has the same datatype for all columns. We should
# be able to efficiently read it. # be able to efficiently read it.
if bps[0] <= 8: if bps[0] <= 8:
nbytes_per_row = num_columns nbytes_per_row = ncols
dtype = np.uint8 dtype = np.uint8
elif bps[0] <= 16: elif bps[0] <= 16:
nbytes_per_row = 2 * num_columns nbytes_per_row = 2 * ncols
dtype = np.uint16 dtype = np.uint16
elif bps[0] <= 32: elif bps[0] <= 32:
nbytes_per_row = 3 * num_columns nbytes_per_row = 3 * ncols
dtype = np.uint32 dtype = np.uint32
read_buffer = fptr.read(num_entries * nbytes_per_row) read_buffer = fptr.read(nrows * nbytes_per_row)
palette = np.frombuffer(read_buffer, dtype=dtype) palette = np.frombuffer(read_buffer, dtype=dtype)
palette = np.reshape(palette, (num_entries, num_columns)) palette = np.reshape(palette, (nrows, ncols))
else: else:
# General case where the columns may not be the same width. # General case where the columns may not be the same width.
@ -1964,9 +1962,9 @@ class PaletteBox(Jp2kBox):
# That means a list comprehension does this in one shot. # That means a list comprehension does this in one shot.
row_nbytes = sum([int(math.ceil(x/8.0)) for x in bps]) row_nbytes = sum([int(math.ceil(x/8.0)) for x in bps])
read_buffer = fptr.read(num_entries * row_nbytes) read_buffer = fptr.read(nrows * row_nbytes)
palette = np.zeros((num_entries, num_columns), dtype=np.int32) palette = np.zeros((nrows, ncols), dtype=np.int32)
for j in range(num_entries): for j in range(nrows):
palette[j] = struct.unpack_from(fmt, read_buffer, palette[j] = struct.unpack_from(fmt, read_buffer,
offset=j * row_nbytes) offset=j * row_nbytes)