-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for side-by-side stereo images (.jps)
- Loading branch information
Raphael Dumusc
committed
Aug 24, 2018
1 parent
278bcc6
commit 42c8565
Showing
35 changed files
with
358 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/*********************************************************************/ | ||
/* Copyright (c) 2018, EPFL/Blue Brain Project */ | ||
/* Raphael Dumusc <raphael.dumusc@epfl.ch> */ | ||
/* All rights reserved. */ | ||
/* */ | ||
/* Redistribution and use in source and binary forms, with or */ | ||
/* without modification, are permitted provided that the following */ | ||
/* conditions are met: */ | ||
/* */ | ||
/* 1. Redistributions of source code must retain the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer. */ | ||
/* */ | ||
/* 2. Redistributions in binary form must reproduce the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer in the documentation and/or other materials */ | ||
/* provided with the distribution. */ | ||
/* */ | ||
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */ | ||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ | ||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ | ||
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ | ||
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ | ||
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */ | ||
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ | ||
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ | ||
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ | ||
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ | ||
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ | ||
/* POSSIBILITY OF SUCH DAMAGE. */ | ||
/* */ | ||
/* The views and conclusions contained in the software and */ | ||
/* documentation are those of the authors and should not be */ | ||
/* interpreted as representing official policies, either expressed */ | ||
/* or implied, of Ecole polytechnique federale de Lausanne. */ | ||
/*********************************************************************/ | ||
|
||
#include "ImageReader.h" | ||
|
||
#include "data/QtImage.h" | ||
|
||
#include <QFileInfo> | ||
|
||
namespace | ||
{ | ||
bool isStereoImage(const QString& uri) | ||
{ | ||
return QFileInfo(uri).suffix().toLower() == "jps"; | ||
} | ||
|
||
QSize getMonoSize(const QSize& stereoSize) | ||
{ | ||
return QSize{stereoSize.width() / 2, stereoSize.height()}; | ||
} | ||
|
||
QRect getMonoRect(const QSize& image, const deflect::View view) | ||
{ | ||
return view == deflect::View::right_eye | ||
? QRect{QPoint{image.width() / 2, 0}, getMonoSize(image)} | ||
: QRect{QPoint{0, 0}, getMonoSize(image)}; | ||
} | ||
|
||
QImage getMonoImage(const QImage& image, const deflect::View view) | ||
{ | ||
return image.copy(getMonoRect(image.size(), view)); | ||
} | ||
|
||
QImage ensureGlCompatibleFormat(const QImage& image) | ||
{ | ||
const auto argb32 = QImage::Format_ARGB32; | ||
return QtImage::is32Bits(image) ? image : image.convertToFormat(argb32); | ||
} | ||
} | ||
|
||
ImageReader::ImageReader(const QString& uri) | ||
: _reader{std::make_unique<QImageReader>(uri)} | ||
, _stereo{isStereoImage(uri)} | ||
{ | ||
} | ||
|
||
bool ImageReader::isValid() const | ||
{ | ||
return _reader->canRead(); | ||
} | ||
|
||
QSize ImageReader::getSize() const | ||
{ | ||
return _stereo ? getMonoSize(_reader->size()) : _reader->size(); | ||
} | ||
|
||
bool ImageReader::isStereo() const | ||
{ | ||
return _stereo; | ||
} | ||
|
||
QImage ImageReader::getImage(const deflect::View view) const | ||
{ | ||
return ensureGlCompatibleFormat(_readImage(view)); | ||
} | ||
|
||
QStringList ImageReader::getSupportedImageFormats() | ||
{ | ||
QStringList extensions; | ||
|
||
for (const auto& entry : QImageReader::supportedImageFormats()) | ||
extensions << entry; | ||
extensions << "jps"; | ||
|
||
return extensions; | ||
} | ||
|
||
QImage ImageReader::_readImage(const deflect::View view) const | ||
{ | ||
return _stereo ? getMonoImage(_reader->read(), view) : _reader->read(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*********************************************************************/ | ||
/* Copyright (c) 2018, EPFL/Blue Brain Project */ | ||
/* Raphael Dumusc <raphael.dumusc@epfl.ch> */ | ||
/* All rights reserved. */ | ||
/* */ | ||
/* Redistribution and use in source and binary forms, with or */ | ||
/* without modification, are permitted provided that the following */ | ||
/* conditions are met: */ | ||
/* */ | ||
/* 1. Redistributions of source code must retain the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer. */ | ||
/* */ | ||
/* 2. Redistributions in binary form must reproduce the above */ | ||
/* copyright notice, this list of conditions and the following */ | ||
/* disclaimer in the documentation and/or other materials */ | ||
/* provided with the distribution. */ | ||
/* */ | ||
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */ | ||
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ | ||
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ | ||
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */ | ||
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ | ||
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ | ||
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */ | ||
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ | ||
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ | ||
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ | ||
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ | ||
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ | ||
/* POSSIBILITY OF SUCH DAMAGE. */ | ||
/* */ | ||
/* The views and conclusions contained in the software and */ | ||
/* documentation are those of the authors and should not be */ | ||
/* interpreted as representing official policies, either expressed */ | ||
/* or implied, of Ecole polytechnique federale de Lausanne. */ | ||
/*********************************************************************/ | ||
|
||
#ifndef IMAGEREADER_H | ||
#define IMAGEREADER_H | ||
|
||
#include "types.h" | ||
|
||
#include <QImage> | ||
#include <QImageReader> | ||
|
||
/** | ||
* Reader for regular 2D / stereo 3D images. | ||
*/ | ||
class ImageReader | ||
{ | ||
public: | ||
ImageReader(const QString& uri); | ||
|
||
bool isValid() const; | ||
QSize getSize() const; | ||
bool isStereo() const; | ||
QImage getImage(deflect::View view = deflect::View::mono) const; | ||
|
||
static QStringList getSupportedImageFormats(); | ||
|
||
private: | ||
std::unique_ptr<QImageReader> _reader; | ||
bool _stereo = false; | ||
|
||
QImage _readImage(const deflect::View view) const; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.