diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0ebcc1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +._* +/input/* +/output +!/**/.gitkeep \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..624deaf --- /dev/null +++ b/README.md @@ -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) \ No newline at end of file diff --git a/convert.py b/convert.py new file mode 100755 index 0000000..01970a7 --- /dev/null +++ b/convert.py @@ -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() \ No newline at end of file diff --git a/input/.gitkeep b/input/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/palettes/ePaper-Black-White-Red.act b/palettes/ePaper-Black-White-Red.act new file mode 100644 index 0000000..a009f16 Binary files /dev/null and b/palettes/ePaper-Black-White-Red.act differ diff --git a/palettes/ePaper-Black-White-Yellow.act b/palettes/ePaper-Black-White-Yellow.act new file mode 100644 index 0000000..62fd260 Binary files /dev/null and b/palettes/ePaper-Black-White-Yellow.act differ diff --git a/palettes/ePaper-Black-White.act b/palettes/ePaper-Black-White.act new file mode 100644 index 0000000..390351d Binary files /dev/null and b/palettes/ePaper-Black-White.act differ diff --git a/palettes/ePaper-N-color.act b/palettes/ePaper-N-color.act new file mode 100644 index 0000000..b6dc2fa Binary files /dev/null and b/palettes/ePaper-N-color.act differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6a21f1f --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Pillow==8.1.2 diff --git a/screenshots/context.png b/screenshots/context.png new file mode 100644 index 0000000..d7382fd Binary files /dev/null and b/screenshots/context.png differ diff --git a/screenshots/create_document.png b/screenshots/create_document.png new file mode 100644 index 0000000..0a16d74 Binary files /dev/null and b/screenshots/create_document.png differ diff --git a/screenshots/load_palette.png b/screenshots/load_palette.png new file mode 100644 index 0000000..6fa5309 Binary files /dev/null and b/screenshots/load_palette.png differ diff --git a/screenshots/save_image.png b/screenshots/save_image.png new file mode 100644 index 0000000..1a3771d Binary files /dev/null and b/screenshots/save_image.png differ diff --git a/screenshots/select_palette.png b/screenshots/select_palette.png new file mode 100644 index 0000000..3637eaa Binary files /dev/null and b/screenshots/select_palette.png differ diff --git a/screenshots/select_preset.png b/screenshots/select_preset.png new file mode 100644 index 0000000..6ae9c12 Binary files /dev/null and b/screenshots/select_preset.png differ