Files
LCD-Game-Shrinker/custom/gnw_ssparky.py
2021-11-30 17:17:49 +01:00

135 lines
4.2 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" ~LCD Game Shrinker~
custom rules to apply to the same basename game.
The keys mapping need to be defined. The information can
found in 'hh_sm510.cpp' MAME driver.
More advanced image transformation can be created using this file.
This program permits to shrink MAME high resolution artwork and
graphics for protable device running LCD game emulator.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
"""
__author__ = "bzhxx"
__contact__ = "https://github.com/bzhxx"
__license__ = "GPLv3"
import os
from PIL import Image
from PIL import ImageOps
from PIL import ImageChops
from custom.rotate_screen import rotate_screen
import rom_config as rom
rom.keep_aspect_ratio = True
rom.crop_jpeg_background_border = True
# Patch address to synchronize TIME with RTC host
rom.ADD_TIME_HOUR_MSB=10
rom.ADD_TIME_HOUR_LSB=11
rom.ADD_TIME_MIN_MSB=12
rom.ADD_TIME_MIN_LSB=13
rom.ADD_TIME_SEC_MSB=14
rom.ADD_TIME_SEC_LSB=15
rom.ADD_TIME_HOUR_MSB_PM_VALUE = 8
# Force to use Background with drop shadow
# rom.background_file="Background.png"
# Enable experimental drop shadow effect on LCD segments
#rom.drop_shadow = True
#Enable the following line to rotate the screen rendering
rom.rotate = True
background_file = 'Background2.png'
subtract_file = 'Subtract.png'
overlay_file = 'Overlay.png'
lines_file = 'Lines.png'
frame_file = 'Frame2.png'
background_file_path = os.path.join(rom.mame_rom_dir, background_file)
if os.path.isfile(background_file_path):
background = Image.open(background_file_path)
frame = Image.open(os.path.join(rom.mame_rom_dir, frame_file))
subtract = Image.open(os.path.join(rom.mame_rom_dir, subtract_file))
overlay = Image.open(os.path.join(rom.mame_rom_dir, overlay_file))
lines = Image.open(os.path.join(rom.mame_rom_dir, lines_file))
#lines2 = Image.open(os.path.join(rom.mame_rom_dir, lines2_file))
#subtract = subtract.resize((background.size))
#frame = ImageOps.fit(frame,background.size,bleed=0.0,centering=(0.5,0.5))
#frame = frame.resize((background.size))
# lines = lines.resize((background.size))
# create an empty layer to mix images with ALPHA channel
img_layer = Image.new("RGBA", (background.size))
# add main background
img_layer = Image.alpha_composite(img_layer, background)
# add subtract
img_layer = ImageChops.multiply(img_layer, subtract)
# add overlay
img_layer = ImageChops.add(img_layer, overlay)
# create an empty image as background with ALPHA channel
img_background = Image.new("RGBA", (background.size))
img_background = Image.alpha_composite(img_background, background)
img_background.paste(img_layer,(0,0), overlay)
#add lines
#lines_tmp = Image.new("RGBA", (lines.size))
img_background.paste(lines,(0,0),lines)
#img_background = Image.blend(img_background,lines_tmp,0.1)
#add frames
img_background.paste(frame,(0,0),frame)
# remove ALPHA channel
img_background = img_background.convert('RGB')
# save it
rom.background_file = "composite.png"
img_background_file = os.path.join(rom.mame_rom_dir, rom.background_file)
img_background.save(img_background_file)
if rom.rotate:
K1 = rom.BTN_UP
K2 = rom.BTN_DOWN
K3 = rom.BTN_A+rom.BTN_RIGHT+rom.BTN_B
K4 = 0
rom.BTN_DATA[rom.S1] = K1 | (K2 << 8) | (K3 << 16) | (K4 << 24)
rotate_screen()
else:
K1 = rom.BTN_LEFT
K2 = rom.BTN_RIGHT
K3 = rom.BTN_A+rom.BTN_UP+rom.BTN_B
K4 = 0
rom.BTN_DATA[rom.S1] = K1 | (K2 << 8) | (K3 << 16) | (K4 << 24)
K1 = rom.BTN_SHORTCUT_B_TIME
K2 = rom.BTN_TIME
K3 = rom.BTN_GAME
K4 = rom.BTN_SHORTCUT_B_GAME
rom.BTN_DATA[rom.S2] = K1 | (K2 << 8) | (K3 << 16) | (K4 << 24)