1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2024-04-01 17:09:24 +03:00
289 changed files with 49794 additions and 38081 deletions
+1 -1
View File
@@ -165,7 +165,7 @@ void ExifReader::parseExif()
*
* @return INTEL, MOTO or NONE
*/
Endianess_t ExifReader::getFormat() const
Endianness_t ExifReader::getFormat() const
{
if (m_data.size() < 1)
return NONE;
+3 -3
View File
@@ -79,7 +79,7 @@ enum ExifTagName
INVALID_TAG = 0xFFFF ///< Shows that the tag was not recognized
};
enum Endianess_t
enum Endianness_t
{
INTEL = 0x49,
MOTO = 0x4D,
@@ -179,7 +179,7 @@ public:
private:
std::vector<unsigned char> m_data;
std::map<int, ExifEntry_t > m_exif;
Endianess_t m_format;
Endianness_t m_format;
void parseExif();
bool checkTagMark() const;
@@ -193,7 +193,7 @@ private:
uint16_t getResolutionUnit( const size_t offset ) const;
uint16_t getYCbCrPos( const size_t offset ) const;
Endianess_t getFormat() const;
Endianness_t getFormat() const;
ExifEntry_t parseExifEntry( const size_t offset );
+43 -39
View File
@@ -402,16 +402,12 @@ int my_jpeg_load_dht (struct jpeg_decompress_struct *info, unsigned char *dht,
bool JpegDecoder::readData( Mat& img )
{
volatile bool result = false;
size_t step = img.step;
bool color = img.channels() > 1;
const bool color = img.channels() > 1;
if( m_state && m_width && m_height )
{
jpeg_decompress_struct* cinfo = &((JpegState*)m_state)->cinfo;
JpegErrorMgr* jerr = &((JpegState*)m_state)->jerr;
#ifndef JCS_EXTENSIONS
JSAMPARRAY buffer = 0;
#endif
if( setjmp( jerr->setjmp_buffer ) == 0 )
{
@@ -431,29 +427,30 @@ bool JpegDecoder::readData( Mat& img )
}
#endif
#ifdef JCS_EXTENSIONS
if( color )
{
cinfo->out_color_space = JCS_EXT_BGR;
cinfo->out_color_components = 3;
}
else
{
cinfo->out_color_space = JCS_GRAYSCALE;
cinfo->out_color_components = 1;
}
#else
// See https://github.com/opencv/opencv/issues/25274
// Conversion CMYK->BGR is not supported in libjpeg-turbo.
// So supporting both directly and indirectly is necessary.
bool doDirectRead = false;
if( color )
{
if( cinfo->num_components != 4 )
{
#ifdef JCS_EXTENSIONS
cinfo->out_color_space = JCS_EXT_BGR;
cinfo->out_color_components = 3;
doDirectRead = true; // BGR -> BGR
#else
cinfo->out_color_space = JCS_RGB;
cinfo->out_color_components = 3;
doDirectRead = false; // RGB -> BGR
#endif
}
else
{
cinfo->out_color_space = JCS_CMYK;
cinfo->out_color_components = 4;
doDirectRead = false; // CMYK -> BGR
}
}
else
@@ -462,14 +459,15 @@ bool JpegDecoder::readData( Mat& img )
{
cinfo->out_color_space = JCS_GRAYSCALE;
cinfo->out_color_components = 1;
doDirectRead = true; // GRAY -> GRAY
}
else
{
cinfo->out_color_space = JCS_CMYK;
cinfo->out_color_components = 4;
doDirectRead = false; // CMYK -> GRAY
}
}
#endif
// Check for Exif marker APP1
jpeg_saved_marker_ptr exif_marker = NULL;
@@ -496,33 +494,39 @@ bool JpegDecoder::readData( Mat& img )
jpeg_start_decompress( cinfo );
#ifndef JCS_EXTENSIONS
buffer = (*cinfo->mem->alloc_sarray)((j_common_ptr)cinfo,
JPOOL_IMAGE, m_width*4, 1 );
#endif
uchar* data = img.ptr();
for( ; m_height--; data += step )
if( doDirectRead)
{
#ifdef JCS_EXTENSIONS
jpeg_read_scanlines( cinfo, &data, 1 );
#else
jpeg_read_scanlines( cinfo, buffer, 1 );
if( color )
for( int iy = 0 ; iy < m_height; iy ++ )
{
if( cinfo->out_color_components == 3 )
icvCvt_RGB2BGR_8u_C3R( buffer[0], 0, data, 0, Size(m_width,1) );
else
icvCvt_CMYK2BGR_8u_C4C3R( buffer[0], 0, data, 0, Size(m_width,1) );
uchar* data = img.ptr<uchar>(iy);
jpeg_read_scanlines( cinfo, &data, 1 );
}
else
}
else
{
JSAMPARRAY buffer = (*cinfo->mem->alloc_sarray)((j_common_ptr)cinfo,
JPOOL_IMAGE, m_width*4, 1 );
for( int iy = 0 ; iy < m_height; iy ++ )
{
if( cinfo->out_color_components == 1 )
memcpy( data, buffer[0], m_width );
uchar* data = img.ptr<uchar>(iy);
jpeg_read_scanlines( cinfo, buffer, 1 );
if( color )
{
if( cinfo->out_color_components == 3 )
icvCvt_RGB2BGR_8u_C3R( buffer[0], 0, data, 0, Size(m_width,1) );
else
icvCvt_CMYK2BGR_8u_C4C3R( buffer[0], 0, data, 0, Size(m_width,1) );
}
else
icvCvt_CMYK2Gray_8u_C4C1R( buffer[0], 0, data, 0, Size(m_width,1) );
{
if( cinfo->out_color_components == 1 )
memcpy( data, buffer[0], m_width );
else
icvCvt_CMYK2Gray_8u_C4C1R( buffer[0], 0, data, 0, Size(m_width,1) );
}
}
#endif
}
result = true;
+2 -2
View File
@@ -27,7 +27,7 @@ bool is_byte_order_swapped(double scale)
#endif
}
void swap_endianess(uint32_t& ui)
void swap_endianness(uint32_t& ui)
{
static const uint32_t A(0x000000ffU);
static const uint32_t B(0x0000ff00U);
@@ -137,7 +137,7 @@ bool PFMDecoder::readData(Mat& mat)
for (int i = 0; i < m_width * buffer.channels(); ++i) {
static_assert( sizeof(uint32_t) == sizeof(float),
"uint32_t and float must have same size." );
swap_endianess(buffer.ptr<uint32_t>(y)[i]);
swap_endianness(buffer.ptr<uint32_t>(y)[i]);
}
}
}
+32 -22
View File
@@ -60,6 +60,16 @@ namespace tiff_dummy_namespace {
}
using namespace tiff_dummy_namespace;
#ifndef _MSC_VER
namespace numeric_types = tiff_dummy_namespace;
#else
#include <cstdint>
namespace numeric_types {
using uint16 = std::uint16_t;
using uint32 = std::uint32_t;
}
#endif
namespace cv
{
@@ -264,8 +274,8 @@ bool TiffDecoder::readHeader()
if (tif)
{
uint32 wdth = 0, hght = 0;
uint16 photometric = 0;
numeric_types::uint32 wdth = 0, hght = 0;
numeric_types::uint16 photometric = 0;
CV_TIFF_CHECK_CALL(TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &wdth));
CV_TIFF_CHECK_CALL(TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &hght));
@@ -273,7 +283,7 @@ bool TiffDecoder::readHeader()
{
bool isGrayScale = photometric == PHOTOMETRIC_MINISWHITE || photometric == PHOTOMETRIC_MINISBLACK;
uint16 bpp = 8, ncn = isGrayScale ? 1 : 3;
numeric_types::uint16 bpp = 8, ncn = isGrayScale ? 1 : 3;
if (0 == TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bpp))
{
// TIFF bi-level images don't require TIFFTAG_BITSPERSAMPLE tag
@@ -296,7 +306,7 @@ bool TiffDecoder::readHeader()
(ncn != 1 && ncn != 3 && ncn != 4)))
bpp = 8;
uint16 sample_format = SAMPLEFORMAT_UINT;
numeric_types::uint16 sample_format = SAMPLEFORMAT_UINT;
TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &sample_format);
int wanted_channels = normalizeChannelsNumber(ncn);
switch (bpp)
@@ -378,7 +388,7 @@ bool TiffDecoder::nextPage()
readHeader();
}
static void fixOrientationPartial(Mat &img, uint16 orientation)
static void fixOrientationPartial(Mat &img, numeric_types::uint16 orientation)
{
switch(orientation) {
case ORIENTATION_RIGHTTOP:
@@ -434,7 +444,7 @@ static void fixOrientationFull(Mat &img, int orientation)
* For 8 bit some corrections are done by TIFFReadRGBAStrip/Tile already.
* Not so for 16/32/64 bit.
*/
static void fixOrientation(Mat &img, uint16 orientation, bool isOrientationFull)
static void fixOrientation(Mat &img, numeric_types::uint16 orientation, bool isOrientationFull)
{
if( isOrientationFull )
{
@@ -595,7 +605,7 @@ bool TiffDecoder::readData( Mat& img )
CV_Assert(!m_tif.empty());
TIFF* tif = (TIFF*)m_tif.get();
uint16 photometric = (uint16)-1;
numeric_types::uint16 photometric = (numeric_types::uint16)-1;
CV_TIFF_CHECK_CALL(TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric));
if (m_hdr && depth >= CV_32F)
@@ -611,14 +621,14 @@ bool TiffDecoder::readData( Mat& img )
{
int is_tiled = TIFFIsTiled(tif) != 0;
bool isGrayScale = photometric == PHOTOMETRIC_MINISWHITE || photometric == PHOTOMETRIC_MINISBLACK;
uint16 bpp = 8, ncn = isGrayScale ? 1 : 3;
numeric_types::uint16 bpp = 8, ncn = isGrayScale ? 1 : 3;
if (0 == TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bpp))
{
// TIFF bi-level images don't require TIFFTAG_BITSPERSAMPLE tag
bpp = 1;
}
CV_TIFF_CHECK_CALL_DEBUG(TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &ncn));
uint16 img_orientation = ORIENTATION_TOPLEFT;
numeric_types::uint16 img_orientation = ORIENTATION_TOPLEFT;
CV_TIFF_CHECK_CALL_DEBUG(TIFFGetField(tif, TIFFTAG_ORIENTATION, &img_orientation));
constexpr const int bitsPerByte = 8;
int dst_bpp = (int)(img.elemSize1() * bitsPerByte);
@@ -628,7 +638,7 @@ bool TiffDecoder::readData( Mat& img )
int wanted_channels = normalizeChannelsNumber(img.channels());
bool doReadScanline = false;
uint32 tile_width0 = m_width, tile_height0 = 0;
numeric_types::uint32 tile_width0 = m_width, tile_height0 = 0;
if (is_tiled)
{
@@ -646,7 +656,7 @@ bool TiffDecoder::readData( Mat& img )
tile_width0 = m_width;
if (tile_height0 == 0 ||
(!is_tiled && tile_height0 == std::numeric_limits<uint32>::max()) )
(!is_tiled && tile_height0 == std::numeric_limits<numeric_types::uint32>::max()) )
tile_height0 = m_height;
const int TILE_MAX_WIDTH = (1 << 24);
@@ -671,7 +681,7 @@ bool TiffDecoder::readData( Mat& img )
( (uint64_t) MAX_TILE_SIZE * 95 / 100)
)
{
uint16_t planerConfig = (uint16)-1;
uint16_t planerConfig = (numeric_types::uint16)-1;
CV_TIFF_CHECK_CALL(TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planerConfig));
doReadScanline = (!is_tiled) // no tile
@@ -727,7 +737,7 @@ bool TiffDecoder::readData( Mat& img )
MAX_TILE_SIZE * 95 / 100
)
{
uint16_t planerConfig = (uint16)-1;
uint16_t planerConfig = (numeric_types::uint16)-1;
CV_TIFF_CHECK_CALL(TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &planerConfig));
doReadScanline = (!is_tiled) // no tile
@@ -811,7 +821,7 @@ bool TiffDecoder::readData( Mat& img )
uchar* bstart = src_buffer;
if (doReadScanline)
{
CV_TIFF_CHECK_CALL((int)TIFFReadScanline(tif, (uint32*)src_buffer, y) >= 0);
CV_TIFF_CHECK_CALL((int)TIFFReadScanline(tif, (numeric_types::uint32*)src_buffer, y) >= 0);
if ( isNeedConvert16to8 )
{
@@ -833,11 +843,11 @@ bool TiffDecoder::readData( Mat& img )
}
else if (!is_tiled)
{
CV_TIFF_CHECK_CALL(TIFFReadRGBAStrip(tif, y, (uint32*)src_buffer));
CV_TIFF_CHECK_CALL(TIFFReadRGBAStrip(tif, y, (numeric_types::uint32*)src_buffer));
}
else
{
CV_TIFF_CHECK_CALL(TIFFReadRGBATile(tif, x, y, (uint32*)src_buffer));
CV_TIFF_CHECK_CALL(TIFFReadRGBATile(tif, x, y, (numeric_types::uint32*)src_buffer));
// Tiles fill the buffer from the bottom up
bstart += (tile_height0 - tile_height) * tile_width0 * 4;
}
@@ -931,15 +941,15 @@ bool TiffDecoder::readData( Mat& img )
{
if (doReadScanline)
{
CV_TIFF_CHECK_CALL((int)TIFFReadScanline(tif, (uint32*)src_buffer, y) >= 0);
CV_TIFF_CHECK_CALL((int)TIFFReadScanline(tif, (numeric_types::uint32*)src_buffer, y) >= 0);
}
else if (!is_tiled)
{
CV_TIFF_CHECK_CALL((int)TIFFReadEncodedStrip(tif, tileidx, (uint32*)src_buffer, src_buffer_size) >= 0);
CV_TIFF_CHECK_CALL((int)TIFFReadEncodedStrip(tif, tileidx, (numeric_types::uint32*)src_buffer, src_buffer_size) >= 0);
}
else
{
CV_TIFF_CHECK_CALL((int)TIFFReadEncodedTile(tif, tileidx, (uint32*)src_buffer, src_buffer_size) >= 0);
CV_TIFF_CHECK_CALL((int)TIFFReadEncodedTile(tif, tileidx, (numeric_types::uint32*)src_buffer, src_buffer_size) >= 0);
}
for (int i = 0; i < tile_height; i++)
@@ -1219,7 +1229,7 @@ bool TiffEncoder::writeLibTiff( const std::vector<Mat>& img_vec, const std::vect
int resUnit = -1, dpiX = -1, dpiY = -1;
readParam(params, IMWRITE_TIFF_COMPRESSION, compression);
readParam(params, TIFFTAG_PREDICTOR, predictor);
readParam(params, IMWRITE_TIFF_PREDICTOR, predictor);
readParam(params, IMWRITE_TIFF_RESUNIT, resUnit);
readParam(params, IMWRITE_TIFF_XDPI, dpiX);
readParam(params, IMWRITE_TIFF_YDPI, dpiY);
@@ -1256,7 +1266,7 @@ bool TiffEncoder::writeLibTiff( const std::vector<Mat>& img_vec, const std::vect
int page_compression = compression;
int bitsPerChannel = -1;
uint16 sample_format = SAMPLEFORMAT_INT;
numeric_types::uint16 sample_format = SAMPLEFORMAT_INT;
switch (depth)
{
case CV_8U:
@@ -1308,7 +1318,7 @@ bool TiffEncoder::writeLibTiff( const std::vector<Mat>& img_vec, const std::vect
CV_Assert(fileStep > 0);
int rowsPerStrip = (int)((1 << 13) / fileStep);
readParam(params, TIFFTAG_ROWSPERSTRIP, rowsPerStrip);
readParam(params, IMWRITE_TIFF_ROWSPERSTRIP, rowsPerStrip);
rowsPerStrip = std::max(1, std::min(height, rowsPerStrip));
int colorspace = channels > 1 ? PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK;
+20 -1
View File
@@ -457,7 +457,16 @@ imread_( const String& filename, int flags, Mat& mat )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
mat.create( size.height, size.width, type );
if (mat.empty())
{
mat.create( size.height, size.width, type );
}
else
{
CV_CheckEQ(size, mat.size(), "");
CV_CheckTypeEQ(type, mat.type(), "");
CV_Assert(mat.isContinuous());
}
// read the image data
bool success = false;
@@ -632,6 +641,16 @@ Mat imread( const String& filename, int flags )
return img;
}
void imread( const String& filename, OutputArray dst, int flags )
{
CV_TRACE_FUNCTION();
Mat img = dst.getMat();
/// load the data
imread_(filename, flags, img);
}
/**
* Read a multi-page image
*