#ifndef EXAMPLE_HPP
#define EXAMPLE_HPP
#include <memory>
#include <boost/gil/gil_all.hpp>
#include <QtGui/QApplication>
#include <QtGui/QHBoxLayout>
#include <QtGui/QImage>
#include <QtGui/QLabel>
#include <QtGui/QWidget>
//#include "image_details.hpp"
static void x_gradient(boost::gil::gray8c_view_t const &src, boost::gil::gray8s_view_t const &dst)
{
for (int y = 0; y != src.height(); ++y)
for (int x = 1; x != src.width() - 1; ++x)
dst(x, y) = (src(x - 1, y) - src(x + 1, y)) / 2;
}
inline void ComputeXGradientGray8(unsigned char const *src_pixels, ptrdiff_t src_row_bytes,
int w, int h, unsigned char *dst_pixels, ptrdiff_t dst_row_bytes)
{
using namespace boost::gil;
gray8c_view_t src = interleaved_view(w, h, (const gray8_pixel_t*)src_pixels, src_row_bytes);
gray8s_view_t dst = interleaved_view(w, h, ( gray8s_pixel_t*)dst_pixels, dst_row_bytes);
x_gradient(src, dst);
}
static inline void x_gradient_qt(QImage const &src, QImage &dst)
{
ComputeXGradientGray8(src.bits(), src.bytesPerLine(), src.height(),
src.width(), dst.bits(), dst.bytesPerLine());
}
static void read_image()
{
QImage src("../GIL_with_Qt/images_00/coneL.bmp");
QImage dst(src.width(), src.height(), src.format());
x_gradient_qt(src, dst); //this will cause segmentation fault
}
#endif // EXAMPLE_HPP
depth : 8bit
format : QImage::Format_Indexed8
image width : 450
image height : 375
bytes per scan line : 452
How to integrate QImage with the example provided by the boost::gil?
This would cause segmentation fault yet I don't know why.
The algorithm seems nothing wrong
Thanks for your help