Skip to content

Instantly share code, notes, and snippets.

@shinyquagsire23
Created June 1, 2020 21:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shinyquagsire23/b69ca343fd2f246aee882ecb5af702bd to your computer and use it in GitHub Desktop.
Save shinyquagsire23/b69ca343fd2f246aee882ecb5af702bd to your computer and use it in GitHub Desktop.
LG raw_resources image extraction
import struct
import imageio
import numpy as np
import sys
if len(sys.argv) < 2:
print ("Usage: image-extract.py [raw_resources_a.image]")
exit(0)
f = open(sys.argv[1], "rb")
header = f.read(0x30)
magic, res_table_cnt, unk, dev_str, part_size = struct.unpack("<16sLL16sQ", header)
magic = magic.rstrip(bytes([0x00])).decode('utf-8')
print(magic, hex(res_table_cnt), hex(unk), dev_str, part_size)
res_table_offs = 0x800
f.seek(res_table_offs)
for i in range(0, res_table_cnt):
f.seek(res_table_offs + i * 0x40)
res_ent = f.read(0x40)
name, offset, size, width, height, offs_x, offs_y = struct.unpack("<40sLLLLLL", res_ent)
name = name.rstrip(bytes([0x00])).decode('utf-8')
print(name, offset, size, width, height, offs_x, offs_y)
f.seek(offset)
image_rle = f.read(size)
image_array = np.zeros((height,width,3), dtype=np.uint8)
xpos = 0
ypos = 0
for j in range(0, size>>2):
num, b, g, r = image_rle[j*4:(j+1)*4]#struct.unpack("<BBBB", f.read(4))
for k in range(0, num):
image_array[ypos][xpos] = (r,g,b)
xpos += 1
if (xpos >= width):
xpos = 0
ypos += 1
imageio.imwrite(name + '.png', image_array)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment