Merge branch 'issue208' into devel

This commit is contained in:
John Evans 2014-04-01 20:56:08 -04:00
commit c2cae15723

View file

@ -1912,17 +1912,34 @@ class PaletteBox(Jp2kBox):
*bps_signed) *bps_signed)
fptr.write(write_buffer) fptr.write(write_buffer)
if self.bits_per_component[0] <= 8: bps = self.bits_per_component
code = 'B' if any(b != bps[0] for b in bps):
elif self.bits_per_component[0] <= 16: # All components are the same. Writing is straightforward.
code = 'H' if self.bits_per_component[0] <= 8:
elif self.bits_per_component[0] <= 32: code = 'B'
code = 'I' dtype = np.uint8
elif self.bits_per_component[0] <= 16:
fmt = '>' + code * self.palette.shape[1] code = 'H'
for row in self.palette: dtype = np.uint16
write_buffer = struct.pack(fmt, *row) elif self.bits_per_component[0] <= 32:
code = 'I'
dtype = np.uint32
nelts = self.palette.shape[0] * self.palette.shape[1]
fmt = '>{0}{1}'.format(nelts, code)
write_buffer = struct.pack(fmt,
self.palette.astype(dtype).flatten())
fptr.write(write_buffer) fptr.write(write_buffer)
else:
# Not all the components are the same. More general, but much rarer
# case. Does this even happen.
code_dict = {8: 'B', 16: 'H', 32: 'I'}
codes = ''
for width in bps:
codes += code_dict[width]
fmt = '>' + codes
for row in self.palette:
write_buffer = struct.pack(fmt, *row)
fptr.write(write_buffer)
@staticmethod @staticmethod
def parse(fptr, offset, length): def parse(fptr, offset, length):