+JpegHandle MakeJpegCompressor()
+{
+ return JpegHandle{tjInitCompress(), tjDestroy};
+}
+
+JpegHandle MakeJpegDecompressor()
+{
+ return JpegHandle{tjInitDecompress(), tjDestroy};
+}
+
+using JpegMemoryHandle = std::unique_ptr<unsigned char, decltype(tjFree)*>;
+
+JpegMemoryHandle MakeJpegMemory()
+{
+ return JpegMemoryHandle{nullptr, tjFree};
+}
+
+template<class T, class Deleter>
+class UniquePointerSetter final
+{
+public:
+ UniquePointerSetter(std::unique_ptr<T, Deleter>& uniquePointer)
+ : mUniquePointer(uniquePointer),
+ mRawPointer(nullptr)
+ {}
+
+ /// @brief Pointer to Pointer cast operator
+ operator T** () { return &mRawPointer; }
+
+ /// @brief Destructor, reset the unique_ptr
+ ~UniquePointerSetter() { mUniquePointer.reset(mRawPointer); }
+
+private:
+ std::unique_ptr<T, Deleter>& mUniquePointer;
+ T* mRawPointer;
+};
+
+template<typename T, typename Deleter>
+UniquePointerSetter<T, Deleter> SetPointer(std::unique_ptr<T, Deleter>& uniquePointer)
+{
+ return UniquePointerSetter<T, Deleter>{uniquePointer};
+}
+
+using TransformFunction = std::function<void(PixelArray,unsigned, unsigned)>;
+using TransformFunctionArray = std::array<TransformFunction, 3>; // 1, 3 and 4 bytes per pixel
+
+/// @brief Select the transform function depending on the pixel format
+TransformFunction GetTransformFunction(const TransformFunctionArray& functions,
+ Pixel::Format pixelFormat)
+{
+ auto function = TransformFunction{};
+
+ int decodedPixelSize = Pixel::GetBytesPerPixel(pixelFormat);
+ switch( decodedPixelSize )