コード例 #1
0
void FrameBufferInterface::saveToFile(const char * _filename, unsigned long int _fbochannel){
	// get the channel we're asking for
	const FrameBufferChannel & channel = frameBufferChannels.at(_fbochannel);
	
	unsigned long int bytes = width*height*channel.numChannels;
	
	GLubyte * pixels = getPixelData(_fbochannel);

	unsigned char * pixelsSOIL = (unsigned char *)malloc(bytes * sizeof(unsigned char));
	
	glBindTexture(GL_TEXTURE_2D, frameBufferChannels.at(_fbochannel).id);
	glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
	
	for(unsigned long int i = 0; i < bytes; ++i){
		pixelsSOIL[i] = pixels[i];
	}
	
	std::stringstream ss;
	ss << "data/images/" << _filename;
	if(stbi_write_tga(ss.str().c_str(), width, height, channel.numChannels, pixelsSOIL, 1)){
		Log::info("FBO \""+ss.str()+"\" saved");
	}else{
		Log::error("FBO \""+ss.str()+"\" not saved");
	}
	
	free(pixels);
	free(pixelsSOIL);
}
コード例 #2
0
ファイル: image.cpp プロジェクト: Anastaciaa/otclient-1
void Image::savePNG(const std::string& fileName)
{
    FileStreamPtr fin = g_resources.createFile(fileName);
    if(!fin)
        stdext::throw_exception(stdext::format("failed to open file '%s' for write", fileName));

    fin->cache();
    std::stringstream data;
    save_png(data, m_size.width(), m_size.height(), 4, (unsigned char*)getPixelData());
    fin->write(data.str().c_str(), data.str().length());
    fin->flush();
    fin->close();
}
コード例 #3
0
    void buildMipMap(const std::shared_ptr<NativeBitmap> &texture) {
        auto bitmap = texture;
        std::shared_ptr<NativeBitmap> old;
        int level = 1;
        while (bitmap->getWidth() > 1) {
            old = bitmap;
            bitmap = old->makeBitmapWithHalfDimensions();
            glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, bitmap->getWidth(), bitmap->getHeight(), 0,
                         GL_RGBA, GL_UNSIGNED_BYTE,
                         bitmap->getPixelData());
            ++level;

        }
    }
コード例 #4
0
ファイル: mainwindow.c プロジェクト: 3Nigma/AVI
GtkWidget *avi_new_appwindow() {
  GtkWidget *window = NULL;
  GtkWidget *windowLayout = NULL;
  GtkWidget *imgCamTop = NULL;
  GtkWidget *imgCamBottom = NULL;

  /* initialize main window */
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "AVI Monitor");
  gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
  g_signal_connect(window, "delete-event", G_CALLBACK(delete_event), NULL);
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);

  /* initialize the camera widgets */
  imgCamTop = avi_new_cam((gpointer *)&topCamPixData[0]);
  imgCamBottom = avi_new_cam((gpointer *)&bottomCamPixData[0]);

  /* add window container and organize widgets */
  windowLayout = gtk_table_new(3, 3, FALSE);
  gtk_table_attach_defaults(GTK_TABLE(windowLayout), imgCamTop, 0, 1, 0, 1);
  gtk_table_attach_defaults(GTK_TABLE(windowLayout), gtk_image_new_from_file("../../doc/avi_cam_layout_small.png"), 1, 2, 0, 1);
  gtk_table_attach_defaults(GTK_TABLE(windowLayout), imgCamBottom, 2, 3, 0, 1);
  gtk_table_attach_defaults(GTK_TABLE(windowLayout), avi_new_console_labeled(), 0, 3, 1, 2);
  gtk_table_attach_defaults(GTK_TABLE(windowLayout), avi_new_button_box(), 0, 3, 2, 3);
  gtk_container_add(GTK_CONTAINER(window), windowLayout);

  /* check if pcavi is present */
  if(isPCAviOnline())
    avi_console_append_text(NULL, "PC Avi ONLINE!\n");
  else
    avi_console_append_text(NULL, "PC Avi OFFLINE!\n");

  softResetCam(CAR_CAMS_ID_MID);
  getPixelData(CAR_CAMS_ID_MID, bottomCamPixData, AVI_CAM_BUFLENGTH);
  powerDownCam(CAR_CAMS_ID_MID);

  return window;
}