Script to convert layout file resolution

A nice (keyboard based) front end for Arcade / Console game emulators.

Moderator: battlecat

Script to convert layout file resolution

Postby snaff » Fri Nov 01, 2013 9:05 pm

Here's another dirty perl script. This one converts a layout file to a given resolution, with an option to keep the aspect ratio. The script needs to know the location of the layout_format.txt file from the wahcade docs so it knows which lines to modify.

Example usage: ./convert_lay.pl --width=1280 --height=720 --keep_aspect < oldlayout.lay >newlayout.lay

It doesn't get everything right, like the options text position.

Code: Select all
#!/usr/bin/perl -w

my $format="~/install/mame/wahcade/devel/doc/file_formats/layout_format.txt";

use strict;
use Getopt::Long;

my ($new_width, $new_height);
my $keep_aspect=0;

my $result=GetOptions(
   "width=i" => \$new_width,
   "height=i" => \$new_height,
   "keep_aspect" => \$keep_aspect);

my ($old_width, $old_height, $width_ratio, $height_ratio, $border);

my $line=1;
while(<STDIN>) {
   chomp();
   my $output;
   my $f=`egrep '^$line\\W' $format`;
   if($line==1) {
      $old_width=$_;
      $old_width=~s/;.*//;
      if(!$keep_aspect) {
         $width_ratio=$new_width/$old_width;
      }
      $output=$new_width;
   } elsif($line==2) {
      $old_height=$_;
      $height_ratio=$new_height/$old_height;
      if($keep_aspect) {
         $width_ratio=$height_ratio;
         $border=($new_width-($old_width*$width_ratio))/2;
      }
      $output=$new_height;
   } elsif($f=~/^$line\s*x-pos\s*$/) {
      if($keep_aspect) {
         $output=int(($_*$width_ratio)+$border);
      } else {
         $output=int($_*$width_ratio);
      }
   } elsif($f=~/^$line\s*y-pos\s*$/) {
      $output=int($_*$height_ratio);
   } elsif($f=~/^$line\s*width\s*$/) {
      $output=int($_*$width_ratio);
   } elsif($f=~/^$line\s*height\s*$/) {
      $output=int($_*$height_ratio);
   } else { $output=$_; }
   print $output."\n";
   $line++;
}



You still need to manually change file names, font sizes and of course convert the image files. You can convert image files with 'convert' from imagemagick like so:

convert -resize 640x480 old.png new.png

or

convert -resize 640x480! old.png new.png

if you don't want to keep the aspect ratio.
snaff
 
Posts: 5
Joined: Thu Oct 31, 2013 9:28 pm

Re: Script to convert layout file resolution

Postby General_Faliure » Sat Nov 02, 2013 7:16 am

Comes a bit too late for me.
I have been converting all my layouts using Gimp, and the layout editor to get the text positions right.
My Arcade cab: https://goo.gl/photos/yE1KACHryQjCaaCj7
Core 2 duo 8400 @3600, 4 gig mem, Geforce 9500. Mame, Mess, Daphne, and some more.
Mah!cade
User avatar
General_Faliure
 
Posts: 154
Joined: Sat Mar 20, 2010 12:51 pm
Location: Drunen, Netherlands

Re: Script to convert layout file resolution

Postby snaff » Sat Nov 02, 2013 8:52 am

To stop it messing up options/message position change:

Code: Select all
   } elsif($f=~/^$line\s*x-pos\s*$/) {
      if($keep_aspect) {
         $output=int(($_*$width_ratio)+$border);
      } else {
         $output=int($_*$width_ratio);
      }


to

Code: Select all
   } elsif($f=~/^$line\s*x-pos\s*$/) {
      if($keep_aspect && $line<294) {
         $output=int(($_*$width_ratio)+$border);
      } else {
         $output=int($_*$width_ratio);
      }
snaff
 
Posts: 5
Joined: Thu Oct 31, 2013 9:28 pm

Re: Script to convert layout file resolution

Postby sairuk » Wed Nov 06, 2013 10:51 pm

I need to try this out at some point, very interesting. I was looking at fluid interfaces / pygame or web based frontend. But this is something that perhaps should be incorporated into the layout editor directly, or ideally incorporated as an on the fly conversion.
mameau - My random bits | Wah!Ki - A Wah!Cade wiki | Mah!Cade - Experimental Wah!cade Branch | ListGen | Lazarus
User avatar
sairuk
 
Posts: 432
Joined: Sat May 22, 2010 12:37 am


Return to Wah!Cade

Who is online

Users browsing this forum: Google [Bot] and 3 guests

cron