Skip to content

Commit 99b0feb

Browse files
committed
.
2 parents 1f9f3dc + 6a69bf7 commit 99b0feb

3 files changed

Lines changed: 66 additions & 77 deletions

File tree

CImg.h

Lines changed: 64 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
// Set version number of the library.
5656
#ifndef cimg_version
57-
#define cimg_version 376
57+
#define cimg_version 377
5858

5959
/*-----------------------------------------------------------
6060
#
@@ -39177,7 +39177,7 @@ namespace cimg_library {
3917739177
**/
3917839178
CImg<T>& mirror(const char axis) {
3917939179
if (is_empty()) return *this;
39180-
T *pf, *pb, *buf = 0;
39180+
T *pf, *pb, *buffer = 0;
3918139181
switch (cimg::lowercase(axis)) {
3918239182
case 'x' : {
3918339183
pf = _data; pb = data(_width - 1);
@@ -39189,14 +39189,15 @@ namespace cimg_library {
3918939189
}
3919039190
} break;
3919139191
case 'y' : {
39192-
buf = new T[_width];
39192+
CImg<T> _buffer(_width);
39193+
buffer = _buffer._data;
3919339194
pf = _data; pb = data(0,_height - 1);
3919439195
const unsigned int height2 = _height/2;
3919539196
for (unsigned int zv = 0; zv<_depth*_spectrum; ++zv) {
3919639197
for (unsigned int y = 0; y<height2; ++y) {
39197-
std::memcpy(buf,pf,_width*sizeof(T));
39198+
std::memcpy(buffer,pf,_width*sizeof(T));
3919839199
std::memcpy(pf,pb,_width*sizeof(T));
39199-
std::memcpy(pb,buf,_width*sizeof(T));
39200+
std::memcpy(pb,buffer,_width*sizeof(T));
3920039201
pf+=_width;
3920139202
pb-=_width;
3920239203
}
@@ -39205,14 +39206,15 @@ namespace cimg_library {
3920539206
}
3920639207
} break;
3920739208
case 'z' : {
39208-
buf = new T[(ulongT)_width*_height];
39209+
CImg<T> _buffer(_width,_height);
39210+
buffer = _buffer._data;
3920939211
pf = _data; pb = data(0,0,_depth - 1);
3921039212
const unsigned int depth2 = _depth/2;
3921139213
cimg_forC(*this,c) {
3921239214
for (unsigned int z = 0; z<depth2; ++z) {
39213-
std::memcpy(buf,pf,_width*_height*sizeof(T));
39215+
std::memcpy(buffer,pf,_width*_height*sizeof(T));
3921439216
std::memcpy(pf,pb,_width*_height*sizeof(T));
39215-
std::memcpy(pb,buf,_width*_height*sizeof(T));
39217+
std::memcpy(pb,buffer,_width*_height*sizeof(T));
3921639218
pf+=(ulongT)_width*_height;
3921739219
pb-=(ulongT)_width*_height;
3921839220
}
@@ -39221,13 +39223,14 @@ namespace cimg_library {
3922139223
}
3922239224
} break;
3922339225
case 'c' : {
39224-
buf = new T[(ulongT)_width*_height*_depth];
39226+
CImg<T> _buffer(_width,_height,_depth);
39227+
buffer = _buffer._data;
3922539228
pf = _data; pb = data(0,0,0,_spectrum - 1);
3922639229
const unsigned int _spectrum2 = _spectrum/2;
3922739230
for (unsigned int v = 0; v<_spectrum2; ++v) {
39228-
std::memcpy(buf,pf,_width*_height*_depth*sizeof(T));
39231+
std::memcpy(buffer,pf,_width*_height*_depth*sizeof(T));
3922939232
std::memcpy(pf,pb,_width*_height*_depth*sizeof(T));
39230-
std::memcpy(pb,buf,_width*_height*_depth*sizeof(T));
39233+
std::memcpy(pb,buffer,_width*_height*_depth*sizeof(T));
3923139234
pf+=(ulongT)_width*_height*_depth;
3923239235
pb-=(ulongT)_width*_height*_depth;
3923339236
}
@@ -39238,7 +39241,6 @@ namespace cimg_library {
3923839241
cimg_instance,
3923939242
axis);
3924039243
}
39241-
delete[] buf;
3924239244
return *this;
3924339245
}
3924439246

@@ -58696,13 +58698,14 @@ namespace cimg_library {
5869658698
unsigned int header_size;
5869758699
cimg::fread(&header_size,1,nfile_header);
5869858700
if (header_size>=4096) { endian = true; cimg::invert_endianness(header_size); }
58699-
if (header_size<128)
58701+
const ulongT fsiz = file?(ulongT)cimg_max_buf_size:(ulongT)cimg::fsize(filename);
58702+
if (header_size<128 || (ulongT)header_size>fsiz)
5870058703
throw CImgIOException(_cimg_instance
5870158704
"load_analyze(): Invalid header size (%u) specified in file '%s'.",
5870258705
cimg_instance,
5870358706
header_size,filename?filename:"(FILE*)");
58704-
58705-
unsigned char *const header = new unsigned char[header_size];
58707+
CImg<ucharT> _header(header_size);
58708+
unsigned char *const header = _header._data;
5870658709
const size_t header_size_read = cimg::fread(header + 4,header_size - 4,nfile_header);
5870758710
if (header_size_read!=header_size - 4)
5870858711
throw CImgIOException(_cimg_instance
@@ -58748,45 +58751,44 @@ namespace cimg_library {
5874858751
const float *vsize = (float*)(header + 76);
5874958752
voxel_size[0] = vsize[1]; voxel_size[1] = vsize[2]; voxel_size[2] = vsize[3];
5875058753
}
58751-
delete[] header;
5875258754

5875358755
// Read pixel data.
5875458756
assign(dimx,dimy,dimz,dimv);
5875558757
const size_t pdim = (size_t)dimx*dimy*dimz*dimv;
5875658758
switch (datatype) {
5875758759
case 2 : {
58758-
unsigned char *const buffer = new unsigned char[pdim];
58760+
CImg<ucharT> _buffer(pdim);
58761+
unsigned char *const buffer = _buffer._data;
5875958762
cimg::fread(buffer,pdim,nfile);
5876058763
cimg_foroff(*this,off) _data[off] = (T)(buffer[off]*scalefactor);
58761-
delete[] buffer;
5876258764
} break;
5876358765
case 4 : {
58764-
short *const buffer = new short[pdim];
58766+
CImg<shortT> _buffer(pdim);
58767+
short *const buffer = _buffer._data;
5876558768
cimg::fread(buffer,pdim,nfile);
5876658769
if (endian) cimg::invert_endianness(buffer,pdim);
5876758770
cimg_foroff(*this,off) _data[off] = (T)(buffer[off]*scalefactor);
58768-
delete[] buffer;
5876958771
} break;
5877058772
case 8 : {
58771-
int *const buffer = new int[pdim];
58773+
CImg<intT> _buffer(pdim);
58774+
int *const buffer = _buffer._data;
5877258775
cimg::fread(buffer,pdim,nfile);
5877358776
if (endian) cimg::invert_endianness(buffer,pdim);
5877458777
cimg_foroff(*this,off) _data[off] = (T)(buffer[off]*scalefactor);
58775-
delete[] buffer;
5877658778
} break;
5877758779
case 16 : {
58778-
float *const buffer = new float[pdim];
58780+
CImg<floatT> _buffer(pdim);
58781+
float *const buffer = _buffer._data;
5877958782
cimg::fread(buffer,pdim,nfile);
5878058783
if (endian) cimg::invert_endianness(buffer,pdim);
5878158784
cimg_foroff(*this,off) _data[off] = (T)(buffer[off]*scalefactor);
58782-
delete[] buffer;
5878358785
} break;
5878458786
case 64 : {
58785-
double *const buffer = new double[pdim];
58787+
CImg<doubleT> _buffer(pdim);
58788+
double *const buffer = _buffer._data;
5878658789
cimg::fread(buffer,pdim,nfile);
5878758790
if (endian) cimg::invert_endianness(buffer,pdim);
5878858791
cimg_foroff(*this,off) _data[off] = (T)(buffer[off]*scalefactor);
58789-
delete[] buffer;
5879058792
} break;
5879158793
default :
5879258794
if (!file) cimg::fclose(nfile);
@@ -59105,9 +59107,7 @@ namespace cimg_library {
5910559107
cimg::fread(buffer,siz,nfile); \
5910659108
if (endian) cimg::invert_endianness(buffer,siz); \
5910759109
T *ptrd = _data; \
59108-
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++); \
59109-
buffer-=siz; \
59110-
delete[] buffer
59110+
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
5911159111

5911259112
#define _cimg_load_pandore_case(nbdim,nwidth,nheight,ndepth,dim,stype1,stype2,stype3,ltype) { \
5911359113
if (sizeof(stype1)==ltype) { __cimg_load_pandore_case(nbdim,nwidth,nheight,ndepth,dim,stype1); } \
@@ -59156,29 +59156,26 @@ namespace cimg_library {
5915659156
assign(dims[1],1,1,1);
5915759157
const unsigned siz = size();
5915859158
if (dims[2]<256) {
59159-
unsigned char *buffer = new unsigned char[siz];
59159+
CImg<ucharT> _buffer(siz);
59160+
unsigned char *buffer = _buffer._data;
5916059161
cimg::fread(buffer,siz,nfile);
5916159162
T *ptrd = _data;
5916259163
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
59163-
buffer-=siz;
59164-
delete[] buffer;
5916559164
} else {
5916659165
if (dims[2]<65536) {
59167-
unsigned short *buffer = new unsigned short[siz];
59166+
CImg<ushortT> _buffer(siz);
59167+
unsigned short *buffer = _buffer._data;
5916859168
cimg::fread(buffer,siz,nfile);
5916959169
if (endian) cimg::invert_endianness(buffer,siz);
5917059170
T *ptrd = _data;
5917159171
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
59172-
buffer-=siz;
59173-
delete[] buffer;
5917459172
} else {
59175-
unsigned int *buffer = new unsigned int[siz];
59173+
CImg<uintT> _buffer(siz);
59174+
unsigned int *buffer = _buffer._data;
5917659175
cimg::fread(buffer,siz,nfile);
5917759176
if (endian) cimg::invert_endianness(buffer,siz);
5917859177
T *ptrd = _data;
5917959178
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
59180-
buffer-=siz;
59181-
delete[] buffer;
5918259179
}
5918359180
}
5918459181
}
@@ -59189,29 +59186,26 @@ namespace cimg_library {
5918959186
assign(dims[2],dims[1],1,1);
5919059187
const size_t siz = size();
5919159188
if (dims[3]<256) {
59192-
unsigned char *buffer = new unsigned char[siz];
59189+
CImg<ucharT> _buffer(siz);
59190+
unsigned char *buffer = _buffer._data;
5919359191
cimg::fread(buffer,siz,nfile);
5919459192
T *ptrd = _data;
5919559193
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
59196-
buffer-=siz;
59197-
delete[] buffer;
5919859194
} else {
5919959195
if (dims[3]<65536) {
59200-
unsigned short *buffer = new unsigned short[siz];
59196+
CImg<ushortT> _buffer(siz);
59197+
unsigned short *buffer = _buffer._data;
5920159198
cimg::fread(buffer,siz,nfile);
5920259199
if (endian) cimg::invert_endianness(buffer,siz);
5920359200
T *ptrd = _data;
5920459201
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
59205-
buffer-=siz;
59206-
delete[] buffer;
5920759202
} else {
59208-
unsigned int *buffer = new unsigned int[siz];
59203+
CImg<uintT> _buffer(siz);
59204+
unsigned int *buffer = _buffer._data;
5920959205
cimg::fread(buffer,siz,nfile);
5921059206
if (endian) cimg::invert_endianness(buffer,siz);
5921159207
T *ptrd = _data;
5921259208
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
59213-
buffer-=siz;
59214-
delete[] buffer;
5921559209
}
5921659210
}
5921759211
}
@@ -59222,29 +59216,26 @@ namespace cimg_library {
5922259216
assign(dims[3],dims[2],dims[1],1);
5922359217
const size_t siz = size();
5922459218
if (dims[4]<256) {
59225-
unsigned char *buffer = new unsigned char[siz];
59219+
CImg<ucharT> _buffer(siz);
59220+
unsigned char *buffer = _buffer._data;
5922659221
cimg::fread(buffer,siz,nfile);
5922759222
T *ptrd = _data;
5922859223
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
59229-
buffer-=siz;
59230-
delete[] buffer;
5923159224
} else {
5923259225
if (dims[4]<65536) {
59233-
unsigned short *buffer = new unsigned short[siz];
59226+
CImg<ushortT> _buffer(siz);
59227+
unsigned short *buffer = _buffer._data;
5923459228
cimg::fread(buffer,siz,nfile);
5923559229
if (endian) cimg::invert_endianness(buffer,siz);
5923659230
T *ptrd = _data;
5923759231
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
59238-
buffer-=siz;
59239-
delete[] buffer;
5924059232
} else {
59241-
unsigned int *buffer = new unsigned int[siz];
59233+
CImg<uintT> _buffer(siz);
59234+
unsigned int *buffer = _buffer._data;
5924259235
cimg::fread(buffer,siz,nfile);
5924359236
if (endian) cimg::invert_endianness(buffer,siz);
5924459237
T *ptrd = _data;
5924559238
cimg_foroff(*this,off) *(ptrd++) = (T)*(buffer++);
59246-
buffer-=siz;
59247-
delete[] buffer;
5924859239
}
5924959240
}
5925059241
}
@@ -59396,10 +59387,10 @@ namespace cimg_library {
5939659387
assign(_size_x,_size_y,_size_z,_size_c,0);
5939759388

5939859389
if (is_bool) { // Boolean data (bitwise)
59399-
unsigned char *const buf = new unsigned char[siz];
59400-
cimg::fread(buf,siz,nfile);
59401-
_uchar2bool(buf,siz,is_multiplexed);
59402-
delete[] buf;
59390+
CImg<ucharT> _buffer(siz);
59391+
unsigned char *const buffer = _buffer._data;
59392+
cimg::fread(buffer,siz,nfile);
59393+
_uchar2bool(buffer,siz,is_multiplexed);
5940359394
} else { // Non-boolean data
5940459395
if (siz && (!is_multiplexed || size_c==1)) { // Non-multiplexed
5940559396
cimg::fread(_data,siz,nfile);
@@ -62871,7 +62862,8 @@ namespace cimg_library {
6287162862

6287262863
std::FILE *const nfile = file?file:cimg::fopen(filename,"wb");
6287362864
const ulongT wh = (ulongT)_width*_height;
62874-
unsigned char *const buffer = new unsigned char[3*wh], *nbuffer = buffer;
62865+
CImg<ucharT> _buffer(3*wh);
62866+
unsigned char *const buffer = _buffer._data, *nbuffer = buffer;
6287562867
const T
6287662868
*ptr1 = data(0,0,0,0),
6287762869
*ptr2 = _spectrum>1?data(0,0,0,1):0,
@@ -62902,7 +62894,6 @@ namespace cimg_library {
6290262894
}
6290362895
cimg::fwrite(buffer,3*wh,nfile);
6290462896
if (!file) cimg::fclose(nfile);
62905-
delete[] buffer;
6290662897
return *this;
6290762898
}
6290862899

@@ -62933,7 +62924,8 @@ namespace cimg_library {
6293362924

6293462925
std::FILE *const nfile = file?file:cimg::fopen(filename,"wb");
6293562926
const ulongT wh = (ulongT)_width*_height;
62936-
unsigned char *const buffer = new unsigned char[4*wh], *nbuffer = buffer;
62927+
CImg<ucharT> _buffer(4*wh);
62928+
unsigned char *const buffer = _buffer._data, *nbuffer = buffer;
6293762929
const T
6293862930
*ptr1 = data(0,0,0,0),
6293962931
*ptr2 = _spectrum>1?data(0,0,0,1):0,
@@ -62976,7 +62968,6 @@ namespace cimg_library {
6297662968
}
6297762969
cimg::fwrite(buffer,4*wh,nfile);
6297862970
if (!file) cimg::fclose(nfile);
62979-
delete[] buffer;
6298062971
return *this;
6298162972
}
6298262973

@@ -63526,14 +63517,12 @@ namespace cimg_library {
6352663517

6352763518
const CImg<T>& _save_pandore(std::FILE *const file, const char *const filename,
6352863519
const unsigned int colorspace) const {
63529-
6353063520
#define __cimg_save_pandore_case(dtype) \
63531-
dtype *buffer = new dtype[size()]; \
63521+
CImg<dtype> _buffer(size()); \
63522+
dtype *buffer = _buffer._data; \
6353263523
const T *ptrs = _data; \
6353363524
cimg_foroff(*this,off) *(buffer++) = (dtype)(*(ptrs++)); \
63534-
buffer-=size(); \
63535-
cimg::fwrite(buffer,size(),nfile); \
63536-
delete[] buffer
63525+
cimg::fwrite(_buffer._data,size(),nfile)
6353763526

6353863527
#define _cimg_save_pandore_case(sy,sz,sv,stype,id) \
6353963528
if (!saved && (sy?(sy==_height):true) && (sz?(sz==_depth):true) && \
@@ -63555,18 +63544,18 @@ namespace cimg_library {
6355563544
cimg_instance, \
6355663545
filename?filename:"(FILE*)"); \
6355763546
if (id==2 || id==5 || id==8 || id==16 || id==19 || id==22 || id==26 || id==30) { \
63558-
__cimg_save_pandore_case(unsigned char); \
63547+
__cimg_save_pandore_case(ucharT); \
6355963548
} else if (id==3 || id==6 || id==9 || id==17 || id==20 || id==23 || id==27 || id==31) { \
63560-
if (sizeof(unsigned long)==4) { __cimg_save_pandore_case(unsigned long); } \
63561-
else if (sizeof(unsigned int)==4) { __cimg_save_pandore_case(unsigned int); } \
63562-
else if (sizeof(unsigned short)==4) { __cimg_save_pandore_case(unsigned short); } \
63549+
if (sizeof(unsigned long)==4) { __cimg_save_pandore_case(ulongT); } \
63550+
else if (sizeof(unsigned int)==4) { __cimg_save_pandore_case(uintT); } \
63551+
else if (sizeof(unsigned short)==4) { __cimg_save_pandore_case(ushortT); } \
6356363552
else throw CImgIOException(_cimg_instance \
6356463553
"save_pandore(): Unsupported datatype for file '%s'.",\
6356563554
cimg_instance, \
6356663555
filename?filename:"(FILE*)"); \
6356763556
} else if (id==4 || id==7 || id==10 || id==18 || id==21 || id==25 || id==29 || id==33) { \
63568-
if (sizeof(double)==4) { __cimg_save_pandore_case(double); } \
63569-
else if (sizeof(float)==4) { __cimg_save_pandore_case(float); } \
63557+
if (sizeof(double)==4) { __cimg_save_pandore_case(doubleT); } \
63558+
else if (sizeof(float)==4) { __cimg_save_pandore_case(floatT); } \
6357063559
else throw CImgIOException(_cimg_instance \
6357163560
"save_pandore(): Unsupported datatype for file '%s'.",\
6357263561
cimg_instance, \

html/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<div class="header">
1717
<a href="index.html"><img alt="Logo" src="img/logo_header.jpg" class="center_image" style="margin-top:1em;"/></a>
1818
<h2 style="padding-bottom: 1em">
19-
Latest stable version: <b><a href="http://cimg.eu/files/CImg_3.7.5.zip">3.7.5</a></b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Current pre-release: <b><a href="http://cimg.eu/files/CImg_latest.zip">3.7.6</a></b> (2026/05/13)
19+
Latest stable version: <b><a href="http://cimg.eu/files/CImg_3.7.6.zip">3.7.6</a></b> (2026/05/13)
2020
</h2>
2121

2222
<hr/>

html/header_doxygen.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<div class="header">
2727
<a href="../index.html"><img alt="Logo" src="../img/logo_header.jpg" class="center_image" style="margin-top:1em;"/></a>
2828
<h2 style="padding-bottom: 1em">
29-
Latest stable version: <b><a href="http://cimg.eu/files/CImg_3.7.5.zip">3.7.5</a></b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Current pre-release: <b><a href="http://cimg.eu/files/CImg_latest.zip">3.7.6</a></b> (2026/05/13)
29+
Latest stable version: <b><a href="http://cimg.eu/files/CImg_3.7.6.zip">3.7.6</a></b> (2026/05/13)
3030
</h2>
3131

3232
<hr/>

0 commit comments

Comments
 (0)