Skip to content

Instantly share code, notes, and snippets.

@samjsharpe
Created February 11, 2023 22:11
Show Gist options
  • Save samjsharpe/4f8d2eda8c5b874d4b548848779da871 to your computer and use it in GitHub Desktop.
Save samjsharpe/4f8d2eda8c5b874d4b548848779da871 to your computer and use it in GitHub Desktop.
extract images from IRG file
from re import A
from PIL import Image, ImageDraw
width = 180
height = 240
diff_start=0x80
first_array_start = diff_start
first_array_end = diff_start + width * height - 1
second_array_start = diff_start + width * height
second_array_end = second_array_start + 2 * width * height
file = open("230119180929.irg", mode='br')
data = file.read()
fir = data[first_array_start:first_array_end]
sus_temp = data[second_array_start:second_array_end]
sus = [sus_temp[x] for x in range(0, len(sus_temp), 2)]
diff = [i - j for i, j in zip(fir, sus)]
sum = [i + j for i, j in zip(fir, sus)]
def draw(array, name):
im = Image.new("L", (width, height))
draw = ImageDraw.Draw(im)
for (i, offset) in enumerate(range(0, len(array))):
x = i % width
y = i // width
value = array[offset]
draw.point((x, y), value)
im.save(f"{name}.png")
draw(fir, "first")
draw(sus, "second")
draw(diff, "diff")
draw(sum, "sum")
@samjsharpe
Copy link
Author

This results in 4 images, the first and second in the input file, plus the difference and the sum (showing that they are not exactly the same values.
first
second
diff
sum

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