示例#1
0
void Image::saveFrameBufferToFile(const std::string &_fname, int _x, int _y, int _width, int _height,ImageModes _mode)
{
  GLenum format=GL_RGB;
  int size=3;
  if(_mode == ImageModes::RGBA)
  {
    size=4;
    format=GL_RGBA;
  }
  int realWidth=_width-_x;
  int realHeight=_height-_y;
  NGL_ASSERT(_x<_width && _y<_height);
  std::unique_ptr<unsigned char []> data( new unsigned char [realWidth * realHeight *size]);
  glReadPixels(_x,_y,realWidth,realHeight,format,GL_UNSIGNED_BYTE,data.get());
  #if defined(USEQIMAGE)
    QImage::Format qformat=QImage::Format::Format_RGB888;
    if(_mode == ImageModes::RGBA)
    {
      qformat=QImage::Format::Format_RGBA8888;
    }
    QImage image(data.get(),realWidth,realHeight,qformat);
    image=image.mirrored(false,true);
    image.save(_fname.c_str());

  #endif
  #if defined(USEOIIO)

    OpenImageIO::ImageOutput *out = OpenImageIO::ImageOutput::create (_fname.c_str());
    OpenImageIO::ImageSpec spec (realWidth, realHeight, size, OpenImageIO::TypeDesc::UINT8);
    int scanlinesize = realWidth * size;
    out->open (_fname.c_str(), spec);
    // note this flips the image vertically on writing
    // (see http://www.openimageio.org/openimageio.pdf pg 20 for details)
    out->write_image (OpenImageIO::TypeDesc::UINT8,
                      data.get() + (realHeight-1)*scanlinesize,
                      OpenImageIO::AutoStride,
                      -scanlinesize,OpenImageIO::AutoStride);
    out->close ();
  #endif
  #if defined(USEIMAGEMAGIC)
    Magick::Image output(realWidth,realHeight,
                           size==3 ? "RGB" : "RGBA",
                           Magick::CharPixel,data.get()
                           );

      // set the output image depth to 16 bit
      output.depth(16);
      // write the file
      output.write(_fname.c_str());
  #endif
}
示例#2
0
bool writeImageFile(std::string filename, int xres, int yres, int channels, deep::ImageDataType * data) {
	/*
	 * WARNING: This makes the assumption that the folder to write the image exists.
	 * It will crash if the filename is pointing to a folder that doesn't exist.
	 */
	OpenImageIO::ImageOutput * out = OpenImageIO::ImageOutput::create(filename);
	if (!out) {
		return false;
	}
	OpenImageIO::ImageSpec spec(xres, yres, channels, OpenImageIO::TypeDesc::DOUBLE); //FLOAT);
	out->open(filename.c_str(), spec);
	out->write_image(OpenImageIO::TypeDesc::DOUBLE, data); //FLOAT, data);
	out->close();
	delete out;
	return true;
}