CImg icon indicating copy to clipboard operation
CImg copied to clipboard

Is Cimg function map() OK ??

Open pwplus7 opened this issue 4 years ago • 1 comments

The for(ff..) loop in the code below generates run time error:

Failed to allocate memory (22.1 Gio) for image (366,366,1,177147). terminate called after throwing an instance of 'cimg_library::CImgInstanceException' what(): [instance(0,0,0,0,(nil),non-shared)] CImg::CImg(): Failed to allocate memory (22.1 Gio) for image (366,366,1,177147).

#include "CImg.h" using namespace cimg_library;

typedef unsigned char u8 ; typedef unsigned int u32 ;

int main(int argc, char **arg) { int W=366, H=366 ; CImg img= CImg (W, H, 1,1) ;

// define a color palette: int npal= 5; u8 cc[3npal]= {255,0,0, 0,255,0, 0,0,255, 240,240,240, 0,0,0} ; CImg pal(npal,1,1,3); u8 pp= pal.data() ; for (int k=0; k< npal; k++) for (int m=0; m< 3; m++) pal(k,m)= cc[3*k +m]; CImgDisplay disp(img, "TEST");

for( int ff=0; ff<15; ff++) { int np= -1; for(int xp=0; xp <W; xp++) for(int yp= H; yp >0; yp--) { np++ ; img (xp,yp) = (np< WH/3) ? 0x00:(np< WH*2/3) ? 0x01 :0x02 ; } img.map(pal); // map the color palette to img disp.display(img).wait(2000); printf(" end ff= %d\n",ff); fflush(stdout); } return 0; }

pwplus7 avatar Dec 20 '20 19:12 pwplus7

Your code does not compile.

dtschump avatar Apr 07 '22 12:04 dtschump