Skip to content

Instantly share code, notes, and snippets.

@iTrooz
Last active January 5, 2024 00:57
Show Gist options
  • Save iTrooz/fddfcce03c1c44b04231be73d6e7982a to your computer and use it in GitHub Desktop.
Save iTrooz/fddfcce03c1c44b04231be73d6e7982a to your computer and use it in GitHub Desktop.
reMarkable 2 splash.dat converter
#!/usr/bin/env python3
"""
This script aims at converting an image to the custom format used by Remarkable 2
After running this script, move the output "splash.dat" file to /var/lib/uboot in the rM2 device
I tried this with PNG images but I guess other formats should work too since I use PIL
Syntax: ./main.py <file> [-x xOffset] [-y yOffset]
(-x and -y are the offsets of the image on the screen. If not set, the image will be centered on the screen)
Input images may need to be rotated 90 degrees before converting them
Licence: MPL 2.0
"""
import sys
from PIL import Image, ImageOps
import argparse
TABLET_HEIGHT = 1872
TABLET_WIDTH = 1404
parser = argparse.ArgumentParser()
parser.add_argument("file", help="image to convert", type=str)
parser.add_argument("-x", help="X offset for image", type=int)
parser.add_argument("-y", help="Y offset for image", type=int)
args = parser.parse_args()
if len(sys.argv)==1:
print("Syntax : "+sys.args[0]+" <image file>")
exit()
img = Image.open(sys.argv[1], "r")
img = ImageOps.grayscale(img)
d = map(lambda i:round(i/16), img.getdata())
if img.width > TABLET_HEIGHT or img.height > TABLET_WIDTH:
print("Error: input image dimensions are larger than the tablet dimensions.")
print(" Hint: you should rotate the image 90 degrees before converting it")
exit(1)
# If offsets are not set, default to centering the image
if args.x == None:
args.x = int(TABLET_HEIGHT/2-img.width/2)
if args.y == None:
args.y = int(TABLET_WIDTH/2-img.height/2)
outf = open("splash.dat", "wb")
def w_header(num):
outf.write(num.to_bytes(4, "little"))
w_header(args.x)
w_header(args.y)
w_header(img.width)
w_header(img.height)
outf.write(bytearray(d))
outf.close()
print("Convertion finished ! Output file: splash.dat")
@iTrooz
Copy link
Author

iTrooz commented Jun 4, 2023

I updated the script to indicate that, feel free to try it and give me feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment