离线超分插件为开发者提供游戏截图(拍照)画质提升能力,提高画面分辨率,并改善画面细节,帮助开发者向玩家提供高质量截图(拍照)功能。
开发者需要:
在这个Codelab中,你将使用已经创建好的Demo Project实现对离线超分插件API的调用,通过Demo Project你可以体验到:

同时配置编译选项。




CSetAssetsDir("/sdcard/osr");
const char *assetsDir = CGetAssetsDir();
printf("Set directory to %s", assetsDir);
CInitialize();
BufferDescriptor inBuffer;
int w, h;
unsigned char *pixels = ReadPPM(path, w, h);
inBuffer.addr = static_cast<void *>(pixels);
inBuffer.width = w;
inBuffer.height = h;
inBuffer.len = w * h * CHANNELS_RGB;
inBuffer.format = PIXEL_FORMAT_R8G8B8_UNORM;
PluginConfig pluginConfig;
CQuerySuperSamplingPluginConfig(inBuffer.width, inBuffer.height, inBuffer.format, pluginConfig);
int outW = pluginConfig.output.width;
int outH = pluginConfig.output.height;
PixelFormat outFormat = pluginConfig.output.format;
int estimatedTime = pluginConfig.estimatedCostTime;
b) 查询图像处理超分的支持情况。
PluginConfig pluginConfig;
CQuerySuperSamplingPluginConfig(inBuffer.width, inBuffer.height, inBuffer.format, pluginConfig);
int outW = pluginConfig.output.width;
int outH = pluginConfig.output.height;
PixelFormat outFormat = pluginConfig.output.format;
int estimatedTime = pluginConfig.estimatedCostTime;
BufferDescriptor outBuffer;
unsigned char *pixels = new(std::nothrow)
unsigned char[outW * outH * Format2Channel(outFormat)];
outBuffer.addr = static_cast<void *>(pixels);
outBuffer.width = outW;
outBuffer.height = outH;
outBuffer.len = outW * outH * Format2Channel(outFormat);
outBuffer.format = outFormat;
int timeout = 10000;
bool success = CSuperSamplingSyncExecute(&inBuffer, &outBuffer, timeout);
b) 同步调用图像处理算法超分接口。
int timeout = 10000;
float sharpness = 0.6;
bool tonemapping = true;
bool success = CImageEnhancingSyncExecute(&inBuffer, &outBuffer, sharpness, tonemapping, timeout);
void CallBack(bool success)
{
// 根据超分功能是否执行成功分别进行处理
return;
}
a) 异步调用AI模型超分接口。<
bool success = CSuperSamplingAsyncExecute(&inBuffer, &outBuffer, CallBack);
std::this_thread::sleep_for(std::chrono::seconds(5));
b) 异步调用图像处理算法超分接口。
int timeout = 10000;
float sharpness = 0.6;
bool tonemapping = true;
bool success = CImageEnhancingAsyncExecute(&inBuffer, &outBuffer, sharpness, tonemapping, CallBack);
std::this_thread::sleep_for(std::chrono::seconds(2));
delete[](static_cast<unsigned char *>(inBuffer.addr));
delete[](static_cast<unsigned char *>(outBuffer.addr));
CUninitialize();
干得好,您已经成功完成了Codelab并学到了:
您可以阅读下面链接,了解更多相关的信息。
相关文档
本Codelab中所用Demo源码下载地址如下: