mirror of
https://github.com/opencv/opencv.git
synced 2026-07-28 23:03:03 +04:00
Merge pull request #26849 from sturkmen72:apng-writeanimation
APNG encoding optimization #26849 related #26840 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -535,9 +535,12 @@ bool SPngEncoder::write(const Mat &img, const std::vector<int> ¶ms)
|
||||
struct spng_ihdr ihdr = {};
|
||||
ihdr.height = height;
|
||||
ihdr.width = width;
|
||||
int compression_level = -1; // Invalid value to allow setting 0-9 as valid
|
||||
int compression_level = Z_BEST_SPEED;
|
||||
int compression_strategy = IMWRITE_PNG_STRATEGY_RLE; // Default strategy
|
||||
int filter = IMWRITE_PNG_FILTER_SUB; // Default filter
|
||||
bool isBilevel = false;
|
||||
bool set_compression_level = false;
|
||||
bool set_filter = false;
|
||||
|
||||
for (size_t i = 0; i < params.size(); i += 2)
|
||||
{
|
||||
@@ -546,6 +549,7 @@ bool SPngEncoder::write(const Mat &img, const std::vector<int> ¶ms)
|
||||
compression_strategy = IMWRITE_PNG_STRATEGY_DEFAULT; // Default strategy
|
||||
compression_level = params[i + 1];
|
||||
compression_level = MIN(MAX(compression_level, 0), Z_BEST_COMPRESSION);
|
||||
set_compression_level = true;
|
||||
}
|
||||
if (params[i] == IMWRITE_PNG_STRATEGY)
|
||||
{
|
||||
@@ -556,6 +560,11 @@ bool SPngEncoder::write(const Mat &img, const std::vector<int> ¶ms)
|
||||
{
|
||||
isBilevel = params[i + 1] != 0;
|
||||
}
|
||||
if( params[i] == IMWRITE_PNG_FILTER )
|
||||
{
|
||||
filter = params[i+1];
|
||||
set_filter = true;
|
||||
}
|
||||
}
|
||||
|
||||
ihdr.bit_depth = depth == CV_8U ? isBilevel ? 1 : 8 : 16;
|
||||
@@ -579,15 +588,9 @@ bool SPngEncoder::write(const Mat &img, const std::vector<int> ¶ms)
|
||||
|
||||
if (m_buf || f)
|
||||
{
|
||||
if (compression_level >= 0)
|
||||
{
|
||||
spng_set_option(ctx, SPNG_IMG_COMPRESSION_LEVEL, compression_level);
|
||||
}
|
||||
else
|
||||
{
|
||||
spng_set_option(ctx, SPNG_FILTER_CHOICE, SPNG_FILTER_CHOICE_SUB);
|
||||
spng_set_option(ctx, SPNG_IMG_COMPRESSION_LEVEL, Z_BEST_SPEED);
|
||||
}
|
||||
if (!set_compression_level || set_filter)
|
||||
spng_set_option(ctx, SPNG_FILTER_CHOICE, filter);
|
||||
spng_set_option(ctx, SPNG_IMG_COMPRESSION_LEVEL, compression_level);
|
||||
spng_set_option(ctx, SPNG_IMG_COMPRESSION_STRATEGY, compression_strategy);
|
||||
|
||||
int ret;
|
||||
|
||||
Reference in New Issue
Block a user