mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge branch 4.x
This commit is contained in:
@@ -633,7 +633,7 @@ bool BmpEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
// sRGB colorspace requires BITMAPV5HEADER.
|
||||
// See https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapv5header
|
||||
bool useV5BitFields = true;
|
||||
for(size_t i = 0 ; i < params.size(); i++)
|
||||
for(size_t i = 0; i < params.size(); i+=2)
|
||||
{
|
||||
const int value = params[i+1];
|
||||
switch(params[i])
|
||||
|
||||
@@ -239,7 +239,7 @@ void write_pixel( const double& pixelValue,
|
||||
else if( image.depth() == CV_32S ){ image.ptr<Vec3i>(row)[col] = Vec3i(newValue,newValue,newValue); }
|
||||
else if( image.depth() == CV_32F ){ image.ptr<Vec3f>(row)[col] = Vec3f(newValue,newValue,newValue); }
|
||||
else if( image.depth() == CV_64F ){ image.ptr<Vec3d>(row)[col] = Vec3d(newValue,newValue,newValue); }
|
||||
else{ throw std::runtime_error("Unknown image depth, gdal:1, img: 3"); }
|
||||
else{ throw std::runtime_error("Unknown image depth, gdal:1, img: 3"); }
|
||||
}
|
||||
|
||||
// input: 3 channel, output: 1 channel
|
||||
|
||||
@@ -389,33 +389,43 @@ bool WebPEncoder::write(const Mat& img, const std::vector<int>& params)
|
||||
channels = 3;
|
||||
}
|
||||
|
||||
uint8_t *out = NULL;
|
||||
uint8_t *encoder_out = NULL;
|
||||
size_t size = 0;
|
||||
if (comp_lossless)
|
||||
{
|
||||
if (channels == 3)
|
||||
{
|
||||
size = WebPEncodeLosslessBGR(image->ptr(), width, height, (int)image->step, &out);
|
||||
size = WebPEncodeLosslessBGR(image->ptr(), width, height, (int)image->step, &encoder_out);
|
||||
}
|
||||
else if (channels == 4)
|
||||
{
|
||||
size = WebPEncodeLosslessBGRA(image->ptr(), width, height, (int)image->step, &out);
|
||||
size = WebPEncodeLosslessBGRA(image->ptr(), width, height, (int)image->step, &encoder_out);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (channels == 3)
|
||||
{
|
||||
size = WebPEncodeBGR(image->ptr(), width, height, (int)image->step, quality, &out);
|
||||
size = WebPEncodeBGR(image->ptr(), width, height, (int)image->step, quality, &encoder_out);
|
||||
}
|
||||
else if (channels == 4)
|
||||
{
|
||||
size = WebPEncodeBGRA(image->ptr(), width, height, (int)image->step, quality, &out);
|
||||
size = WebPEncodeBGRA(image->ptr(), width, height, (int)image->step, quality, &encoder_out);
|
||||
}
|
||||
}
|
||||
|
||||
WebPData finalData = { out, size };
|
||||
if (!m_metadata.empty()) {
|
||||
#if WEBP_DECODER_ABI_VERSION >= 0x0206
|
||||
Ptr<uint8_t> out_cleaner(encoder_out, WebPFree);
|
||||
#else
|
||||
Ptr<uint8_t> out_cleaner(encoder_out, free);
|
||||
#endif
|
||||
|
||||
uint8_t *out = encoder_out;
|
||||
uint8_t *muxer_out = nullptr;
|
||||
|
||||
if (!m_metadata.empty())
|
||||
{
|
||||
WebPData muxerData;
|
||||
|
||||
WebPMux* mux = WebPMuxNew();
|
||||
WebPData imageData = { out, size };
|
||||
@@ -442,8 +452,10 @@ bool WebPEncoder::write(const Mat& img, const std::vector<int>& params)
|
||||
WebPMuxSetChunk(mux, "ICCP", &metadata, 1);
|
||||
}
|
||||
|
||||
if (WebPMuxAssemble(mux, &finalData) == WEBP_MUX_OK) {
|
||||
size = finalData.size;
|
||||
if (WebPMuxAssemble(mux, &muxerData) == WEBP_MUX_OK) {
|
||||
size = muxerData.size;
|
||||
muxer_out = const_cast<uint8_t*>(muxerData.bytes);
|
||||
out = muxer_out;
|
||||
WebPMuxDelete(mux);
|
||||
}
|
||||
else {
|
||||
@@ -453,9 +465,9 @@ bool WebPEncoder::write(const Mat& img, const std::vector<int>& params)
|
||||
}
|
||||
|
||||
#if WEBP_DECODER_ABI_VERSION >= 0x0206
|
||||
Ptr<uint8_t> out_cleaner(out, WebPFree);
|
||||
Ptr<const uint8_t> muxer_cleaner(muxer_out, WebPFree);
|
||||
#else
|
||||
Ptr<uint8_t> out_cleaner(out, free);
|
||||
Ptr<const uint8_t> muxer_cleaner(muxer_out, free);
|
||||
#endif
|
||||
|
||||
CV_Assert(size > 0);
|
||||
@@ -463,7 +475,7 @@ bool WebPEncoder::write(const Mat& img, const std::vector<int>& params)
|
||||
if (m_buf)
|
||||
{
|
||||
m_buf->resize(size);
|
||||
memcpy(&(*m_buf)[0], finalData.bytes, size);
|
||||
memcpy(&(*m_buf)[0], out, size);
|
||||
bytes_written = size;
|
||||
}
|
||||
else
|
||||
@@ -471,7 +483,7 @@ bool WebPEncoder::write(const Mat& img, const std::vector<int>& params)
|
||||
FILE *fd = fopen(m_filename.c_str(), "wb");
|
||||
if (fd != NULL)
|
||||
{
|
||||
bytes_written = fwrite(finalData.bytes, sizeof(uint8_t), size, fd);
|
||||
bytes_written = fwrite(out, sizeof(uint8_t), size, fd);
|
||||
if (size != bytes_written)
|
||||
{
|
||||
CV_LOG_ERROR(NULL, cv::format("Only %zu or %zu bytes are written\n",bytes_written, size));
|
||||
|
||||
Reference in New Issue
Block a user