Commit 1ce19737 authored by edwin.carlinet's avatar edwin.carlinet
Browse files

Add QT base application.

parent a838fc6b
......@@ -46,7 +46,9 @@ endif()
ENABLE_TESTING()
SUBDIRS(tests bench)
add_subdirectory(tests)
add_subdirectory(bench)
add_subdirectory(apps)
set(CPACK_SOURCE_GENERATOR "TBZ2")
set(CPACK_SOURCE_IGNORE_FILES "${CMAKE_CURRENT_BINARY_DIR}/;/\\\\.git/;.*~;#.*#")
......
add_subdirectory(imview)
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE(${QT_USE_FILE})
link_libraries(-lfreeimage)
add_executable(imview imview.cpp
${CMAKE_HOME_DIRECTORY}/mln/qt/qtimage.cpp
${CMAKE_HOME_DIRECTORY}/mln/qt/mainwin.cpp)
target_link_libraries(imview ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES})
#include <QApplication>
#include <mln/qt/mainwin.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/io/imread.hpp>
#include <QtGui>
int main(int argc, char** argv)
{
using namespace mln;
QApplication a(argc, argv);
image2d<uint8> ima;
io::imread(argv[1], ima);
qt::MainWindow<uint8> main(ima);
main.show();
// QImage image("../../../img/small.pgm");
// QGraphicsPixmapItem item(QPixmap::fromImage(image));
// QGraphicsScene* m_scene = new QGraphicsScene;
// m_scene->addItem(&item);
// QGraphicsView* view = new QGraphicsView(m_scene);
// QMainWindow win;
// win.setCentralWidget(view);
// win.show();
a.exec();
}
#include <mln/qt/mainwin.hpp>
#include <QtGui>
#include <iostream>
#include <QSize>
namespace mln
{
namespace qt
{
MainWindowBase::MainWindowBase(QtImageBase* ima)
: m_ima(ima)
{
m_pixmap.setPixmap(QPixmap::fromImage(*m_ima));
m_scene = new QGraphicsScene;
m_scene->addItem(&m_pixmap);
m_view = new QGraphicsView(m_scene);
this->setCentralWidget(m_view);
}
MainWindowBase::~MainWindowBase()
{
delete m_ima;
}
}
}
#ifndef MLN_QT_MAINWIN_HPP
# define MLN_QT_MAINWIN_HPP
# include <QMainWindow>
# include <QGraphicsScene>
# include <QGraphicsView>
# include <QGraphicsPixmapItem>
# include <mln/qt/qtimage.hpp>
namespace mln
{
namespace qt
{
class MainWindowBase : public QMainWindow
{
//Q_OBJECT;
public:
MainWindowBase(QtImageBase* image);
virtual ~MainWindowBase();
private:
QGraphicsPixmapItem m_pixmap;
QGraphicsScene* m_scene;
QGraphicsView* m_view;
QtImageBase* m_ima;
};
template <typename V>
class MainWindow : public MainWindowBase
{
public:
MainWindow(const image2d<V>& ima);
};
/******************************************/
/**** Implementation ****/
/******************************************/
template <typename V>
MainWindow<V>::MainWindow(const image2d<V>& ima)
: MainWindowBase(new QtImage<V>(ima))
{
}
} // end of namespace mln::qt
} // end of namespace mln
#endif //!MLN_QT_MAINWIN_HPP
#include <mln/qt/qtimage.hpp>
namespace mln
{
namespace qt
{
QtImageBase::QtImageBase(const uchar * data, int width, int height,
int bytesPerLine, Format format)
: QImage(data, width, height, bytesPerLine, format)
{
}
QVector<QRgb> QtImageBase::default_lut8;
}
}
#ifndef MLN_QT_QTIMAGE_HPP
# define MLN_QT_QTIMAGE_HPP
# include <QImage>
# include <QColor>
# include <mln/core/image/image2d.hpp>
# include <mln/core/grays.hpp>
# include <mln/core/colors.hpp>
namespace mln
{
namespace qt
{
class QtImageBase : public QImage
{
//Q_OBJECT;
public:
QtImageBase(const uchar * data, int width, int height,
int bytesPerLine, Format format);
protected:
static QVector<QRgb> default_lut8;
};
template <typename V>
class QtImage : public QtImageBase
{
public:
QtImage(const image2d<V>& ima);
private:
const image2d<V>& m_ima;
};
/******************************************/
/**** Implementation ****/
/******************************************/
namespace internal
{
// FIXME overload or specialization ?
template <typename V>
struct qt_format
{
static const QImage::Format format = QImage::Format_Invalid;
};
template <>
struct qt_format<uint8>
{
static const QImage::Format format = QImage::Format_Indexed8;
};
template <>
struct qt_format<rgb8>
{
static const QImage::Format format = QImage::Format_RGB888;
};
}
template <typename V>
QtImage<V>::QtImage(const image2d<V>& ima)
: QtImageBase((uchar*)&ima(ima.domain().pmin),
ima.ncols(),
ima.nrows(),
ima.strides()[0],
internal::qt_format<V>::format),
m_ima(ima)
{
mln_precondition(ima.strides()[1] == sizeof(V));
if (internal::qt_format<V>::format == QImage::Format_Indexed8)
{
if (this->default_lut8.empty()) {
this->default_lut8.resize(256);
for (int i = 0; i < 256; ++i)
this->default_lut8[i] = QColor(i,i,i).rgb();
}
this->setColorTable(this->default_lut8);
}
}
} // end of namespace mln::qt
} // end of namespace mln
#endif //!MLN_QT_QTIMAGE_HPP
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment