Commits

Mikhail Korobov committed 7a7557f

16bit composite images reading

Comments (0)

Files changed (3)

psd_tools/user_api/layers.py

 # -*- coding: utf-8 -*-
-from __future__ import absolute_import, unicode_literals, print_function
+from __future__ import absolute_import, unicode_literals, print_function, division
 import warnings
 
 from psd_tools.constants import (Compression, ChannelID, ColorMode,
                                  TaggedBlock, SectionDivider)
 
-
 def group_layers(decoded_data):
     """
     Returns a nested dict with PSD layer group information.
     bands = {}
     if depth == 8:
         mode, raw_mode = 'L', 'L'
+    elif depth == 16:
+        mode, raw_mode = 'I', 'I;16B'
     elif depth == 32:
         mode, raw_mode = 'I', 'I;32B'
     else:
 
         if channel.compression == Compression.RAW:
             im = frombytes(mode, size, channel.data, "raw", raw_mode)
+            if depth == 16:
+                im = im.point(lambda i: i * (1/(256.0)))
+
         elif channel.compression == Compression.PACK_BITS:
             im = frombytes(mode, size, channel.data, "packbits", raw_mode)
         else:

tests/psd_files/16bit5x5.psd

Added
New image

tests/test_pixels.py

 def test_composite_image_pixels_32bit(filename, probe_point, pixel_value):
     _assert_image_pixel(filename, probe_point, pixel_value)
 
+def test_composite_16bit():
+    _assert_image_pixel('16bit5x5.psd', (0, 0), (236, 242, 251))
+    _assert_image_pixel('16bit5x5.psd', (4, 0), (0, 0, 0))
+    _assert_image_pixel('16bit5x5.psd', (1, 3), (46, 196, 104))