MCPcopy Index your code
hub / github.com/plotly/plotly.py / rescale_rows

Function rescale_rows

_plotly_utils/png.py:933–960  ·  view source on GitHub ↗

Take each row in rows (an iterator) and yield a fresh row with the pixels scaled according to the rescale parameters in the list `rescale`. Each element of `rescale` is a tuple of (source_bitdepth, target_bitdepth), with one element per channel.

(rows, rescale)

Source from the content-addressed store, hash-verified

931
932
933def rescale_rows(rows, rescale):
934 """
935 Take each row in rows (an iterator) and yield
936 a fresh row with the pixels scaled according to
937 the rescale parameters in the list `rescale`.
938 Each element of `rescale` is a tuple of
939 (source_bitdepth, target_bitdepth),
940 with one element per channel.
941 """
942
943 # One factor for each channel
944 fs = [float(2 ** s[1] - 1) / float(2 ** s[0] - 1) for s in rescale]
945
946 # Assume all target_bitdepths are the same
947 target_bitdepths = set(s[1] for s in rescale)
948 assert len(target_bitdepths) == 1
949 (target_bitdepth,) = target_bitdepths
950 typecode = "BH"[target_bitdepth > 8]
951
952 # Number of channels
953 n_chans = len(rescale)
954
955 for row in rows:
956 rescaled_row = array(typecode, iter(row))
957 for i in range(n_chans):
958 channel = array(typecode, (int(round(fs[i] * x)) for x in row[i::n_chans]))
959 rescaled_row[i::n_chans] = channel
960 yield rescaled_row
961
962
963def pack_rows(rows, bitdepth):

Callers 1

write_passesMethod · 0.85

Calls 1

intFunction · 0.85

Tested by

no test coverage detected