Added IMREAD_IGNORE_ORIENTATION flag

This commit is contained in:
Arkadiusz Raj
2016-11-09 18:09:22 +01:00
parent 17ffb28807
commit f893ee5cec
8 changed files with 93 additions and 88 deletions
-62
View File
@@ -41,7 +41,6 @@
#include "precomp.hpp"
#include "grfmt_jpeg.hpp"
#include "jpeg_exif.hpp"
#ifdef HAVE_JPEG
@@ -178,7 +177,6 @@ JpegDecoder::JpegDecoder()
m_state = 0;
m_f = 0;
m_buf_supported = true;
m_orientation = JPEG_ORIENTATION_TL;
}
@@ -255,71 +253,12 @@ bool JpegDecoder::readHeader()
}
}
m_orientation = getOrientation();
if( !result )
close();
return result;
}
int JpegDecoder::getOrientation()
{
int orientation = JPEG_ORIENTATION_TL;
if (m_filename.size() > 0)
{
ExifReader reader( m_filename );
if( reader.parse() )
{
ExifEntry_t entry = reader.getTag( ORIENTATION );
if (entry.tag != INVALID_TAG)
{
orientation = entry.field_u16; //orientation is unsigned short, so check field_u16
}
}
}
return orientation;
}
void JpegDecoder::setOrientation(Mat& img)
{
switch( m_orientation )
{
case JPEG_ORIENTATION_TL: //0th row == visual top, 0th column == visual left-hand side
//do nothing, the image already has proper orientation
break;
case JPEG_ORIENTATION_TR: //0th row == visual top, 0th column == visual right-hand side
flip(img, img, 1); //flip horizontally
break;
case JPEG_ORIENTATION_BR: //0th row == visual bottom, 0th column == visual right-hand side
flip(img, img, -1);//flip both horizontally and vertically
break;
case JPEG_ORIENTATION_BL: //0th row == visual bottom, 0th column == visual left-hand side
flip(img, img, 0); //flip vertically
break;
case JPEG_ORIENTATION_LT: //0th row == visual left-hand side, 0th column == visual top
transpose(img, img);
break;
case JPEG_ORIENTATION_RT: //0th row == visual right-hand side, 0th column == visual top
transpose(img, img);
flip(img, img, 1); //flip horizontally
break;
case JPEG_ORIENTATION_RB: //0th row == visual right-hand side, 0th column == visual bottom
transpose(img, img);
flip(img, img, -1); //flip both horizontally and vertically
break;
case JPEG_ORIENTATION_LB: //0th row == visual left-hand side, 0th column == visual bottom
transpose(img, img);
flip(img, img, 0); //flip vertically
break;
default:
//by default the image read has normal (JPEG_ORIENTATION_TL) orientation
break;
}
}
/***************************************************************************
* following code is for supporting MJPEG image files
* based on a message of Laurent Pinchart on the video4linux mailing list
@@ -536,7 +475,6 @@ bool JpegDecoder::readData( Mat& img )
result = true;
jpeg_finish_decompress( cinfo );
setOrientation( img );
}
}