Added reading of EXIF_Orientation tags when present in a jpeg file.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14817 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -48,13 +48,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include <jpeglib.h>
|
||||
#include "jerror.h"
|
||||
}
|
||||
#include "EXIF_Orientation.h"
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
@@ -467,11 +461,11 @@ copyScanline(unsigned char *currPtr, unsigned char *from, int cnt)
|
||||
return currPtr;
|
||||
}
|
||||
|
||||
unsigned char *
|
||||
simage_jpeg_load(std::istream& fin,
|
||||
int *width_ret,
|
||||
int *height_ret,
|
||||
int *numComponents_ret)
|
||||
unsigned char* simage_jpeg_load(std::istream& fin,
|
||||
int *width_ret,
|
||||
int *height_ret,
|
||||
int *numComponents_ret,
|
||||
unsigned int* exif_orientation)
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
@@ -535,8 +529,12 @@ int *numComponents_ret)
|
||||
//jpeg_stdio_src(&cinfo, infile);
|
||||
jpeg_istream_src(&cinfo,&fin);
|
||||
|
||||
|
||||
|
||||
/* Step 3: read file parameters with jpeg_read_header() */
|
||||
|
||||
jpeg_save_markers (&cinfo, EXIF_JPEG_MARKER, 0xffff);
|
||||
|
||||
(void) jpeg_read_header(&cinfo, TRUE);
|
||||
/* We can ignore the return value from jpeg_read_header since
|
||||
* (a) suspension is not possible with the stdio data source, and
|
||||
@@ -544,6 +542,14 @@ int *numComponents_ret)
|
||||
* See libjpeg.doc for more info.
|
||||
*/
|
||||
|
||||
/* check for orientation tag */
|
||||
*exif_orientation = EXIF_Orientation (&cinfo);
|
||||
if (*exif_orientation!=0)
|
||||
{
|
||||
OSG_INFO<<"We have an EXIF_Orientation "<<exif_orientation<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
/* Step 4: set parameters for decompression */
|
||||
/* In this example, we don't need to change any of the defaults set by
|
||||
* jpeg_read_header(), so we do nothing here.
|
||||
@@ -825,8 +831,9 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
|
||||
int width_ret;
|
||||
int height_ret;
|
||||
int numComponents_ret;
|
||||
unsigned int exif_orientation=0;
|
||||
|
||||
imageData = osgDBJPEG::simage_jpeg_load(fin,&width_ret,&height_ret,&numComponents_ret);
|
||||
imageData = osgDBJPEG::simage_jpeg_load(fin, &width_ret, &height_ret, &numComponents_ret, &exif_orientation);
|
||||
|
||||
if (imageData==NULL) return ReadResult::ERROR_IN_READING_FILE;
|
||||
|
||||
@@ -857,6 +864,23 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
|
||||
imageData,
|
||||
osg::Image::USE_NEW_DELETE);
|
||||
|
||||
if (exif_orientation>0)
|
||||
{
|
||||
// guide for meaning of exif_orientation provided by webpage: http://sylvana.net/jpegcrop/exif_orientation.html
|
||||
switch(exif_orientation)
|
||||
{
|
||||
case(1): OSG_NOTICE<<"EXIF_Orientation 1 (top, left side), No need to rotate image. "<<std::endl; break; // do noting
|
||||
case(2): OSG_NOTICE<<"EXIF_Orientation 2 (top, right side), flip x."<<std::endl; break;
|
||||
case(3): OSG_NOTICE<<"EXIF_Orientation 3 (bottom, right side), rotate 180."<<std::endl; break;
|
||||
case(4): OSG_NOTICE<<"EXIF_Orientation 4 (bottom, left side). flip y, rotate 180."<<std::endl; break;
|
||||
case(5): OSG_NOTICE<<"EXIF_Orientation 5 (left side, top). flip y, rotate 90."<<std::endl; break;
|
||||
case(6): OSG_NOTICE<<"EXIF_Orientation 6 (right side, top). rotate 90."<<std::endl; break;
|
||||
case(7): OSG_NOTICE<<"EXIF_Orientation 7 (right side, bottom), flip Y, rotate 270."<<std::endl; break;
|
||||
case(8): OSG_NOTICE<<"EXIF_Orientation 8 (left side, bottom). rotate 270."<<std::endl; break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return pOsgImage;
|
||||
}
|
||||
|
||||
@@ -883,6 +907,8 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
|
||||
std::string fileName = osgDB::findDataFile( file, options );
|
||||
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
|
||||
|
||||
OSG_NOTICE<<std::endl<<"readImage("<<file<<")"<<std::endl;
|
||||
|
||||
osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary);
|
||||
if(!istream) return ReadResult::ERROR_IN_READING_FILE;
|
||||
ReadResult rr = readJPGStream(istream);
|
||||
|
||||
Reference in New Issue
Block a user