Basic Example

#include "RadeonImageFilters.h"

int main()
{
   rif_int status = RIF_SUCCESS;
   rif_context context = nullptr;
   rif_command_queue queue = nullptr;
   rif_image_filter filter = nullptr;
   rif_image inputImage = nullptr;
   rif_image outputImage = nullptr;

   // First create context and queue
   int deviceCount = 0;
   status = rifGetDeviceCount(RIF_BACKEND_API_OPENCL, &deviceCount);
   if (status != RIF_SUCCESS) return -1;
   if (deviceCount > 0 || status)
   {
          status = rifCreateContext(RIF_API_VERSION, RIF_BACKEND_API_OPENCL, 0, nullptr, &context);
          if (status != RIF_SUCCESS || !context) return -1;
   }
   status = rifContextCreateCommandQueue(context, &queue);
   if (status != RIF_SUCCESS || !queue) return -1;

   //Create image filter
   status = rifContextCreateImageFilter(context, RIF_IMAGE_FILTER_GAMMA_CORRECTION, &filter);
   if (status != RIF_SUCCESS) return -1;

   //Create input and output images
   rif_image_desc desc;
   desc.image_width = 100;
   desc.image_height = 100;
   desc.num_components = 3; // rgb image
   desc.type = RIF_COMPONENT_TYPE_FLOAT16;

   status = rifContextCreateImage(context, &desc, nullptr, &inputImage);
   if (status != RIF_SUCCESS) return -1;
   status = rifContextCreateImage(context, &desc, nullptr, &outputImage);
   if (status != RIF_SUCCESS) return -1;

   //Set input image data
   void* data = nullptr;
   status = rifImageMap(inputImage, RIF_IMAGE_MAP_WRITE, (void**)&data);
   if (status != RIF_SUCCESS) return -1;
   //Fill data
   status = rifImageUnmap(inputImage, data);
   if (status != RIF_SUCCESS) return -1;

   //Attach filter and set parameters
   status = rifImageFilterSetParameter1f(filter, "gamma", 0.1f);
   if (status != RIF_SUCCESS) return -1;
   status = rifCommandQueueAttachImageFilter(queue, filter, inputImage, outputImage);
   if (status != RIF_SUCCESS) return -1;

   //Execute queue
   status = rifContextExecuteCommandQueue(context, queue, nullptr, nullptr, nullptr);
   if (status != RIF_SUCCESS) return -1;

   //Free resources
   rifCommandQueueDetachImageFilter(queue, filter);
   rifObjectDelete(inputImage);
   rifObjectDelete(outputImage);
   rifObjectDelete(filter);
   rifObjectDelete(queue);
   rifObjectDelete(context);
   return 0;
}