本文整理汇总了C++中Image::DecodeJpeg方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::DecodeJpeg方法的具体用法?C++ Image::DecodeJpeg怎么用?C++ Image::DecodeJpeg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::DecodeJpeg方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Capture
int RemoteCameraHttp::Capture( Image &image )
{
int content_length = GetResponse();
if ( content_length == 0 )
{
Warning( "Unable to capture image, retrying" );
return( 1 );
}
if ( content_length < 0 )
{
Error( "Unable to get response" );
Disconnect();
return( -1 );
}
switch( format )
{
case JPEG :
{
if ( !image.DecodeJpeg( buffer.extract( content_length ), content_length, colours, subpixelorder ) )
{
Error( "Unable to decode jpeg" );
Disconnect();
return( -1 );
}
break;
}
case X_RGB :
{
if ( content_length != image.Size() )
{
Error( "Image length mismatch, expected %d bytes, content length was %d", image.Size(), content_length );
Disconnect();
return( -1 );
}
image.Assign( width, height, colours, subpixelorder, buffer, imagesize );
break;
}
case X_RGBZ :
{
if ( !image.Unzip( buffer.extract( content_length ), content_length ) )
{
Error( "Unable to unzip RGB image" );
Disconnect();
return( -1 );
}
image.Assign( width, height, colours, subpixelorder, buffer, imagesize );
break;
}
default :
{
Error( "Unexpected image format encountered" );
Disconnect();
return( -1 );
}
}
return( 0 );
}
示例2: Capture
//.........这里部分代码省略.........
/* Copy the subheader, excluding the crlf */
subheader.assign(databuffer, crlf_start);
/* Advance the buffer past this one */
databuffer.consume(crlf_start+crlf_size);
Debug(7,"Got subheader: %s",subheader.c_str());
/* Find where the data in this header starts */
size_t subheader_data_start = subheader.rfind(' ');
if ( subheader_data_start == std::string::npos ) {
subheader_data_start = subheader.find(':');
}
/* Extract the data into a string */
std::string subheader_data = subheader.substr(subheader_data_start+1, std::string::npos);
Debug(8,"Got subheader data: %s",subheader_data.c_str());
/* Check the header */
if(strncasecmp(subheader.c_str(),content_length_match,content_length_match_len) == 0) {
/* Found the content-length header */
frame_content_length = atoi(subheader_data.c_str());
Debug(6,"Got content-length subheader: %d",frame_content_length);
} else if(strncasecmp(subheader.c_str(),content_type_match,content_type_match_len) == 0) {
/* Found the content-type header */
frame_content_type = subheader_data;
Debug(6,"Got content-type subheader: %s",frame_content_type.c_str());
}
}
/* Attempt to extract the frame */
if(!need_more_data) {
if(!SubHeadersParsingComplete) {
/* We haven't parsed all headers yet */
need_more_data = true;
} else if ( ! frame_content_length ) {
/* Invalid frame */
Error("Invalid frame: invalid content length");
} else if ( frame_content_type != "image/jpeg" ) {
/* Unsupported frame type */
Error("Unsupported frame: %s",frame_content_type.c_str());
} else if(frame_content_length > databuffer.size()) {
/* Incomplete frame, wait for more data */
need_more_data = true;
} else {
/* All good. decode the image */
image.DecodeJpeg(databuffer.extract(frame_content_length), frame_content_length, colours, subpixelorder);
frameComplete = true;
}
}
/* Attempt to get more data */
if(need_more_data) {
nRet = pthread_cond_wait(&data_available_cond,&shareddata_mutex);
if(nRet != 0) {
Error("Failed waiting for available data condition variable: %s",strerror(nRet));
return -18;
}
need_more_data = false;
}
} else if(mode == MODE_SINGLE) {
/* Check if we have anything */
if (!single_offsets.empty()) {
if( (single_offsets.front() > 0) && (databuffer.size() >= single_offsets.front()) ) {
/* Extract frame */
image.DecodeJpeg(databuffer.extract(single_offsets.front()), single_offsets.front(), colours, subpixelorder);
single_offsets.pop_front();
frameComplete = true;
} else {
/* This shouldn't happen */
Error("Internal error. Attempting recovery");
databuffer.consume(single_offsets.front());
single_offsets.pop_front();
}
} else {
/* Don't have a frame yet, wait for the request complete condition variable */
nRet = pthread_cond_wait(&request_complete_cond,&shareddata_mutex);
if(nRet != 0) {
Error("Failed waiting for request complete condition variable: %s",strerror(nRet));
return -19;
}
}
} else {
/* Failed to match content-type */
Fatal("Unable to match Content-Type. Check URL, username and password");
} /* mode */
} /* frameComplete loop */
/* Release the mutex */
unlock();
if(!frameComplete)
return -1;
return 1;
}