diff libinterp/dldfcn/__magick_read__.cc @ 20441:5b8e4f668c53

Add compression option to imwrite and default to "none" (bug #45565) * libinterp/dldfcn/__magick_read__.cc: we did not specify compression type and let it up to GM coder. However, Matlab users seem to be expect it to be uncompressed since Matlab only does that (except for jpeg). So we add the compression method and apply to the images being writen. * scripts/image/imwrite.m: document new option and add tests (bug was about bmp and type compression is defined at offset byte 30) * scripts/image/private/__imwrite__.m: parse new compression option.
author Carnë Draug <carandraug@octave.org>
date Tue, 28 Jul 2015 17:43:23 +0100
parents a7770c66cb3d
children b70cc4bd8109
line wrap: on
line diff
--- a/libinterp/dldfcn/__magick_read__.cc	Tue Jul 28 08:52:39 2015 -0700
+++ b/libinterp/dldfcn/__magick_read__.cc	Tue Jul 28 17:43:23 2015 +0100
@@ -1551,6 +1551,23 @@
   // Note that this only needs to be set on the first frame
   imvec[0].animationIterations (options.getfield ("loopcount").uint_value ());
 
+  const std::string compression = options.getfield ("compression").string_value ();
+#define COMPRESS_MAGICK_IMAGE_VECTOR(COMPRESSION_STRING, GM_TYPE) \
+  if (compression == COMPRESSION_STRING) \
+    for (std::vector<Magick::Image>::size_type i = 0; i < imvec.size (); i++) \
+      imvec[i].compressType (GM_TYPE);
+
+  COMPRESS_MAGICK_IMAGE_VECTOR("none", Magick::NoCompression)
+  else COMPRESS_MAGICK_IMAGE_VECTOR("bzip", Magick::BZipCompression)
+  else COMPRESS_MAGICK_IMAGE_VECTOR("fax3", Magick::FaxCompression)
+  else COMPRESS_MAGICK_IMAGE_VECTOR("fax4", Magick::Group4Compression)
+  else COMPRESS_MAGICK_IMAGE_VECTOR("jpeg", Magick::JPEGCompression)
+  else COMPRESS_MAGICK_IMAGE_VECTOR("lzw", Magick::LZWCompression)
+  else COMPRESS_MAGICK_IMAGE_VECTOR("rle", Magick::RLECompression)
+  else COMPRESS_MAGICK_IMAGE_VECTOR("deflate", Magick::ZipCompression)
+
+#undef COMPRESS_MAGICK_IMAGE_VECTOR
+
   write_file (filename, ext, imvec);
   if (error_state)
     return retval;