sub test { my $fn = shift; my $img = PDL::IO::Image-> new_from_file( $fn ) or die "Failed to load image"; my $pdl = $img->pixels_to_pdl->short; my $s = cc8compt( $pdl != 0 ); my $str = ${ $s-> get_dataref }; my ( $w, $h ) = $s-> dims; my $bounds = pack 'n4', $w, 0, $h, 0; $bounds x= $s->max; for my $y ( 0 .. $h - 1 ) { my $s = substr( $str, 2 * $y * $w, 2 * $w ); while( $s =~ m[(?:[^\0][^\0])+]g ) { my( $l, $r ) = ( $-[0]/2, (($+[0])-1)/2 ); my $c = ord( $& ); vec( $bounds, 4*$c+0, 16 ) = $l if $l < vec( $bounds, 4*$c+0, 16 ); vec( $bounds, 4*$c+1, 16 ) = $r if $r > vec( $bounds, 4*$c+1, 16 ); vec( $bounds, 4*$c+2, 16 ) = $y if $y < vec( $bounds, 4*$c+2, 16 ); vec( $bounds, 4*$c+3, 16 ) = $y if $y > vec( $bounds, 4*$c+3, 16 ); } } return $bounds; }