def test_create_green_image_from_string(self): image = ImageFactory.generate_gradient_image((8, 8), (0, 255, 0)) (data, size, mode) = TestImageFactory.get_image_data(image) image_from_string = ImageFactory.create_image_from_string( mode, size, data) self.assertEqual(image, image_from_string)
def unpack_display_frame_command(command): concrete_command = command[COMMAND_DISPLAY_FRAME] size = concrete_command[SIZE] mode = concrete_command[MODE] data = BinaryEncoder.decode_bytes(concrete_command[PIXELS]) image = ImageFactory.create_image_from_string(mode, size, data) return image
def pre_render(self, start_point, end_point, steps_amount): x = generate_range_points(start_point[0], end_point[0], steps_amount) y = generate_range_points(start_point[1], end_point[1], steps_amount) for frame_id in range(steps_amount): # fill frame with background color current_frame = ImageFactory.create_rgb_image( self.__animation_size, self.__background_color) bounding_box = (int(-x[frame_id]), int(y[frame_id]), int(-x[frame_id]) + self.__animation_size[0], int(y[frame_id]) + self.__animation_size[1]) # crop the frame even if it's outside the original image frame = self.__image.crop(bounding_box) # when cropping contains only part of the original image the rest of the frame is black # so get the part of the image containing the actual image meaningful_pixels_bounding_box = frame.getbbox() # if there are any pixels on the cropped area if meaningful_pixels_bounding_box is not None: # copy this part to separate image meaningful_pixels = frame.crop(meaningful_pixels_bounding_box) # and paste on the background that was created with the proper background color current_frame.paste(meaningful_pixels, meaningful_pixels_bounding_box) if current_frame.size != self.__animation_size: raise ArithmeticError('problem in bounding box calculation') self.__frames.append(current_frame)
def test_create_green_gradient_image_frame_message(self): size = (10, 2) color = (0, 255, 0) image = ImageFactory.generate_gradient_image(size, color) message = MessageFactory.create_display_frame_message(image) self.assertEqual(message, '{"command": {"display_frame": {"mode": "RGB", "pixels": "AAAAABkAADMAAEwAAGYAAH8AAJkAALIAAMwAAOUAAAAAABkAADMAAEwAAGYAAH8AAJkAALIAAMwA\\nAOUA\\n", "size": [10, 2]}}}')
def test_create_red_image_frame_message(self): size = (8, 8) color = (255, 0, 0) image = ImageFactory.generate_gradient_image(size, color) message = MessageFactory.create_display_frame_message(image) self.assertEqual(message, '{"command": {"display_frame": {"mode": "RGB", "pixels": "AAAAHwAAPwAAXwAAfwAAnwAAvwAA3wAAAAAAHwAAPwAAXwAAfwAAnwAAvwAA3wAAAAAAHwAAPwAA\\nXwAAfwAAnwAAvwAA3wAAAAAAHwAAPwAAXwAAfwAAnwAAvwAA3wAAAAAAHwAAPwAAXwAAfwAAnwAA\\nvwAA3wAAAAAAHwAAPwAAXwAAfwAAnwAAvwAA3wAAAAAAHwAAPwAAXwAAfwAAnwAAvwAA3wAAAAAA\\nHwAAPwAAXwAAfwAAnwAAvwAA3wAA\\n", "size": [8, 8]}}}')
def test_send_image_frame_from_client_to_server(self): size = (6, 9) color = (0, 255, 0) image = ImageFactory.generate_gradient_image(size, color) reactor.callLater(1, self.client.send_image_frame, image) reactor.run() self.assertEqual(self.device.image, image)
def test_random_images(): display_size = (8, 8) max_luminance = 10 device = Ws281xDevice(display_size, max_luminance) green = (0, 255, 0) image = ImageFactory.generate_gradient_image(display_size, green) while True: #fill_image_uniformly(image) #fill_image_randomly(image) #fill_image_increasingly(image) device.display_frame(image) time.sleep(1/30.)
def test_3x1_panel(self): size = (3, 1) stripe, device = self.create_stripe_and_device(size) image = ImageFactory.create_rgb_image(size) image.putpixel((0, 0), self.red.get_as_tuple()) image.putpixel((1, 0), self.green.get_as_tuple()) image.putpixel((2, 0), self.blue.get_as_tuple()) device.display_frame(image) self.assertEqual(stripe.getPixelColor(0), self.red.get_as_int()) self.assertEqual(stripe.getPixelColor(1), self.green.get_as_int()) self.assertEqual(stripe.getPixelColor(2), self.blue.get_as_int())
def clear(self): black_image = ImageFactory.create_rgb_image(self._size) self.display_frame(black_image)
def __init__(self, size): self._count = 0 self._size = size self._image = ImageFactory.create_rgb_image(size)
def __init__(self, size, widget_size): self.__size = size self.__widget_size = widget_size self.__point_size = 10 self.__line_color = Color.White() self.__image = ImageFactory.create_rgb_image(self.__size)
def clear(self): self.__image = ImageFactory.create_rgb_image(self.__size)