From 4a9c84c570917ad75e35e454c508018814c551e7 Mon Sep 17 00:00:00 2001 From: Arkadiusz Raj Date: Thu, 10 Nov 2016 15:04:28 +0100 Subject: [PATCH] Add static to local function --- modules/imgcodecs/src/loadsave.cpp | 109 ++++++++++++++--------------- 1 file changed, 53 insertions(+), 56 deletions(-) diff --git a/modules/imgcodecs/src/loadsave.cpp b/modules/imgcodecs/src/loadsave.cpp index 8c639333b2..1dd54abc57 100644 --- a/modules/imgcodecs/src/loadsave.cpp +++ b/modules/imgcodecs/src/loadsave.cpp @@ -232,7 +232,57 @@ static ImageEncoder findEncoder( const String& _ext ) enum { LOAD_CVMAT=0, LOAD_IMAGE=1, LOAD_MAT=2 }; -void RotateImage(const String& filename, Mat& img); +static void RotateImage(const String& filename, Mat& img) +{ + int orientation = IMAGE_ORIENTATION_TL; + + if (filename.size() > 0) + { + ExifReader reader( 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 + } + } + } + + switch( orientation ) + { + case IMAGE_ORIENTATION_TL: //0th row == visual top, 0th column == visual left-hand side + //do nothing, the image already has proper orientation + break; + case IMAGE_ORIENTATION_TR: //0th row == visual top, 0th column == visual right-hand side + flip(img, img, 1); //flip horizontally + break; + case IMAGE_ORIENTATION_BR: //0th row == visual bottom, 0th column == visual right-hand side + flip(img, img, -1);//flip both horizontally and vertically + break; + case IMAGE_ORIENTATION_BL: //0th row == visual bottom, 0th column == visual left-hand side + flip(img, img, 0); //flip vertically + break; + case IMAGE_ORIENTATION_LT: //0th row == visual left-hand side, 0th column == visual top + transpose(img, img); + break; + case IMAGE_ORIENTATION_RT: //0th row == visual right-hand side, 0th column == visual top + transpose(img, img); + flip(img, img, 1); //flip horizontally + break; + case IMAGE_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 IMAGE_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; + } +} /** * Read an image into memory and return the information @@ -409,7 +459,7 @@ imreadmulti_(const String& filename, int flags, std::vector& mats) if (!decoder->readData(mat)) { // optionally rotate the data if EXIF' orientation flag says so - if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 ) + if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) { RotateImage(filename, mat); } @@ -427,59 +477,6 @@ imreadmulti_(const String& filename, int flags, std::vector& mats) return !mats.empty(); } -void RotateImage(const String& filename, Mat& img) -{ - int orientation = IMAGE_ORIENTATION_TL; - - if (filename.size() > 0) - { - ExifReader reader( 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 - } - } - } - - switch( orientation ) - { - case IMAGE_ORIENTATION_TL: //0th row == visual top, 0th column == visual left-hand side - //do nothing, the image already has proper orientation - break; - case IMAGE_ORIENTATION_TR: //0th row == visual top, 0th column == visual right-hand side - flip(img, img, 1); //flip horizontally - break; - case IMAGE_ORIENTATION_BR: //0th row == visual bottom, 0th column == visual right-hand side - flip(img, img, -1);//flip both horizontally and vertically - break; - case IMAGE_ORIENTATION_BL: //0th row == visual bottom, 0th column == visual left-hand side - flip(img, img, 0); //flip vertically - break; - case IMAGE_ORIENTATION_LT: //0th row == visual left-hand side, 0th column == visual top - transpose(img, img); - break; - case IMAGE_ORIENTATION_RT: //0th row == visual right-hand side, 0th column == visual top - transpose(img, img); - flip(img, img, 1); //flip horizontally - break; - case IMAGE_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 IMAGE_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; - } -} - - /** * Read an image * @@ -497,7 +494,7 @@ Mat imread( const String& filename, int flags ) imread_( filename, flags, LOAD_MAT, &img ); /// optionally rotate the data if EXIF' orientation flag says so - if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 ) + if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) { RotateImage(filename, img); }