File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -222,10 +222,16 @@ def getPixels(self):
222
222
223
223
print(a.getPixels()[0][0])
224
224
"""
225
- array = np .array (list (self .raw [Image (self .raw ).__getBytesAwayFromColorTable ():]))
226
- grid = array .reshape (- 1 , Image .getBitmapWidth (self ), 3 )
227
- self .grid = grid .tolist ()
228
- return grid .tolist ()
225
+ padding = ((Image .getBitmapWidth (self ) * 3 ) - (Image .getBitmapWidth (self ) * 3 ) % 4 + 4 ) - (Image .getBitmapWidth (self ) * 3 ) if Image .getBitmapWidth (self ) * 3 % 4 != 0 else 0
226
+ dataStart = Image (self .raw ).__getBytesAwayFromColorTable ()
227
+ dataEnd = Image (self .raw ).__getBytesAwayFromColorTable () + (Image .getBitmapWidth (self ) * Image .getBitmapHeight (self ) * 3 ) + (Image .getBitmapHeight (self ) * padding )
228
+ array = np .array (list (self .raw [dataStart :dataEnd ]))
229
+ lines = array .reshape (Image .getBitmapHeight (self ), - 1 )
230
+ for line in lines :
231
+ # ignore the end-of-line padding when generating grid and get pixel color data
232
+ cleanLine = line [:Image .getBitmapWidth (self ) * 3 ].reshape (Image .getBitmapWidth (self ), 3 )
233
+ self .grid = self .grid + [cleanLine .tolist ()]
234
+ return self .grid
229
235
230
236
# -------------------------------------------------------------------------
231
237
# HIGHER LEVEL
You can’t perform that action at this time.
0 commit comments