Added colour optimisation function
A new function handles correct rendering of images (especially text) by converting grey areas to black.
This commit is contained in:
		| @@ -35,17 +35,14 @@ else: | |||||||
| top_section_width = middle_section_width = bottom_section_width = display_width | top_section_width = middle_section_width = bottom_section_width = display_width | ||||||
|  |  | ||||||
| if top_section and bottom_section: | if top_section and bottom_section: | ||||||
|   print('top and bottom section occupied') |  | ||||||
|   top_section_height = int(display_height*0.11) |   top_section_height = int(display_height*0.11) | ||||||
|   bottom_section_height = int(display_height*0.24) |   bottom_section_height = int(display_height*0.24) | ||||||
|  |  | ||||||
| elif top_section and not bottom_section: | elif top_section and not bottom_section: | ||||||
|   print('top section occupied') |  | ||||||
|   top_section_height = int(display_height*0.11) |   top_section_height = int(display_height*0.11) | ||||||
|   bottom_section_height = 0 |   bottom_section_height = 0 | ||||||
|  |  | ||||||
| elif bottom_section and not top_section: | elif bottom_section and not top_section: | ||||||
|   print('bottom_section occupied') |  | ||||||
|   top_section_height = 0 |   top_section_height = 0 | ||||||
|   bottom_section_height = int(display_height*0.24) |   bottom_section_height = int(display_height*0.24) | ||||||
|  |  | ||||||
| @@ -245,6 +242,13 @@ def image_cleanup(): | |||||||
|       os.remove(temp_files) |       os.remove(temp_files) | ||||||
|   print('Done') |   print('Done') | ||||||
|  |  | ||||||
|  | def optimise_colours(image, threshold=220): | ||||||
|  |   buffer = numpy.array(image.convert('RGB')) | ||||||
|  |   red, green = buffer[:, :, 0], buffer[:, :, 1] | ||||||
|  |   buffer[numpy.logical_and(red <= threshold, green <= threshold)] = [0,0,0] #grey->black | ||||||
|  |   image = Image.fromarray(buffer) | ||||||
|  |   return image | ||||||
|  |  | ||||||
| def calibrate_display(no_of_cycles): | def calibrate_display(no_of_cycles): | ||||||
|   """How many times should each colour be calibrated? Default is 3""" |   """How many times should each colour be calibrated? Default is 3""" | ||||||
|   epaper = driver.EPD() |   epaper = driver.EPD() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user