1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
package Imager::File::ICO;
use strict;
use Imager;
use vars qw($VERSION @ISA);
BEGIN {
$VERSION = "0.01";
eval {
require XSLoader;
XSLoader::load('Imager::File::ICO', $VERSION);
1;
} or do {
require DynaLoader;
push @ISA, 'DynaLoader';
bootstrap Imager::File::ICO $VERSION;
};
}
Imager->register_reader
(
type=>'ico',
single =>
sub {
my ($im, $io, %hsh) = @_;
my $masked =
exists $hsh{ico_masked} ? $hsh{ico_masked} : 1;
$im->{IMG} = i_readico_single($io, $hsh{page} || 0, $masked);
unless ($im->{IMG}) {
$im->_set_error(Imager->_error_as_msg);
return;
}
return $im;
},
multiple =>
sub {
my ($io, %hsh) = @_;
my $masked =
exists $hsh{ico_masked} ? $hsh{ico_masked} : 1;
my @imgs = i_readico_multi($io, $masked);
unless (@imgs) {
Imager->_set_error(Imager->_error_as_msg);
return;
}
return map {
bless { IMG => $_, DEBUG => $Imager::DEBUG, ERRSTR => undef }, 'Imager'
} @imgs;
},
);
# the readers can read CUR files too
Imager->register_reader
(
type=>'cur',
single =>
sub {
my ($im, $io, %hsh) = @_;
my $masked =
exists $hsh{ico_masked} ? $hsh{ico_masked} : 1;
$im->{IMG} = i_readico_single($io, $hsh{page} || 0, $masked);
unless ($im->{IMG}) {
$im->_set_error(Imager->_error_as_msg);
return;
}
return $im;
},
multiple =>
sub {
my ($io, %hsh) = @_;
my $masked =
exists $hsh{ico_masked} ? $hsh{ico_masked} : 1;
my @imgs = i_readico_multi($io, $masked);
unless (@imgs) {
Imager->_set_error(Imager->_error_as_msg);
return;
}
return map {
bless { IMG => $_, DEBUG => $Imager::DEBUG, ERRSTR => undef }, 'Imager'
} @imgs;
},
);
Imager->register_writer
(
type=>'ico',
single =>
sub {
my ($im, $io, %hsh) = @_;
unless (i_writeico_wiol($io, $im->{IMG})) {
$im->_set_error(Imager->_error_as_msg);
return;
}
return $im;
},
multiple =>
sub {
my ($class, $io, $opts, @images) = @_;
if (!i_writeico_multi_wiol($io, map $_->{IMG}, @images)) {
Imager->_set_error(Imager->_error_as_msg);
return;
}
return 1;
},
);
Imager->register_writer
(
type=>'cur',
single =>
sub {
my ($im, $io, %hsh) = @_;
unless (i_writecur_wiol($io, $im->{IMG})) {
$im->_set_error(Imager->_error_as_msg);
return;
}
return $im;
},
multiple =>
sub {
my ($class, $io, $opts, @images) = @_;
if (!i_writecur_multi_wiol($io, map $_->{IMG}, @images)) {
Imager->_set_error(Imager->_error_as_msg);
return;
}
return 1;
},
);
1;
__END__
=head1 NAME
Imager::File::ICO - read MS Icon files
=head1 SYNOPSIS
use Imager;
my $img = Imager->new;
$img->read(file=>"foo.ico")
or die $img->errstr;
my @imgs = Imager->read_multi(file => "foo.ico")
or die Imager->errstr;
$img->write(file => "foo.ico")
or die $img->errstr;
Imager->write_multi({ file => "foo.ico" }, @imgs)
or die Imager->errstr;
=head1 DESCRIPTION
Imager's MS Icon support is documented in L<Imager::Files>.
=head1 AUTHOR
Tony Cook <tony@imager.perl.org>
=head1 SEE ALSO
Imager, Imager::Files.
=cut
|