Skip to content

Instantly share code, notes, and snippets.

@iTrooz
Last active January 5, 2024 00:57
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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")
@Eeems
Copy link

Eeems commented May 25, 2023

What license is this under?

@iTrooz
Copy link
Author

iTrooz commented May 26, 2023

Hey, let's say MPL 2.0: https://www.mozilla.org/en-US/MPL/2.0/

@timelord1102
Copy link

timelord1102 commented Jun 4, 2023

what are the offset values meant to be, coverting with an offfset of 0 or the width and height of the image result in a blank startup screen

@timelord1102
Copy link

what are the offset values meant to be, coverting with an offfset of 0 or the width and height of the image result in a blank startup screen

Nevermind, had to rotate the image 90 degrees

@iTrooz
Copy link
Author

iTrooz commented Jun 4, 2023

From what I remember:

  • Yes, you have to rotate the image 90 degrees
  • the x and y offsets indicate where to start drawing the image on the screen, if the image is smaller than it. Their default value will automatically center the image (https://gist.github.com/iTrooz/fddfcce03c1c44b04231be73d6e7982a#file-main-py-L34-L37)
  • I assume you had a blank screen before because since you didn't rotate the image, it had dimensions larger than the tablet screen, and it didn't like that

@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