Add a new module for resizing images including Lanczos

This commit is contained in:
luisangelsm
2026-03-06 17:10:59 +01:00
parent fe8e1670cb
commit 61a7e3b9c6
6 changed files with 2473 additions and 0 deletions

View File

@ -132,6 +132,7 @@ add_subdirectory(common)
if(NOT BUILD_SERVER_STANDALONE)
add_subdirectory(shortcuts_management)
add_subdirectory(custom_widgets)
add_subdirectory(image_processing)
endif()
add_subdirectory(YACReaderLibrary/server)

View File

@ -98,6 +98,7 @@ target_link_libraries(YACReader PRIVATE
custom_widgets_reader
shortcuts_reader
cbx_backend
image_processing
QsLog
)

View File

@ -0,0 +1,9 @@
add_library(image_processing STATIC
resize_image.h
resize_image.cpp
lancir.h
)
target_include_directories(image_processing PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(image_processing PRIVATE Qt::Gui)

2383
image_processing/lancir.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,60 @@
#include "resize_image.h"
#include "lancir.h"
static QImage scaleImageLancir(const QImage &image, int width, int height)
{
QImage src = (image.format() == QImage::Format_ARGB32)
? image
: image.convertToFormat(QImage::Format_ARGB32);
QImage dst(width, height, QImage::Format_ARGB32);
// SrcSSize / NewSSize are in elements; for uint8_t that equals bytes,
// so bytesPerLine() covers any Qt row-alignment padding correctly.
avir::CLancIRParams params(src.bytesPerLine(), dst.bytesPerLine());
params.la = 4.0; // Lanczos4
avir::CLancIR lancir;
lancir.resizeImage<uint8_t, uint8_t>(
src.constBits(), src.width(), src.height(),
dst.bits(), width, height, 4, &params);
return dst;
}
// ---- QPixmap API ------------------------------------------------------------
QPixmap scalePixmap(const QPixmap &pixmap, int width, int height, ScaleMethod method)
{
if ((pixmap.width() == width && pixmap.height() == height) || pixmap.isNull())
return pixmap;
switch (method) {
case ScaleMethod::Nearest:
return pixmap.scaled(width, height, Qt::IgnoreAspectRatio, Qt::FastTransformation);
case ScaleMethod::Bilinear:
return pixmap.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
case ScaleMethod::Lanczos:
return QPixmap::fromImage(scaleImageLancir(pixmap.toImage(), width, height));
}
return pixmap;
}
// ---- QImage API (avoids QPixmap round-trip in ContinuousPageWidget) ---------
QImage scaleImage(const QImage &image, int width, int height, ScaleMethod method)
{
if ((image.width() == width && image.height() == height) || image.isNull())
return image;
switch (method) {
case ScaleMethod::Nearest:
return image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::FastTransformation);
case ScaleMethod::Bilinear:
return image.scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
case ScaleMethod::Lanczos:
return scaleImageLancir(image, width, height);
}
return image;
}

View File

@ -0,0 +1,19 @@
#ifndef RESIZE_IMAGE_H
#define RESIZE_IMAGE_H
#include <QImage>
#include <QPixmap>
enum class ScaleMethod {
Nearest = 0,
Bilinear = 1,
Lanczos = 2
};
// Base scaling API — callers are responsible for supplying the correct target dimensions.
QPixmap scalePixmap(const QPixmap &pixmap, int width, int height, ScaleMethod method = ScaleMethod::Lanczos);
QImage scaleImage(const QImage &image, int width, int height, ScaleMethod method = ScaleMethod::Lanczos);
#endif // RESIZE_IMAGE_H