void fgSampler( const FgSample & sample, FgImgRgbaUb & img, uint antiAliasBitDepth) { FgImgRgbaF fimg(img.dims()); fgSampler(sample,fimg,antiAliasBitDepth); for (FgIter2UI it(img.dims()); it.valid(); it.next()) { const FgRgbaF & fpix = fimg[it()]; img[it()] = FgRgbaUB( uchar(fgClamp(fpix.red(),0.0f,255.0f)), uchar(fgClamp(fpix.green(),0.0f,255.0f)), uchar(fgClamp(fpix.blue(),0.0f,255.0f)), uchar(fgClamp(fpix.alpha(),0.0f,255.0f))); } }
static void uvmask(const FgArgs & args) { FgSyntax syntax(args, "<meshIn>.<ext0> <imageIn>.<ext1> <meshOut>.<ext2>\n" " <ext0> = " + fgLoadMeshFormatsDescription() + "\n" " <ext1> = " + fgImgCommonFormatsDescription() + "\n" " <ext2> = " + fgSaveMeshFormatsDescription() ); Fg3dMesh mesh = fgLoadMeshAnyFormat(syntax.next()); FgImgRgbaUb img; fgLoadImgAnyFormat(syntax.next(),img); FgImage<FgBool> mask = FgImage<FgBool>(img.dims()); for (FgIter2UI it(img.dims()); it.valid(); it.next()) { FgVect4UC px = img[it()].m_c; mask[it()] = (px[0] > 0) || (px[1] > 0) || (px[2] > 0); } mask = fgAnd(mask,fgFlipHoriz(mask)); mesh = fg3dMaskFromUvs(mesh,mask); fgSaveMeshAnyFormat(mesh,syntax.next()); }
bool fgCompareImages( const FgImgRgbaUb & test, const FgImgRgbaUb & ref, uint maxDelta) { if (test.dims() != ref.dims()) return false; int lim = int(maxDelta * maxDelta); for (FgIter2UI it(test.dims()); it.valid(); it.next()) { FgVect4I delta = FgVect4I(test[it()].m_c) - FgVect4I(ref[it()].m_c); if ((fgSqr(delta[0]) > lim) || (fgSqr(delta[1]) > lim) || (fgSqr(delta[2]) > lim) || (fgSqr(delta[3]) > lim)) return false; } return true; }