-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TgBot++: imagep: Add version getter, make dependencies optional
- Loading branch information
Showing
15 changed files
with
185 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "ImageProcAll.hpp" | ||
|
||
#include <filesystem> | ||
|
||
#include "imagep/ImagePBase.hpp" | ||
|
||
ImageProcessingAll::ImageProcessingAll(std::filesystem::path filename) | ||
: _filename(std::move(filename)) { | ||
#ifdef HAVE_OPENCV | ||
impls.emplace_back(std::make_unique<OpenCVImage>()); | ||
#endif | ||
#ifdef HAVE_LIBJPEG | ||
impls.emplace_back(std::make_unique<JPEGImage>()); | ||
#endif | ||
#ifdef HAVE_LIBPNG | ||
impls.emplace_back(std::make_unique<PngImage>()); | ||
#endif | ||
#ifdef HAVE_LIBWEBP | ||
impls.emplace_back(std::make_unique<WebPImage>()); | ||
#endif | ||
} | ||
|
||
bool ImageProcessingAll::read() { | ||
for (auto& impl : impls) { | ||
if (impl->read(_filename)) { | ||
// We found the backend suitable. Select one and dealloc others. | ||
_impl = std::move(impl); | ||
impls.clear(); | ||
|
||
LOG(INFO) << "Using implementation: " << _impl->version(); | ||
return true; | ||
} | ||
} | ||
LOG(INFO) << "No backend was suitable to read"; | ||
return false; | ||
} | ||
|
||
PhotoBase::Result ImageProcessingAll::rotate(int angle) { | ||
if (!_impl) { | ||
LOG(ERROR) << "No backend selected for rotation"; | ||
return PhotoBase::Result::kErrorNoData; | ||
} | ||
DLOG(INFO) << "Calling impl->rotate with angle: " << angle; | ||
return _impl->rotate_image(angle); | ||
} | ||
|
||
void ImageProcessingAll::to_greyscale() { | ||
if (!_impl) { | ||
LOG(ERROR) << "No backend selected for greyscale conversion"; | ||
return; | ||
} | ||
DLOG(INFO) << "Calling impl->to_greyscale"; | ||
_impl->to_greyscale(); | ||
} | ||
|
||
bool ImageProcessingAll::write(const std::filesystem::path& filename) { | ||
if (!_impl) { | ||
LOG(ERROR) << "No backend selected for writing"; | ||
return false; | ||
} | ||
if (filename.empty()) { | ||
LOG(ERROR) << "Filename is empty"; | ||
return false; | ||
} | ||
DLOG(INFO) << "Calling impl->write with filename: " << filename; | ||
return _impl->write(filename); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#ifdef HAVE_OPENCV | ||
#include "ImageProcOpenCV.hpp" | ||
#endif | ||
#ifdef HAVE_LIBJPEG | ||
#include "ImageTypeJPEG.hpp" | ||
#endif | ||
#ifdef HAVE_LIBPNG | ||
#include "ImageTypePNG.hpp" | ||
#endif | ||
#ifdef HAVE_LIBWEBP | ||
#include "ImageTypeWEBP.hpp" | ||
#endif | ||
#include "imagep/ImagePBase.hpp" | ||
|
||
struct ImageProcessingAll { | ||
bool read(); | ||
PhotoBase::Result rotate(int angle); | ||
void to_greyscale(); | ||
bool write(const std::filesystem::path& filename); | ||
|
||
explicit ImageProcessingAll(std::filesystem::path filename); | ||
|
||
private: | ||
std::filesystem::path _filename; | ||
std::vector<std::unique_ptr<PhotoBase>> impls; | ||
std::unique_ptr<PhotoBase> _impl; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.