#!/usr/bin/perl # Last updated: <2007/04/23 14:43:38 +0900> # # gif画像中のパレット値を取得。テキストで出力 # カレントフォルダ中の .gif 全てを検索。読み込み。パレット値取得。 use strict; use Image::Magick; my @flist = (); my @filelist = (); my $dir = '.'; opendir DH, $dir or die "$dir:$!"; while (my $file = readdir DH) { next if $file =~ /^\.{1,2}$/; next unless $file =~ /\.(gif|GIF)$/; push(@flist, $file); } closedir DH; @filelist = sort @flist; # foreach (@filelist) { # print "\t// $_\n"; # } print "\n\tstatic final int[][] paldata = {\n"; my $cnt = 0; foreach my $fname (@filelist) { my $image = Image::Magick->new; $image->Read($fname); # 画像の情報を得る my ($width, $height, $size, $format, $colors) = $image->Get('width', 'height', 'filesize', 'magick', 'colors'); # print $fname, " : format=", $format, " width=", $width, " height=", $height, " colors=", $colors, " size=", $size, "\n"; print "\t\t{\n"; print "\t\t\t// $cnt\n"; # パレット数分、ループ for ( my $i=0; $i < $colors; $i++ ) { # パレット値の情報を取得。 # "255,255,255,0" といった状態で取得される。 my $colmap = $image->Get("colormap[$i]"); my @c = split(/,/, $colmap); foreach my $tc (@c) { if ( $tc > 255 ) { print "Error:\n"; } } printf("\t\t\t0x0%02x%02x%02x, // %d\n", $c[0], $c[1], $c[2], $i); } $cnt++; if ( $cnt > $#filelist ) { print "\t\t}\n"; } else { print "\t\t},\n"; } undef $image; } print "\t};\n"; exit;