Esempio n. 1
0
void RaytracerApplication::output_image()
{
    static const size_t MAX_LEN = 256;
    const char* filename;
    char buf[MAX_LEN];

    if ( !buffer ) {
        std::cout << "No image to output.\n";
        return;
    }

    assert( buf_width > 0 && buf_height > 0 );

    filename = options.output_filename;

    if ( !filename ) {
        imageio_gen_name( buf, MAX_LEN );
        filename = buf;
    }

    if ( imageio_save_image( filename, buffer, buf_width, buf_height ) ) {
        std::cout << "Saved raytraced image to '" << filename << "'.\n";
    } else {
        std::cout << "Error saving raytraced image to '" << filename << "'.\n";
    }
}
void ArnoldFileFrameManager::saveToFile(string file, float *frame, size_t width, size_t height) {
  unsigned char *bytes = new unsigned char[width * height * 4];
  floats_to_bytes(bytes, frame, width, height);

  if (!imageio_save_image(file.c_str(), bytes, width, height)) {
    std::stringstream err_ss;
    err_ss << "Error to write png: " << file;
    Logger::log(ERR, err_ss.str());
  }
}
Esempio n. 3
0
// Wraps the general functionality of saving an image and writes the current
// frame buffer to a specified file name.  Also returns true on succces,
// false otherwise.
bool imageio_save_screenshot( const char *fileName, int width, int height )
{

    unsigned char *buffer = new unsigned char[width * height * 4];
    if (!buffer)
        return false;
    glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
    bool result = imageio_save_image(fileName, buffer, width, height);
    delete [] buffer;
    return result;
}
void ArnoldFileFrameManager::dump(time_t time, float *frame, size_t width, size_t height) {
	size_t floor_frame = (float)time * m_fps / 1000;
	unsigned char *bytes = new unsigned char[width * height * 4];
	floats_to_bytes(bytes, frame, width, height);
	char digits[7];

	for (size_t i = m_prev_frame + 1; i <= floor_frame; i++) {
		sprintf(digits, "%06d", i);

		std::stringstream ss;
		ss << "\\" << digits << ".png";
		std::string file = m_frame_path;
		file.append(ss.str());
		
		if (!imageio_save_image(file.c_str(), bytes, width, height)) {
			std::stringstream err_ss;
			err_ss << "Error to write png: " << file;
			Logger::log(ERR, err_ss.str());
		}
	}

	m_prev_frame = floor_frame;
}
void ArnoldAnimationPatch::renderSingleFrame(const set<Device*>& devices, string basepath, string filename) {
  if (m_mode != SimulationAnimationMode::STOPPED)
    disableContinuousRenderMode();

  FrameDeviceInfo frame;

  // Fulls time and mode for frame info.
  createFrameInfoHeader(frame);
  createFrameInfoBody(devices, frame);

  std::stringstream ss;
  ss << "Rendering single frame: " << frame.time;
  Logger::log(LDEBUG, ss.str());

  // Interrupts the current rendering if in the interactive mode.
  if (m_mode == SimulationAnimationMode::INTERACTIVE ||
    m_mode == SimulationAnimationMode::RECORDING) {
    interruptRender();
  }

  // Render immediately.
  if (!m_interface->isDistributedOpen()) {
	  m_interface->init(this->toJSON());
	  
	  // Check if we were able to open a connection
	  if (!m_interface->isDistributedOpen()) {
		  std::cerr << "Connection could not be established. " << 
			  "Check to make sure your host and port " << 
			  "parameters are correct and that nobody " << 
			  "else is currently using the remote renderer" << std::endl;

		  return;
	  }
  }

  bool success = false;
  float* bp = nullptr;
  int cid;
  int w = getWidth();
  int h = getHeight();

  if (CachingArnoldInterface* ci = dynamic_cast<CachingArnoldInterface*>(m_interface)) {
#ifdef USE_ARNOLD
    success = ci->render(devices, w, h, cid) == AI_SUCCESS;
#else
    success = ci->render(devices, w, h, cid) == 0;
#endif
    // we need to pull the proper buffer from the right context
    bp = ci->getBufferForContext(cid);
    frame.clear();
  }
  else {
    updateLight(devices);
    success = ArnoldPatch::renderLoop(devices);
    frame.clear();
    bp = getBufferPointer();
  }

  if (success) {
    unsigned char *bytes = new unsigned char[w * h * 4];
    floats_to_bytes(bytes, bp, w, h);

    string file = basepath + "/" + filename + ".png";

    if (!imageio_save_image(file.c_str(), bytes, getWidth(), getHeight())) {
      std::stringstream err_ss;
      err_ss << "Error to write png: " << filename;
      Logger::log(ERR, err_ss.str());
    }
  }

  if (CachingArnoldInterface* ci = dynamic_cast<CachingArnoldInterface*>(m_interface)) {
    ci->closeContext(cid);
  }
}