안녕하세요 클릭해 주셔서 감사합니다. 2차원 이미지 배열을 받아서 1차원 배열 버퍼로 변환하는 함수라고 생각되는데, X, Y 포문이 이해가 잘 안됩니다.
buf[(x + y * self.width) / 8] |= 0x80 >> (x % 8) 이 구문에서 x=1, y=0일 경우 buf 배열의 인덱스로 1/8 분수가 들어가게 되는데, 그러면 안되는것 아닌가요? x=1, y=0일 경우는 안생긴다고 하더라도, 분수가 인덱스로 들어갈 경우가 반드시 생기지 않나요?
def get_frame_buffer(self, image):
buf = [0x00] * (self.width * self.height / 8)
# Set buffer to value of Python Imaging Library image.
# Image must be in mode 1.
image_monocolor = image.convert('1')
imwidth, imheight = image_monocolor.size
if imwidth != self.width or imheight != self.height:
raise ValueError('Image must be same dimensions as display \
({0}x{1}).' .format(self.width, self.height))
pixels = image_monocolor.load()
for y in range(self.height):
for x in range(self.width):
# Set the bits for the column of pixels at the current position.
if pixels[x, y] != 0:
buf[(x + y * self.width) / 8] |= 0x80 >> (x % 8)
return buf
감사합니다.