Overview

The Offline Super-Resolution plug-in enables high-quality game-scene screenshots with improved image resolution and detail performance.
To use the Occlusion Culling plug-in, you need to:

What You Will Create

In this codelab, you will use the demo project to call Offline Super-Resolution plug-in SDK APIs. Through this demo project, you will:

What You Will Learn

Hardware Requirements

Software Requirements

Required Knowledge

Integrating the Offline Super-Resolution SDK

  1. Create an Android Studio project.
  2. Specify the C++ file for CMake building and create the build dependencies of CMake in the /app/build.gradle file.
  3. Configure build options.

  4. Copy libraries and header files.
    a) Download the SDK package.
    b) Copy the header files in the SDK to the resource library.

    c) Copy the .so file in the SDK to the resource library.
    Copy libs\arm64-v8a\libthirdpartyengine_plugin_offlineSupRes.so in the SDK to /libs/arm64-v8a in Android Studio.

    d) Modify the app/src/main/cpp/CMakeLists.txt file as follows.

    e) Copy the resource file to the custom directory in the smartphone.

Calling Offline Super-Resolution APIs

  1. Set the directory of resource files.
    CSetAssetsDir("/sdcard/osr"); const char *assetsDir = CGetAssetsDir(); printf("Set directory to %s", assetsDir);
  2. Initialize the plug-in and import the resource file to the plug-in.
    CInitialize();
  3. Open an image and configure the BufferDescriptor structure based on image information.
    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;
  4. Query the support for the super-resolution capability based on the image resolution and format.
    a) Query the support for the AI super-resolution capability.
    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) Query the support for the image processing super-resolution capability.
    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;
  5. If outW,outH or estimatedTime is set –1, the plug-in is incompatible with the device model, input resolution, or input format. Otherwise, create the BufferDescriptor or structure object based on the return value.
    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;
  6. If the plug-in supports the current super-resolution scenario, call related APIs.
    a) Synchronously execute the AI super-resolution API.
    int timeout = 10000; bool success = CSuperSamplingSyncExecute(&inBuffer, &outBuffer, timeout);
    a) Synchronously execute the image processing super-resolution capability.
    int timeout = 10000; float sharpness = 0.6; bool tonemapping = true; bool success = CImageEnhancingSyncExecute(&inBuffer, &outBuffer, sharpness, tonemapping, timeout);
  7. For asynchronous execution, first define the callback function.
    void CallBack(bool success) { // Perform operations based on the execution result. return; }
    a) Asynchronously execute the AI super-resolution API.
    bool success = CSuperSamplingAsyncExecute(&inBuffer, &outBuffer, CallBack); std::this_thread::sleep_for(std::chrono::seconds(5));
    b) Asynchronously execute the image processing super-resolution capability.
    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));
  8. Save the image data stored in outBuffer.addr in any image format you want.
  9. Unload the plug-in.
    delete[](static_cast<unsigned char *>(inBuffer.addr)); delete[](static_cast<unsigned char *>(outBuffer.addr)); CUninitialize();

Well done. You have successfully completed this codelab and learned how to:

For more information, click the following links:

Related documents
Download the demo source code used in this codelab from the following address:

Download source code

Code copied