imageresizer_web_logo

ImageResizer C++ library

v1.0.1

Table of contents

Overview

ImageResizer C++ library provides image resizing with SIMD-optimized bicubic interpolation (Keys cubic, a = -0.75). The library implements a two-pass separable filter with platform-specific vectorization: SSSE3 + AVX2 on x86/x64, NEON on ARM64, and a scalar fallback for other architectures. Tile-based processing ensures L2 cache locality for upscale paths, while a row-cache strategy is used for downscale. The library supports multi-threaded row-level parallelism via OpenMP with automatic or user-defined thread count. Input data must be 3-byte-per-pixel interleaved format (BGR24, RGB24 and YUV24). The library uses C++17 standard.

Versions

Table 1 - Library versions.

Version Release date What’s new
1.0.0 03.04.2026 First version of the library.
1.0.1 05.04.2026 Fixed alignments in data structures.

Library files

The library supplied by source code only. The user would be given a set of files in the form of a CMake project (repository). The repository structure is shown below:

CMakeLists.txt ------------------- Main CMake file of the library.
src ------------------------------ Folder with source code of the library.
    CMakeLists.txt --------------- CMake file of the library.
    ImageResizer.cpp ------------- C++ implementation file.
    ImageResizer.h --------------- Header file which includes ImageResizer class declaration.
    ImageResizerVersion.h -------- Header file which includes version of the library.
    ImageResizerVersion.h.in ----- CMake service file to generate version file.
example -------------------------- Folder for example application.
    CMakeLists.txt --------------- CMake file for example application.
    main.cpp --------------------- Source code file of example application.
static --------------------------- Folder with static resources.
    imageresizer_web_logo.png ---- Web logo image.

ImageResizer class description

ImageResizer class declaration

The ImageResizer class declared in ImageResizer.h file. Class declaration:

namespace cr
{
namespace video
{
/// Image resizer class.
class ImageResizer
{
public:

    /// Get the version of the ImageResizer class.
    static std::string getVersion();

    /// Resize image.
    bool resize(uint8_t* src, int srcWidth, int srcHeight,
                uint8_t* dst, int dstWidth, int dstHeight,
                int numThreads = 0);
};
}
}

getVersion method

The getVersion() static method returns string of current class version. Method declaration:

static std::string getVersion();

Method can be used without ImageResizer class instance:

std::cout << "ImageResizer version: " << cr::video::ImageResizer::getVersion();

Console output:

ImageResizer version: 1.0.1

resize method

The resize(…) method performs image resizing with bicubic interpolation. Method declaration:

bool resize(uint8_t* src, int srcWidth, int srcHeight,
            uint8_t* dst, int dstWidth, int dstHeight,
            int numThreads = 0);
Parameter Description
src Pointer to source image data. Only 3-byte-per-pixel interleaved data (BGR24, RGB24, YUV24).
srcWidth Width of source image in pixels. Must be > 0.
srcHeight Height of source image in pixels. Must be > 0.
dst Pointer to destination image data buffer. Must be pre-allocated with size >= dstWidth * dstHeight * 3 bytes.
dstWidth Width of destination image in pixels. Must be > 0.
dstHeight Height of destination image in pixels. Must be > 0.
numThreads Number of threads for parallel processing. 0 - auto-detect via OpenMP.

Returns: TRUE if resizing was successful, FALSE otherwise (invalid parameters or unsupported method).

Build and connect to your project

Typical commands to build ImageResizer:

cd ImageResizer
mkdir build
cd build
cmake ..
make

By default the library is built in Release mode with aggressive compiler optimizations:

  • MSVC: /O2 /Ob3 /GL /fp:fast /Qpar /Gy /arch:AVX2 /LTCG
  • GCC/Clang: -Ofast -march=native -mtune=native -funroll-loops -flto

If you want connect ImageResizer to your CMake project as source code you can make follow. For example, if your repository has structure:

CMakeLists.txt
src
    CMakeLists.txt
    yourLib.h
    yourLib.cpp

Create folder 3rdparty in your repository and copy ImageResizer repository folder there. New structure of your repository:

CMakeLists.txt
src
    CMakeLists.txt
    yourLib.h
    yourLib.cpp
3rdparty
    ImageResizer

Create CMakeLists.txt file in 3rdparty folder. CMakeLists.txt should contain:

cmake_minimum_required(VERSION 3.13)

################################################################################
## 3RD-PARTY
## dependencies for the project
################################################################################
project(3rdparty LANGUAGES CXX)

################################################################################
## SETTINGS
## basic 3rd-party settings before use
################################################################################
# To inherit the top-level architecture when the project is used as a submodule.
SET(PARENT ${PARENT}_YOUR_PROJECT_3RDPARTY)
# Disable self-overwriting of parameters inside included subdirectories.
SET(${PARENT}_SUBMODULE_CACHE_OVERWRITE OFF CACHE BOOL "" FORCE)

################################################################################
## INCLUDING SUBDIRECTORIES
## Adding subdirectories according to the 3rd-party configuration
################################################################################
if (${PARENT}_SUBMODULE_IMAGE_RESIZER)
    add_subdirectory(ImageResizer)
endif()

File 3rdparty/CMakeLists.txt adds folder ImageResizer to your project and excludes the example application from compiling (by default it is excluded when ImageResizer included as sub-repository). Your repository new structure will be:

CMakeLists.txt
src
    CMakeLists.txt
    yourLib.h
    yourLib.cpp
3rdparty
    CMakeLists.txt
    ImageResizer

Next you need include folder 3rdparty in main CMakeLists.txt file of your repository. Add string at the end of your main CMakeLists.txt:

add_subdirectory(3rdparty)

Next you have to include ImageResizer library in your src/CMakeLists.txt file:

target_link_libraries(${PROJECT_NAME} ImageResizer)

Done!

Example

The example resizes a synthetic image from 640x512 to 1920x1080 and measures execution time:

#include <iostream>
#include <cstdint>
#include <vector>
#include <chrono>
#include "ImageResizer.h"

using namespace std;
using namespace cr::video;
using namespace std::chrono;

int main(void)
{
    cout << "ImageResizer v" << ImageResizer::getVersion() << endl;

    // Source image size.
    const int srcWidth = 640;
    const int srcHeight = 512;

    // Destination image size.
    const int dstWidth = 1920;
    const int dstHeight = 1080;

    // Create source image with deterministic pattern.
    vector<uint8_t> srcImg(srcWidth * srcHeight * 3);
    for (int y = 0; y < srcHeight; ++y)
        for (int x = 0; x < srcWidth; ++x) {
            int idx = (y * srcWidth + x) * 3;
            srcImg[idx + 0] = (uint8_t)((x * 37 + y * 13) & 0xFF);
            srcImg[idx + 1] = (uint8_t)((x * 59 + y * 7)  & 0xFF);
            srcImg[idx + 2] = (uint8_t)((x * 23 + y * 41) & 0xFF);
        }

    // Create destination image buffer.
    vector<uint8_t> dstImg(dstWidth * dstHeight * 3);

    // Image resizer.
    ImageResizer imageResizer;

    // Resize image.
    auto begin = steady_clock::now();
    bool result = imageResizer.resize(srcImg.data(), srcWidth, srcHeight,
                                      dstImg.data(), dstWidth, dstHeight, 0);
    auto end = steady_clock::now();

    cout << "Result: " << (result ? "OK" : "FAIL") << endl;
    cout << "Resize time: " <<
    duration_cast<microseconds>(end - begin).count() << " us" << endl;

    return 0;
}

Table of contents