Permalink
Browse files

add support for file write plugins

fix write_multi() writing to scalars
  https://rt.cpan.org/Ticket/Display.html?id=19982

add support for writing to ICO/CUR image files

added file limit check functions to the API
  • Loading branch information...
Tony Cook
Tony Cook committed Jun 26, 2006
1 parent c64eee3 commit 2b405c9e0e655ef3c1a219f53195da7ddb6eadbc
Showing with 2,783 additions and 197 deletions.
  1. +91 −1 ICO/ICO.pm
  2. +91 −0 ICO/ICO.xs
  3. +2 −0 ICO/Makefile.PL
  4. +436 −14 ICO/imicon.c
  5. +12 −0 ICO/imicon.h
  6. +7 −0 ICO/lib/Imager/File/CUR.pm
  7. +733 −25 ICO/msicon.c
  8. +10 −0 ICO/msicon.h
  9. +169 −7 ICO/t/t10icon.t
  10. +73 −0 ICO/t/t30cursor.t
  11. +10 −0 ICO/t/t40readcurone.t
  12. +10 −0 ICO/t/t41curmultread.t
  13. +337 −0 ICO/t/t50readfail.t
  14. +253 −0 ICO/t/t60writefail.t
  15. +11 −0 ICO/t/t70icosing.t
  16. +11 −0 ICO/t/t71icomult.t
  17. +11 −0 ICO/t/t72cursing.t
  18. +11 −0 ICO/t/t73curmult.t
  19. BIN ICO/testimg/pal43232.cur
  20. +230 −117 Imager.pm
  21. +15 −5 Imager.xs
  22. +11 −0 MANIFEST
  23. +4 −0 MANIFEST.SKIP
  24. +1 −1 Makefile.PL
  25. +0 −2 image.c
  26. +2 −0 imager.h
  27. +0 −3 imageri.h
  28. +5 −0 imext.c
  29. +7 −0 imext.h
  30. +7 −2 imexttypes.h
  31. +17 −13 iolayer.c
  32. +2 −2 iolayert.h
  33. +187 −3 lib/Imager/Files.pod
  34. +17 −2 t/t106tiff.t
View
@@ -46,6 +46,88 @@ Imager->register_reader
},
);
+# the readers can read CUR files too
+Imager->register_reader
+ (
+ type=>'cur',
+ single =>
+ sub {
+ my ($im, $io, %hsh) = @_;
+ $im->{IMG} = i_readico_single($io, $hsh{page} || 0);
+
+ unless ($im->{IMG}) {
+ $im->_set_error(Imager->_error_as_msg);
+ return;
+ }
+ return $im;
+ },
+ multiple =>
+ sub {
+ my ($io, %hsh) = @_;
+
+ my @imgs = i_readico_multi($io);
+ 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__
@@ -65,12 +147,20 @@ Imager::File::ICO - read MS Icon files
my @imgs = Imager->read_multi(file => "foo.ico")
or die Imager->errstr;
-=head1 DESCRIPTION
+ $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.
View
@@ -35,6 +35,97 @@ i_readico_multi(ig)
myfree(imgs);
}
+int
+i_writeico_wiol(ig, im)
+ Imager::IO ig
+ Imager::ImgRaw im
+
+undef_int
+i_writeico_multi_wiol(ig, ...)
+ Imager::IO ig
+ PREINIT:
+ int i;
+ int img_count;
+ i_img **imgs;
+ CODE:
+ if (items < 2)
+ croak("Usage: i_writeico_multi_wiol(ig, images...)");
+ img_count = items - 1;
+ RETVAL = 1;
+ if (img_count < 1) {
+ RETVAL = 0;
+ i_clear_error();
+ i_push_error(0, "You need to specify images to save");
+ }
+ else {
+ imgs = mymalloc(sizeof(i_img *) * img_count);
+ for (i = 0; i < img_count; ++i) {
+ SV *sv = ST(1+i);
+ imgs[i] = NULL;
+ if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
+ imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(sv)));
+ }
+ else {
+ i_clear_error();
+ i_push_error(0, "Only images can be saved");
+ myfree(imgs);
+ RETVAL = 0;
+ break;
+ }
+ }
+ if (RETVAL) {
+ RETVAL = i_writeico_multi_wiol(ig, imgs, img_count);
+ }
+ myfree(imgs);
+ }
+ OUTPUT:
+ RETVAL
+
+int
+i_writecur_wiol(ig, im)
+ Imager::IO ig
+ Imager::ImgRaw im
+
+undef_int
+i_writecur_multi_wiol(ig, ...)
+ Imager::IO ig
+ PREINIT:
+ int i;
+ int img_count;
+ i_img **imgs;
+ CODE:
+ if (items < 2)
+ croak("Usage: i_writecur_multi_wiol(ig, images...)");
+ img_count = items - 1;
+ RETVAL = 1;
+ if (img_count < 1) {
+ RETVAL = 0;
+ i_clear_error();
+ i_push_error(0, "You need to specify images to save");
+ }
+ else {
+ imgs = mymalloc(sizeof(i_img *) * img_count);
+ for (i = 0; i < img_count; ++i) {
+ SV *sv = ST(1+i);
+ imgs[i] = NULL;
+ if (SvROK(sv) && sv_derived_from(sv, "Imager::ImgRaw")) {
+ imgs[i] = INT2PTR(i_img *, SvIV((SV*)SvRV(sv)));
+ }
+ else {
+ i_clear_error();
+ i_push_error(0, "Only images can be saved");
+ myfree(imgs);
+ RETVAL = 0;
+ break;
+ }
+ }
+ if (RETVAL) {
+ RETVAL = i_writecur_multi_wiol(ig, imgs, img_count);
+ }
+ myfree(imgs);
+ }
+ OUTPUT:
+ RETVAL
BOOT:
PERL_INITIALIZE_IMAGER_CALLBACKS;
View
@@ -1,3 +1,5 @@
+#!perl -w
+use strict;
use ExtUtils::MakeMaker;
my %opts =
Oops, something went wrong.

0 comments on commit 2b405c9

Please sign in to comment.