Remove sBIT shifting in asDirect

GitOrigin-RevId: 14faaffc334b7e12c0a66bb036895e5ea56fa38b
Change-Id: Ia78e3b66cfdae9febd92e93e20984fa8b40ef403
diff --git a/code/png.py b/code/png.py
index 11b19b5..d7245c7 100755
--- a/code/png.py
+++ b/code/png.py
@@ -1881,16 +1881,8 @@
 
         (*width*, *height*, *rows*, *info*)
 
-        This method normally returns pixel values with
-        the bit depth they have in the source image, but
-        when the source PNG has an ``sBIT`` chunk it is inspected and
-        can reduce the bit depth of the result pixels;
-        pixel values will be reduced according to the bit depth
-        specified in the ``sBIT`` chunk.
-        PNG nerds should note a single result bit depth is
-        used for all channels:
-        the maximum of the ones specified in the ``sBIT`` chunk.
-        An RGB565 image will be rescaled to 6-bit RGB666.
+        This method returns pixel values with
+        the bit depth they have in the source image.
 
         The *info* dictionary that is returned reflects
         the `direct` format and not the original source image.
@@ -1922,11 +1914,11 @@
             info["alpha"] = bool(self.trns)
             info["bitdepth"] = 8
             info["planes"] = 3 + bool(self.trns)
-            plte = self.palette()
+            palette = self.palette()
 
             def iterpal(pixels):
                 for row in pixels:
-                    row = [plte[x] for x in row]
+                    row = [palette[x] for x in row]
                     yield array("B", itertools.chain(*row))
 
             pixels = iterpal(pixels)
@@ -1961,23 +1953,7 @@
                     )
 
             pixels = itertrns(pixels)
-        targetbitdepth = None
-        if self.sbit:
-            sbit = struct.unpack("%dB" % len(self.sbit), self.sbit)
-            targetbitdepth = max(sbit)
-            if targetbitdepth > info["bitdepth"]:
-                raise Error("sBIT chunk %r exceeds bitdepth %d" % (sbit, self.bitdepth))
-            if min(sbit) <= 0:
-                raise Error("sBIT chunk %r has a 0-entry" % sbit)
-        if targetbitdepth:
-            shift = info["bitdepth"] - targetbitdepth
-            info["bitdepth"] = targetbitdepth
 
-            def itershift(pixels):
-                for row in pixels:
-                    yield [p >> shift for p in row]
-
-            pixels = itershift(pixels)
         return x, y, pixels, info
 
     def asRGB(self):
diff --git a/code/test_png.py b/code/test_png.py
index 06b7de3..81fe5cd 100644
--- a/code/test_png.py
+++ b/code/test_png.py
@@ -105,10 +105,12 @@
         source_pixels = bytearray(mask & x for x in range(1, 256))
         w.write_array(f, source_pixels)
         r = png.Reader(bytes=f.getvalue())
-        x, y, pixels, meta = r.asDirect()
+        x, y, pixels, info = r.asDirect()
         self.assertEqual(x, 15)
         self.assertEqual(y, 17)
-        self.assertEqual(list(itertools.chain(*pixels)), list(source_pixels))
+        rbitdepth = info["bitdepth"]
+        shift = rbitdepth - n
+        self.assertEqual([v >> shift for v in itertools.chain(*pixels)], list(source_pixels))
 
     def test_L2(self):
         """Test L2."""