tags:

views:

99

answers:

2

IPP is a C library, with hundreds of functions like this:

IppStatus ippiTranspose_8u_C1R(const Ipp8u* pSrc, int srcStep,
                               Ipp8u* pDst, int dstStep,
                               IppiSize roiSize));

To be able to call these functions in a more convenient, safe and consistent way, we need a C++ wrapper function for each C function. For example:

void ippiTranspose(const Image<Ipp8u> &src, Rect srcRect, Image<Ipp8u> &dst, Point dstPos)
{
  if (!src.valid()) throw "Invalid src";
  if (!dst.valid()) throw "Invalid dst";
  Rect srcRoi = srcRect.isEmpty() ? src.rect() : srcRect;
  if (!src.rect().contains(srcRoi)) throw "Invalid src rect";
  Rect dstRoi = Rect(dstPos, srcRoi.size());
  if (!dst.rect().contains(dstRoi)) throw "Invalid dst rect";
  IppStatus st = ippiTranspose_8u_C1R(&src.at(srcRoi.topLeft()), src.step(), &dst.at(dstRoi.topLeft()), dst.step(), toIppiSize(srcRoi.size());
  if (st < 0) throw "ippiTranspose_8u_C1R failed";
}

There are logical patterns, which can be applied to all the functions in IPP.

How to automatically generate all these wrappers?

A: 

Look at the examples there is ippi.hpp file in "language" examples section. It is C++ wrapper.

Ross
Also, in examples of beta 7.0 version there is more complete implementation.
Ross
Thanks, I will post my comment as a new answer, because source code can't be posted in a comment.
Hristo Hristov
A: 

There are some kind of wrappers, provided by Intel, which are well hidden in ipp-samples for windows only. I'm using the latest 7.0 beta version. They provide C++ headers, generated by a perl script, which are supposed to be used as a C++ wrappers. The "wrapper" for the ippiTranspose_8u_C1R function in the question is this:

 static inline IppStatus ippiTranspose_C1R( const Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep, IppiSize roiSize) {
   return ippiTranspose_8u_C1R( pSrc, srcStep, pDst, dstStep, roiSize );
 }

This is just a shorter version of the function call.

What I expect from a good C++ wrapper for a C function:

  • map C-like params to C++ (objects, templates)
  • check if the input params are valid
  • check if the result is a success, error or warning
  • error handling using exceptions

We need a real solution for the C++ world, Intel!

I am currently working on a program, which automatically generates wrappers like the example in the question, and the things look nice.

Thanks to Ross for pointing the solution from Intel.

Hristo Hristov
Don't expect too much from Intel.
Ross
Why not? IPP, OpenCV, Intel TBB - these are the reasons to expect more goodness :)
Hristo Hristov