| 1 | # -*- perl -*- | ||||||||||||||
| 2 | |||||||||||||||
| 3 | # | ||||||||||||||
| 4 | # Copyright (C) 2013 Slaven Rezic. All rights reserved. | ||||||||||||||
| 5 | # This package is free software; you can redistribute it and/or | ||||||||||||||
| 6 | # modify it under the same terms as Perl itself. | ||||||||||||||
| 7 | # | ||||||||||||||
| 8 | |||||||||||||||
| 9 | package Image::Info::WBMP; | ||||||||||||||
| 10 | |||||||||||||||
| 11 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 1 | ▶ | use vars qw($VERSION @EXPORT_OK); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 1 | $VERSION = '0.01'; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 1 | require Exporter; | |||||||||||||
| 16 | 1 | *import = \&Exporter::import; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 1 | @EXPORT_OK = qw(wbmp_image_info); | |||||||||||||
| 19 | |||||||||||||||
| 20 | sub process_file { | ||||||||||||||
| 21 | 1 | ▶ | my($info, $fh) = @_; | ||||||||||||
|
Subroutine
process_file: called CC=3 SCAR=13.5
Pod
undocumented
| |||||||||||||||
| 22 | |||||||||||||||
| 23 | # wbmp files have no magic, so no signature check | ||||||||||||||
| 24 | |||||||||||||||
| 25 | 1 | $info->push_info(0, 'file_media_type' => 'image/vnd.wap.wbmp'); | |||||||||||||
| 26 | 1 | $info->push_info(0, 'file_ext' => 'wbmp'); | |||||||||||||
| 27 | |||||||||||||||
| 28 | # logic taken from netpbm's wbmptopbm.c and adapted to perl | ||||||||||||||
| 29 | |||||||||||||||
| 30 | my $readint = sub { | ||||||||||||||
| 31 | 3 | ▶ | my $sum = 0; | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||
| 32 | 3 | my $pos = 0; | |||||||||||||
| 33 | 3 | my $c; | |||||||||||||
| 34 | 3 | ▶ | do { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 3 | $c = ord(getc $fh); | |||||||||||||
| 36 | 3 | $sum = ($sum << 7*$pos++) | ($c & 0x7f); | |||||||||||||
| 37 | } while($c & 0x80); | ||||||||||||||
| 38 | 3 | return $sum; | |||||||||||||
| 39 | 1 | }; | |||||||||||||
| 40 | |||||||||||||||
| 41 | my $readheader = sub { | ||||||||||||||
| 42 | 0 | ▶ | my $h = shift; | ||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||
| 43 | 0 | ▶ | if ($h & 0x60 == 0) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 44 | # type 00: read multi-byte bitfield | ||||||||||||||
| 45 | 0 | my $c; | |||||||||||||
| 46 | 0 | ▶ | do { $c = ord(getc $fh) } while($c & 0x80); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | } elsif ($h & 0x60 == 0x60) { | ||||||||||||||
| 48 | # type 11: read name/value pair | ||||||||||||||
| 49 | 0 | ▶ | for(my $i=0; $i < (($h & 0x70) >> 4) + ($h & 0x0f); $i++) { getc $fh } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | } | ||||||||||||||
| 51 | 1 | }; | |||||||||||||
| 52 | |||||||||||||||
| 53 | 1 | my $c; | |||||||||||||
| 54 | 1 | $c = $readint->(); | |||||||||||||
| 55 | 1 | ▶ | $c == 0 | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 56 | or die "Unrecognized WBMP type (got $c)"; | ||||||||||||||
| 57 | 1 | $c = ord(getc $fh); # FixHeaderField | |||||||||||||
| 58 | 1 | ▶ | while($c & 0x80) { # ExtheaderFields | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | 0 | $c = ord(getc $fh); | |||||||||||||
| 60 | 0 | $readheader->($c); | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | 1 | my $w = $readint->(); | |||||||||||||
| 63 | 1 | my $h = $readint->(); | |||||||||||||
| 64 | 1 | $info->push_info(0, 'width', $w); | |||||||||||||
| 65 | 1 | $info->push_info(0, 'height', $h); | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | sub wbmp_image_info { | ||||||||||||||
| 69 | 1 | ▶ | my $source = Image::Info::_source(shift); | ||||||||||||
|
Subroutine
wbmp_image_info: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||
| 70 | 1 | ▶ | return $source if ref $source eq 'HASH'; # Pass on errors | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 71 | |||||||||||||||
| 72 | 1 | return Image::Info::_image_info_for_format('WBMP', $source); | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 1 | 1; | |||||||||||||
| 76 | |||||||||||||||
| 77 | __END__ | ||||||||||||||