mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Several type of formal refactoring:
1. someMatrix.data -> someMatrix.prt() 2. someMatrix.data + someMatrix.step * lineIndex -> someMatrix.ptr( lineIndex ) 3. (SomeType*) someMatrix.data -> someMatrix.ptr<SomeType>() 4. someMatrix.data -> !someMatrix.empty() ( or !someMatrix.data -> someMatrix.empty() ) in logical expressions
This commit is contained in:
@@ -183,7 +183,7 @@ bool BmpDecoder::readHeader()
|
||||
|
||||
bool BmpDecoder::readData( Mat& img )
|
||||
{
|
||||
uchar* data = img.data;
|
||||
uchar* data = img.ptr();
|
||||
int step = (int)img.step;
|
||||
bool color = img.channels() > 1;
|
||||
uchar gray_palette[256];
|
||||
@@ -553,7 +553,7 @@ bool BmpEncoder::write( const Mat& img, const std::vector<int>& )
|
||||
width *= channels;
|
||||
for( int y = height - 1; y >= 0; y-- )
|
||||
{
|
||||
strm.putBytes( img.data + img.step*y, width );
|
||||
strm.putBytes( img.ptr(y), width );
|
||||
if( fileStep > width )
|
||||
strm.putBytes( zeropad, fileStep - width );
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ bool ExrDecoder::readData( Mat& img )
|
||||
m_native_depth = CV_MAT_DEPTH(type()) == img.depth();
|
||||
bool color = img.channels() > 1;
|
||||
|
||||
uchar* data = img.data;
|
||||
uchar* data = img.ptr();
|
||||
int step = img.step;
|
||||
bool justcopy = m_native_depth;
|
||||
bool chromatorgb = false;
|
||||
@@ -583,8 +583,7 @@ bool ExrEncoder::write( const Mat& img, const std::vector<int>& )
|
||||
bool issigned = depth == CV_8S || depth == CV_16S || depth == CV_32S;
|
||||
bool isfloat = depth == CV_32F || depth == CV_64F;
|
||||
depth = CV_ELEM_SIZE1(depth)*8;
|
||||
uchar* data = img.data;
|
||||
int step = img.step;
|
||||
const int step = img.step;
|
||||
|
||||
Header header( width, height );
|
||||
Imf::PixelType type;
|
||||
@@ -618,7 +617,7 @@ bool ExrEncoder::write( const Mat& img, const std::vector<int>& )
|
||||
int size;
|
||||
if( type == FLOAT && depth == 32 )
|
||||
{
|
||||
buffer = (char *)const_cast<uchar *>(data);
|
||||
buffer = (char *)const_cast<uchar *>(img.ptr());
|
||||
bufferstep = step;
|
||||
size = 4;
|
||||
}
|
||||
@@ -674,18 +673,19 @@ bool ExrEncoder::write( const Mat& img, const std::vector<int>& )
|
||||
|
||||
if( depth <= 8 )
|
||||
{
|
||||
const uchar* sd = img.ptr(line);
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = data[i] + offset;
|
||||
buf[i] = sd[i] + offset;
|
||||
}
|
||||
else if( depth <= 16 )
|
||||
{
|
||||
unsigned short *sd = (unsigned short *)data;
|
||||
const unsigned short *sd = img.ptr<unsigned short>(line);
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = sd[i] + offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
int *sd = (int *)data; // FIXME 64-bit problems
|
||||
const int *sd = img.ptr<int>(line); // FIXME 64-bit problems
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = (unsigned) sd[i] + offset;
|
||||
}
|
||||
@@ -696,12 +696,13 @@ bool ExrEncoder::write( const Mat& img, const std::vector<int>& )
|
||||
|
||||
if( depth <= 8 )
|
||||
{
|
||||
const uchar* sd = img.ptr(line);
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = data[i];
|
||||
buf[i] = sd[i];
|
||||
}
|
||||
else if( depth <= 16 )
|
||||
{
|
||||
unsigned short *sd = (unsigned short *)data;
|
||||
const unsigned short *sd = img.ptr<unsigned short>(line);
|
||||
for(int i = 0; i < width * channels; i++)
|
||||
buf[i] = sd[i];
|
||||
}
|
||||
@@ -715,7 +716,6 @@ bool ExrEncoder::write( const Mat& img, const std::vector<int>& )
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
data += step;
|
||||
}
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ bool JpegDecoder::readHeader()
|
||||
if( !m_buf.empty() )
|
||||
{
|
||||
jpeg_buffer_src(&state->cinfo, &state->source);
|
||||
state->source.pub.next_input_byte = m_buf.data;
|
||||
state->source.pub.next_input_byte = m_buf.ptr();
|
||||
state->source.pub.bytes_in_buffer = m_buf.cols*m_buf.rows*m_buf.elemSize();
|
||||
}
|
||||
else
|
||||
@@ -449,7 +449,7 @@ bool JpegDecoder::readData( Mat& img )
|
||||
buffer = (*cinfo->mem->alloc_sarray)((j_common_ptr)cinfo,
|
||||
JPOOL_IMAGE, m_width*4, 1 );
|
||||
|
||||
uchar* data = img.data;
|
||||
uchar* data = img.ptr();
|
||||
for( ; m_height--; data += step )
|
||||
{
|
||||
jpeg_read_scanlines( cinfo, buffer, 1 );
|
||||
|
||||
@@ -134,7 +134,7 @@ void PngDecoder::readDataFromBuf( void* _png_ptr, uchar* dst, size_t size )
|
||||
png_error(png_ptr, "PNG input buffer is incomplete");
|
||||
return;
|
||||
}
|
||||
memcpy( dst, &decoder->m_buf.data[decoder->m_buf_pos], size );
|
||||
memcpy( dst, decoder->m_buf.ptr() + decoder->m_buf_pos, size );
|
||||
decoder->m_buf_pos += size;
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ bool PngDecoder::readData( Mat& img )
|
||||
AutoBuffer<uchar*> _buffer(m_height);
|
||||
uchar** buffer = _buffer;
|
||||
int color = img.channels() > 1;
|
||||
uchar* data = img.data;
|
||||
uchar* data = img.ptr();
|
||||
int step = (int)img.step;
|
||||
|
||||
if( m_png_ptr && m_info_ptr && m_end_info && m_width && m_height )
|
||||
|
||||
@@ -189,7 +189,7 @@ bool PxMDecoder::readHeader()
|
||||
bool PxMDecoder::readData( Mat& img )
|
||||
{
|
||||
int color = img.channels() > 1;
|
||||
uchar* data = img.data;
|
||||
uchar* data = img.ptr();
|
||||
int step = (int)img.step;
|
||||
PaletteEntry palette[256];
|
||||
bool result = false;
|
||||
@@ -418,16 +418,16 @@ bool PxMEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
|
||||
for( y = 0; y < height; y++ )
|
||||
{
|
||||
uchar* data = img.data + img.step*y;
|
||||
const uchar* const data = img.ptr(y);
|
||||
if( isBinary )
|
||||
{
|
||||
if( _channels == 3 )
|
||||
{
|
||||
if( depth == 8 )
|
||||
icvCvt_BGR2RGB_8u_C3R( (uchar*)data, 0,
|
||||
icvCvt_BGR2RGB_8u_C3R( (const uchar*)data, 0,
|
||||
(uchar*)buffer, 0, cvSize(width,1) );
|
||||
else
|
||||
icvCvt_BGR2RGB_16u_C3R( (ushort*)data, 0,
|
||||
icvCvt_BGR2RGB_16u_C3R( (const ushort*)data, 0,
|
||||
(ushort*)buffer, 0, cvSize(width,1) );
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ bool PxMEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
buffer[x + 1] = v;
|
||||
}
|
||||
}
|
||||
strm.putBytes( (channels > 1 || depth > 8) ? buffer : (char*)data, fileStep );
|
||||
strm.putBytes( (channels > 1 || depth > 8) ? buffer : (const char*)data, fileStep );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -469,11 +469,11 @@ bool PxMEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
{
|
||||
for( x = 0; x < width*channels; x += channels )
|
||||
{
|
||||
sprintf( ptr, "% 6d", ((ushort *)data)[x + 2] );
|
||||
sprintf( ptr, "% 6d", ((const ushort *)data)[x + 2] );
|
||||
ptr += 6;
|
||||
sprintf( ptr, "% 6d", ((ushort *)data)[x + 1] );
|
||||
sprintf( ptr, "% 6d", ((const ushort *)data)[x + 1] );
|
||||
ptr += 6;
|
||||
sprintf( ptr, "% 6d", ((ushort *)data)[x] );
|
||||
sprintf( ptr, "% 6d", ((const ushort *)data)[x] );
|
||||
ptr += 6;
|
||||
*ptr++ = ' ';
|
||||
*ptr++ = ' ';
|
||||
@@ -494,7 +494,7 @@ bool PxMEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
{
|
||||
for( x = 0; x < width; x++ )
|
||||
{
|
||||
sprintf( ptr, "% 6d", ((ushort *)data)[x] );
|
||||
sprintf( ptr, "% 6d", ((const ushort *)data)[x] );
|
||||
ptr += 6;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ bool SunRasterDecoder::readHeader()
|
||||
bool SunRasterDecoder::readData( Mat& img )
|
||||
{
|
||||
int color = img.channels() > 1;
|
||||
uchar* data = img.data;
|
||||
uchar* data = img.ptr();
|
||||
int step = (int)img.step;
|
||||
uchar gray_palette[256];
|
||||
bool result = false;
|
||||
@@ -414,7 +414,7 @@ bool SunRasterEncoder::write( const Mat& img, const std::vector<int>& )
|
||||
strm.putDWord( 0 );
|
||||
|
||||
for( y = 0; y < height; y++ )
|
||||
strm.putBytes( img.data + img.step*y, fileStep );
|
||||
strm.putBytes( img.ptr(y), fileStep );
|
||||
|
||||
strm.close();
|
||||
result = true;
|
||||
|
||||
@@ -190,7 +190,7 @@ bool TiffDecoder::readData( Mat& img )
|
||||
}
|
||||
bool result = false;
|
||||
bool color = img.channels() > 1;
|
||||
uchar* data = img.data;
|
||||
uchar* data = img.ptr();
|
||||
|
||||
if( img.depth() != CV_8U && img.depth() != CV_16U && img.depth() != CV_32F && img.depth() != CV_64F )
|
||||
return false;
|
||||
@@ -587,25 +587,25 @@ bool TiffEncoder::writeLibTiff( const Mat& img, const std::vector<int>& params)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
memcpy(buffer, img.data + img.step * y, scanlineSize);
|
||||
memcpy(buffer, img.ptr(y), scanlineSize);
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
{
|
||||
if (depth == CV_8U)
|
||||
icvCvt_BGR2RGB_8u_C3R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) );
|
||||
icvCvt_BGR2RGB_8u_C3R( img.ptr(y), 0, buffer, 0, cvSize(width,1) );
|
||||
else
|
||||
icvCvt_BGR2RGB_16u_C3R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) );
|
||||
icvCvt_BGR2RGB_16u_C3R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, cvSize(width,1) );
|
||||
break;
|
||||
}
|
||||
|
||||
case 4:
|
||||
{
|
||||
if (depth == CV_8U)
|
||||
icvCvt_BGRA2RGBA_8u_C4R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) );
|
||||
icvCvt_BGRA2RGBA_8u_C4R( img.ptr(y), 0, buffer, 0, cvSize(width,1) );
|
||||
else
|
||||
icvCvt_BGRA2RGBA_16u_C4R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) );
|
||||
icvCvt_BGRA2RGBA_16u_C4R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, cvSize(width,1) );
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -742,22 +742,22 @@ bool TiffEncoder::write( const Mat& img, const std::vector<int>& /*params*/)
|
||||
if( channels == 3 )
|
||||
{
|
||||
if (depth == CV_8U)
|
||||
icvCvt_BGR2RGB_8u_C3R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) );
|
||||
icvCvt_BGR2RGB_8u_C3R( img.ptr(y), 0, buffer, 0, cvSize(width,1) );
|
||||
else
|
||||
icvCvt_BGR2RGB_16u_C3R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) );
|
||||
icvCvt_BGR2RGB_16u_C3R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, cvSize(width,1) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( channels == 4 )
|
||||
{
|
||||
if (depth == CV_8U)
|
||||
icvCvt_BGRA2RGBA_8u_C4R( img.data + img.step*y, 0, buffer, 0, cvSize(width,1) );
|
||||
icvCvt_BGRA2RGBA_8u_C4R( img.ptr(y), 0, buffer, 0, cvSize(width,1) );
|
||||
else
|
||||
icvCvt_BGRA2RGBA_16u_C4R( (const ushort*)(img.data + img.step*y), 0, (ushort*)buffer, 0, cvSize(width,1) );
|
||||
icvCvt_BGRA2RGBA_16u_C4R( img.ptr<ushort>(y), 0, (ushort*)buffer, 0, cvSize(width,1) );
|
||||
}
|
||||
}
|
||||
|
||||
strm.putBytes( channels > 1 ? buffer : img.data + img.step*y, fileStep );
|
||||
strm.putBytes( channels > 1 ? buffer : img.ptr(y), fileStep );
|
||||
}
|
||||
|
||||
stripCounts[i] = (short)(strm.getPos() - stripOffsets[i]);
|
||||
|
||||
@@ -118,7 +118,7 @@ bool WebPDecoder::readHeader()
|
||||
|
||||
data.create(1, wfile_size, CV_8U);
|
||||
|
||||
size_t data_size = fread(data.data, 1, wfile_size, wfile);
|
||||
size_t data_size = fread(data.ptr(), 1, wfile_size, wfile);
|
||||
|
||||
if(wfile)
|
||||
{
|
||||
@@ -136,7 +136,7 @@ bool WebPDecoder::readHeader()
|
||||
}
|
||||
|
||||
WebPBitstreamFeatures features;
|
||||
if(VP8_STATUS_OK == WebPGetFeatures(data.data, WEBP_HEADER_SIZE, &features))
|
||||
if(VP8_STATUS_OK == WebPGetFeatures(data.ptr(), WEBP_HEADER_SIZE, &features))
|
||||
{
|
||||
m_width = features.width;
|
||||
m_height = features.height;
|
||||
@@ -167,18 +167,18 @@ bool WebPDecoder::readData(Mat &img)
|
||||
img.create(m_height, m_width, m_type);
|
||||
}
|
||||
|
||||
uchar* out_data = img.data;
|
||||
uchar* out_data = img.ptr();
|
||||
size_t out_data_size = img.cols * img.rows * img.elemSize();
|
||||
|
||||
uchar *res_ptr = 0;
|
||||
if (channels == 3)
|
||||
{
|
||||
res_ptr = WebPDecodeBGRInto(data.data, data.total(), out_data,
|
||||
res_ptr = WebPDecodeBGRInto(data.ptr(), data.total(), out_data,
|
||||
(int)out_data_size, (int)img.step);
|
||||
}
|
||||
else if (channels == 4)
|
||||
{
|
||||
res_ptr = WebPDecodeBGRAInto(data.data, data.total(), out_data,
|
||||
res_ptr = WebPDecodeBGRAInto(data.ptr(), data.total(), out_data,
|
||||
(int)out_data_size, (int)img.step);
|
||||
}
|
||||
|
||||
@@ -255,22 +255,22 @@ bool WebPEncoder::write(const Mat& img, const std::vector<int>& params)
|
||||
{
|
||||
if(channels == 3)
|
||||
{
|
||||
size = WebPEncodeLosslessBGR(image->data, width, height, (int)image->step, &out);
|
||||
size = WebPEncodeLosslessBGR(image->ptr(), width, height, (int)image->step, &out);
|
||||
}
|
||||
else if(channels == 4)
|
||||
{
|
||||
size = WebPEncodeLosslessBGRA(image->data, width, height, (int)image->step, &out);
|
||||
size = WebPEncodeLosslessBGRA(image->ptr(), width, height, (int)image->step, &out);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(channels == 3)
|
||||
{
|
||||
size = WebPEncodeBGR(image->data, width, height, (int)image->step, quality, &out);
|
||||
size = WebPEncodeBGR(image->ptr(), width, height, (int)image->step, quality, &out);
|
||||
}
|
||||
else if(channels == 4)
|
||||
{
|
||||
size = WebPEncodeBGRA(image->data, width, height, (int)image->step, quality, &out);
|
||||
size = WebPEncodeBGRA(image->ptr(), width, height, (int)image->step, quality, &out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -303,7 +303,7 @@ bool imwrite( const String& filename, InputArray _img,
|
||||
static void*
|
||||
imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
|
||||
{
|
||||
CV_Assert(buf.data && buf.isContinuous());
|
||||
CV_Assert(!buf.empty() && buf.isContinuous());
|
||||
IplImage* image = 0;
|
||||
CvMat *matrix = 0;
|
||||
Mat temp, *data = &temp;
|
||||
@@ -320,7 +320,7 @@ imdecode_( const Mat& buf, int flags, int hdrtype, Mat* mat=0 )
|
||||
if( !f )
|
||||
return 0;
|
||||
size_t bufSize = buf.cols*buf.rows*buf.elemSize();
|
||||
fwrite( &buf.data[0], 1, bufSize, f );
|
||||
fwrite( buf.ptr(), 1, bufSize, f );
|
||||
fclose(f);
|
||||
decoder->setSource(filename);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user