code: def _finalize(self, dtype=np.uint8):
          
          channels = []
          if self.mode == "P":
              self.convert("RGB")
          if self.mode == "PA":
              self.convert("RGBA")
  
          for chn in self.channels:
              if isinstance(chn, np.ma.core.MaskedArray):
                  final_data = chn.data.clip(0, 1) * np.iinfo(dtype).max
              else:
                  final_data = chn.clip(0, 1) * np.iinfo(dtype).max
  
              if np.issubdtype(dtype, np.integer):
                  final_data = np.round(final_data)
              channels.append(np.ma.array(final_data,
                                          dtype,
                                          mask=np.ma.getmaskarray(chn)))
          if self.fill_value is not None:
              fill_value = [int(col * np.iinfo(dtype).max)
                            for col in self.fill_value]
          else:
              fill_value = None
          return channels, fill_value
docs: Finalize the image, that is put it in RGB mode, and set the channels
          in unsigned 8bit format ([0,255] range) (if the *dtype* doesn't say
          otherwise).