| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| namespace |
| { |
| |
| TRasterImageP convert32(const TImageP &img) |
| { |
| struct locals { |
| static TRasterImageP depremultiplied(const TRasterImageP &ri) |
| { |
| assert(ri->getRaster()); |
| |
| TRop::depremultiply(ri->getRaster()); |
| return ri; |
| } |
| }; |
| |
| if (TRasterImageP ri = img) { |
| TRasterP ras(ri->getRaster()); |
| |
| TRaster32P ras32; |
| { |
| if (TRaster32P(ras)) |
| ras32 = ras->clone(); |
| else { |
| ras32 = TRaster32P(ras->getSize()); |
| TRop::convert(ras32, ras); |
| } |
| } |
| |
| TPointD dpi; |
| ri->getDpi(dpi.x, dpi.y); |
| |
| TRasterImageP ri32(ras32); |
| ri32->setDpi(dpi.x, dpi.y); |
| ri32->setSubsampling(ri->getSubsampling()); |
| ri32->setOffset(ri->getOffset()); |
| |
| return locals::depremultiplied(ri32); |
| } |
| |
| if (TToonzImageP ti = img) { |
| TRasterCM32P rasCM32(ti->getRaster()); |
| |
| TRaster32P ras32(rasCM32->getSize()); |
| TRop::convert(ras32, rasCM32, ti->getPalette()); |
| |
| TPointD dpi; |
| ti->getDpi(dpi.x, dpi.y); |
| |
| TRasterImageP ri32(ras32); |
| ri32->setDpi(dpi.x, dpi.y); |
| ri32->setSubsampling(ti->getSubsampling()); |
| ri32->setOffset(ti->getOffset()); |
| |
| return locals::depremultiplied(ri32); |
| } |
| |
| return TRasterImageP(); |
| } |
| |
| |
| |
| TRasterImageP getTexture(const TXshSimpleLevel *sl, const TFrameId &fid, int subsampling) |
| { |
| if (sl->getType() != PLI_XSHLEVEL) { |
| TImageP texImg = sl->getFrame(fid, ImageManager::dontPutInCache, subsampling); |
| return convert32(texImg); |
| } |
| |
| |
| std::string id = sl->getImageId(fid) + "_rasterized"; |
| |
| ImageLoader::BuildExtData extData(sl, fid); |
| TRasterImageP ri(ImageManager::instance()->getImage(id, ImageManager::dontPutInCache, &extData)); |
| |
| return ri; |
| } |
| |
| } |
| |
| |
| |
| |
| |
| DrawableTextureDataP texture_utils::getTextureData( |
| const TXshSimpleLevel *sl, const TFrameId &fid, int subsampling) |
| { |
| const std::string &texId = sl->getImageId(fid); |
| |
| |
| DrawableTextureDataP data(TTexturesStorage::instance()->getTextureData(texId)); |
| if (data) |
| return data; |
| |
| |
| |
| |
| TRasterImageP ri(::getTexture(sl, fid, subsampling)); |
| if (!ri) |
| return DrawableTextureDataP(); |
| |
| TRaster32P ras(ri->getRaster()); |
| assert(ras); |
| |
| TRectD geom(0, 0, ras->getLx(), ras->getLy()); |
| geom = TScale(ri->getSubsampling()) * |
| TTranslation(convert(ri->getOffset()) - ras->getCenterD()) * |
| geom; |
| |
| return TTexturesStorage::instance()->loadTexture(texId, ras, geom); |
| } |
| |
| |
| |
| void texture_utils::invalidateTexture(const TXshSimpleLevel *sl, const TFrameId &fid) |
| { |
| const std::string &texId = sl->getImageId(fid); |
| TTexturesStorage::instance()->unloadTexture(texId); |
| } |
| |
| |
| |
| void texture_utils::invalidateTextures(const TXshSimpleLevel *sl) |
| { |
| int f, fCount = sl->getFrameCount(); |
| |
| for (f = 0; f != fCount; ++f) |
| invalidateTexture(sl, sl->getFrameId(f)); |
| } |
| |
| |
| |
| |
| |
| namespace |
| { |
| |
| std::string getImageId(const TXsheet *xsh, int frame) |
| { |
| return "X" + toString(xsh->id()) + "_" + toString(frame); |
| } |
| |
| } |
| |
| |
| |
| |
| |
| DrawableTextureDataP texture_utils::getTextureData(const TXsheet *xsh, int frame) |
| { |
| |
| const std::string &texId = ::getImageId(xsh, frame); |
| |
| DrawableTextureDataP data(TTexturesStorage::instance()->getTextureData(texId)); |
| if (data) |
| return data; |
| |
| |
| TRaster32P tex(1024, 1024); |
| |
| |
| |
| |
| TRectD bbox(xsh->getBBox(frame)); |
| |
| |
| const TAffine &cameraAff = xsh->getPlacement(xsh->getStageObjectTree()->getCurrentCameraId(), frame); |
| bbox = (cameraAff.inv() * bbox).enlarge(1.0); |
| |
| |
| |
| |
| TGlContext currentContext = tglGetCurrentContext(); |
| { |
| tglDoneCurrent(currentContext); |
| xsh->getScene()->renderFrame(tex, frame, xsh, bbox, TAffine()); |
| tglMakeCurrent(currentContext); |
| } |
| |
| TRop::depremultiply(tex); |
| |
| |
| return TTexturesStorage::instance()->loadTexture(texId, tex, bbox); |
| } |
| |
| |
| |
| void texture_utils::invalidateTexture(const TXsheet *xsh, int frame) |
| { |
| const std::string &texId = ::getImageId(xsh, frame); |
| TTexturesStorage::instance()->unloadTexture(texId); |
| } |
| |
| |
| |
| void texture_utils::invalidateTextures(const TXsheet *xsh) |
| { |
| int f, fCount = xsh->getFrameCount(); |
| for (f = 0; f != fCount; ++f) |
| invalidateTexture(xsh, f); |
| } |
| |