Skip to content

Commit 238dd4c

Browse files
committed
Replace numpy.fromstring with numpy.frombuffer
`qubesimgconverter` library uses deprecated binary mode of fromstring. This form was finally removed in the recent versions of numpy. Switching to `numpy.frombuffer` resolves the issue. source: numpy/numpy@491f66a#diff-71aadf0228c9cd61ea260748af1dcd4a726eea8476b8cbd667367466c1e39077R2303
1 parent 673e1e9 commit 238dd4c

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

imgconverter/qubesimgconverter/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ def tint(self, colour):
114114

115115
# use a 1D image representation since we only process a single pixel at a time
116116
pixels = self._size[0] * self._size[1]
117-
x = numpy.fromstring(self._rgba, 'B').reshape(pixels, 4)
117+
x = numpy.frombuffer(self._rgba, dtype=numpy.uint8).reshape(pixels, 4)
118118
r = x[:, 0]
119119
g = x[:, 1]
120120
b = x[:, 2]
121121
a = x[:, 3]
122-
M = numpy.maximum(numpy.maximum(r, g), b).astype('u4')
123-
m = numpy.minimum(numpy.minimum(r, g), b).astype('u4')
122+
M = numpy.maximum(numpy.maximum(r, g), b).astype(numpy.uint32)
123+
m = numpy.minimum(numpy.minimum(r, g), b).astype(numpy.uint32)
124124

125125
# Tn/Td is how much chroma range is reserved for the tint color
126126
# 0 -> greyscale image becomes greyscale image
@@ -150,9 +150,9 @@ def tint(self, colour):
150150
c2_m2d = c2 * m2d
151151

152152
# float vt = m2 + tvn * c2
153-
rt = ((m2_c2d_tdn + trn * c2_m2d) // m2d_c2d_tdn).astype('B')
154-
gt = ((m2_c2d_tdn + tgn * c2_m2d) // m2d_c2d_tdn).astype('B')
155-
bt = ((m2_c2d_tdn + tbn * c2_m2d) // m2d_c2d_tdn).astype('B')
153+
rt = ((m2_c2d_tdn + trn * c2_m2d) // m2d_c2d_tdn).astype(numpy.uint8)
154+
gt = ((m2_c2d_tdn + tgn * c2_m2d) // m2d_c2d_tdn).astype(numpy.uint8)
155+
bt = ((m2_c2d_tdn + tbn * c2_m2d) // m2d_c2d_tdn).astype(numpy.uint8)
156156

157157
xt = numpy.column_stack((rt, gt, bt, a))
158158
return self.__class__(rgba=xt.tobytes(), size=self._size)

0 commit comments

Comments
 (0)