1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

removed C API in the following modules: photo, video, imgcodecs, videoio (#13060)

* removed C API in the following modules: photo, video, imgcodecs, videoio

* trying to fix various compile errors and warnings on Windows and Linux

* continue to fix compile errors and warnings

* continue to fix compile errors, warnings, as well as the test failures

* trying to resolve compile warnings on Android

* Update cap_dc1394_v2.cpp

fix warning from the new GCC
This commit is contained in:
Vadim Pisarevsky
2018-11-09 00:52:09 +03:00
committed by GitHub
parent 5087ff0814
commit 11eafca3e2
34 changed files with 389 additions and 1403 deletions
+1 -1
View File
@@ -142,7 +142,7 @@ void BaseImageEncoder::throwOnEror() const
if(!m_last_error.empty())
{
String msg = "Raw image encoder error: " + m_last_error;
CV_Error( CV_BadImageSize, msg.c_str() );
CV_Error( Error::BadImageSize, msg.c_str() );
}
}
+11 -11
View File
@@ -55,7 +55,7 @@ BmpDecoder::BmpDecoder()
m_signature = fmtSignBmp;
m_offset = -1;
m_buf_supported = true;
m_origin = 0;
m_origin = ORIGIN_TL;
m_bpp = 0;
m_rle_code = BMP_RGB;
}
@@ -179,7 +179,7 @@ bool BmpDecoder::readHeader()
}
// in 32 bit case alpha channel is used - so require CV_8UC4 type
m_type = iscolor ? (m_bpp == 32 ? CV_8UC4 : CV_8UC3 ) : CV_8UC1;
m_origin = m_height > 0 ? IPL_ORIGIN_BL : IPL_ORIGIN_TL;
m_origin = m_height > 0 ? ORIGIN_BL : ORIGIN_TL;
m_height = std::abs(m_height);
if( !result )
@@ -206,7 +206,7 @@ bool BmpDecoder::readData( Mat& img )
if( m_offset < 0 || !m_strm.isOpened())
return false;
if( m_origin == IPL_ORIGIN_BL )
if( m_origin == ORIGIN_BL )
{
data += (m_height - 1)*(size_t)step;
step = -step;
@@ -238,7 +238,7 @@ bool BmpDecoder::readData( Mat& img )
m_strm.getBytes( src, src_pitch );
FillColorRow1( color ? data : bgr, src, m_width, m_palette );
if( !color )
icvCvt_BGR2Gray_8u_C3C1R( bgr, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR2Gray_8u_C3C1R( bgr, 0, data, 0, Size(m_width,1) );
}
result = true;
break;
@@ -441,9 +441,9 @@ decode_rle8_bad: ;
{
m_strm.getBytes( src, src_pitch );
if( !color )
icvCvt_BGR5552Gray_8u_C2C1R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR5552Gray_8u_C2C1R( src, 0, data, 0, Size(m_width,1) );
else
icvCvt_BGR5552BGR_8u_C2C3R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR5552BGR_8u_C2C3R( src, 0, data, 0, Size(m_width,1) );
}
result = true;
break;
@@ -453,9 +453,9 @@ decode_rle8_bad: ;
{
m_strm.getBytes( src, src_pitch );
if( !color )
icvCvt_BGR5652Gray_8u_C2C1R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR5652Gray_8u_C2C1R( src, 0, data, 0, Size(m_width,1) );
else
icvCvt_BGR5652BGR_8u_C2C3R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR5652BGR_8u_C2C3R( src, 0, data, 0, Size(m_width,1) );
}
result = true;
break;
@@ -465,7 +465,7 @@ decode_rle8_bad: ;
{
m_strm.getBytes( src, src_pitch );
if(!color)
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, Size(m_width,1) );
else
memcpy( data, src, m_width*3 );
}
@@ -478,9 +478,9 @@ decode_rle8_bad: ;
m_strm.getBytes( src, src_pitch );
if( !color )
icvCvt_BGRA2Gray_8u_C4C1R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_BGRA2Gray_8u_C4C1R( src, 0, data, 0, Size(m_width,1) );
else if( img.channels() == 3 )
icvCvt_BGRA2BGR_8u_C4C3R(src, 0, data, 0, cvSize(m_width, 1));
icvCvt_BGRA2BGR_8u_C4C3R(src, 0, data, 0, Size(m_width, 1));
else if( img.channels() == 4 )
memcpy(data, src, m_width * 4);
}
+7 -1
View File
@@ -73,9 +73,15 @@ public:
protected:
enum Origin
{
ORIGIN_TL = 0,
ORIGIN_BL = 1
};
RLByteStream m_strm;
PaletteEntry m_palette[256];
int m_origin;
Origin m_origin;
int m_bpp;
int m_offset;
BmpCompression m_rle_code;
+5 -5
View File
@@ -453,16 +453,16 @@ bool JpegDecoder::readData( Mat& img )
if( color )
{
if( cinfo->out_color_components == 3 )
icvCvt_RGB2BGR_8u_C3R( buffer[0], 0, data, 0, cvSize(m_width,1) );
icvCvt_RGB2BGR_8u_C3R( buffer[0], 0, data, 0, Size(m_width,1) );
else
icvCvt_CMYK2BGR_8u_C4C3R( buffer[0], 0, data, 0, cvSize(m_width,1) );
icvCvt_CMYK2BGR_8u_C4C3R( buffer[0], 0, data, 0, Size(m_width,1) );
}
else
{
if( cinfo->out_color_components == 1 )
memcpy( data, buffer[0], m_width );
else
icvCvt_CMYK2Gray_8u_C4C1R( buffer[0], 0, data, 0, cvSize(m_width,1) );
icvCvt_CMYK2Gray_8u_C4C1R( buffer[0], 0, data, 0, Size(m_width,1) );
}
}
@@ -689,12 +689,12 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
if( _channels == 3 )
{
icvCvt_BGR2RGB_8u_C3R( data, 0, buffer, 0, cvSize(width,1) );
icvCvt_BGR2RGB_8u_C3R( data, 0, buffer, 0, Size(width,1) );
ptr = buffer;
}
else if( _channels == 4 )
{
icvCvt_BGRA2BGR_8u_C4C3R( data, 0, buffer, 0, cvSize(width,1), 2 );
icvCvt_BGRA2BGR_8u_C4C3R( data, 0, buffer, 0, Size(width,1), 2 );
ptr = buffer;
}
+4 -4
View File
@@ -132,12 +132,12 @@ rgb_convert (void *src, void *target, int width, int target_channels, int target
switch (target_depth) {
case CV_8U:
icvCvt_RGB2BGR_8u_C3R( (uchar*) src, 0, (uchar*) target, 0,
cvSize(width,1) );
Size(width,1) );
ret = true;
break;
case CV_16U:
icvCvt_RGB2BGR_16u_C3R( (ushort *)src, 0, (ushort *)target, 0,
cvSize(width,1) );
Size(width,1) );
ret = true;
break;
default:
@@ -147,12 +147,12 @@ rgb_convert (void *src, void *target, int width, int target_channels, int target
switch (target_depth) {
case CV_8U:
icvCvt_BGR2Gray_8u_C3C1R( (uchar*) src, 0, (uchar*) target, 0,
cvSize(width,1), 2 );
Size(width,1), 2 );
ret = true;
break;
case CV_16U:
icvCvt_BGRA2Gray_16u_CnC1R( (ushort *)src, 0, (ushort *)target, 0,
cvSize(width,1), 3, 2 );
Size(width,1), 3, 2 );
ret = true;
break;
default:
+6 -6
View File
@@ -342,14 +342,14 @@ bool PxMDecoder::readData( Mat& img )
if( color )
{
if( img.depth() == CV_8U )
icvCvt_RGB2BGR_8u_C3R( src, 0, data, 0, cvSize(m_width,1) );
icvCvt_RGB2BGR_8u_C3R( src, 0, data, 0, Size(m_width,1) );
else
icvCvt_RGB2BGR_16u_C3R( (ushort *)src, 0, (ushort *)data, 0, cvSize(m_width,1) );
icvCvt_RGB2BGR_16u_C3R( (ushort *)src, 0, (ushort *)data, 0, Size(m_width,1) );
}
else if( img.depth() == CV_8U )
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, cvSize(m_width,1), 2 );
icvCvt_BGR2Gray_8u_C3C1R( src, 0, data, 0, Size(m_width,1), 2 );
else
icvCvt_BGRA2Gray_16u_CnC1R( (ushort *)src, 0, (ushort *)data, 0, cvSize(m_width,1), 3, 2 );
icvCvt_BGRA2Gray_16u_CnC1R( (ushort *)src, 0, (ushort *)data, 0, Size(m_width,1), 3, 2 );
}
}
result = true;
@@ -522,10 +522,10 @@ bool PxMEncoder::write(const Mat& img, const std::vector<int>& params)
{
if( depth == 8 )
icvCvt_BGR2RGB_8u_C3R( (const uchar*)data, 0,
(uchar*)buffer, 0, cvSize(width,1) );
(uchar*)buffer, 0, Size(width,1) );
else
icvCvt_BGR2RGB_16u_C3R( (const ushort*)data, 0,
(ushort*)buffer, 0, cvSize(width,1) );
(ushort*)buffer, 0, Size(width,1) );
}
// swap endianness if necessary
+4 -4
View File
@@ -343,13 +343,13 @@ bad_decoding_end:
if( color )
{
if( m_type == RAS_FORMAT_RGB )
icvCvt_RGB2BGR_8u_C3R(src, 0, data, 0, cvSize(m_width,1) );
icvCvt_RGB2BGR_8u_C3R(src, 0, data, 0, Size(m_width,1) );
else
memcpy(data, src, std::min(step, (size_t)src_pitch));
}
else
{
icvCvt_BGR2Gray_8u_C3C1R(src, 0, data, 0, cvSize(m_width,1),
icvCvt_BGR2Gray_8u_C3C1R(src, 0, data, 0, Size(m_width,1),
m_type == RAS_FORMAT_RGB ? 2 : 0 );
}
}
@@ -364,10 +364,10 @@ bad_decoding_end:
m_strm.getBytes( src + 3, src_pitch );
if( color )
icvCvt_BGRA2BGR_8u_C4C3R( src + 4, 0, data, 0, cvSize(m_width,1),
icvCvt_BGRA2BGR_8u_C4C3R( src + 4, 0, data, 0, Size(m_width,1),
m_type == RAS_FORMAT_RGB ? 2 : 0 );
else
icvCvt_BGRA2Gray_8u_C4C1R( src + 4, 0, data, 0, cvSize(m_width,1),
icvCvt_BGRA2Gray_8u_C4C1R( src + 4, 0, data, 0, Size(m_width,1),
m_type == RAS_FORMAT_RGB ? 2 : 0 );
}
result = true;
+13 -13
View File
@@ -408,19 +408,19 @@ bool TiffDecoder::readData( Mat& img )
{
icvCvt_BGRA2RGBA_8u_C4R( bstart + i*tile_width0*4, 0,
data + x*4 + img.step*(tile_height - i - 1), 0,
cvSize(tile_width,1) );
Size(tile_width,1) );
}
else
{
icvCvt_BGRA2BGR_8u_C4C3R( bstart + i*tile_width0*4, 0,
data + x*3 + img.step*(tile_height - i - 1), 0,
cvSize(tile_width,1), 2 );
Size(tile_width,1), 2 );
}
}
else
icvCvt_BGRA2Gray_8u_C4C1R( bstart + i*tile_width0*4, 0,
data + x + img.step*(tile_height - i - 1), 0,
cvSize(tile_width,1), 2 );
Size(tile_width,1), 2 );
break;
}
@@ -445,13 +445,13 @@ bool TiffDecoder::readData( Mat& img )
{
icvCvt_Gray2BGR_16u_C1C3R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x*3, 0,
cvSize(tile_width,1) );
Size(tile_width,1) );
}
else if( ncn == 3 )
{
icvCvt_RGB2BGR_16u_C3R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x*3, 0,
cvSize(tile_width,1) );
Size(tile_width,1) );
}
else if (ncn == 4)
{
@@ -459,20 +459,20 @@ bool TiffDecoder::readData( Mat& img )
{
icvCvt_BGRA2RGBA_16u_C4R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x * 4, 0,
cvSize(tile_width, 1));
Size(tile_width, 1));
}
else
{
icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x * 3, 0,
cvSize(tile_width, 1), 2);
Size(tile_width, 1), 2);
}
}
else
{
icvCvt_BGRA2BGR_16u_C4C3R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x*3, 0,
cvSize(tile_width,1), 2 );
Size(tile_width,1), 2 );
}
}
else
@@ -487,7 +487,7 @@ bool TiffDecoder::readData( Mat& img )
{
icvCvt_BGRA2Gray_16u_CnC1R(buffer16 + i*tile_width0*ncn, 0,
(ushort*)(data + img.step*i) + x, 0,
cvSize(tile_width,1), ncn, 2 );
Size(tile_width,1), ncn, 2 );
}
}
}
@@ -859,18 +859,18 @@ bool TiffEncoder::writeLibTiff( const std::vector<Mat>& img_vec, const std::vect
case 3:
{
if (depth == CV_8U)
icvCvt_BGR2RGB_8u_C3R( img.ptr(y), 0, buffer, 0, cvSize(width, 1));
icvCvt_BGR2RGB_8u_C3R( img.ptr(y), 0, buffer, 0, Size(width, 1));
else
icvCvt_BGR2RGB_16u_C3R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, cvSize(width, 1));
icvCvt_BGR2RGB_16u_C3R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, Size(width, 1));
break;
}
case 4:
{
if (depth == CV_8U)
icvCvt_BGRA2RGBA_8u_C4R( img.ptr(y), 0, buffer, 0, cvSize(width, 1));
icvCvt_BGRA2RGBA_8u_C4R( img.ptr(y), 0, buffer, 0, Size(width, 1));
else
icvCvt_BGRA2RGBA_16u_C4R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, cvSize(width, 1));
icvCvt_BGRA2RGBA_16u_C4R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, Size(width, 1));
break;
}
+25 -154
View File
@@ -301,8 +301,6 @@ static ImageEncoder findEncoder( const String& _ext )
}
enum { LOAD_CVMAT=0, LOAD_IMAGE=1, LOAD_MAT=2 };
static void ExifTransform(int orientation, Mat& img)
{
switch( orientation )
@@ -397,15 +395,9 @@ static void ApplyExifOrientation(const Mat& buf, Mat& img)
* @param[in] scale_denom Scale value
*
*/
static void*
imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 )
static bool
imread_( const String& filename, int flags, Mat& mat )
{
CV_Assert(mat || hdrtype != LOAD_MAT); // mat is required in LOAD_MAT case
IplImage* image = 0;
CvMat *matrix = 0;
Mat temp, *data = &temp;
/// Search for the relevant decoder to handle the imagery
ImageDecoder decoder;
@@ -476,30 +468,13 @@ imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
if( hdrtype == LOAD_CVMAT || hdrtype == LOAD_MAT )
{
if( hdrtype == LOAD_CVMAT )
{
matrix = cvCreateMat( size.height, size.width, type );
temp = cvarrToMat( matrix );
}
else
{
mat->create( size.height, size.width, type );
data = mat;
}
}
else
{
image = cvCreateImage(cvSize(size), cvIplDepth(type), CV_MAT_CN(type));
temp = cvarrToMat( image );
}
mat.create( size.height, size.width, type );
// read the image data
bool success = false;
CV_TRY
{
if (decoder->readData(*data))
if (decoder->readData(mat))
success = true;
}
CV_CATCH (cv::Exception, e)
@@ -512,20 +487,16 @@ imread_( const String& filename, int flags, int hdrtype, Mat* mat=0 )
}
if (!success)
{
cvReleaseImage( &image );
cvReleaseMat( &matrix );
if( mat )
mat->release();
return 0;
mat.release();
return false;
}
if( decoder->setScale( scale_denom ) > 1 ) // if decoder is JpegDecoder then decoder->setScale always returns 1
{
resize( *mat, *mat, Size( size.width / scale_denom, size.height / scale_denom ), 0, 0, INTER_LINEAR_EXACT);
resize( mat, mat, Size( size.width / scale_denom, size.height / scale_denom ), 0, 0, INTER_LINEAR_EXACT);
}
return hdrtype == LOAD_CVMAT ? (void*)matrix :
hdrtype == LOAD_IMAGE ? (void*)image : (void*)mat;
return true;
}
@@ -650,7 +621,7 @@ Mat imread( const String& filename, int flags )
Mat img;
/// load the data
imread_( filename, flags, LOAD_MAT, &img );
imread_( filename, flags, img );
/// optionally rotate the data if EXIF' orientation flag says so
if( !img.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
@@ -687,7 +658,7 @@ static bool imwrite_( const String& filename, const std::vector<Mat>& img_vec,
ImageEncoder encoder = findEncoder( filename );
if( !encoder )
CV_Error( CV_StsError, "could not find a writer for the specified extension" );
CV_Error( Error::StsError, "could not find a writer for the specified extension" );
for (size_t page = 0; page < img_vec.size(); page++)
{
@@ -748,13 +719,10 @@ bool imwrite( const String& filename, InputArray _img,
return imwrite_(filename, img_vec, params, false);
}
static void*
imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
static bool
imdecode_( const Mat& buf, int flags, Mat& mat )
{
CV_Assert(!buf.empty() && buf.isContinuous());
IplImage* image = 0;
CvMat *matrix = 0;
Mat temp, *data = &temp;
String filename;
ImageDecoder decoder = findDecoder(buf);
@@ -771,11 +739,11 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
if( fwrite( buf.ptr(), 1, bufSize, f ) != bufSize )
{
fclose( f );
CV_Error( CV_StsError, "failed to write image data to temporary file" );
CV_Error( Error::StsError, "failed to write image data to temporary file" );
}
if( fclose(f) != 0 )
{
CV_Error( CV_StsError, "failed to write image data to temporary file" );
CV_Error( Error::StsError, "failed to write image data to temporary file" );
}
decoder->setSource(filename);
}
@@ -823,29 +791,12 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1);
}
if( hdrtype == LOAD_CVMAT || hdrtype == LOAD_MAT )
{
if( hdrtype == LOAD_CVMAT )
{
matrix = cvCreateMat( size.height, size.width, type );
temp = cvarrToMat(matrix);
}
else
{
mat->create( size.height, size.width, type );
data = mat;
}
}
else
{
image = cvCreateImage(cvSize(size), cvIplDepth(type), CV_MAT_CN(type));
temp = cvarrToMat(image);
}
mat.create( size.height, size.width, type );
success = false;
CV_TRY
{
if (decoder->readData(*data))
if (decoder->readData(mat))
success = true;
}
CV_CATCH (cv::Exception, e)
@@ -867,15 +818,11 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
if (!success)
{
cvReleaseImage( &image );
cvReleaseMat( &matrix );
if( mat )
mat->release();
return 0;
mat.release();
return false;
}
return hdrtype == LOAD_CVMAT ? (void*)matrix :
hdrtype == LOAD_IMAGE ? (void*)image : (void*)mat;
return true;
}
@@ -884,7 +831,7 @@ Mat imdecode( InputArray _buf, int flags )
CV_TRACE_FUNCTION();
Mat buf = _buf.getMat(), img;
imdecode_( buf, flags, LOAD_MAT, &img );
imdecode_( buf, flags, img );
/// optionally rotate the data if EXIF' orientation flag says so
if( !img.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
@@ -901,7 +848,7 @@ Mat imdecode( InputArray _buf, int flags, Mat* dst )
Mat buf = _buf.getMat(), img;
dst = dst ? dst : &img;
imdecode_( buf, flags, LOAD_MAT, dst );
imdecode_( buf, flags, *dst );
/// optionally rotate the data if EXIF' orientation flag says so
if( !dst->empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED )
@@ -924,7 +871,7 @@ bool imencode( const String& ext, InputArray _image,
ImageEncoder encoder = findEncoder( ext );
if( !encoder )
CV_Error( CV_StsError, "could not find encoder for the specified extension" );
CV_Error( Error::StsError, "could not find encoder for the specified extension" );
if( !encoder->isFormatSupported(image.depth()) )
{
@@ -964,94 +911,18 @@ bool imencode( const String& ext, InputArray _image,
return code;
}
}
/****************************************************************************************\
* Imgcodecs loading & saving function implementation *
\****************************************************************************************/
CV_IMPL int
cvHaveImageReader( const char* filename )
bool haveImageReader( const String& filename )
{
cv::ImageDecoder decoder = cv::findDecoder(filename);
ImageDecoder decoder = cv::findDecoder(filename);
return !decoder.empty();
}
CV_IMPL int cvHaveImageWriter( const char* filename )
bool haveImageWriter( const String& filename )
{
cv::ImageEncoder encoder = cv::findEncoder(filename);
return !encoder.empty();
}
CV_IMPL IplImage*
cvLoadImage( const char* filename, int iscolor )
{
return (IplImage*)cv::imread_(filename, iscolor, cv::LOAD_IMAGE );
}
CV_IMPL CvMat*
cvLoadImageM( const char* filename, int iscolor )
{
return (CvMat*)cv::imread_( filename, iscolor, cv::LOAD_CVMAT );
}
CV_IMPL int
cvSaveImage( const char* filename, const CvArr* arr, const int* _params )
{
int i = 0;
if( _params )
{
for( ; _params[i] > 0; i += 2 )
CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
}
return cv::imwrite_(filename, cv::cvarrToMat(arr),
i > 0 ? std::vector<int>(_params, _params+i) : std::vector<int>(),
CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL );
}
/* decode image stored in the buffer */
CV_IMPL IplImage*
cvDecodeImage( const CvMat* _buf, int iscolor )
{
CV_Assert( _buf && CV_IS_MAT_CONT(_buf->type) );
cv::Mat buf(1, _buf->rows*_buf->cols*CV_ELEM_SIZE(_buf->type), CV_8U, _buf->data.ptr);
return (IplImage*)cv::imdecode_(buf, iscolor, cv::LOAD_IMAGE );
}
CV_IMPL CvMat*
cvDecodeImageM( const CvMat* _buf, int iscolor )
{
CV_Assert( _buf && CV_IS_MAT_CONT(_buf->type) );
cv::Mat buf(1, _buf->rows*_buf->cols*CV_ELEM_SIZE(_buf->type), CV_8U, _buf->data.ptr);
return (CvMat*)cv::imdecode_(buf, iscolor, cv::LOAD_CVMAT );
}
CV_IMPL CvMat*
cvEncodeImage( const char* ext, const CvArr* arr, const int* _params )
{
int i = 0;
if( _params )
{
for( ; _params[i] > 0; i += 2 )
CV_Assert(i < CV_IO_MAX_IMAGE_PARAMS*2); // Limit number of params for security reasons
}
cv::Mat img = cv::cvarrToMat(arr);
if( CV_IS_IMAGE(arr) && ((const IplImage*)arr)->origin == IPL_ORIGIN_BL )
{
cv::Mat temp;
cv::flip(img, temp, 0);
img = temp;
}
std::vector<uchar> buf;
bool code = cv::imencode(ext, img, buf,
i > 0 ? std::vector<int>(_params, _params+i) : std::vector<int>() );
if( !code )
return 0;
CvMat* _buf = cvCreateMat(1, (int)buf.size(), CV_8U);
memcpy( _buf->data.ptr, &buf[0], buf.size() );
return _buf;
}
/* End of file. */
-2
View File
@@ -48,8 +48,6 @@
#include "opencv2/core/private.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgcodecs/imgcodecs_c.h"
#include <stdlib.h>
#include <stdio.h>
+21 -117
View File
@@ -42,6 +42,9 @@
#include "precomp.hpp"
#include "utils.hpp"
namespace cv
{
int validateToInt(size_t sz)
{
int valueInt = (int)sz;
@@ -56,7 +59,7 @@ int validateToInt(size_t sz)
void icvCvt_BGR2Gray_8u_C3C1R( const uchar* rgb, int rgb_step,
uchar* gray, int gray_step,
CvSize size, int _swap_rb )
Size size, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
@@ -75,7 +78,7 @@ void icvCvt_BGR2Gray_8u_C3C1R( const uchar* rgb, int rgb_step,
void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* rgb, int rgb_step,
ushort* gray, int gray_step,
CvSize size, int ncn, int _swap_rb )
Size size, int ncn, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
@@ -94,7 +97,7 @@ void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* rgb, int rgb_step,
void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* rgba, int rgba_step,
uchar* gray, int gray_step,
CvSize size, int _swap_rb )
Size size, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
@@ -112,7 +115,7 @@ void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* rgba, int rgba_step,
void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
uchar* bgr, int bgr_step, CvSize size )
uchar* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; gray += gray_step )
@@ -127,7 +130,7 @@ void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step,
ushort* bgr, int bgr_step, CvSize size )
ushort* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; gray += gray_step/sizeof(gray[0]) )
@@ -143,7 +146,7 @@ void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step,
void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
uchar* bgr, int bgr_step,
CvSize size, int _swap_rb )
Size size, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
@@ -163,7 +166,7 @@ void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step,
ushort* bgr, int bgr_step,
CvSize size, int _swap_rb )
Size size, int _swap_rb )
{
int i;
int swap_rb = _swap_rb ? 2 : 0;
@@ -182,7 +185,7 @@ void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step,
void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
uchar* rgba, int rgba_step, CvSize size )
uchar* rgba, int rgba_step, Size size )
{
int i;
for( ; size.height--; )
@@ -200,7 +203,7 @@ void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
}
void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step,
ushort* rgba, int rgba_step, CvSize size )
ushort* rgba, int rgba_step, Size size )
{
int i;
for( ; size.height--; )
@@ -220,7 +223,7 @@ void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step,
void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
uchar* rgb, int rgb_step, CvSize size )
uchar* rgb, int rgb_step, Size size )
{
int i;
for( ; size.height--; )
@@ -237,7 +240,7 @@ void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
ushort* rgb, int rgb_step, CvSize size )
ushort* rgb, int rgb_step, Size size )
{
int i;
for( ; size.height--; )
@@ -256,7 +259,7 @@ void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
typedef unsigned short ushort;
void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
uchar* gray, int gray_step, CvSize size )
uchar* gray, int gray_step, Size size )
{
int i;
for( ; size.height--; gray += gray_step, bgr555 += bgr555_step )
@@ -273,7 +276,7 @@ void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
uchar* gray, int gray_step, CvSize size )
uchar* gray, int gray_step, Size size )
{
int i;
for( ; size.height--; gray += gray_step, bgr565 += bgr565_step )
@@ -290,7 +293,7 @@ void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
uchar* bgr, int bgr_step, CvSize size )
uchar* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; bgr555 += bgr555_step )
@@ -308,7 +311,7 @@ void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
uchar* bgr, int bgr_step, CvSize size )
uchar* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; bgr565 += bgr565_step )
@@ -326,7 +329,7 @@ void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
uchar* bgr, int bgr_step, CvSize size )
uchar* bgr, int bgr_step, Size size )
{
int i;
for( ; size.height--; )
@@ -346,7 +349,7 @@ void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* cmyk, int cmyk_step,
uchar* gray, int gray_step, CvSize size )
uchar* gray, int gray_step, Size size )
{
int i;
for( ; size.height--; )
@@ -371,7 +374,7 @@ void CvtPaletteToGray( const PaletteEntry* palette, uchar* grayPalette, int entr
int i;
for( i = 0; i < entries; i++ )
{
icvCvt_BGR2Gray_8u_C3C1R( (uchar*)(palette + i), 0, grayPalette + i, 0, cvSize(1,1) );
icvCvt_BGR2Gray_8u_C3C1R( (uchar*)(palette + i), 0, grayPalette + i, 0, Size(1,1) );
}
}
@@ -598,103 +601,4 @@ uchar* FillGrayRow1( uchar* data, uchar* indices, int len, uchar* palette )
return data;
}
CV_IMPL void
cvConvertImage( const CvArr* srcarr, CvArr* dstarr, int flags )
{
CvMat* temp = 0;
CV_FUNCNAME( "cvConvertImage" );
__BEGIN__;
CvMat srcstub, *src;
CvMat dststub, *dst;
int src_cn, dst_cn, swap_rb = flags & CV_CVTIMG_SWAP_RB;
CV_CALL( src = cvGetMat( srcarr, &srcstub ));
CV_CALL( dst = cvGetMat( dstarr, &dststub ));
src_cn = CV_MAT_CN( src->type );
dst_cn = CV_MAT_CN( dst->type );
if( src_cn != 1 && src_cn != 3 && src_cn != 4 )
CV_ERROR( CV_BadNumChannels, "Source image must have 1, 3 or 4 channels" );
if( CV_MAT_DEPTH( dst->type ) != CV_8U )
CV_ERROR( CV_BadDepth, "Destination image must be 8u" );
if( CV_MAT_CN(dst->type) != 1 && CV_MAT_CN(dst->type) != 3 )
CV_ERROR( CV_BadNumChannels, "Destination image must have 1 or 3 channels" );
if( !CV_ARE_DEPTHS_EQ( src, dst ))
{
int src_depth = CV_MAT_DEPTH(src->type);
double scale = src_depth <= CV_8S ? 1 : src_depth <= CV_32S ? 1./256 : 255;
double shift = src_depth == CV_8S || src_depth == CV_16S ? 128 : 0;
if( !CV_ARE_CNS_EQ( src, dst ))
{
temp = cvCreateMat( src->height, src->width,
(src->type & CV_MAT_CN_MASK)|(dst->type & CV_MAT_DEPTH_MASK));
cvConvertScale( src, temp, scale, shift );
src = temp;
}
else
{
cvConvertScale( src, dst, scale, shift );
src = dst;
}
}
if( src_cn != dst_cn || (src_cn == 3 && swap_rb) )
{
uchar *s = src->data.ptr, *d = dst->data.ptr;
int s_step = src->step, d_step = dst->step;
int code = src_cn*10 + dst_cn;
CvSize size = {src->cols, src->rows};
if( CV_IS_MAT_CONT(src->type & dst->type) )
{
size.width *= size.height;
size.height = 1;
s_step = d_step = /*CV_STUB_STEP*/ (1 << 30);
}
switch( code )
{
case 13:
icvCvt_Gray2BGR_8u_C1C3R( s, s_step, d, d_step, size );
break;
case 31:
icvCvt_BGR2Gray_8u_C3C1R( s, s_step, d, d_step, size, swap_rb );
break;
case 33:
CV_Assert(swap_rb);
icvCvt_RGB2BGR_8u_C3R( s, s_step, d, d_step, size );
break;
case 41:
icvCvt_BGRA2Gray_8u_C4C1R( s, s_step, d, d_step, size, swap_rb );
break;
case 43:
icvCvt_BGRA2BGR_8u_C4C3R( s, s_step, d, d_step, size, swap_rb );
break;
default:
CV_ERROR( CV_StsUnsupportedFormat, "Unsupported combination of input/output formats" );
}
src = dst;
}
if( flags & CV_CVTIMG_FLIP )
{
CV_CALL( cvFlip( src, dst, 0 ));
}
else if( src != dst )
{
CV_CALL( cvCopy( src, dst ));
}
__END__;
cvReleaseMat( &temp );
}
+22 -17
View File
@@ -42,6 +42,9 @@
#ifndef _UTILS_H_
#define _UTILS_H_
namespace cv
{
int validateToInt(size_t step);
template <typename _Tp> static inline
@@ -68,53 +71,53 @@ struct PaletteEntry
void icvCvt_BGR2Gray_8u_C3C1R( const uchar* bgr, int bgr_step,
uchar* gray, int gray_step,
CvSize size, int swap_rb=0 );
Size size, int swap_rb=0 );
void icvCvt_BGRA2Gray_8u_C4C1R( const uchar* bgra, int bgra_step,
uchar* gray, int gray_step,
CvSize size, int swap_rb=0 );
Size size, int swap_rb=0 );
void icvCvt_BGRA2Gray_16u_CnC1R( const ushort* bgra, int bgra_step,
ushort* gray, int gray_step,
CvSize size, int ncn, int swap_rb=0 );
Size size, int ncn, int swap_rb=0 );
void icvCvt_Gray2BGR_8u_C1C3R( const uchar* gray, int gray_step,
uchar* bgr, int bgr_step, CvSize size );
uchar* bgr, int bgr_step, Size size );
void icvCvt_Gray2BGR_16u_C1C3R( const ushort* gray, int gray_step,
ushort* bgr, int bgr_step, CvSize size );
ushort* bgr, int bgr_step, Size size );
void icvCvt_BGRA2BGR_8u_C4C3R( const uchar* bgra, int bgra_step,
uchar* bgr, int bgr_step,
CvSize size, int swap_rb=0 );
Size size, int swap_rb=0 );
void icvCvt_BGRA2BGR_16u_C4C3R( const ushort* bgra, int bgra_step,
ushort* bgr, int bgr_step,
CvSize size, int _swap_rb );
Size size, int _swap_rb );
void icvCvt_BGR2RGB_8u_C3R( const uchar* bgr, int bgr_step,
uchar* rgb, int rgb_step, CvSize size );
uchar* rgb, int rgb_step, Size size );
#define icvCvt_RGB2BGR_8u_C3R icvCvt_BGR2RGB_8u_C3R
void icvCvt_BGR2RGB_16u_C3R( const ushort* bgr, int bgr_step,
ushort* rgb, int rgb_step, CvSize size );
ushort* rgb, int rgb_step, Size size );
#define icvCvt_RGB2BGR_16u_C3R icvCvt_BGR2RGB_16u_C3R
void icvCvt_BGRA2RGBA_8u_C4R( const uchar* bgra, int bgra_step,
uchar* rgba, int rgba_step, CvSize size );
uchar* rgba, int rgba_step, Size size );
#define icvCvt_RGBA2BGRA_8u_C4R icvCvt_BGRA2RGBA_8u_C4R
void icvCvt_BGRA2RGBA_16u_C4R( const ushort* bgra, int bgra_step,
ushort* rgba, int rgba_step, CvSize size );
ushort* rgba, int rgba_step, Size size );
#define icvCvt_RGBA2BGRA_16u_C4R icvCvt_BGRA2RGBA_16u_C4R
void icvCvt_BGR5552Gray_8u_C2C1R( const uchar* bgr555, int bgr555_step,
uchar* gray, int gray_step, CvSize size );
uchar* gray, int gray_step, Size size );
void icvCvt_BGR5652Gray_8u_C2C1R( const uchar* bgr565, int bgr565_step,
uchar* gray, int gray_step, CvSize size );
uchar* gray, int gray_step, Size size );
void icvCvt_BGR5552BGR_8u_C2C3R( const uchar* bgr555, int bgr555_step,
uchar* bgr, int bgr_step, CvSize size );
uchar* bgr, int bgr_step, Size size );
void icvCvt_BGR5652BGR_8u_C2C3R( const uchar* bgr565, int bgr565_step,
uchar* bgr, int bgr_step, CvSize size );
uchar* bgr, int bgr_step, Size size );
void icvCvt_CMYK2BGR_8u_C4C3R( const uchar* cmyk, int cmyk_step,
uchar* bgr, int bgr_step, CvSize size );
uchar* bgr, int bgr_step, Size size );
void icvCvt_CMYK2Gray_8u_C4C1R( const uchar* ycck, int ycck_step,
uchar* gray, int gray_step, CvSize size );
uchar* gray, int gray_step, Size size );
void FillGrayPalette( PaletteEntry* palette, int bpp, bool negative = false );
bool IsColorPalette( PaletteEntry* palette, int bpp );
@@ -136,4 +139,6 @@ CV_INLINE bool isBigEndian( void )
return (((const int*)"\0\x1\x2\x3\x4\x5\x6\x7")[0] & 255) != 0;
}
}
#endif/*_UTILS_H_*/