OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [mwin/] [bmp/] [convxpm.perl] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
#!/bin/perl
2
 
3
# This is a little perl script that converts XPM colors from
4
# X colors to their true RGB format
5
 
6
# Change this first, if you rgb.txt file lives somewhere else
7
$RFILE="/usr/X11R6/lib/X11/rgb.txt";
8
 
9
# First, Open up the RGBFILE, and make a hash table
10
 
11
open (RGBIN, $RFILE) || die "Can not file $RGBFILE!";
12
 
13
while()
14
{
15
    chop($_);
16
 
17
    $firstchar = substr($_, 0, 1);
18
 
19
    if ($firstchar ne "!")
20
    {
21
        ($r, $g, $b, $val) = /\s*(\d*)\s*(\d*)\s*(\d*)\s*(\w*)/;
22
        $rgbvals{$val} = sprintf("#%2.2x%2.2x%2.2x", $r, $g, $b);
23
    }
24
}
25
 
26
close(RGBIN);
27
 
28
# Ok then, are we in batch mode or individual mode?
29
 
30
if ($ARGV[0] eq "--batch")
31
{
32
    $srcdir = $ARGV[1];
33
    $destdir = $ARGV[2];
34
 
35
    # Batch mode, open up directory and fire
36
    opendir(INDIR, $srcdir) || die "Directory $ARGV[1] doesn't exist";
37
    my @xpms = readdir(INDIR);
38
    closedir(INDIR);
39
 
40
    foreach $xpmfile (@xpms)
41
    {
42
        if ($xpmfile =~ /\.xpm/g)
43
        {
44
            print "Converting $srcdir/$xpmfile to $destdir/$xpmfile...\n"
45
            &convert_xpm("$srcdir/$xpmfile", "$destdir/$xpmfile");
46
        }
47
    }
48
}
49
else
50
{
51
    # regular mode
52
    &convert_xpm($ARGV[0], $ARGV[1]);
53
}
54
 
55
 
56
sub convert_xpm
57
{
58
    # Open up the file to convert it
59
 
60
    $filea = $_[0];
61
    $fileb = $_[1];
62
 
63
    print"Writing from $filea to $fileb...\n";
64
 
65
    open(XPMIN, $filea) || die "Could not file $filea for processing...\n";
66
    open(XPMOUT,">$fileb") || die "Could not open file $fileb for writing...\n";
67
 
68
    $xpmline = ;
69
 
70
    die "$fila is Not an XPM file!\n" if (!($xpmline =~ /\/\* XPM \*\/\n/));
71
 
72
    $firstchar = substr($xpmline, 0, 1);
73
 
74
    while($firstchar ne "\"")
75
    {
76
        print XPMOUT $xpmline;
77
        $xpmline = ;
78
        $firstchar = substr($xpmline, 0, 1);
79
    }
80
 
81
    # Now we have the numbers.  Grab em!
82
 
83
    ($width, $height, $colors, $chars) = ($xpmline =~ /\"(\d*) (\d*) (\d*) (\d*)\",\n/);
84
 
85
    print XPMOUT $xpmline;
86
 
87
    # Now read in the appropriate number of colors
88
 
89
    for($i = 0; $i < $colors; $i++)
90
    {
91
        $xpmline = ;
92
        chop($xpmline);
93
 
94
        ($str, $val, $color) = ($xpmline =~ /\"(.+)\s+(\w*)\s+(.+)\"/);
95
 
96
        $firstchar = substr($color, 0, 1);
97
 
98
        if ($firstchar ne "#")
99
        {
100
            $color = $rgbvals{$color} if ($color ne "None");
101
        }
102
 
103
        print XPMOUT "\"$str  $val $color\",\n";
104
    }
105
 
106
    while()
107
    {
108
        print XPMOUT $_;
109
    }
110
 
111
    close(XPMIN);
112
    close(XPMOUT);
113
}
114
 
115
 
116
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.