Permalink
Browse files

- file write plugins

- ICO write support, including extensive tests

- code coverage tests for reading icons/cursors

- write_multi() will now write to scalars, aka the data => \$scalar
output parameter

- added ignores for gcov data
  • Loading branch information...
1 parent 6205786 commit 43c4c3960c72f28a5a1916f7489cdcce8f2621d3 Tony Cook committed Jun 24, 2006
Showing with 921 additions and 181 deletions.
  1. +9 −1 ICO/ICO.pm
  2. +21 −18 ICO/imicon.c
  3. +128 −14 ICO/msicon.c
  4. +149 −1 ICO/t/t10icon.t
  5. +46 −7 ICO/t/t30cursor.t
  6. +142 −2 ICO/t/t60writefail.t
  7. +11 −0 ICO/t/t70icosing.t
  8. +11 −0 ICO/t/t71icomult.t
  9. +11 −0 ICO/t/t72cursing.t
  10. +11 −0 ICO/t/t73curmult.t
  11. +164 −132 Imager.pm
  12. +9 −0 MANIFEST
  13. +4 −0 MANIFEST.SKIP
  14. +1 −1 Makefile.PL
  15. +187 −3 lib/Imager/Files.pod
  16. +17 −2 t/t106tiff.t
View
@@ -147,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
@@ -220,14 +220,14 @@ validate_image(i_img *im) {
}
static int
-translate_mask(i_img *im, unsigned char *out, unsigned char *in) {
+translate_mask(i_img *im, unsigned char *out, const char *in) {
int x, y;
int one, zero;
int len = strlen(in);
int pos;
int newline; /* set to the first newline type we see */
int notnewline; /* set to whatever in ( "\n\r" newline isn't ) */
-
+
if (len < 3)
return 0;
@@ -245,7 +245,6 @@ translate_mask(i_img *im, unsigned char *out, unsigned char *in) {
y = 0;
while (y < im->ysize && pos < len) {
x = 0;
-
while (x < im->xsize && pos < len) {
if (in[pos] == newline) {
/* don't process it, we look for it later */
@@ -256,10 +255,12 @@ translate_mask(i_img *im, unsigned char *out, unsigned char *in) {
}
else if (in[pos] == one) {
*out++ = 1;
+ ++x;
++pos;
}
else if (in[pos] == zero) {
*out++ = 0;
+ ++x;
++pos;
}
else if (in[pos] == ' ' || in[pos] == '\t') {
@@ -275,6 +276,8 @@ translate_mask(i_img *im, unsigned char *out, unsigned char *in) {
}
while (pos < len && in[pos] != newline)
++pos;
+ if (pos < len && in[pos] == newline)
+ ++pos; /* actually skip the newline */
++y;
}
@@ -287,19 +290,18 @@ translate_mask(i_img *im, unsigned char *out, unsigned char *in) {
}
static void
-derive_mask(i_img *im, unsigned char *out) {
+derive_mask(i_img *im, ico_image_t *ico) {
if (im->channels == 1 || im->channels == 3) {
- int i;
-
- for (i = 0; i < im->xsize * im->ysize; ++i) {
- *out++ = 0;
- }
+ /* msicon.c's default mask is what we want */
+ myfree(ico->mask_data);
+ ico->mask_data = NULL;
}
else {
int channel = im->channels - 1;
i_sample_t *linebuf = mymalloc(sizeof(i_sample_t) * im->xsize);
int x, y;
+ unsigned char *out = ico->mask_data;
for (y = 0; y < im->ysize; ++y) {
i_gsamp(im, 0, im->xsize, y, linebuf, &channel, 1);
@@ -408,14 +410,15 @@ fill_image_base(i_img *im, ico_image_t *ico, const char *mask_name) {
{
/* build the mask */
- /* can't overflow, max icon size too small */
- int mask_size = im->xsize * im->ysize + 4;
- char *mask_buf = mymalloc(mask_size); /* checked */
+ int mask_index;
+
ico->mask_data = mymalloc(im->xsize * im->ysize);
-
- if (!i_tags_get_string(&im->tags, mask_name, 0, mask_buf, mask_size)
- || !translate_mask(im, ico->mask_data, mask_buf)) {
- derive_mask(im, ico->mask_data);
+
+ if (!i_tags_find(&im->tags, mask_name, 0, &mask_index)
+ || !im->tags.tags[mask_index].data
+ || !translate_mask(im, ico->mask_data,
+ im->tags.tags[mask_index].data)) {
+ derive_mask(im, ico);
}
}
}
@@ -471,7 +474,7 @@ i_writeico_multi_wiol(i_io_glue_t *ig, i_img **ims, int count) {
i_clear_error();
- if (count > 255) {
+ if (count > 0xFFFF) {
i_push_error(0, "too many images for ico files");
return 0;
}
@@ -579,7 +582,7 @@ i_writecur_multi_wiol(i_io_glue_t *ig, i_img **ims, int count) {
for (i = 0; i < count; ++i)
fill_image_cursor(ims[i], icons + i);
- if (!ico_write(ig, icons, count, ICON_ICON, &error)) {
+ if (!ico_write(ig, icons, count, ICON_CURSOR, &error)) {
ico_push_error(error);
for (i = 0; i < count; ++i)
unfill_image(icons + i);
Oops, something went wrong.

0 comments on commit 43c4c39

Please sign in to comment.