Comments (7)
@Gadgetoid this is what I ended up using:
def load_image(path):
i = Image.open(path)
if display.colour == 'multi':
data = np.array(i)
black = data == display.BLACK
white = data == display.WHITE
green = data == display.GREEN
data[black], data[white], data[green] = display.WHITE, display.BLACK, display.YELLOW
i = Image.fromarray(data)
return i
from inky.
These are the real-world numbers that represent white/black on this particular e-ink display. Prior displays had a weirder, separate bit-packed buffer for white/black white/yellow (or red) so the mapping of number to colour was comparatively arbitary. Here I've opted to stay close to the metal, so to speak, and use the 4-bit values that actually get sent to the display.
The underlying buffer is just a numpy array, though, so you could replace colour values out at runtime if you needed.
from inky.
I will add a mapping dict to my code (e.g.
{ "black": display.BLACK, ... }
that will solve the issue but will change the format of the json causing some incompatibilities, but users will have to live with it (I don't think there are many users yet, ins a fairly new project).
from inky.
@Gadgetoid I am also having a similar problem converting code from the wHat - except I paste images from disk into a new PIL image that is black and white:
image = Image.new('P', (width, height))
icon = Image.open('icon.png')
image.paste(icon, (0, 0))
This code results in the correct image (as seen with an image editor) displayed on a wHat, but an inverted image on an Impression.
from inky.
You could try to setup your image as RGB for the impression. The impression-code will do the mapping to a palette image automatically hopefully preserving black&white. I use the colour
-attribute of the display-object (returned by auto()
) to distinguish the hardware (the impression will have the value multi
).
from inky.
For the black/white swap you could run a pass after setting your image to swap Black and White in Inky's buffer, like so:
black = display.buf == display.BLACK
white = display.buf == display.WHITE
display.buf[black] = display.WHITE
display.buf[white] = display.BLACK
If this works, I'll add a display.swap
method for Impressions, which you can pass any two colours into, ie:
display.swap(display.BLACK, display.WHITE)
from inky.
It seems to me that this is still broken. A PNG that I try to paste in has inverted black and white. The text in the example below, however, has the correct color...
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)
for y in range(inky_display.height):
for x in range(inky_display.width):
img.putpixel((x, y), inky_display.WHITE)
font = ImageFont.truetype(FredokaOne, 48)
message = u"{}°".format(temperature)
w, h = font.getsize(message)
x = int((inky_display.WIDTH / 2) - (w / 2))
y = int((inky_display.HEIGHT / 2) - (h / 2))
draw.text((x, y), message, inky_display.BLACK, font)
img.paste(icon, (x, y + 20))
inky_display.set_image(img)
inky_display.show()
from inky.
Related Issues (20)
- eeprom.py SMBus needs to be closed HOT 1
- SSD1608 Custom Lookup table HOT 2
- How to map palette to impression 7.3 colours and avoid dithering
- Make inky work with NVIDIA Jetson Nano HOT 1
- Magic number and checksum for eeprom HOT 1
- Pi Zero W - Not Enough Ram to pip install seaborn HOT 1
- `InkyMockImpression.set_image` fails with `AttributeError`
- `InkyMockImpression` class doesn't easily support multiple resolutions
- Use on any non-Pi machines? HOT 3
- Treating Inky pHAT-Red as Black/White doesn't work
- Busy Wait error - Line 323/333 HOT 1
- AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
- Odd permissions issue on new Inky Impressions 7.3" HOT 1
- error: externally-managed-environment HOT 1
- Forcing black and white only on 7 color. HOT 2
- Partial Update or Single Pixel Update for all Inky Impression HOT 1
- Incompatible with Raspberry Pi 5B? HOT 8
- Not installable on MacOS for development
- Can't get Inky to work on Raspberry Pi Zero 2 W HOT 3
- It didn't blow up HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inky.