Show image.jpg when switching fb address

This commit is contained in:
Takumi Sueda 2022-02-21 06:29:21 +09:00
parent 4cb07e77bb
commit 4b5601c738
4 changed files with 42 additions and 3 deletions

View File

@ -8,10 +8,13 @@ all: AppMain.bin m4_loader.bin
.PHONY:
clean:
@rm -f *.bin *.elf
@rm -f *.bin *.elf pixels.c
AppMain.bin:
@$(AS) main.S -o main.elf
pixels.c:
@python3 img2c.py image.jpg pixels.c
AppMain.bin: pixels.c
@$(CC) -nostdlib -static -fPIC -mcpu=cortex-a7 main.S pixels.c -o main.elf
@./extract.py -p main.elf AppMain.bin
m4_loader.bin:

34
img2c.py Normal file
View File

@ -0,0 +1,34 @@
import sys
from PIL import Image
template = '''void load_pixels() {{
{lines}
}};
'''
im = Image.open(sys.argv[-2]).convert('RGB')
with open(sys.argv[-1], 'w') as f:
pixels = []
lines = []
count = 0
for y in range(im.size[1]):
for x in range(0, im.size[0], 2):
r, g, b = im.getpixel((x, y))
rgb565 = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
pixels.append(rgb565 >> 8)
pixels.append(rgb565 & 0xff)
r, g, b = im.getpixel((x+1, y))
rgb565 = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)
pixels.append(rgb565 >> 8)
pixels.append(rgb565 & 0xff)
u32 = (pixels[0] << 24) + (pixels[1] << 16) + (pixels[2] << 8) + pixels[3]
lines.append(f'\t*(unsigned int *)(0x62000000 + {count:7d}) = {u32:#08x};')
pixels = []
count += 4;
f.write(template.format(lines='\n'.join(lines)))

1
main.S
View File

@ -3,6 +3,7 @@
.global _start
_start:
bl load_pixels
//M4 RTOS loader snipet prep
ldr r4, =0x60006400 //fopen addr
adr r0, [.LC2] //file name

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
pillow