summaryrefslogtreecommitdiffstats
path: root/mkindex.pl
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2013-08-15 19:45:41 +0200
committerGuilhem Moulin <guilhem@fripost.org>2013-08-15 19:45:41 +0200
commit68557062451e96c21393ca270d83b50cae9a2c16 (patch)
tree2f009dffc461f102824ab6666f042040bb188c93 /mkindex.pl
parent10bab7c95bcdaedbfdfeb1dea5599aa7edb63d90 (diff)
Put the caption on a separate layer.
(Beetween the index and the border.)
Diffstat (limited to 'mkindex.pl')
-rwxr-xr-xmkindex.pl51
1 files changed, 22 insertions, 29 deletions
diff --git a/mkindex.pl b/mkindex.pl
index c2d2bee..d9dbbe0 100755
--- a/mkindex.pl
+++ b/mkindex.pl
@@ -256,6 +256,7 @@ pod2usage(2) unless $#ARGV > 0;
my $index = pop;
my @mapset = map {{ filename => $_ }} @ARGV;
+$config{fontcolor} //= $config{bordercolor};
&debug( "Using mapset:", map {" - ".$_->{filename}} @mapset );
&debug( "Building index: $index" );
@@ -285,7 +286,7 @@ foreach my $map (@mapset) {
if $notband;
if ($stripped or $notband) {
- warn "WARN: To fix '$name', run the following command in a POSIX-compatible shell.\n";
+ warn "WARN: To fix '$name', paste the following command in a POSIX-compatible shell.\n";
warn "WARN: This is a lossless and usually size-preserving conversion.\n";
my $old = $name;
my ($new,$path,$ext) = fileparse ($name, qr/\.[^.]*$/);
@@ -358,7 +359,7 @@ my $tmpdir = File::Temp::tempdir( CLEANUP => 1 );
# Ensure the existence of the internal driver.
my $driver = 'GTiff';
-my $driver_opts = { BIGTIFF => 'IF_NEEDED' };
+my $driver_opts = { BIGTIFF => 'IF_NEEDED' };
my $driver_type = 'Byte';
die "Error: Unknown driver: '$driver'.\n"
unless Geo::GDAL::GetDriverByName($driver);
@@ -500,11 +501,14 @@ sub annotate {
# Inverse the transformation, so that we can convert from projected
# coordinates to pixel coordinates.
my $ds = Geo::GDAL::Open($filename, 'ReadOnly') or exit 1;
- my ($width, $height) = $ds->Size();
my ($ok,@invt) = Geo::GDAL::InvGeoTransform([ $ds->GetGeoTransform() ]);
undef $ds;
die "Error: Couldn't inverse affine transformation\n" unless $ok;
+ my $img = Image::Magick::->new();
+ $img->Read( $filename );
+ my ($width, $height) = $img->Get(qw/width height/);
+
my @draw = ( fill => 'none'
, strokewidth => $config{border}
, primitive => 'polygon'
@@ -522,8 +526,13 @@ sub annotate {
# values.
#
# To get the list of supported colors: `convert -list color`.
- my ($b_rgb, $b_alpha) = &getRGB_Gray( $config{bordercolor} );
- my ($f_rgb, $f_alpha) = &getRGB_Gray( $config{fontcolor} // $config{bordercolor} );
+ my $pix = Image::Magick::->new();
+ my ($r, $g, $b, $a) = $pix->QueryColor( $config{bordercolor} );
+ my $max = (2 << ($pix->Get('depth') - 1)) - 1.;
+ undef $pix;
+ ($r,$g,$b,$a) = map { ($_ * 100. / $max).'%' } ($r,$g,$b,$a);
+ my ($b_rgb, $b_alpha) = ("RGB($r,$g,$b)", "GRAY($a)");
+
my $rgb= Image::Magick::->new( size => "${width}x${height}" );
$rgb->Read( 'xc:none' );
@@ -546,6 +555,11 @@ sub annotate {
my $points = join (' ', map {join ',', @$_} @points);
&debug( "Polygon: " . $points );
+ # Add the borders. We do that after the text to draw over in
+ # case of intersection.
+ $rgb->Draw( @draw, stroke => $b_rgb, points => $points );
+ $mask->Draw(@draw, stroke => $b_alpha, points => $points );
+
# Get the extremes of this polygon.
my ($lx,$uy,$rx,$ly);
foreach (@points) {
@@ -559,16 +573,11 @@ sub annotate {
&debug( "Cell: $cell" );
# Add the caption. ('gravity' is relative to the 'geometry'.)
- # Everithing that's not in the cell's region is trimmed away.
+ # Everything that's not in the cell's region is trimmed away.
my @ann = ( @ann, geometry => $cell, gravity => 'Center'
, text => $map->{text} );
- $rgb->MogrifyRegion( $cell, 'Annotate', @ann, fill => $f_rgb );
- $mask->MogrifyRegion( $cell, 'Annotate', @ann, fill => $f_alpha );
-
- # Add the borders. We do that after the text to draw over in
- # case of intersection.
- $rgb->Draw( @draw, stroke => $b_rgb, points => $points );
- $mask->Draw(@draw, stroke => $b_alpha, points => $points );
+ $img->MogrifyRegion( $cell, 'Annotate',
+ @ann, fill => $config{fontcolor} );
}
# Change the colorspace (now to non-linear gray), and turn off
@@ -579,8 +588,6 @@ sub annotate {
undef $mask;
# Merge all the annotations into the mosaic.
- my $img = Image::Magick::->new();
- $img->Read( $filename );
$img->Composite( image => $rgb, compose => 'Over' );
undef $rgb;
@@ -589,20 +596,6 @@ sub annotate {
undef $img;
}
-# Get the RGB and Gray values of the given color.
-sub getRGB_Gray {
- my $color = shift;
-
- my $pix = Image::Magick::->new();
- my ($r, $g, $b, $a) = $pix->QueryColor($color);
- my $max = (2 << ($pix->Get('depth') - 1)) - 1.;
- undef $pix;
-
- ($r,$g,$b,$a) = map { ($_ * 100. / $max).'%' } ($r,$g,$b,$a);
- return ("RGB($r,$g,$b)", "GRAY($a)");
-}
-
-
__END__
__C__