Example #1
0
bool CGuildMarkImage::Build(const char * c_szFileName)
{
	sys_log(0, "GuildMarkImage: creating new file %s", c_szFileName);

	Destroy();
	Create();

	ilBindImage(m_uImg);
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);

	BYTE * data = (BYTE *) malloc(sizeof(Pixel) * WIDTH * HEIGHT);
	memset(data, 0, sizeof(Pixel) * WIDTH * HEIGHT);

	if (!ilTexImage(WIDTH, HEIGHT, 1, 4, IL_BGRA, IL_UNSIGNED_BYTE, data))
	{
		sys_err("GuildMarkImage: cannot initialize image");
		return false;
	}

	free(data);

	ilEnable(IL_FILE_OVERWRITE);

	if (!ilSave(IL_TGA, (const ILstring)c_szFileName))
		return false;

	return true;
}
Example #2
0
void DevILInit(void)
{
	ilInit();
	ilEnable(IL_CONV_PAL);
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
}
Example #3
0
// Image saver...
bit DevilSave(cstrconst filename,nat32 width,nat32 height,nat32 format,nat32 type,void * data,bit overwrite)
{
 unsigned int handle;
 ilGenImages(1,(unsigned int *)&handle); 
 ilBindImage(handle);
 ilEnable(0x0600);
 ilOriginFunc(0x0601);

 if (overwrite) ilEnable(DEVIL_FILE_SQUISH);
           else ilDisable(DEVIL_FILE_SQUISH);
  
 int num;
 switch (format)
 {
  case DEVIL_FORM_RGB: num = 3; break;
  case DEVIL_FORM_RGBA: num = 4; break;
  default: num =  1; break;
 }
 ilTexImage(width,height,1,num,format,type,data);

 ilSaveImage(filename);
 if (ilGetError())
 {
  ilDeleteImages(1,(unsigned int *)&handle);
  return false;
 }
 else
 { 
  ilDeleteImages(1,(unsigned int *)&handle);
  return true;
 }
}
Example #4
0
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG			msg;
    WNDCLASSEX	wcex;
    HACCEL		hAccelTable;

    hInstance = hInst;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style			= CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc	= (WNDPROC)WndProc;
    wcex.cbClsExtra		= 0;
    wcex.cbWndExtra		= 0;
    wcex.hInstance		= hInstance;
    wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
    wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName	= (LPCSTR)IDR_MENU1;
    wcex.lpszClassName	= TITLE;
    wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);

    RegisterClassEx(&wcex);

    HWnd = CreateWindow(TITLE, TITLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                        50, 50, 400, 300, NULL, NULL, hInstance, NULL);
    if (HWnd == NULL)
        return FALSE;

    // Display the window
    ShowWindow(HWnd, nCmdShow);
    UpdateWindow(HWnd);

    ilInit();
    ilEnable(IL_ORIGIN_SET);
    ilEnable(IL_TYPE_SET);
    ilEnable(IL_FORMAT_SET);

    ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
    ilTypeFunc(IL_UNSIGNED_BYTE);
    ilFormatFunc(IL_BGR);

    // Is there a file to load from the command-line?
    if (__argc > 1) {
        LoadImages(__argv[1]);
    }

    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDR_MENU1);

    while (GetMessage(&msg, NULL, 0, 0)) {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return msg.wParam;
}
Example #5
0
void IMG_InitDevil()
{
	//initialize devIL
	ilInit();
	ilOriginFunc( IL_ORIGIN_UPPER_LEFT );
	ilEnable( IL_ORIGIN_SET );
	ilEnable( IL_TYPE_SET );
	ilTypeFunc( IL_UNSIGNED_BYTE );
}
Example #6
0
int main(const int argc, const char* const argv[]) {
	param_t parameters;
	if(!parse_args(argc, argv, &parameters)) {
		return EXIT_FAILURE;
	}

	ilInit();
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
	ILuint image;
	ilGenImages(1, &image);
	ilBindImage(image);
	const ILboolean load_success = ilLoadImage(parameters.in);
	if(load_success== IL_FALSE) {
		// handle error TODO
		ilDeleteImages(1, &image);
		return EXIT_FAILURE;
	}
	const ILboolean convert_success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
	if(convert_success == IL_FALSE) {
		// handle error TODO
		ilDeleteImages(1, &image);
		return EXIT_FAILURE;
	}

	const ILint width = ilGetInteger(IL_IMAGE_WIDTH);
	const ILint height = ilGetInteger(IL_IMAGE_HEIGHT);
	const ILint out_width = width / parameters.scale;
	const ILint out_height = height / parameters.scale;

	ILubyte out_data[out_width * out_height];

	const image_t in = {
		.width = width,
		.height = height,
		.data = ilGetData(),
	};
	const image_t out = {
		.width = out_width,
		.height = out_height,
		.data = out_data,
	};
	convert(in, out, parameters);

	ilDeleteImages(1, &image);

	ILuint out_image;
	ilGenImages(1, &out_image);
	ilBindImage(out_image);

	ilTexImage(out_width, out_height, 1, 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, &out_data);
	ilEnable(IL_FILE_OVERWRITE);
	ilSaveImage(parameters.out);
	ilDeleteImages(1, &image);
	return EXIT_SUCCESS;
}
Example #7
0
ImagesLoader::ImagesLoader(){
    ilInit();

    ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
    ilEnable(IL_ORIGIN_SET);

    ilEnable(IL_FILE_OVERWRITE);

    ilSetInteger(IL_FORMAT_MODE, IL_BGRA);
    ilEnable(IL_FORMAT_SET);
}
Example #8
0
void LoadImages(char *FileName)
{
    ILuint Image, i;

    hDC = GetDC(HWnd);
    hMemDC = CreateCompatibleDC(hDC);

    ilGenImages(1, &Image);
    ilBindImage(Image);
    if (!ilLoadImage(FileName)) {
        ilDeleteImages(1, &Image);
        return;
    }

    ilEnable(IL_ORIGIN_SET);
    ilEnable(IL_FORMAT_SET);
    ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
    //ilFormatFunc(IL_BGRA);
    ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
    ilutRenderer(ILUT_WIN32);

    CurImage = 0;
    NumImages = ilGetInteger(IL_NUM_IMAGES) + 1;
    Bitmaps = new HBITMAP[NumImages];
    BmpInfo = new BITMAPINFOHEADER[NumImages];
    Durations = new ILuint[NumImages];
    if (Bitmaps == NULL || BmpInfo == NULL || Durations == NULL) {
        ilDeleteImages(1, &Image);
        return;
    }

    for (i = 0; i < NumImages; i++) {
        ilActiveImage(0);
        ilActiveImage(i);
        Durations[i] = ilGetInteger(IL_IMAGE_DURATION);
        *(Bitmaps + i) = ilutConvertToHBitmap(hDC);
        ilutGetBmpInfo((BITMAPINFO*)(BmpInfo + i));
    }

    SelectObject(hMemDC, Bitmaps[0]);

    ilDeleteImages(1, &Image);

    sprintf(NewTitle, "%s - %s", TITLE, FileName);
    SetWindowText(HWnd, NewTitle);

    QueryPerformanceFrequency((LARGE_INTEGER*)&TimerFreq);
    TimerRes = 1.0 / TimerFreq;
    QueryPerformanceCounter((LARGE_INTEGER*)&StartTime);

    return;
}
Example #9
0
int main(int argc, char* argv[])
{
	ilInit();                                //inicializa biblioteca de imagens
	ilEnable(IL_FILE_OVERWRITE);             //permite que a biblioteca sobrescreva arquivos em disco
	ilEnable(IL_ORIGIN_SET);                 //define a origem das imagens como o canto superior esquerdo
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
	setlocale(LC_ALL, "Portuguese");

	while (1)
		interface();

	return 0;
}
Example #10
0
bool M_saveImage(const char * filename, void * data, unsigned int quality)
{
	DevILInit();

	ILuint ImgId = 0;
	ilGenImages(1, &ImgId);

	// bind this image name.
	ilBindImage(ImgId);

	MImage * image = (MImage *)data;
	unsigned int width = image->getWidth();
	unsigned int height = image->getHeight();
	unsigned int components = image->getComponents();

	if(components == 3)
		ilTexImage(width, height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, image->getData());
	else if(components == 4)
		ilTexImage(width, height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, image->getData());

	iluFlipImage();

	if(quality < 100)
		ilSetInteger(IL_JPG_QUALITY, quality);

	ilEnable(IL_FILE_OVERWRITE);
	ilSaveImage(filename);

	ilDeleteImages(1, &ImgId);
	DevILShutDown();
	return true;
}
Example #11
0
const ImageData Texture::loadFile(const std::string &path, const ImageFormat &format) {
	ilInit();

	ILuint image;
	ilGenImages(1, &image);
	ilBindImage(image);
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_LOWER_LEFT);

	ImageData imageData;

	ILboolean result = ilLoadImage(path.c_str());
	if (result) {
		//ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

		imageData.format = format;

		imageData.width = ilGetInteger(IL_IMAGE_WIDTH);
		imageData.height = ilGetInteger(IL_IMAGE_HEIGHT);
		imageData.sizeInBytes = imageData.width * imageData.height * imageData.format.numberOfChannels * imageData.format.bytesPerChannel;

		imageData.data = new uint8_t[imageData.sizeInBytes];
		memcpy(imageData.data, ilGetData(), imageData.sizeInBytes);
	}
	else {
		std::cout << "Failed to load image from file: " << path << std::endl;
	}

	ilDeleteImages(1, &image);

	return imageData;
}
Example #12
0
void
SaveTextureToImageFile( uint32 aWidth, uint32 aHeight, GLuint aTexture, std::string aPath, bool aOverwrite )
{
	//TODO auto_ptr on textures
	ILuint imageID; // The image name to return.
	DEVIL_CHECKED_CALL( ilGenImages( 1, &imageID ) );
	DEVIL_CHECKED_CALL( ilBindImage( imageID ) );
	if ( aOverwrite ) {
		DEVIL_CHECKED_CALL( ilEnable(IL_FILE_OVERWRITE) );
	} else {
		DEVIL_CHECKED_CALL( ilDisable(IL_FILE_OVERWRITE) );
	}

	DEVIL_CHECKED_CALL( ilTexImage( aWidth, aHeight, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, NULL ) );
	ILubyte* data = new ILubyte[ 3 * aWidth * aHeight ];

	GL_CHECKED_CALL( glBindTexture( GL_TEXTURE_2D, aTexture ) );
	GL_CHECKED_CALL( glGetTexImage(	
				GL_TEXTURE_2D, 
				0, 
				GL_RGB, 
				GL_UNSIGNED_BYTE, 
				(void*)data
				) );
	GL_CHECKED_CALL( glBindTexture( GL_TEXTURE_2D, 0 ) );

	DEVIL_CHECKED_CALL( ilSetPixels( 0, 0, 0, aWidth, aHeight, 1, IL_RGB, IL_UNSIGNED_BYTE, data ) );
	delete [] data;

	DEVIL_CHECKED_CALL( ilSaveImage( aPath.data() ) );
	DEVIL_CHECKED_CALL( ilDeleteImages( 1, &imageID) );
}
Example #13
0
TextureReaderDevil::TextureReaderDevil() {
    name_ = "DevIL Reader";
    extensions_.push_back("bmp");
    extensions_.push_back("cut");
    extensions_.push_back("dcx");
    extensions_.push_back("dds");
    extensions_.push_back("ico");
    extensions_.push_back("gif");
    extensions_.push_back("jpg");
    extensions_.push_back("jpeg");
    extensions_.push_back("lbm");
    extensions_.push_back("lif");
    extensions_.push_back("mdl");
    extensions_.push_back("pcd");
    extensions_.push_back("pcx");
    extensions_.push_back("pic");
    extensions_.push_back("png");
    extensions_.push_back("pnm");
    extensions_.push_back("psd");
    extensions_.push_back("psp");
    extensions_.push_back("raw");
    extensions_.push_back("sgi");
    extensions_.push_back("tga");
    extensions_.push_back("tif");
    extensions_.push_back("wal");
    extensions_.push_back("act");
    extensions_.push_back("pal");
    extensions_.push_back("hdr");

    // Initialize DevIL
    ilInit();
    ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
    ilEnable(IL_ORIGIN_SET); // Flip images
}
Example #14
0
void ofxTexture::DrawString(string text, ofxBitmapFont* font, ofRectangle dest_rect, unsigned char font_size)
{
    if(m_Locked) return;
    // TODO: implement draw text with boundary
    float scale;
    if(font_size == 0)
    {
        scale = 1.0f;
    }
    else
    {
        scale = (float)font_size/font->GetFontSize();
    }
    ofVec2f cursor(dest_rect.x, dest_rect.y);
    ilDisable(IL_BLIT_BLEND);
    for (int i = 0; i < text.size(); i++)
    {
        ofVec2f draw_region = scale*font->GetRect(text[i]);
        ILuint character_image = font->GetImageId(text[i]);
        ILuint dummy = ilGenImage();
        ilBindImage(dummy);
        ilCopyImage(character_image);
        iluScale(draw_region.x, draw_region.y, 1);
        ilBindImage(m_ImageId);
        ilBlit(dummy, cursor.x, cursor.y, 0, 0, 0, 0, draw_region.x, draw_region.y, 1);
        ilDeleteImage(dummy);
        cursor.x += draw_region.x;
    }
    ilEnable(IL_BLIT_BLEND);

}
Example #15
0
bool CGuildMarkImage::Load(const char * c_szFileName) 
{
	Destroy();
	Create();	

	ilBindImage(m_uImg);
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);

	if (!ilLoad(IL_TYPE_UNKNOWN, (const ILstring) c_szFileName))
	{
		sys_err("GuildMarkImage: %s cannot open file.", c_szFileName);
		return false;
	}

	if (ilGetInteger(IL_IMAGE_WIDTH) != WIDTH)	
	{
		sys_err("GuildMarkImage: %s width must be %u", c_szFileName, WIDTH);
		return false;
	}

	if (ilGetInteger(IL_IMAGE_HEIGHT) != HEIGHT)
	{
		sys_err("GuildMarkImage: %s height must be %u", c_szFileName, HEIGHT);
		return false;
	}

	ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE);

	BuildAllBlocks();
	return true;
}
bool CGuildMarkUploader::__Load(const char* c_szFileName, UINT* peError)
{
	ILuint uImg;
	ilGenImages(1, &uImg);
	ilBindImage(uImg);
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);

	if (!ilLoad(IL_TYPE_UNKNOWN, (const ILstring)c_szFileName))	
	{
		*peError=ERROR_LOAD;
		return false;
	}

	if (ilGetInteger(IL_IMAGE_WIDTH)!=SGuildMark::WIDTH)	
	{
		*peError=ERROR_WIDTH;
		return false;
	}

	if (ilGetInteger(IL_IMAGE_HEIGHT)!=SGuildMark::HEIGHT)
	{
		*peError=ERROR_HEIGHT;
		return false;
	}

	ilConvertImage(IL_BGRA, IL_BYTE);

	ilCopyPixels(0, 0, 0, SGuildMark::WIDTH, SGuildMark::HEIGHT, 1, IL_BGRA, IL_BYTE, (ILvoid*)m_kMark.m_apxBuf);

	ilDeleteImages(1, &uImg);
	return true;
}
	void				TextureManager::loadTexture(const std::string &filename)
	{
		ILboolean		success;
		unsigned int	imageID;
		GLuint			textureId;

		ilGenImages(1, &imageID);
		ilBindImage(imageID);
		ilEnable(IL_ORIGIN_SET);
		ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
		success = ilLoadImage((ILstring)filename.c_str());
		if (!success) {
			GameTools::debugManager::getInstance().dAssert("png file not loaded : " + filename);
		}
		ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

		glGenTextures(1, &textureId);
		glBindTexture(GL_TEXTURE_2D, textureId);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
			ilGetInteger(IL_IMAGE_WIDTH),
			ilGetInteger(IL_IMAGE_HEIGHT),
			0, GL_RGBA, GL_UNSIGNED_BYTE,
			ilGetData());
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		this->textureMap.insert(std::pair<std::string, Texture>(filename, Texture(filename, textureId, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT))));
	}
Example #18
0
BundlerMatcher::BundlerMatcher(float matchThreshold, int firstOctave, bool binaryWritingEnabled, bool sequenceMatching, int sequenceMatchingLength)
{
    mBinaryKeyFileWritingEnabled = binaryWritingEnabled;
    mSequenceMatchingEnabled     = sequenceMatching;
    mSequenceMatchingLength      = sequenceMatchingLength;

    //DevIL init
    ilInit();
    ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
    ilEnable(IL_ORIGIN_SET);

    std::cout << "[BundlerMatcher]"<<std::endl;
    std::cout << "[Initialization]";

    mIsInitialized = true;
    mMatchThreshold = matchThreshold; //0.0 means few match and 1.0 many match

    char fo[10];
    sprintf(fo, "%d", firstOctave);
    char* args[] = {"-fo", fo};

    mSift = new SiftGPU;
    mSift->ParseParam(2, args);
    mSift->SetVerbose(-2);

    int support = mSift->CreateContextGL();
    if (support != SiftGPU::SIFTGPU_FULL_SUPPORTED)
        mIsInitialized = false;

    if (mIsInitialized)
        mSift->AllocatePyramid(1600, 1600);

    mMatcher = new SiftMatchGPU(4096);
}
Example #19
0
void init()
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	// OpenGL assumes all textures have their origin in lower left corner. We
	// must inform IL about this fact, or we shall get upside-down textures.
	ilEnable(IL_ORIGIN_SET);
	ilOriginFunc(IL_ORIGIN_LOWER_LEFT);

	// As mentioned, we use classes to simplify manipulation with images.
	// We use the following methods:
	//		- Load		.. loads image from file
	//		- Width		.. returns width of loaded image
	//		- Height	.. returns height of loaded image
	//		- GetData	.. returns pointer to data of image
	ilImage image;
	
	// Try several image formats, at least PNG and JPG. Try only textures with
	// power-of-two sizes (like 256x256, 512x512 etc.). Loading images with
	// other dimensions may need some additional steps to make them work, and
	// they are not necessary to deal with to get ready for the fourth lesson.
	// Also, some platforms needs 'const char *' and some 'const wchar_t *',
	// so add/remove 'L' before the path when necessary.
	image.Load(L"coordinates.png");		// We use Load method here

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	// We use Width, Height and GetData methods here
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.Width(), image.Height(), 0,
		GL_RGB, GL_UNSIGNED_BYTE, image.GetData());
}
Example #20
0
void ImageSequenceSave::saveImage(const std::string& filename, tgt::Texture* image) throw (VoreenException) {
    tgtAssert(filename != "", "filename is empty");
    tgtAssert(tgt::FileSystem::fileExtension(filename) != "", "filename has no extension");
    tgtAssert(image, "no texture");
    if (image->getDepth() > 1)
        throw VoreenException("Passed image is a 3D texture");

    // get color buffer content
    tgt::ivec2 dim = image->getDimensions().xy();
    bool luminance = (image->getFormat() == GL_LUMINANCE);

    GLushort* colorBuffer;
    if (luminance)
        colorBuffer = reinterpret_cast<GLushort*>(image->downloadTextureToBuffer(GL_LUMINANCE, GL_UNSIGNED_SHORT));
    else
        colorBuffer = reinterpret_cast<GLushort*>(image->downloadTextureToBuffer(GL_RGBA, GL_UNSIGNED_SHORT));

    // create Devil image from image data and write it to file
    ILuint img;
    ilGenImages(1, &img);
    ilBindImage(img);
    // put pixels into IL-Image
    ilTexImage(dim.x, dim.y, 1, (luminance ? 1 : 4), (luminance ? IL_LUMINANCE : IL_RGBA), IL_UNSIGNED_SHORT, colorBuffer);
    ilEnable(IL_FILE_OVERWRITE);
    ilResetWrite();
    ILboolean success = ilSaveImage(const_cast<char*>(filename.c_str()));
    ilDeleteImages(1, &img);

    delete[] colorBuffer;

    if (!success) {
        throw VoreenException(DevILModule::getDevILError());
    }
}
Example #21
0
static void captureImage(void) {

	// capture
	//ILuint ratz;
	//vector<GLubyte> store;
	char *savePath[200];

	//GLubyte *store= GLubyte[xsize * ysize * 4];
	GLubyte store[307200];
	/* capture */



	//ilGenImages(1, &ratz);
	//ilBindImage(ratz);

	//store.resize(xsize * ysize * 4);
	glReadPixels(0, 0, xsize, ysize, GL_RGBA, GL_UNSIGNED_BYTE, &store[0]);
	//glReadPixels(0, 0, 240, 320, GL_RGBA, GL_UNSIGNED_BYTE, &store[0]);

	ilTexImage(xsize, ysize, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, &store[0]);
	
	ilEnable(IL_FILE_OVERWRITE);
	//ilSaveImage(sortie.c_str());
	
	strcpy(savePath, outputDir);
	strcat(savePath, filename);
	//ilSaveImage("C:\\Documents and Settings\\Administrator\\Desktop\\carpark - AR\\out.jpg");
	printf("Saving %s\n", savePath);
	ilSaveImage(savePath);
	//ilSaveImage("C:\\Documents and Settings\\Administrator\\Desktop\\carpark - AR\\output\\out.jpg");
	
	/* capture */
}
Example #22
0
void CBitmap::Save(string const& filename)
{
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
	ilEnable(IL_ORIGIN_SET);

	unsigned char* buf=new unsigned char[xsize*ysize*4];
	/* HACK Flip the image so it saves the right way up.
		(Fiddling with ilOriginFunc didn't do anything?)
		Duplicated with ReverseYAxis. */
	for(int y=0;y<ysize;++y){
		for(int x=0;x<xsize;++x){
			buf[((ysize-1-y)*xsize+x)*4+0]=mem[((y)*xsize+x)*4+0];
			buf[((ysize-1-y)*xsize+x)*4+1]=mem[((y)*xsize+x)*4+1];
			buf[((ysize-1-y)*xsize+x)*4+2]=mem[((y)*xsize+x)*4+2];
			buf[((ysize-1-y)*xsize+x)*4+3]=mem[((y)*xsize+x)*4+3];
		}
	}

	ilHint(IL_COMPRESSION_HINT, IL_USE_COMPRESSION);
	ilSetInteger (IL_JPG_QUALITY, 80);

	ILuint ImageName = 0;
	ilGenImages(1, &ImageName);
	ilBindImage(ImageName);

	ilTexImage(xsize,ysize,1,4,IL_RGBA,IL_UNSIGNED_BYTE,NULL);
	ilSetData(buf);
	ilSaveImage((char*)filename.c_str());
	ilDeleteImages(1,&ImageName);
	delete[] buf;
}
Example #23
0
void CMainDlg::ExportTextures(const CString &path)
{
	ILuint handle;
	ilInit();
	iluInit();
	ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
	ilEnable(IL_ORIGIN_SET);
	for(int i = 0; i < m_Textures.GetCount(); i++)
	{
		if(texdata[i] != -1)
		{
			ilGenImages(1, & handle);
			ilBindImage(handle);
			CString file;
			m_Textures.GetText(i, file);
			vector<char> data;
			data.resize(sc.index[texdata[i]].fileSize);
			ifstream is;
			is.sync_with_stdio(false);
			is.open(sc.index[texdata[i]].cachename.c_str(), ios::binary|ios::in);
			is.read(reinterpret_cast<char*>(&data[0]), sc.index[texdata[i]].fileSize);
			is.close();
			ILboolean ret = ilLoadL(IL_DDS, reinterpret_cast<char*>(&data[0]), sc.index[texdata[i]].fileSize);
			file.Replace(".dds", ".png");
			iluFlipImage();
			ilSaveImage((path + file));
			/*ofstream out;
			out.sync_with_stdio(false);
			out.open(path + file, ios::binary);
			out.write(reinterpret_cast<char*>(&data[0]), sc.index[texdata[i]].fileSize);
			out.close();*/
			ilDeleteImages(1, & handle);
		}
	}
}
Example #24
0
TextureManager::TextureManager(){
    ilInit();
    iluInit();
    ilEnable(IL_CONV_PAL);
    ilutRenderer(ILUT_OPENGL);
    ilutEnable(ILUT_OPENGL_CONV);
    
}
Example #25
0
void DevILModule::initialize() throw (tgt::Exception) {
    VoreenModule::initialize();

    // initialize DevIL
    ilInit();
    iluInit();
    ilEnable(IL_ORIGIN_SET); //< flip images
}
Example #26
0
void QTWindow::saveImage(const char * outputFilename, BYTE * imgData, int width, int height)
{
	ILuint imageID = ilGenImage();
	ilBindImage(imageID);
	ilTexImage(width, height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, imgData);
  	ilEnable(IL_FILE_OVERWRITE);
	ilSave(IL_JPG, outputFilename);
}
Example #27
0
GLubyte* OpenImageDevIL(const std::string& filename, unsigned int& w, unsigned int& h, unsigned int& d)
{
	static bool first = true;
	if(first) {
		first = false;

		// Init DevIL
		ilInit();

		// Set origin of image to upper left corner
		ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
		ilEnable(IL_ORIGIN_SET);

		ilEnable(IL_TYPE_SET);
		ilTypeFunc(IL_UNSIGNED_BYTE);
	}

    // Generating a new texture
    ILuint ilTexture;
    ilGenImages(1, &ilTexture);
    ilBindImage(ilTexture);

    // Loading image
	if (!ilLoadImage(filename.c_str()))
		return false;

	w = ilGetInteger(IL_IMAGE_WIDTH);
	h = ilGetInteger(IL_IMAGE_HEIGHT);
	d = ilGetInteger(IL_IMAGE_BPP);
	
	if(d==4)
		ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

    // Get the size of image
    const unsigned char* Pixels = ilGetData();

	GLubyte* img = new GLubyte[(size_t)(w) * (size_t)(h) * (size_t)(d)];
	memcpy(img, Pixels, (size_t)(w) * (size_t)(h) * (size_t)(d));
	
    // Remove the texture
    ilBindImage(0);
    ilDeleteImages(1, &ilTexture);
	
	return img;
	//return NULL;
}
Example #28
0
File: test.c Project: AMDmi3/DevIL
int main(int argc, char **argv)
{
	ILuint	ImgId;
	ILenum	Error;
	char	*Data;
	long	Size;

	// We use the filename specified in the first argument of the command-line.
	if (argc < 3) {
		printf("Please specify a .rar file and file inside to open.\n");
		return 1;
	}

	// Check if the shared lib's version matches the executable's version.
	if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
		iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
		printf("DevIL version is different...exiting!\n");
		return 2;
	}

	// Initialize DevIL.
	ilInit();
	// Generate the main image name to use.
	ilGenImages(1, &ImgId);
	// Bind this image name.
	ilBindImage(ImgId);

	if (!urarlib_get(&Data, &Size, argv[2], argv[1], "none")) {
		printf("Error loading .rar file.\n");
		return 3;
	} 

	// Loads the image specified by File into the image named by ImgId.
	ilLoadL(IL_TGA, Data, Size);

	// Display the image's dimensions to the end user.
	printf("Width: %d  Height: %d  Depth: %d  Bpp: %d\n", ilGetInteger(IL_IMAGE_WIDTH),
		ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_DEPTH), ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL));

	// Enable this to let us overwrite the destination file if it already exists.
	ilEnable(IL_FILE_OVERWRITE);

	// If argv[2] is present, we save to this filename, else we save to test.tga.
	if (argc > 2)
		ilSaveImage(argv[3]);
	else
		ilSaveImage("test.tga");

	// We're done with the image, so let's delete it.
	ilDeleteImages(1, &ImgId);

	// Simple Error detection loop that displays the Error to the user in a human-readable form.
	while ((Error = ilGetError())) {
		printf("Error: %s\n", iluErrorString(Error));
	}

	return 0;
}
Example #29
0
 //---------------------------------------------------------------------
 void ILImageCodec::initialiseIL(void)
 {
     if( !_is_initialised )
     {
         ilInit();
         ilEnable( IL_FILE_OVERWRITE );
         _is_initialised = true;
     }
 }
Example #30
0
void ofxTexture::BlockTransfer(ofxTexture* source, ofRectangle source_rect, ofVec2f dest_pos, int alpha)
{
    if(m_Locked || source->IsLocked()) return;
    ilBindImage(m_ImageId);
    ilDisable(IL_BLIT_BLEND);
    ilBlit(source->GetDevilId(), dest_pos.x, dest_pos.y, 0,
           source_rect.x, source_rect.y, 0, source_rect.width, source_rect.height, 1);
    ilEnable(IL_BLIT_BLEND);
}