mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Add a new module for resizing images including Lanczos
This commit is contained in:
@ -132,6 +132,7 @@ add_subdirectory(common)
|
|||||||
if(NOT BUILD_SERVER_STANDALONE)
|
if(NOT BUILD_SERVER_STANDALONE)
|
||||||
add_subdirectory(shortcuts_management)
|
add_subdirectory(shortcuts_management)
|
||||||
add_subdirectory(custom_widgets)
|
add_subdirectory(custom_widgets)
|
||||||
|
add_subdirectory(image_processing)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(YACReaderLibrary/server)
|
add_subdirectory(YACReaderLibrary/server)
|
||||||
|
|||||||
@ -98,6 +98,7 @@ target_link_libraries(YACReader PRIVATE
|
|||||||
custom_widgets_reader
|
custom_widgets_reader
|
||||||
shortcuts_reader
|
shortcuts_reader
|
||||||
cbx_backend
|
cbx_backend
|
||||||
|
image_processing
|
||||||
QsLog
|
QsLog
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
9
image_processing/CMakeLists.txt
Normal file
9
image_processing/CMakeLists.txt
Normal 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
2383
image_processing/lancir.h
Normal file
File diff suppressed because it is too large
Load Diff
60
image_processing/resize_image.cpp
Normal file
60
image_processing/resize_image.cpp
Normal 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, ¶ms);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
19
image_processing/resize_image.h
Normal file
19
image_processing/resize_image.h
Normal 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
|
||||||
Reference in New Issue
Block a user