示例#1
0
文件: test.c 项目: 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;
}
void CDevILCodec::CodeToFile(const nstring & filename, const CImage &image)
{
	ILuint imageid;
	CDevILFormats informat;
	informat.SetExFormat(image.GetPixelFormat());
	// Generate the main image name to use.
	ilGenImages(1, &imageid);

	// Bind this image name.
	ilBindImage(imageid);

	ilTexImage(image.GetWidth(), image.GetHeight(), image.GetDepth(), informat.GetInternalChannels(),
		informat.GetFormat(), IL_UNSIGNED_BYTE, image.GetBitsPtr());

	ilSaveImage(filename.c_str());

	ilDeleteImages(1, &imageid);

	ILenum Error = 0;
	if((Error = ilGetError()) != NULL)
	{
		nstring str("CDevILCodec::CodeToFile: ");
		str.append(iluErrorString(Error));
		throw NOVA_EXP(str.c_str(), BAD_OPERATION);
	}
}
示例#3
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 */
}
示例#4
0
bool nTextureManager::saveTexture(nTexture *tex, string name) {
    if(!glIsTexture(tex->tex)) {
        return false;
    }
    mutex->lock();
    unsigned char *dat = new unsigned char[3 * (unsigned int)(tex->size.x * tex->size.y)];
    glBindTexture(GL_TEXTURE_2D, tex->tex);
    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, dat);
    ILuint img;
    ilGenImages(1, &img);
    ilBindImage(img);
    iluScale(tex->size.x, tex->size.y, 1);
    ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
    bool t = ilTexImage(tex->size.x, tex->size.y, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, dat);
    ILuint error = ilGetError();
    GLuint glError = glGetError();
    if(error || !t || glError) {
        nGine::instance()->getLogger()->addDebugLog("Error while saving file : " + nLogger::numToString((int)error) + "/" + nLogger::numToString((int)glError));
        mutex->unlock();
        return false;
    }
    bool a = ilSaveImage((nGine::instance()->appPath() + name).c_str());
    mutex->unlock();
    return a;
}
示例#5
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;
}
示例#6
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);
		}
	}
}
示例#7
0
    //---------------------------------------------------------------------
    void ILImageCodec::codeToFile(MemoryDataStreamPtr& input, 
        const String& outFileName, Codec::CodecDataPtr& pData) const
    {

        ILuint ImageName;

        ilGenImages( 1, &ImageName );
        ilBindImage( ImageName );

		ImageData* pImgData = static_cast< ImageData * >( pData.getPointer() );
		PixelBox src(pImgData->width, pImgData->height, pImgData->depth, pImgData->format, input->getPtr());

		// Convert image from OGRE to current IL image
		ILUtil::fromOgre(src);

        iluFlipImage();

        // Implicitly pick DevIL codec
        ilSaveImage(const_cast< char * >( outFileName.c_str() ) );
	
        // Check if everything was ok
        ILenum PossibleError = ilGetError() ;
        if( PossibleError != IL_NO_ERROR ) {
           ilDeleteImages(1, &ImageName);
           OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED,
                "IL Error, could not save file: " + outFileName,
                iluErrorString(PossibleError) ) ;
        }

        ilDeleteImages(1, &ImageName);

    }
示例#8
0
文件: draw.c 项目: Fadis/euc2png
// ページを書き出す
void dumpPage ( Page *_page, const char *_name ) {
  // 画像出力はDevIL任せ
  ilTexImage ( PAGE_SIZE_X * 6, PAGE_SIZE_Y * 8, 1, 1, IL_LUMINANCE, IL_UNSIGNED_BYTE, ( void* ) ( _page->buffer ) );
  char filename[ MAX_FILENAME_LENGTH ];
  snprintf ( filename, 256, "%s_%02d.png", _name, _page->current_page );
  ilSaveImage ( filename );
}
示例#9
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());
    }
}
示例#10
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;
 }
}
示例#11
0
文件: Image.cpp 项目: hfink/pixelnoir
void Image::save_to_file(const string& filename)
{
    if (!devil_initialized) {
        ilInit();
        devil_initialized = true;
    }

    ILuint il_image;
    ilGenImages(1, &il_image);

    ilTexImage(_width, _height, 0, _bpp, _format, _type, _data);
    ILboolean success = ilSaveImage(filename.c_str());

    if (!success) {
        cerr << "Image::Image "
             << "Failed to save to image file " 
             << filename << endl;
        
        _data = NULL;
        return;
    }    

    ilBindImage(0);
    ilDeleteImages(1, &il_image);
    
}
示例#12
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;
}
示例#13
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) );
}
示例#14
0
文件: test.cpp 项目: wg-lesta/ResIL
void test_ilLoad(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	ilResetRead();
	ILenum sourceType = ilDetermineType(sourceFN);
	if (!ilLoad(sourceType, sourceFN)) {
		printf("test_ilLoad: Failed to load %S\n", sourceFN);
		++errors;
		return;
	}
	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (!ilSaveImage(targetFN)) {
		printf("test_ilLoad: Failed to save " PathCharMod "\n", targetFN);
		++errors;
	}
	testHeap();
	ilDeleteImage(handle);
}
示例#15
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;
}
示例#16
0
文件: test.cpp 项目: wg-lesta/ResIL
void test_ilLoadFuncs(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	FILE* f = _wfopen(sourceFN, L"rb");
	bool loaded = false;

	if (f != NULL) {
		fseek(f, 0, SEEK_END);
		myDataSize = ftell(f);
		if (myDataSize > 0) {
			fseek(f, 0, SEEK_SET);
			myData = new BYTE[myDataSize];
			size_t read = fread(myData, 1, myDataSize, f);
			myReadPos = 0;
			if (read == myDataSize) {
				//loaded = ilLoadL(IL_TYPE_UNKNOWN, lump, read);
				ilSetRead(myOpenProc, myCloseProc, myEofProc, myGetcProc, myReadProc, mySeekProc, myTellProc);
				loaded = ilLoadFuncs(IL_TYPE_UNKNOWN);
				if (!loaded) {
					printf("test_ilLoadFuncs: Failed to load " PathCharMod "\n", sourceFN);
					++errors;
				}
			} else {
				printf("test_ilLoadFuncs: Failed to read " PathCharMod "\n", sourceFN);
				++errors;
			}
			delete myData;
		}
		fclose(f);
	} else {
		printf("test_ilLoadFuncs: Failed to open %S\n", sourceFN);
		++errors;
	}

	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (loaded)
		if(!ilSaveImage(targetFN)) {
			printf("Failed to save " PathCharMod " after ilLoadFuncs\n", targetFN);
			++errors;
		}
	testHeap();
	ilDeleteImage(handle);
}
示例#17
0
void ilFSaveImage_(int *RetVal, struct descriptor *Desc)
{
	char *Filename = malloc(Desc->length + 1);
	strncpy(Filename, Desc->string_ptr, Desc->length);
	Filename[Desc->length] = 0;  // Should really be NULL...getting a warning, though.
	*RetVal = ilSaveImage(Filename);

	free(Filename);
	return;
}
示例#18
0
文件: test.cpp 项目: wg-lesta/ResIL
void test_ilLoadL(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	FILE* f = _wfopen(sourceFN, L"rb");
	bool loaded = false;

	if (f != NULL) {
		fseek(f, 0, SEEK_END);
		INT64 size = ftell(f);
		if (size > 0) {
			fseek(f, 0, SEEK_SET);
			char* lump = new char[size];
			size_t read = fread(lump, 1, size, f);
			if (read == size) {
				loaded = ilLoadL(IL_TYPE_UNKNOWN, lump, read);
				if (!loaded) {
					printf("test_ilLoadL: Failed to load " PathCharMod "\n", sourceFN);
					++errors;
				}
			} else {
				printf("test_ilLoadL: Failed to read " PathCharMod "\n", sourceFN);
				++errors;
			}
			delete lump;
		}
		fclose(f);
	} else {
		printf("test_ilLoadL: Failed to load %S\n", sourceFN);
		++errors;
	}

	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (loaded)
		if (!ilSaveImage(targetFN)) {
			printf("test_ilLoadL: Failed to save " PathCharMod "\n", targetFN);
			++errors;
		}
	testHeap();
	ilDeleteImage(handle);
}
示例#19
0
void Texture::SaveAs(std::string pszFileName, size_t piWidth, size_t piHeight, size_t pType, size_t pFmt, void * pData)
{
    ILuint  _iImageId   = 0;

    _iImageId = ilGenImage();
    ilBindImage(_iImageId);

    ASSERT(  ilTexImage(piWidth,    piHeight, 0, 3, pType, pFmt, pData) == IL_TRUE  , "Texture: Unable to set data!");
    VERIFY(  ilSaveImage(pszFileName.c_str()) == IL_TRUE  , "Texture: Unable to save Image!");

    ilDeleteImage(_iImageId);
}
示例#20
0
bool DrawAbstract::save(std::string path){

	unsigned char *data = new unsigned char[4*screen_width*screen_height];
	glReadBuffer(GL_BACK);
	glReadPixels(0,0,screen_width,screen_height,GL_RGBA, GL_UNSIGNED_BYTE,data);
	ilTexImage(screen_width,screen_height,1,4,IL_RGBA, IL_UNSIGNED_BYTE,data);
	ilEnable(IL_FILE_OVERWRITE);

	ilSaveImage(path.c_str());

	delete data;
	return true;
}
示例#21
0
void Renderer::saveScreenshot(const std::string& filename, int width, int height)
{
    ILuint tex;
    tex = IL_CHECK(ilGenImage());
    IL_CHECK(ilBindImage(tex));

    void* data = malloc(width * height * 3);
    glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
    ilTexImage(width, height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, data);
    free(data);

    IL_CHECK(ilSaveImage(filename.c_str()));
    IL_CHECK(ilDeleteImage(tex));
}
示例#22
0
// methods
void Texture::Save(const char* filename)
{
	uint handle = 0;

	ilGenImages(1, &handle);
	ilBindImage(handle);

	ilTexImage(width, height, 0, channels, format, IL_FLOAT, data);
	ilConvertImage(format, IL_UNSIGNED_BYTE);
	ilSaveImage(filename);

	ilDeleteImage(handle);
	ilBindImage(0);
}
示例#23
0
void takeScreenShot(const string prefix) {
	ILuint handle=0;
	ilGenImages(1, &handle);
	
	ilBindImage(handle);
	ilutGLScreen();
	
	createDirectory(FileName("sshots/"));
	
	char *pszScreenShotFileName = strdup(getScreenShotFileName(prefix).str());
	ilSaveImage(pszScreenShotFileName);
	delete[] pszScreenShotFileName;
	
	ilDeleteImages(1, &handle);
}
示例#24
0
文件: plot.c 项目: TChotibut/moshpits
void plot_saveimage(const char* name){
  ILubyte *data = ilGetData();

  int viewport[4];
  glGetIntegerv(GL_VIEWPORT, viewport);
  int x      = viewport[0];
  int y      = viewport[1];
  int width  = viewport[2];
  int height = viewport[3];

  glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
  
  ilEnable(IL_FILE_OVERWRITE);
  ilSaveImage(name);
}
示例#25
0
bool CBitmap::Save(std::string const& filename, bool opaque) const
{
	if (type == BitmapTypeDDS) {
#ifndef BITMAP_NO_OPENGL
		return ddsimage->save(filename);
#else
		return false;
#endif // !BITMAP_NO_OPENGL
	}

	unsigned char* buf = new unsigned char[xsize * ysize * 4];
	const int ymax = (ysize - 1);
	/* 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) {
			const int bi = 4 * (x + (xsize * (ymax - y)));
			const int mi = 4 * (x + (xsize * (y)));
			buf[bi + 0] = mem[mi + 0];
			buf[bi + 1] = mem[mi + 1];
			buf[bi + 2] = mem[mi + 2];
			buf[bi + 3] = opaque ? 0xff : mem[mi + 3];
		}
	}

	boost::mutex::scoped_lock lck(devilMutex);
	ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
	ilEnable(IL_ORIGIN_SET);

	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, buf);

	const std::string fullpath = dataDirsAccess.LocateFile(filename, FileQueryFlags::WRITE);
	const bool success = ilSaveImage((char*)fullpath.c_str());

	ilDeleteImages(1, &ImageName);
	ilDisable(IL_ORIGIN_SET);
	delete[] buf;

	return success;
}
示例#26
0
文件: data_to_png.c 项目: 8l/beri
int main(int argc, char* argv[]) {
    if (argc != 3) {
        printf("Usage: %s <input data file> <output image file>", argv[0]);
    }

    byte* img = malloc(IMG_ARRAY_LENGTH);
    ilInit();

    uint pos = 0;
    FILE* dataFile = fopen(argv[1], "r");
    while (fscanf(dataFile, "%2hhx", &(img[pos++])) == 1) { }
    fclose(dataFile);

    ilTexImage(IMG_WIDTH, IMG_HEIGHT, 0, 3, IL_RGB, IL_UNSIGNED_BYTE, img);
    ilSaveImage(argv[2]);
}
示例#27
0
文件: test.cpp 项目: wg-lesta/ResIL
void test_ilLoadF(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	bool loaded = false;

	//FILE* f = _wfopen(sourceFN, L"rb");
	FILE * f;
	char buf[10];
	_wfopen_s(&f, sourceFN, L"rb");
	fread(buf, 1, 10, f);
	fseek(f, 0, IL_SEEK_SET);
	if (f != NULL) {
		loaded = ilLoadF(IL_TYPE_UNKNOWN, f);
		if(!loaded) {
			printf("test_ilLoadF: Failed to load %S\n", sourceFN);
			++errors;
		}
	} else {
		printf("test_ilLoadF: Failed to open %S\n", sourceFN);
		++errors;
	}

	fclose(f);
	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);

	if (loaded)
		if (!ilSaveImage(targetFN)) {
			printf ("test_ilLoadF: Failed to save %S\n", targetFN);
			++errors;
		}

	testHeap();
	ilDeleteImage(handle);
}
示例#28
0
bool ImageLoader::saveImageRGBA(const char* image, u8* data, u32 width, u32 height)
{
	ILuint handle;

	// In the next section, we load one image
	ilGenImages(1, &handle);
	ilBindImage(handle);

	ilTexImage(width, height, 1, 4, IL_RGBA, IL_UNSIGNED_BYTE, data);
	ilEnable(IL_FILE_OVERWRITE);
	const ILboolean saved = ilSaveImage(image);

	// Finally, clean the mess!
	ilDeleteImages(1, &handle);

	return saved ? true : false;
}
示例#29
0
文件: ilur.c 项目: 123woodman/minko
int do_stuff(const Params * parameters)
{
	if (parameters->Flags & FLAG_HELP || ((parameters->Flags | FLAG_LOAD |  FLAG_SAVE) != parameters->Flags) )
	{/* We wanted HELP or we did not get SAVE or LOAD */
		print_help(); /* tell the loser what to do, then :-) */
		return 0;
	}
	int verbose = parameters->Flags & FLAG_VERBOSE;

	int image_handle;
	int w, h;
	ILboolean result;

	/* Quite obvious stuff, just load an image */
	ilGenImages(1, & image_handle);
	ilBindImage(image_handle);
	result = ilLoadImage(parameters->Load_filename);
	if (result == IL_FALSE)
	{
		int error = ilGetError();
		fprintf(stderr, "Error: Something went wrong when loading file '%s' (%s)\n", parameters->Load_filename, iluErrorString(error));
		return error;
	}
	/* If we get image's dimensions, people will believe that we have actually loaded something :-) */
	w = ilGetInteger(IL_IMAGE_WIDTH);
	h = ilGetInteger(IL_IMAGE_HEIGHT);
	if (verbose)
		printf("Loaded '%s', size %dx%d\n", parameters->Load_filename, w, h);
	/* Now let's do our stuff!!! */
	int i;
	for (i = 0; i < parameters->Calls_count; i++)
		perform_operation(parameters->Calls_strings[i], verbose);
	/* our stuff has been done... */

	result = ilSaveImage(parameters->Save_filename);
	if (result == IL_FALSE)
	{
		int error = ilGetError();
		fprintf(stderr, "Error: Something went wrong when saving file '%s' (%s)\n", parameters->Save_filename, iluErrorString(error));
		ilDeleteImages(1, & image_handle);
		return error;
	}
	ilDeleteImages(1, & image_handle);
	return 0;
}
示例#30
0
	void SaveImage(const char *fn, int components, GLenum type, int w,int h, void *data)
	{
		// We use the fact that DevIL has the same constants for component type as OpenGL
		/// ( GL_UNSIGNED_BYTE = IL_UNSIGNED_BYTE for example )
#ifdef TERRAIN_USE_IL
		// Save image
		ILuint out;
		ilGenImages(1,&out);
		ilBindImage(out);
		ILenum fmt=IL_RGB;
		if (components==4) fmt = IL_RGBA;
		if (components==1) fmt = IL_LUMINANCE;
		ilTexImage(w,h,1,components,fmt,type,data);
		filesystem.Remove(fn);
		ilSaveImage((ILstring)fn);
		ilDeleteImages(1,&out);
#endif
	}