~ubuntu-branches/ubuntu/karmic/frozen-bubble/karmic

« back to all changes in this revision

Viewing changes to gfx/shoot/create.pl

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2002-04-17 09:21:51 UTC
  • Revision ID: james.westby@ubuntu.com-20020417092151-7ye6ril7bgg9g0he
Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# For faster multiple execs, start a gimp, and do Xtns/Perl/Server.
 
4
 
 
5
# Warning! Error message are the worst ever. Unquote the "set_trace" if you need troubleshooting.
 
6
 
 
7
 
 
8
$ARGV[0] && -r $ARGV[0] && $ARGV[1] && !$ARGV[2] or
 
9
  die "Usage: create <base_image> <number_steps_each_side>\n";
 
10
 
 
11
 
 
12
#- (gc) this shit wasted me something like 2 hours: opposedly to what's
 
13
#- claimed in the doc, we need to precise `:auto' in the imports, grrrrr..
 
14
use Gimp qw(:consts main xlfd_size :auto);
 
15
 
 
16
Gimp::init();
 
17
#Gimp::set_trace(TRACE_ALL);
 
18
 
 
19
print "Using base file <$ARGV[0]> with <$ARGV[1]> steps each side.\n";
 
20
 
 
21
$| = 1;
 
22
 
 
23
my $data;
 
24
 
 
25
 
 
26
sub rot {
 
27
    my ($filename, $step, $max) = @_;
 
28
 
 
29
    my $img;
 
30
    eval { $img = gimp_file_load($filename, $filename) };
 
31
    if ($@) {
 
32
        die "Failed to load <$filename> into a Gimp image ($@).\n";
 
33
    }
 
34
 
 
35
    my $w = gimp_image_width($img);
 
36
    my $h = gimp_image_height($img);
 
37
    
 
38
    my $rot = gimp_rotate(gimp_image_active_drawable($img), 1, 3.1415926535897932384626433832795028841972/2 * (-$step)/$max);
 
39
    
 
40
    #- dunno why, interactive "rotate" keeps same width/height, this one not.. this is beautiful
 
41
    gimp_crop($img, $w, $h, 0, 0);
 
42
    
 
43
    $filename =~ s/\.([^\.]+)/_$step.$1/;
 
44
 
 
45
    #- now we want to crop the image a maximum, to reduce time of drawing in the game
 
46
    my @pixels = gimp_drawable_get_pixel($rot, $w-1, $h-1);
 
47
 
 
48
    #- since I need to know which shift this crop produced, first I forbid croping right and bottom...
 
49
    gimp_drawable_set_pixel($rot, $w-1, $h-1, 4, [255, 255, 255, 255]);
 
50
    plug_in_autocrop($img, $rot);
 
51
 
 
52
    #- ...and I measure shift...
 
53
    $data .= sprintf "$step %d %d\n", $w-gimp_image_width($img), $h-gimp_image_height($img);
 
54
    
 
55
    #- ...and now I can finally crop the rest of the image
 
56
    gimp_drawable_set_pixel($rot, gimp_image_width($img)-1, gimp_image_height($img)-1, 4, \@pixels);
 
57
    plug_in_autocrop($img, $rot);
 
58
 
 
59
    gimp_file_save($img, $rot, $filename, $filename);
 
60
}
 
61
 
 
62
 
 
63
foreach my $step (0..$ARGV[1]) {
 
64
    print ".";
 
65
    rot($ARGV[0], $step, $ARGV[1]);
 
66
    print ".";
 
67
    rot($ARGV[0], -$step, $ARGV[1]);
 
68
}
 
69
 
 
70
open DAT, ">data" or fail_with_message("Can't open data for writing.");
 
71
print DAT $data;
 
72
close DAT;
 
73
 
 
74
print "done.\n";
 
75
 
 
76
Gimp::end();
 
77