Python png.from_array() Examples

The following are 5 code examples of png.from_array(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module png , or try the search function .
Example #1
Source File: rendered_env_problem.py    From tensor2tensor with Apache License 2.0 6 votes vote down vote up
def _generate_time_steps(self, trajectory_list):
    """Transforms time step observations to frames of a video."""
    for time_step in gym_env_problem.GymEnvProblem._generate_time_steps(
        self, trajectory_list):
      # Convert the rendered observations from numpy to png format.
      frame_np = np.array(time_step.pop(env_problem.OBSERVATION_FIELD))
      frame_np = frame_np.reshape(
          [self.frame_height, self.frame_width, self.num_channels])
      # TODO(msaffar) Add support for non RGB rendered environments
      frame = png.from_array(frame_np, "RGB", info={"bitdepth": 8})
      frame_buffer = six.BytesIO()
      frame.save(frame_buffer)

      # Put the encoded frame back.
      time_step[_IMAGE_ENCODED_FIELD] = [frame_buffer.getvalue()]
      time_step[_IMAGE_FORMAT_FIELD] = [_FORMAT]
      time_step[_IMAGE_HEIGHT_FIELD] = [self.frame_height]
      time_step[_IMAGE_WIDTH_FIELD] = [self.frame_width]

      # Add the frame number
      time_step[_FRAME_NUMBER_FIELD] = time_step[env_problem.TIMESTEP_FIELD]
      yield time_step 
Example #2
Source File: rendered_env_problem.py    From BERT with Apache License 2.0 6 votes vote down vote up
def _generate_time_steps(self, trajectory_list):
    """Transforms time step observations to frames of a video."""
    for time_step in gym_env_problem.GymEnvProblem._generate_time_steps(
        self, trajectory_list):
      # Convert the rendered observations from numpy to png format.
      frame_np = np.array(time_step.pop(env_problem.OBSERVATION_FIELD))
      frame_np = frame_np.reshape(
          [self.frame_height, self.frame_width, self.num_channels])
      # TODO(msaffar) Add support for non RGB rendered environments
      frame = png.from_array(frame_np, "RGB", info={"bitdepth": 8})
      frame_buffer = six.BytesIO()
      frame.save(frame_buffer)

      # Put the encoded frame back.
      time_step[_IMAGE_ENCODED_FIELD] = [frame_buffer.getvalue()]
      time_step[_IMAGE_FORMAT_FIELD] = [_FORMAT]
      time_step[_IMAGE_HEIGHT_FIELD] = [self.frame_height]
      time_step[_IMAGE_WIDTH_FIELD] = [self.frame_width]

      # Add the frame number
      time_step[_FRAME_NUMBER_FIELD] = time_step[env_problem.TIMESTEP_FIELD]
      yield time_step 
Example #3
Source File: CreateStatusGraph.py    From BrundleFuzz with MIT License 5 votes vote down vote up
def main():
	if len(sys.argv) != 2:
		print "python %s <filename>" % sys.argv[0]
		sys.exit(1)

	try:
		filename = sys.argv[1]
		with open(filename, 'rb') as f:
			saved_state = pickle.load(f)
		
		bitmap = saved_state['bitmap']

	except:
		print "[!] Could not load bitmap"
		sys.exit(1)

	# Get rough code coverage value
	coverage = get_coverage(bitmap)
	print "[*] Code coverage (basic block calls): %.2f" % coverage

	if HAS_PYPNG:		
		# Create PNG image from bitmap values
		p = populate_array(bitmap)
		img = png.from_array(p, 'RGB')
		img.save('status_graph.png')

		print "[*] Created PNG file" 
Example #4
Source File: test_dump.py    From HDMI2USB-litex-firmware with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def main(wb):
    wb.open()
    regs = wb.regs
    # # #
    print("dumping framebuffer memory...")
    dump = []
    for n in range(DUMP_SIZE//(WORDS_PER_PACKET*4)):
        data = wb.read(SDRAM_BASE + n*WORDS_PER_PACKET*4, WORDS_PER_PACKET)
        for pixel in data:
            dump += extract_rgb(pixel)
    dump = [dump[x:x+LINE_SIZE] for x in range(0, len(dump), LINE_SIZE)]
    print("dumping to png file...")
    png.from_array(dump, "RGB").save("dump.png")
    # # #
    wb.close() 
Example #5
Source File: test_dump.py    From litex-buildenv with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def main(wb):
    wb.open()
    regs = wb.regs
    # # #
    print("dumping framebuffer memory...")
    dump = []
    for n in range(DUMP_SIZE//(WORDS_PER_PACKET*4)):
        data = wb.read(SDRAM_BASE + n*WORDS_PER_PACKET*4, WORDS_PER_PACKET)
        for pixel in data:
            dump += extract_rgb(pixel)
    dump = [dump[x:x+LINE_SIZE] for x in range(0, len(dump), LINE_SIZE)]
    print("dumping to png file...")
    png.from_array(dump, "RGB").save("dump.png")
    # # #
    wb.close()