23 #if defined(USEQIMAGE) 24 #include <QtGui/QImage> 26 #if defined(USEIMAGEMAGIC) 27 #include <ImageMagick-6/Magick++.h> 30 #include <OpenImageIO/imageio.h> 38 #define IMAGE_DEBUG_ON 1 51 m_data.reset(
new unsigned char[ size]);
114 int realWidth=_width-_x;
115 int realHeight=_height-_y;
117 std::unique_ptr<unsigned char []>
data(
new unsigned char [realWidth * realHeight *size]);
119 #if defined(USEQIMAGE) 120 QImage::Format qformat=QImage::Format::Format_RGB888;
123 qformat=QImage::Format::Format_RGBA8888;
125 QImage
image(data.get(),realWidth,realHeight,qformat);
126 image=image.mirrored(
false,
true);
127 image.save(_fname.c_str());
132 OpenImageIO::ImageOutput *out = OpenImageIO::ImageOutput::create (_fname.c_str());
133 OpenImageIO::ImageSpec spec (realWidth, realHeight, size, OpenImageIO::TypeDesc::UINT8);
134 int scanlinesize = realWidth *
size;
135 out->open (_fname.c_str(), spec);
138 out->write_image (OpenImageIO::TypeDesc::UINT8,
139 data.get() + (realHeight-1)*scanlinesize,
140 OpenImageIO::AutoStride,
141 -scanlinesize,OpenImageIO::AutoStride);
144 #if defined(USEIMAGEMAGIC) 145 Magick::Image output(realWidth,realHeight,
146 size==3 ?
"RGB" :
"RGBA",
147 Magick::CharPixel,data.get()
153 output.write(_fname.c_str());
158 #if defined(USEQIMAGE) 165 #ifdef IMAGE_DEBUG_ON 166 std::cerr<<
"loading with QImage"<<std::endl;
169 bool loaded=image.load(_fName.c_str());
172 std::cerr<<
"error loading image "<<_fName.c_str()<<
"\n";
176 image=image.mirrored();
192 unsigned int index=0;
198 colour=image.pixel(
x,
y);
200 m_data[index++]=
static_cast<unsigned char> (qRed(colour));
201 m_data[index++]=
static_cast<unsigned char> (qGreen(colour));
202 m_data[index++]=
static_cast<unsigned char> (qBlue(colour));
205 m_data[index++]=
static_cast<unsigned char> (qAlpha(colour));
209 #ifdef IMAGE_DEBUG_ON 210 std::cerr<<
"size "<<
m_width<<
" "<<m_height<<std::endl;
211 std::cerr<<
"channels "<<m_channels<<std::endl;
221 #endif // end of QImage loading routines 224 #if defined(USEIMAGEMAGIC) 231 #ifdef IMAGE_DEBUG_ON 232 std::cerr<<
"loading with ImageMagick"<<std::endl;
242 image.write(&blob,
"RGBA");
244 catch (Magick::Error& Error)
246 std::cout <<
"Error loading texture '" << _fname <<
"': " << Error.what() << std::endl;
256 memcpy(
m_data.get(),blob.data(),blob.length());
259 #endif // end of image magick loading routines 268 #ifdef IMAGE_DEBUG_ON 269 std::cerr<<
"loading with OpenImageIO"<<std::endl;
271 OpenImageIO::ImageInput *
in = OpenImageIO::ImageInput::open (_fname);
276 const OpenImageIO::ImageSpec &spec = in->spec();
286 int scanlinesize = spec.width * spec.nchannels *
sizeof(
m_data[0]);
287 in->read_image (OpenImageIO::TypeDesc::UINT8,
289 OpenImageIO::AutoStride,
291 OpenImageIO::AutoStride);
299 #endif // end USEOIIO
simple class to hold colour information and set the basic opengl colour state. also has overloaded me...
GLenum GLsizei GLenum GLenum const void * image
GLuint m_channels
bits per pixel (RGB / RGBA)
GLint GLint GLint GLint GLint GLint y
bool m_hasAlpha
do we have an alpha channel
GLint GLenum GLsizei GLint GLsizei const void * data
implementation files for RibExport class
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
static void saveFrameBufferToFile(const std::string &_fname, int _x, int _y, int _width, int _height, ImageModes _mode=ImageModes::RGB)
GLuint m_height
the size of the image in the Y direction
A generic Image loader / wrapper for different Image libs this allows us to load an image to be used ...
GLuint m_format
image format, use GL types for this as we are going to use this class mainly for OpenGL ...
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
GLint GLint GLint GLint GLint x
#define NGL_ASSERT(X)
re-define the standard assert to work for ngl first check to see if assert is defined and undef it th...
Image()=default
default ctor
bool load(const std::string &_fname) noexcept
load the image data, this will clear the previous data and attempt to load the new image data ...
GLuint m_width
the size of the image in the X direction
std::unique_ptr< unsigned char[] > m_data
the actual image data loaded packed in r,g,b,(a) format in contiguous memory stored in a smart_pointe...
GLAPI void GLAPIENTRY glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels)
re impliment asserts so we don't exit on failure
GLsizei const GLchar *const * string
Colour getColour(const GLuint _x, const GLuint _y) const noexcept
get the colour value from X,Y co-ordinates (image absolute 0,0 = top Left)
ImageModes
save the FrameBuffer to file using current built in I/O