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()); } }
void DevilImageWriter::writeIlImage(const WeaklyTypedPointer& wtp, const cgt::ivec2& size, const std::string& filename) const { // create Devil image from image data and write it to file ILuint img; ilGenImages(1, &img); ilBindImage(img); // put pixels into IL-Image ilTexImage(size.x, size.y, 1, static_cast<ILubyte>(wtp._numChannels), wtp.getIlFormat(), wtp.getIlDataType(), wtp._pointer); ilEnable(IL_FILE_OVERWRITE); ilResetWrite(); ILboolean success = ilSaveImage(filename.c_str()); ilDeleteImages(1, &img); if (! success) { ILenum errorcode; while ((errorcode = ilGetError()) != IL_NO_ERROR) { LERROR("Error while writing '" << filename << "': "<< (errorcode)); } } }
// ONLY call at startup. ILvoid ILAPIENTRY ilInit() { // if it is already initialized skip initialization if (IsInit == IL_TRUE ) return; //ilSetMemory(NULL, NULL); Now useless 3/4/2006 (due to modification in il_alloc.c) ilSetError(IL_NO_ERROR); ilDefaultStates(); // Set states to their defaults. // Sets default file-reading callbacks. ilResetRead(); ilResetWrite(); #if (!defined(_WIN32_WCE)) && (!defined(IL_STATIC_LIB)) atexit((void*)ilRemoveRegistered); #endif //_WIN32_WCE //ilShutDown(); iSetImage0(); // Beware! Clears all existing textures! iBindImageTemp(); // Go ahead and create the temporary image. IsInit = IL_TRUE; return; }