5454
5555// Set version number of the library.
5656#ifndef cimg_version
57- #define cimg_version 402
57+ #define cimg_version 403
5858
5959/*-----------------------------------------------------------
6060 #
@@ -9441,7 +9441,7 @@ namespace cimg_library {
94419441
94429442 // Destroy previous window if existing.
94439443 if (!is_empty()) assign();
9444- if (!dimw || !dimh) return;
9444+ if (!dimw || !dimh) return *this ;
94459445
94469446 // Set display variables.
94479447 _width = std::min(dimw,(unsigned int)screen_width());
@@ -56432,6 +56432,31 @@ namespace cimg_library {
5643256432 "load_tiff(): Specified filename is (null).",
5643356433 cimg_instance);
5643456434
56435+ if (*filename=='-' && (!filename[1] || filename[1]=='.')) { // Input from stdin
56436+ CImg<charT> filename_tmp(1024);
56437+ do {
56438+ cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.tiff",
56439+ cimg::temporary_path(),cimg_directory_separator,cimg::filenamerand());
56440+ } while (cimg::path_exists(filename_tmp));
56441+
56442+ // Copy stdin content to temporary file.
56443+ std::FILE
56444+ *const file = cimg::fopen(filename,"rb"),
56445+ *const ftmp = std::fopen(filename_tmp,"wb");
56446+ if (!ftmp) {
56447+ throw CImgIOException(_cimg_instance
56448+ "load_tiff(): Failed to create temporary file '%s'.",
56449+ cimg_instance,filename_tmp.data());
56450+ }
56451+ CImg<charT> buffer(65536);
56452+ size_t n;
56453+ while ((n=std::fread(buffer,1,sizeof(buffer),file))>0) std::fwrite(buffer,1,n,ftmp);
56454+ std::fclose(ftmp);
56455+ load_tiff(filename_tmp,first_frame,last_frame,step_frame,bits_per_value,voxel_size,description);
56456+ std::remove(filename_tmp);
56457+ return *this;
56458+ }
56459+
5643556460 const unsigned int
5643656461 nfirst_frame = first_frame<last_frame?first_frame:last_frame,
5643756462 nstep_frame = step_frame?step_frame:1;
@@ -58073,7 +58098,7 @@ namespace cimg_library {
5807358098 throw CImgArgumentException(_cimg_instance
5807458099 "load_graphicsmagick_external(): Specified filename is (null) or does not exist.",
5807558100 cimg_instance);
58076- CImg<charT> command(1024), filename_tmp(256 );
58101+ CImg<charT> command(1024), filename_tmp(1024 );
5807758102 const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();
5807858103#if cimg_OS==1
5807958104 if (cimg::posix_searchpath("gm")) {
@@ -58162,7 +58187,7 @@ namespace cimg_library {
5816258187 throw CImgIOException(_cimg_instance
5816358188 "load_gzip_external(): Specified filename is (null) or does not exist.",
5816458189 cimg_instance);
58165- CImg<charT> command(1024), filename_tmp(256 ), body(256 );
58190+ CImg<charT> command(1024), filename_tmp(1024 ), body(1024 );
5816658191 const char
5816758192 *const ext = cimg::split_filename(filename,body),
5816858193 *const ext2 = cimg::split_filename(body,0);
@@ -58216,7 +58241,7 @@ namespace cimg_library {
5821658241 throw CImgArgumentException(_cimg_instance
5821758242 "load_imagemagick_external(): Specified filename is (null) or does not exist.",
5821858243 cimg_instance);
58219- CImg<charT> command(1024), filename_tmp(256 );
58244+ CImg<charT> command(1024), filename_tmp(1024 );
5822058245 const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();
5822158246 const char *magick_path = cimg::imagemagick_path();
5822258247#if cimg_OS==1
@@ -58310,7 +58335,7 @@ namespace cimg_library {
5831058335 throw CImgArgumentException(_cimg_instance
5831158336 "load_medcon_external(): Specified filename is (null) or does not exist.",
5831258337 cimg_instance);
58313- CImg<charT> command(1024), filename_tmp(256 ), body(256 );
58338+ CImg<charT> command(1024), filename_tmp(1024 ), body(1024 );
5831458339 do {
5831558340 cimg_snprintf(filename_tmp,filename_tmp._width,"%s.hdr",cimg::filenamerand());
5831658341 } while (cimg::path_exists(filename_tmp));
@@ -58353,7 +58378,7 @@ namespace cimg_library {
5835358378 throw CImgArgumentException(_cimg_instance
5835458379 "load_pdf_external(): Specified filename is (null).",
5835558380 cimg_instance);
58356- CImg<charT> command(1024), filename_tmp(256 );
58381+ CImg<charT> command(1024), filename_tmp(1024 );
5835758382 const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();
5835858383#if cimg_OS==1
5835958384 std::FILE *file = 0;
@@ -58408,7 +58433,7 @@ namespace cimg_library {
5840858433 throw CImgArgumentException(_cimg_instance
5840958434 "load_dcraw_external(): Specified filename is (null) or does not exist.",
5841058435 cimg_instance);
58411- CImg<charT> command(1024), filename_tmp(256 );
58436+ CImg<charT> command(1024), filename_tmp(1024 );
5841258437 const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();
5841358438#if cimg_OS==1
5841458439 cimg_snprintf(command,command._width,"%s -w -4 -c \"%s\"",
@@ -61179,6 +61204,32 @@ namespace cimg_library {
6117961204 cimg_instance);
6118061205 if (is_empty()) { cimg::fempty(0,filename); return *this; }
6118161206
61207+ if (*filename=='-' && (!filename[1] || filename[1]=='.')) { // Output to stdout
61208+ CImg<charT> filename_tmp(1024);
61209+ do {
61210+ cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.tiff",
61211+ cimg::temporary_path(),cimg_directory_separator,cimg::filenamerand());
61212+ } while (cimg::path_exists(filename_tmp));
61213+ save_tiff(filename_tmp,compression_type,voxel_size,description,use_bigtiff);
61214+
61215+ // Copy file content to stdout.
61216+ std::FILE
61217+ *const ftmp = std::fopen(filename_tmp,"rb"),
61218+ *const file = cimg::fopen(filename,"wb");
61219+ if (!ftmp) {
61220+ std::remove(filename_tmp);
61221+ throw CImgIOException(_cimg_instance "save_tiff(): Failed to reopen temporary file '%s'.",
61222+ cimg_instance,filename_tmp);
61223+ }
61224+ CImg<charT> buffer(65536);
61225+ size_t n;
61226+ while ((n=std::fread(buffer,1,sizeof(buffer),ftmp))>0) std::fwrite(buffer,1,n,file);
61227+ std::fclose(ftmp);
61228+ cimg::fclose(file);
61229+ std::remove(filename_tmp);
61230+ return *this;
61231+ }
61232+
6118261233#ifdef cimg_use_tiff
6118361234 const bool
6118461235 _use_bigtiff = use_bigtiff && sizeof(ulongT)>=8 && size()*sizeof(T)>=1UL<<31; // No bigtiff for small images
@@ -62127,7 +62178,7 @@ namespace cimg_library {
6212762178 cimg_instance);
6212862179 if (is_empty()) { cimg::fempty(0,filename); return *this; }
6212962180
62130- CImg<charT> command(1024), filename_tmp(256 ), body(256 );
62181+ CImg<charT> command(1024), filename_tmp(1024 ), body(1024 );
6213162182 const char
6213262183 *ext = cimg::split_filename(filename,body),
6213362184 *ext2 = cimg::split_filename(body,0);
@@ -62191,7 +62242,7 @@ namespace cimg_library {
6219162242#define _cimg_sge_extension1 "pgm"
6219262243#define _cimg_sge_extension2 "ppm"
6219362244#endif
62194- CImg<charT> command(1024), filename_tmp(256 );
62245+ CImg<charT> command(1024), filename_tmp(1024 );
6219562246 do {
6219662247 cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.%s",
6219762248 cimg::temporary_path(),cimg_directory_separator,cimg::filenamerand(),
@@ -62248,7 +62299,7 @@ namespace cimg_library {
6224862299#define _cimg_sie_extension1 "pgm"
6224962300#define _cimg_sie_extension2 "ppm"
6225062301#endif
62251- CImg<charT> command(1024), filename_tmp(256 );
62302+ CImg<charT> command(1024), filename_tmp(1024 );
6225262303 do {
6225362304 cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.%s",cimg::temporary_path(),
6225462305 cimg_directory_separator,cimg::filenamerand(),
@@ -62295,7 +62346,7 @@ namespace cimg_library {
6229562346 cimg_instance);
6229662347 if (is_empty()) { cimg::fempty(0,filename); return *this; }
6229762348
62298- CImg<charT> command(1024), filename_tmp(256 ), body(256 );
62349+ CImg<charT> command(1024), filename_tmp(1024 ), body(1024 );
6229962350 do {
6230062351 cimg_snprintf(filename_tmp,filename_tmp._width,"%s.hdr",cimg::filenamerand());
6230162352 } while (cimg::path_exists(filename_tmp));
@@ -65867,7 +65918,7 @@ namespace cimg_library {
6586765918 throw CImgArgumentException(_cimglist_instance
6586865919 "load_ffmpeg_external(): Specified filename is (null) or does not exist.",
6586965920 cimglist_instance);
65870- CImg<charT> command(1024), filename_tmp(256 ), filename_tmp2(256 );
65921+ CImg<charT> command(1024), filename_tmp(1024 ), filename_tmp2(1024 );
6587165922 do {
6587265923 cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s",
6587365924 cimg::temporary_path(),cimg_directory_separator,cimg::filenamerand());
@@ -65928,7 +65979,7 @@ namespace cimg_library {
6592865979 }
6592965980
6593065981 CImgList<T>& _load_gif_external(const char *const filename, const bool use_graphicsmagick=false) {
65931- CImg<charT> command(1024), filename_tmp(256 ), filename_tmp2(256 );
65982+ CImg<charT> command(1024), filename_tmp(1024 ), filename_tmp2(1024 );
6593265983 do {
6593365984 cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s",
6593465985 cimg::temporary_path(),cimg_directory_separator,cimg::filenamerand());
@@ -65982,7 +66033,7 @@ namespace cimg_library {
6598266033 throw CImgIOException(_cimglist_instance
6598366034 "load_gzip_external(): Specified filename is (null) or does not exist.",
6598466035 cimglist_instance);
65985- CImg<charT> command(1024), filename_tmp(256 ), body(256 );
66036+ CImg<charT> command(1024), filename_tmp(1024 ), body(1024 );
6598666037 const char
6598766038 *ext = cimg::split_filename(filename,body),
6598866039 *ext2 = cimg::split_filename(body,0);
@@ -66040,6 +66091,36 @@ namespace cimg_library {
6604066091 const unsigned int first_frame=0, const unsigned int last_frame=~0U,
6604166092 const unsigned int step_frame=1, unsigned int *const bits_per_value=0,
6604266093 float *const voxel_size=0, CImg<charT> *const description=0) {
66094+ if (!filename)
66095+ throw CImgArgumentException(_cimglist_instance
66096+ "load_tiff(): Specified filename is (null).",
66097+ cimglist_instance);
66098+
66099+ if (*filename=='-' && (!filename[1] || filename[1]=='.')) { // Input from stdin
66100+ CImg<charT> filename_tmp(1024);
66101+ do {
66102+ cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.tiff",
66103+ cimg::temporary_path(),cimg_directory_separator,cimg::filenamerand());
66104+ } while (cimg::path_exists(filename_tmp));
66105+
66106+ // Copy stdin content to temporary file.
66107+ std::FILE
66108+ *const file = cimg::fopen(filename,"rb"),
66109+ *const ftmp = std::fopen(filename_tmp,"wb");
66110+ if (!ftmp) {
66111+ throw CImgIOException(_cimglist_instance
66112+ "load_tiff(): Failed to create temporary file '%s'.",
66113+ cimglist_instance,filename_tmp.data());
66114+ }
66115+ CImg<charT> buffer(65536);
66116+ size_t n;
66117+ while ((n=std::fread(buffer,1,sizeof(buffer),file))>0) std::fwrite(buffer,1,n,ftmp);
66118+ std::fclose(ftmp);
66119+ load_tiff(filename_tmp,first_frame,last_frame,step_frame,bits_per_value,voxel_size,description);
66120+ std::remove(filename_tmp);
66121+ return *this;
66122+ }
66123+
6604366124 const unsigned int
6604466125 nfirst_frame = first_frame<last_frame?first_frame:last_frame,
6604566126 nstep_frame = step_frame?step_frame:1;
@@ -66049,8 +66130,7 @@ namespace cimg_library {
6604966130 if (nfirst_frame || nlast_frame!=~0U || nstep_frame!=1)
6605066131 throw CImgArgumentException(_cimglist_instance
6605166132 "load_tiff(): Unable to load sub-images from file '%s' unless libtiff is enabled.",
66052- cimglist_instance,
66053- filename);
66133+ cimglist_instance,filename);
6605466134
6605566135 return assign(CImg<T>::get_load_tiff(filename));
6605666136#else
@@ -66424,7 +66504,7 @@ namespace cimg_library {
6642466504 **/
6642566505 const CImgList<T>& save_gif_external(const char *const filename, const float fps=25,
6642666506 const unsigned int nb_loops=0) {
66427- CImg<charT> command(1024), filename_tmp(256 ), filename_tmp2(256 );
66507+ CImg<charT> command(1024), filename_tmp(1024 ), filename_tmp2(1024 );
6642866508 CImgList<charT> filenames;
6642966509
6643066510#ifdef cimg_use_png
@@ -66847,6 +66927,32 @@ namespace cimg_library {
6684766927 cimglist_instance);
6684866928 if (is_empty()) { cimg::fempty(0,filename); return *this; }
6684966929
66930+ if (*filename=='-' && (!filename[1] || filename[1]=='.')) { // Output to stdout
66931+ CImg<charT> filename_tmp(1024);
66932+ do {
66933+ cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.tiff",
66934+ cimg::temporary_path(),cimg_directory_separator,cimg::filenamerand());
66935+ } while (cimg::path_exists(filename_tmp));
66936+ save_tiff(filename_tmp,compression_type,voxel_size,description,use_bigtiff);
66937+
66938+ // Copy file content to stdout.
66939+ std::FILE
66940+ *const ftmp = std::fopen(filename_tmp,"rb"),
66941+ *const file = cimg::fopen(filename,"wb");
66942+ if (!ftmp) {
66943+ std::remove(filename_tmp);
66944+ throw CImgIOException(_cimglist_instance "save_tiff(): Failed to reopen temporary file '%s'.",
66945+ cimglist_instance,filename_tmp);
66946+ }
66947+ CImg<charT> buffer(65536);
66948+ size_t n;
66949+ while ((n=std::fread(buffer,1,sizeof(buffer),ftmp))>0) std::fwrite(buffer,1,n,file);
66950+ std::fclose(ftmp);
66951+ cimg::fclose(file);
66952+ std::remove(filename_tmp);
66953+ return *this;
66954+ }
66955+
6685066956#ifndef cimg_use_tiff
6685166957 if (_width==1) _data[0].save_tiff(filename,compression_type,voxel_size,description,use_bigtiff);
6685266958 else cimglist_for(*this,l) {
@@ -66889,7 +66995,7 @@ namespace cimg_library {
6688966995 throw CImgIOException(_cimglist_instance
6689066996 "save_gzip_external(): Specified filename is (null).",
6689166997 cimglist_instance);
66892- CImg<charT> command(1024), filename_tmp(256 ), body(256 );
66998+ CImg<charT> command(1024), filename_tmp(1024 ), body(1024 );
6689366999 const char
6689467000 *ext = cimg::split_filename(filename,body),
6689567001 *ext2 = cimg::split_filename(body,0);
@@ -67084,7 +67190,7 @@ namespace cimg_library {
6708467190 !cimg::strcasecmp(ext,"flv")?"flv":
6708567191 !cimg::strcasecmp(ext,"mp4")?"h264":"mpeg2video";
6708667192
67087- CImg<charT> command(1024), filename_tmp(256 ), filename_tmp2(256 );
67193+ CImg<charT> command(1024), filename_tmp(1024 ), filename_tmp2(1024 );
6708867194 CImgList<charT> filenames;
6708967195 cimglist_for(*this,l) if (!_data[l].is_sameXYZ(_data[0]))
6709067196 throw CImgInstanceException(_cimglist_instance
@@ -68255,7 +68361,7 @@ namespace cimg_library {
6825568361 } else if (!s_path) {
6825668362 s_path.assign(1024);
6825768363 bool path_found = false;
68258- CImg<char> tmp(1024), filename_tmp(256 );
68364+ CImg<char> tmp(1024), filename_tmp(1024 );
6825968365 std::FILE *file = 0;
6826068366 cimg_snprintf(filename_tmp,filename_tmp._width,"%s.tmp",cimg::filenamerand());
6826168367 char *tmpPath = std::getenv("TMP");
0 commit comments