Initial commit
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
.DS_Store
|
||||||
|
._*
|
||||||
|
/input/*
|
||||||
|
/output
|
||||||
|
!/**/.gitkeep
|
||||||
50
README.md
Normal file
50
README.md
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# Convert GIF to binary
|
||||||
|
|
||||||
|
## Apply color palette using Photoshop
|
||||||
|
|
||||||
|
### 1. Create document
|
||||||
|
Create document with the exact resolution of the screen.
|
||||||
|

|
||||||
|
|
||||||
|
### 2. Save for Web (Legacy)
|
||||||
|

|
||||||
|
|
||||||
|
### 3. Select preset
|
||||||
|
Select `GIF 128 Dithered` preset.
|
||||||
|

|
||||||
|
|
||||||
|
### 4. Load color palette
|
||||||
|

|
||||||
|
|
||||||
|
### 5. Select color palette
|
||||||
|
The palette files can be found in the `palettes/` folder.
|
||||||
|

|
||||||
|
|
||||||
|
### 6. Save image
|
||||||
|
Save the image into the `input/` folder.
|
||||||
|

|
||||||
|
|
||||||
|
### 7. Convert image
|
||||||
|
Convert image using this command:
|
||||||
|
```bash
|
||||||
|
./convert.py input/[filename].gif
|
||||||
|
```
|
||||||
|
|
||||||
|
### 8. Copy byte array into Arduino project
|
||||||
|
Copy the `output.c` files content into the Arduino project and upload it to ESP32 (see `examples/` folder).
|
||||||
|
|
||||||
|
### 9. Connect screen to ESP32
|
||||||
|
|
||||||
|
ePaper | ESP32
|
||||||
|
------ | -----
|
||||||
|
VCC | 3.3V
|
||||||
|
GND | GND
|
||||||
|
DIN | 14
|
||||||
|
CLK | 13
|
||||||
|
CS | 15
|
||||||
|
DC | 27
|
||||||
|
RST | 26
|
||||||
|
BUSY | 25
|
||||||
|
|
||||||
|
### Sources
|
||||||
|
[Make BMP file for e-Paper](https://www.waveshare.com/wiki/E-Paper_Floyd-Steinberg)
|
||||||
93
convert.py
Executable file
93
convert.py
Executable file
@@ -0,0 +1,93 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import os, sys, io, shutil
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
DISPLAY_RESOLUTION = (400, 300)
|
||||||
|
|
||||||
|
COLOR_WHITE = 0
|
||||||
|
COLOR_RED = 1
|
||||||
|
COLOR_BLACK = 2
|
||||||
|
|
||||||
|
for infile in sys.argv[1:]:
|
||||||
|
filename, ext = os.path.splitext(infile)
|
||||||
|
filename = os.path.basename(filename)
|
||||||
|
|
||||||
|
black_array = []
|
||||||
|
red_array = []
|
||||||
|
|
||||||
|
with Image.open(infile) as im:
|
||||||
|
if (im.size != DISPLAY_RESOLUTION):
|
||||||
|
print("Image resolution does not match display resolution")
|
||||||
|
exit(2)
|
||||||
|
px = im.load()
|
||||||
|
blackImg = Image.new('L', im.size)
|
||||||
|
redImg = Image.new('L', im.size)
|
||||||
|
i = 7
|
||||||
|
blackByte = 0
|
||||||
|
redByte = 0
|
||||||
|
for y in range(0, im.size[1]):
|
||||||
|
for x in range(0, im.size[0]):
|
||||||
|
|
||||||
|
if px[x, y] == COLOR_BLACK:
|
||||||
|
blackByte |= 1 << i
|
||||||
|
redByte |= 1 << i
|
||||||
|
elif px[x, y] == COLOR_RED:
|
||||||
|
blackByte |= 0
|
||||||
|
redByte |= 0
|
||||||
|
else:
|
||||||
|
blackByte |= 0
|
||||||
|
redByte |= 1 << i
|
||||||
|
|
||||||
|
if i == 0:
|
||||||
|
black_array.append(blackByte)
|
||||||
|
red_array.append(redByte)
|
||||||
|
blackByte = 0
|
||||||
|
redByte = 0
|
||||||
|
i = 7
|
||||||
|
else:
|
||||||
|
i -= 1
|
||||||
|
|
||||||
|
# Write pixels
|
||||||
|
if px[x, y] == COLOR_BLACK:
|
||||||
|
blackImg.putpixel((x, y), 255)
|
||||||
|
redImg.putpixel((x, y), 255)
|
||||||
|
elif px[x, y] == COLOR_RED:
|
||||||
|
blackImg.putpixel((x, y), 0)
|
||||||
|
redImg.putpixel((x, y), 0)
|
||||||
|
else:
|
||||||
|
blackImg.putpixel((x, y), 0)
|
||||||
|
redImg.putpixel((x, y), 255)
|
||||||
|
|
||||||
|
# Construct black image
|
||||||
|
black_string = "const unsigned char gImage_4in2bc_b[] = {"
|
||||||
|
|
||||||
|
for px in black_array:
|
||||||
|
black_string += "0x{:02x},".format(px)
|
||||||
|
|
||||||
|
black_string = black_string.rstrip(',') + "};\n"
|
||||||
|
|
||||||
|
# Construct red image
|
||||||
|
red_string = "const unsigned char gImage_4in2bc_ry[] = {"
|
||||||
|
|
||||||
|
for px in red_array:
|
||||||
|
red_string += "0x{:02x},".format(px)
|
||||||
|
|
||||||
|
red_string = red_string.rstrip(',') + "};"
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
if not os.path.exists('output'):
|
||||||
|
os.mkdir('output')
|
||||||
|
if (os.path.exists('output/' + filename)):
|
||||||
|
shutil.rmtree('output/' + filename)
|
||||||
|
os.mkdir('output/' + filename)
|
||||||
|
shutil.copy(infile, 'output/' + filename + '/original' + ext)
|
||||||
|
|
||||||
|
|
||||||
|
# Write images
|
||||||
|
blackImg.save('output/' + filename + '/' + 'black.bmp')
|
||||||
|
redImg.save('output/' + filename + '/' + 'red.bmp')
|
||||||
|
|
||||||
|
# Write file
|
||||||
|
f = open('output/' + filename + '/' + 'output.c', 'w')
|
||||||
|
f.write("#include \"ImageData.h\"\n\n" + black_string + red_string)
|
||||||
|
f.close()
|
||||||
0
input/.gitkeep
Normal file
0
input/.gitkeep
Normal file
BIN
palettes/ePaper-Black-White-Red.act
Normal file
BIN
palettes/ePaper-Black-White-Red.act
Normal file
Binary file not shown.
BIN
palettes/ePaper-Black-White-Yellow.act
Normal file
BIN
palettes/ePaper-Black-White-Yellow.act
Normal file
Binary file not shown.
BIN
palettes/ePaper-Black-White.act
Normal file
BIN
palettes/ePaper-Black-White.act
Normal file
Binary file not shown.
BIN
palettes/ePaper-N-color.act
Normal file
BIN
palettes/ePaper-N-color.act
Normal file
Binary file not shown.
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Pillow==8.1.2
|
||||||
BIN
screenshots/context.png
Normal file
BIN
screenshots/context.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
BIN
screenshots/create_document.png
Normal file
BIN
screenshots/create_document.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 272 KiB |
BIN
screenshots/load_palette.png
Normal file
BIN
screenshots/load_palette.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
BIN
screenshots/save_image.png
Normal file
BIN
screenshots/save_image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 370 KiB |
BIN
screenshots/select_palette.png
Normal file
BIN
screenshots/select_palette.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 684 KiB |
BIN
screenshots/select_preset.png
Normal file
BIN
screenshots/select_preset.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 600 KiB |
Reference in New Issue
Block a user