Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

Requires ImageMagick and pdftoppm to convert images, and Docker to compile the
ROM using SGDK. On Ubuntu, install packages "python3", "imagemagick",
"poppler-utils", and "docker.io".
"poppler-utils", "Pillow" and "docker.io".
"""

import argparse
Expand All @@ -28,6 +28,7 @@
import subprocess
import sys
import tempfile
from PIL import Image


# SGDK image to compile the ROM.
Expand All @@ -44,6 +45,10 @@
{image_pointers}
}};

const Image* slides_top[] = {{
{image_pointers_top}
}};

const int num_slides = {num_slides};

#endif // _RES_SLIDES_H_
Expand Down Expand Up @@ -137,6 +142,7 @@ def process_slides(pdf_path, pages_dir, start_page, end_page, app_dir):
# Process those pages by downscaling and reducing colors.
resource_list = []
image_pointers = []
image_pointers_top = []
page_paths = sorted(glob.glob(os.path.join(pages_dir, 'page-*.png')))

page_num = 1
Expand Down Expand Up @@ -173,18 +179,52 @@ def process_slides(pdf_path, pages_dir, start_page, end_page, app_dir):
# Dithering settings.
args.extend(dithering_args)
args.extend([
# Reduce to 15 colors (the max you can do in one palette on Sega).
'-colors', '15',
# Reduce to 30 colors (the max you can do in two palettes on Sega).
'-colors', '30',
# Output a PNG image with an 8-bit palette.
'PNG8:{}'.format(output_path),
])
subprocess.run(check=True, args=args)

#open file and split into backgounds
img = Image.open(output_path)

palette = img.getpalette()
palette_bottom = palette[0:45]
palette_bottom.extend([0] * (768 - len(palette_bottom)))
palette_top = palette_bottom[0:3]
palette_top.extend(palette[45:])
palette_top.extend([0] * (768 - len(palette_top)))

img_bottom = Image.new(mode="P", size=(320,224))
img_bottom.putpalette(palette_bottom)
img_top = Image.new(mode="P", size=(320,224))
img_top.putpalette(palette_top)
img_top.info['transparency'] = 0

for y in range(224):
for x in range(320):
pixel = img.getpixel((x,y))
if pixel < 15:
img_bottom.putpixel((x,y),pixel)
img_top.putpixel((x,y),0)
else:
img_top.putpixel((x,y),pixel-15+1)

img_bottom.save(output_path.replace(".png","_bottom.png"))
img_top.save(output_path.replace(".png","_top.png"))

resource_list.append(
'IMAGE slide_{page_num} {page_filename} BEST'.format(
page_num=page_num, page_filename=page_filename))
'IMAGE slide_{page_num}_bottom {page_filename} BEST'.format(
page_num=page_num, page_filename=page_filename.replace(".png","_bottom.png")))
image_pointers.append(
' &slide_{page_num},'.format(
' &slide_{page_num}_bottom,'.format(
page_num=page_num))
resource_list.append(
'IMAGE slide_{page_num}_top {page_filename_top} BEST'.format(
page_num=page_num, page_filename_top=page_filename.replace(".png","_top.png")))
image_pointers_top.append(
' &slide_{page_num}_top,'.format(
page_num=page_num))

print('\rProcessed {} / {}... '.format(
Expand All @@ -197,6 +237,7 @@ def process_slides(pdf_path, pages_dir, start_page, end_page, app_dir):
with open(os.path.join(app_dir, 'src', 'slides.h'), 'w') as f:
f.write(SLIDES_H_TEMPLATE.format(
image_pointers='\n'.join(image_pointers),
image_pointers_top='\n'.join(image_pointers_top),
num_slides=len(image_pointers)))

with open(os.path.join(app_dir, 'res', 'slide_data.res'), 'w') as f:
Expand Down
10 changes: 8 additions & 2 deletions template/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
static int16_t slide_num;

// Decompress a slide into memory, then flip it to the screen at 0,0 in
// background layer A.
// background layers A & B.
static void displayNewSlide() {
const Image* slide = slides[slide_num];
VDP_drawImage(BG_A, slide, /* x= */ 0, /* y= */ 0);
const Image* slide_top = slides_top[slide_num];
PAL_fadeOutAll(1, false);
VDP_drawImageEx(BG_B, slide, TILE_ATTR_FULL(PAL0, false, false, false, 0),/* x= */ 0, /* y= */ 0, false, false);
int numTile = slide->tileset->numTile;
VDP_drawImageEx(BG_A, slide_top, TILE_ATTR_FULL(PAL1, false, false, false, numTile), /* x= */ 0, /* y= */ 0, false, false);
PAL_fadeToPalette(PAL0,slide->palette->data,1,false);
PAL_fadeToPalette(PAL1,slide_top->palette->data,1,false);
}

// Handle controller events.
Expand Down