Initial commit

This commit is contained in:
2021-03-20 02:35:51 +01:00
parent def69cc2a6
commit 16f0786122
15 changed files with 149 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.DS_Store
._*
/input/*
/output
!/**/.gitkeep

50
README.md Normal file
View 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.
![](screenshots/create_document.png)
### 2. Save for Web (Legacy)
![](screenshots/context.png)
### 3. Select preset
Select `GIF 128 Dithered` preset.
![](screenshots/select_preset.png)
### 4. Load color palette
![](screenshots/load_palette.png)
### 5. Select color palette
The palette files can be found in the `palettes/` folder.
![](screenshots/select_palette.png)
### 6. Save image
Save the image into the `input/` folder.
![](screenshots/save_image.png)
### 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
View 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
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
palettes/ePaper-N-color.act Normal file

Binary file not shown.

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
Pillow==8.1.2

BIN
screenshots/context.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

BIN
screenshots/save_image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 684 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 KiB