]> git.imager.perl.org - imager.git/commitdiff
- set i_format to jpeg for jpeg files and test for it
authorTony Cook <tony@develop=help.com>
Thu, 25 Nov 2004 12:16:46 +0000 (12:16 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 25 Nov 2004 12:16:46 +0000 (12:16 +0000)
Changes
jpeg.c
t/t101jpeg.t

diff --git a/Changes b/Changes
index 5a356ac82138d3b30ed478b5619027081700f250..673b850fd22dabb33db335e05051d02164263e1b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -888,6 +888,7 @@ Revision history for Perl extension Imager.
   overflow an integer would cause too small a buffer to be allocated.
   This could potentially be a security hole.
   partly resolves https://rt.cpan.org/Ticket/Display.html?id=8213
+- set i_format to jpeg for jpeg files and test for it
 
 =================================================================
 
diff --git a/jpeg.c b/jpeg.c
index 6aa9eb0d12665683769f2010dcb3a0871511f490..394c6245535cdbc5be4444aede6318b6578babdd 100644 (file)
--- a/jpeg.c
+++ b/jpeg.c
@@ -371,6 +371,10 @@ i_readjpeg_wiol(io_glue *data, int length, char** iptc_itext, int *itlength) {
   (void) jpeg_read_header(&cinfo, TRUE);
   (void) jpeg_start_decompress(&cinfo);
   im=i_img_empty_ch(NULL,cinfo.output_width,cinfo.output_height,cinfo.output_components);
+  if (!im) {
+    jpeg_destroy_decompress(&cinfo);
+    return NULL;
+  }
   row_stride = cinfo.output_width * cinfo.output_components;
   buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
   while (cinfo.output_scanline < cinfo.output_height) {
@@ -380,6 +384,9 @@ i_readjpeg_wiol(io_glue *data, int length, char** iptc_itext, int *itlength) {
   (void) jpeg_finish_decompress(&cinfo);
   jpeg_destroy_decompress(&cinfo);
   *itlength=tlength;
+
+  i_tags_add(&im->tags, "i_format", 0, "jpeg", 4, 0);
+
   mm_log((1,"i_readjpeg_wiol -> (0x%x)\n",im));
   return im;
 }
index 2a4653e8017b91321324dd3606262f8fe8d6d290..4366748e7c678f1711ddac42a20bb2e7583023ad 100644 (file)
@@ -1,6 +1,6 @@
 use Imager qw(:all);
 
-print "1..8\n";
+print "1..9\n";
 
 init_log("testout/t101jpeg.log",1);
 
@@ -18,7 +18,7 @@ i_conv($img,[0.1, 0.2, 0.4, 0.2, 0.1]);
 
 i_has_format("jpeg") && print "# has jpeg\n";
 if (!i_has_format("jpeg")) {
-  for (1..8) {
+  for (1..9) {
     print "ok $_ # skip no jpeg support\n";
   }
 } else {
@@ -66,6 +66,10 @@ if (!i_has_format("jpeg")) {
   ok(8, !$imoo->write(fd=>fileno(FH), type=>'jpeg'), 'failure handling');
   close FH;
   print "# ",$imoo->errstr,"\n";
+
+  # check that the i_format tag is set
+  my @fmt = $imoo->tags(name=>'i_format');
+  ok(9, @fmt == 1 && $fmt[0] eq 'jpeg', 'i_format tag');
 }
 
 sub ok {