All pastes #384632 Raw Edit

Mine

public text v1 · immutable
·published 2007-03-07 06:00 UTC
rendered paste body
//gcc -Wall -I/usr/include -o phimage phimage.cpp `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` -L/usr/X11R6/lib -lX11 -lglut -lGL -lGLU -lm

#include <GL/glut.h>    // Header File For The GLUT Library 
#include <GL/gl.h>	// Header File For The OpenGL32 Library
#include <GL/glu.h>	// Header File For The GLu32 Library
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <unistd.h>     // needed to sleep
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string.h>
#include <dirent.h>
#include <sstream>
#include <vector>

using namespace std;

class TextureLoader
{
	private:
		int idl, buffersize, tilesize;
		float nix, niy;
		GdkInterpType tilequality;
		string filename;
		bool closed;
		bool resize;
		GdkPixbufLoader *pixbuf;
		GdkPixbuf *pixbuf_new, *pixbuf_old;
		ifstream file;

	public:
		TextureLoader(string, int, int, int, GdkInterpType);
		bool next_chunk();
		GdkPixbuf* transfer(void);
		int get_width();
		int get_height();
};

TextureLoader::TextureLoader(string in_filename, int in_idl, int in_buffersize, int in_tilesize, GdkInterpType in_tilequality)
{
	filename = in_filename;
	idl = in_idl;
	buffersize = in_buffersize;
	tilesize = in_tilesize;
	tilequality = in_tilequality;
	closed = false;
	resize = false;
	pixbuf = gdk_pixbuf_loader_new();
	pixbuf_new = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, tilesize, tilesize);
	gdk_pixbuf_fill(pixbuf_new, 0x00000000);
	file.open("/home/pete/NeHe.bmp", ios::in | ios::binary);
	file.seekg(0, ios::beg);
}

bool TextureLoader::next_chunk(void)
{
	float ix, iy;
	char *buffer;

	buffer = new char [buffersize];

	if (!closed)
	{
		if (file.eof())
		{
			gdk_pixbuf_loader_close(pixbuf, NULL);
			file.close();
			closed = true;
			pixbuf_old = gdk_pixbuf_loader_get_pixbuf(pixbuf);
			pixbuf_old = gdk_pixbuf_add_alpha(pixbuf_old, false, 'a', 'a', 'a');
			ix = gdk_pixbuf_get_width(pixbuf_old);
			iy = gdk_pixbuf_get_height(pixbuf_old);
			if (ix > iy)
			{
				nix = tilesize - 4;
				niy = (nix / ix) * iy;
			}
			else
			{
				niy = tilesize - 4;
				nix = (niy / iy) * ix;
			}
			return true; 
		}

		else
		{
		file.read(buffer, buffersize);
		gdk_pixbuf_loader_write(pixbuf, reinterpret_cast<const guchar*>(buffer), buffersize, NULL);
		return true;
		}
	}
	else if (!resize)
	{
		pixbuf_old = gdk_pixbuf_scale_simple(pixbuf_old, (int)nix, (int)niy, tilequality);
		gdk_pixbuf_copy_area(pixbuf_old, 0, 0, (int)nix, (int)niy, pixbuf_new, (int)(2+(tilesize - 4 - nix)/2), (int)(2+(tilesize - 4 - niy)/2));
		resize = true; 
	}
	return false;
}

GdkPixbuf* TextureLoader::transfer()
{
	return pixbuf_new;
}

int TextureLoader::get_width()
{
	return (int)nix;
}

int TextureLoader::get_height()
{
	return (int)niy;
}

class phimage
{

gint tilesize, tilequality, buffersize, blendtime, hangtime;
guchar *dir, *resolution, *angle, *constraint, *speed, *distance, *perspective;
gboolean window;
GdkInterpType realtilequality;
vector <string> files;

	public:
		phimage(int, char**);
		void init_options(int argc, char **argv);
		void check_options();
		void get_files();
};

phimage::phimage(int argc, char **argv)
{
	this->check_options();
	this->init_options(argc, argv);
	this->get_files;
	GdkPixbuf *man;

	gtk_init(&argc, &argv);

	////Example for texture loader function
	//TextureLoader test("/home/pete/NeHe.bmp", 0, 16384, 512, realtilequality);
	//while (test.next_chunk());
	//man = test.transfer();
	//gdk_pixbuf_save(man, "/home/pete/opengl/test.png", "png", NULL, NULL);

	////Example of float to string conversion
	//float jim;
	//string s = "33.2";
	//std::istringstream i(s);
	//i >> jim;
	//cout << jim;

}

void phimage::get_files()
{

}

void phimage::check_options()
{
	tilesize=512;
	tilequality=1;
	dir=(guchar *)".";
	angle=(guchar *)"5";
	buffersize=16384;
	blendtime=300;
	hangtime=100;
	constraint=(guchar *)"0.5,0.5,30,30";
	speed=(guchar *)"0.05,0.05";
	resolution=(guchar *)"1024x768:8@75";
	window=false;
	distance=(guchar *)"2.5";
	perspective=(guchar *)"45.0";
}

void phimage::init_options(int argc, char **argv)
{
static GOptionEntry entries[] = 
{
  { "tilesize", 't', 0, G_OPTION_ARG_INT, &tilesize, "Tile Size", "N" },
  { "tilequality", 'q', 0, G_OPTION_ARG_INT, &tilequality, "Tile Quality", "M" },
  { "dir", 'd', 0, G_OPTION_ARG_STRING, &dir, "Directory", NULL },
  { "angle", 'a', 0, G_OPTION_ARG_STRING, &angle, "Angle", NULL },

  { "buffersize", 'b', 0, G_OPTION_ARG_INT, &buffersize, "Buffer Size", "N" },
  { "blendtime", 'B', 0, G_OPTION_ARG_INT, &blendtime, "Blend Time", "M" },
  { "hangtime", 'H', 0, G_OPTION_ARG_INT, &hangtime, "Hang Time", NULL },
  { "constraint", 'c', 0, G_OPTION_ARG_STRING, &constraint, "Constraint", NULL },

  { "speed", 's', 0, G_OPTION_ARG_STRING, &speed, "Speed", "N" },
  { "resolution", 'r', 0, G_OPTION_ARG_STRING, &resolution, "Resolution", "M" },
  { "window", 'w', 0, G_OPTION_ARG_NONE, &window, "Window", NULL },
  { "distance", 'D', 0, G_OPTION_ARG_STRING, &distance, "Distance", NULL },
  { "perspective", 'p', 0, G_OPTION_ARG_STRING, &perspective, "Perspective", NULL },

  { NULL }
};
  GOptionContext *context;
  context = g_option_context_new ("- test tree model performance");
  g_option_context_add_main_entries (context, entries, NULL);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  g_option_context_parse (context, &argc, &argv, NULL);

if (tilequality == 0) realtilequality = GDK_INTERP_NEAREST;
else if (tilequality == 1) realtilequality = GDK_INTERP_BILINEAR;
}

int main(int argc, char *argv[]) {

phimage main(argc, argv);


//dir * = opendir("./");

}

//change the next line too (buffer=) new char, and then pass to pixbufloader reinterpret_cast<const guchar*>(buffer)