void PortraitCut::saveLabels(const char* name) { fprintf(_fp, "Trying to save file %s\n",name); fflush(_fp); GrayImage im = (GrayImage) imNew(IMAGE_GRAY, _w, _h); int i, j,index=0; for (j=0; j<_h; j++) for (i=0; i<_w; i++, ++index) { Coord p(i,j); IMREF(im,p) = (unsigned char) _labels[index]; } imSave(im,name); imFree(im); }
void PortraitCut::saveComp(char* name) { RGBImage im = (RGBImage) imNew(IMAGE_RGB, _w, _h); int i, j,index=0; for (j=0; j<_h; j++) for (i=0; i<_w; i++, ++index) { Coord p(i,j); unsigned char* cref = _imptr(_labels[index], p); IMREF(im,p).r = cref[0]; IMREF(im,p).g = cref[1]; IMREF(im,p).b = cref[2]; } int res = imSave(im,name); assert(res==0); imFree(im); }
// Load Bitmaps And Convert To Textures unsigned int LoadGLTexture(const char* nomfichier, bool isTransparency) { Image image1; imInitPPM( image1, nomfichier); if (isTransparency) imCreateTransparency(image1); unsigned int texture; // Create Textures glGenTextures(1, &texture); // mipmapped texture glBindTexture(GL_TEXTURE_2D, texture); // 2d texture (x and y size) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); //GL_LINEAR_MIPMAP_NEAREST); // scale mipmap when image smalled than texture switch (imGetDimC(image1)) { case 1: gluBuild2DMipmaps(GL_TEXTURE_2D, 1, imGetDimX(image1), imGetDimY(image1), GL_LUMINANCE, GL_UNSIGNED_BYTE, imGetData(image1) ); break; case 3: gluBuild2DMipmaps(GL_TEXTURE_2D, 3, imGetDimX(image1), imGetDimY(image1), GL_RGB, GL_UNSIGNED_BYTE, imGetData(image1) ); break; case 4: gluBuild2DMipmaps(GL_TEXTURE_2D, 4, imGetDimX(image1), imGetDimY(image1), GL_RGBA, GL_UNSIGNED_BYTE, imGetData(image1) ); break; default: printf("LoadGLTexture: can not load GL texture! dimColor is not managed!\n"); break; } imFree(image1); return texture; }
PortraitCut::~PortraitCut() { imFree(indeces_a); imFree(D_a); //if (_ownRequired) delete[] _required; //delete[] _labels; }