// eng: loading from memory // rus: загрузка из памяти unsigned char* LoadTextureFromMemory(const unsigned char* buffer, int len, int* width, int* height) { #ifdef LOADER_OPENIL if (first_loading_openil) { first_loading_openil=false; ilInit(); } ILuint image; ilGenImages(1,&image); ilBindImage(image); ilLoadL(IL_TYPE_UNKNOWN, buffer, len); ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE); *width=ilGetInteger(IL_IMAGE_WIDTH); *height=ilGetInteger(IL_IMAGE_HEIGHT); int len4=(*width)*(*height); int* pixels=(int*)ilGetData(); int* data=new int[len4]; for (int i=0;i<len4;i++) data[i]=pixels[i]; ilDeleteImages(1, &image); return (unsigned char*)data; #else #ifdef LOADER_STDIMAGE int comp; return stbi_load_from_memory(buffer, len, width, height, &comp, 4); #else #ifdef LOADER_LIBPNGJPG return LoadPNGJPGFromMemory(buffer, len, width, height); #endif #endif #endif }
bool Anim::LoadFile(){ for( this->for_int_i=0; this->for_int_i<this->Size; this->for_int_i++){ ilGenImages( 1, &this->ImageID[for_int_i] ); ilBindImage( this->ImageID[for_int_i] ); this->Success = ilLoadImage( this->File_Name[for_int_i].c_str() ); if( this->Success == IL_TRUE ){ this->Width = ilGetInteger(IL_IMAGE_WIDTH); this->Height = ilGetInteger(IL_IMAGE_HEIGHT); this->Success = ilConvertImage( IL_RGBA, IL_UNSIGNED_BYTE ); if( this->Success == IL_TRUE ){ glGenTextures( 1, &this->ImageID[for_int_i] ); glBindTexture( GL_TEXTURE_2D, this->ImageID[for_int_i] ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexImage2D( GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), this->Width, this->Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLuint*)ilGetData() ); GLenum error = glGetError(); if( error != GL_NO_ERROR ){ LogGame::Write( "[ERR] " ); LogGame::Write( SDL_GetTicks() ); LogGame::Write( ": Nie przetworzono grafiki: " ); LogGame::Write( this->File_Name[for_int_i] ); LogGame::Write( " Błąd: " ); LogGame::Write( error ); LogGame::NewLine(); return false; } } else{ LogGame::Write( "[ERR] " ); LogGame::Write( SDL_GetTicks() ); LogGame::Write( ": Nie przekształcono grafiki: " ); LogGame::Write( this->File_Name[for_int_i] ); LogGame::NewLine(); return false; } } else{ LogGame::Write( "[ERR] " ); LogGame::Write( SDL_GetTicks() ); LogGame::Write( ": Nie załadowano grafiki: " ); LogGame::Write( this->File_Name[for_int_i] ); LogGame::Write( " (PLIK NIE ISTNIEJE)\n" ); return false; } } return true; }
BITMAP* ILAPIENTRY ilutAllegLoadImage(ILstring FileName) { ILuint ImgId; PALETTE Pal; ilGenImages(1, &ImgId); ilBindImage(ImgId); if (!ilLoadImage(FileName)) { ilDeleteImages(1, &ImgId); return 0; } ilDeleteImages(1, &ImgId); return ilutConvertToAlleg(Pal); }
GLuint CGLTexture::LoadGL(string f) { glBmap=0; filename=f; ILuint imageID; ILboolean success; ILenum error; ilGenImages(1, &imageID); ilBindImage(imageID); success = ilLoadImage(filename.c_str()); if (success) { ILinfo ImageInfo; iluGetImageInfo(&ImageInfo); if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT) iluFlipImage(); success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); if (!success){ error = ilGetError(); pLog->_Add(" CGLTexture::LoadGL() Image conversion failed - IL reports error: %d %s",error,iluErrorString(error)); return 0; } width=ilGetInteger(IL_IMAGE_WIDTH); height=ilGetInteger(IL_IMAGE_HEIGHT); format=ilGetInteger(IL_IMAGE_FORMAT); bpp=ilGetInteger(IL_IMAGE_BPP)*8; glEnable(GL_TEXTURE_2D); glGenTextures(1, &glBmap); glBindTexture(GL_TEXTURE_2D, glBmap); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D( GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); } else { error = ilGetError(); pLog->_Add(" CGLTexture::LoadGL() Image load failed - IL reports error: %d %s",error,iluErrorString(error)); return 0; } ilDeleteImages(1, &imageID); return glBmap; }
int GLText::LoadFont(char* fname, int Width, int Height) { ScreenWidth = Width; ScreenHeight = Height; unsigned img; ilGenImages(1, &img); ilBindImage(img); if (ilLoadImage(fname) == false) { printf("Cannot load image file %s - %d\n", fname, ilGetError()); return 1; } glGenTextures(1, &fontTexture); glBindTexture(GL_TEXTURE_2D, fontTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); ilDeleteImages(1, &img); char data[256]; memset(data, 0, 256); strcpy(data, fname); int len = strlen(data); data[len] = 0; data[len - 1] = 't'; data[len - 2] = 'a'; data[len - 3] = 'd'; FILE* f = 0; f = fopen(data, "rb"); if (!f) { printf("Cannot load character spacing file %s", data); return 1; } fread(charSpace, 1, 256, f); fclose(f); return 0; }
bool Image32::load_texture_from_file_32(const char *path) { // generate image ILuint image_id = 0; ilGenImages(1, &image_id); ilBindImage(image_id); //Load image bool got = ilLoadImage( path ); if (got == IL_TRUE) { // convert image bool converted = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); if (converted == IL_TRUE) { // init dimensions GLuint image_width = (GLuint)ilGetInteger(IL_IMAGE_WIDTH); GLuint image_height = (GLuint)ilGetInteger(IL_IMAGE_HEIGHT); GLuint texture_width = power_of_two(image_width); GLuint texture_height = power_of_two(image_height); if (image_width != texture_width || image_height != texture_height) { // place image in upper left iluImageParameter(ILU_PLACEMENT, ILU_UPPER_LEFT); // resize image iluEnlargeCanvas((int)texture_width, (int)texture_height, 1); } bool loaded = load_texture_from_pixels_32((GLuint*)ilGetData(), image_width, image_height, texture_width, texture_height); if (!loaded) { std::cout << "unable to load image: " << path << std::endl; return false; } } ilDeleteImages(1,&image_id); } _pixel_format = GL_RGBA; return true; }
int image_load(lua_State *L, const char *path, const char *name) { ILuint imageID; ilGenImages(1, &imageID); ilBindImage(imageID); if (!ilLoadImage(path)) { ilDeleteImages(1, &imageID); return luaL_error(L, "loading %s failed: %s", path, iluErrorString(ilGetError())); } ILinfo ImageInfo; iluGetImageInfo(&ImageInfo); if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT) iluFlipImage(); if (!ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE)) { ilDeleteImages(1, &imageID); return luaL_error(L, "converting %s failed: %s", path, iluErrorString(ilGetError())); } int width = ilGetInteger(IL_IMAGE_WIDTH); int height = ilGetInteger(IL_IMAGE_HEIGHT); GLuint tex; glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), width, height, 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); glGenerateMipmap(GL_TEXTURE_2D); ilDeleteImages(1, &imageID); image_t *image = push_image(L); image->tex = tex; image->fbo = 0; image->width = width; image->height = height; return 1; }
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; }
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; }
ILuint ImagePrivate::DevilLoadImage(std::string name) { ILuint ImageName; ilGenImages(1, &ImageName); ilBindImage(ImageName); if(!ilLoadImage((char*)name.c_str())) { string str = "Failed to load image: " + name + "!\n"; gLog.OutPut(str); return 0; } textureMem += (ilGetInteger(IL_IMAGE_WIDTH)*ilGetInteger(IL_IMAGE_HEIGHT)*4); string str = "Image Loaded: " + name + "\n"; gLog.OutPut(str); return ImageName; }
void readTextures(scene_data* scene, const boost::property_tree::ptree& pt) { boost::property_tree::ptree::const_iterator iter = pt.begin(); for (; iter != pt.end(); ++iter) { std::string name = iter->first; std::string filename = iter->second.get_value<std::string>(); ILuint texid; ilGenImages(1, &texid); ilBindImage(texid); ILboolean success = ilLoadImage((wchar_t*)filename.c_str()); if (success) { success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); if (!success) { printf("Error converting %s to RGBA\n", filename); ilDeleteImages(1, &texid); return; } GLuint image; glGenTextures(1, &image); glBindTexture(GL_TEXTURE_2D, image); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); float maxAnistropy; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnistropy); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnistropy); glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); glGenerateMipmap(GL_TEXTURE_2D); scene->textures[name] = image; ilDeleteImages(1, &texid); } else printf("Error loading file %s\n", filename); } }
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; }
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 }
void initGraphics() { ilGenImages( 1, &ImageName ); ilBindImage( ImageName ); glEnable( GL_TEXTURE_2D ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); if (!ilLoadImage( "gamedata/bg-art.png" )) { printf("Loading image bg-art failed\n"); } gl_tex_id = ilutGLBindTexImage(); //ilutGLTexImage( gl_tex_id ); initGamepadDiagram(); }
/* ================= - create the texture for use. ================= */ bool cTexture::createTexture(LPCSTR theFilename) // create the texture for use. { ILboolean success = false; if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION) { return false; } ilInit(); /*Initialize the DevIL library*/ ilGenImages(1, &ilTextureID); //Generate DevIL image objects ilBindImage(ilTextureID); /* Binding of image object */ success = ilLoadImage((const ILstring)theFilename); /* Loading of image*/ if (!success) { ilDeleteImages(1, &ilTextureID); return false; } success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); // Convert every colour component into unsigned byte. if (!success) { return false; } textureWidth = ilGetInteger(IL_IMAGE_WIDTH); textureHeight = ilGetInteger(IL_IMAGE_HEIGHT); glGenTextures(1, &GLTextureID); // GLTexture name generation glBindTexture(GL_TEXTURE_2D, GLTextureID); // Binding of GLtexture name glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Use linear interpolation for magnification filter glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); // Use linear interpolation for minifying filter glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); /* Texture specification */ glBindTexture(GL_TEXTURE_2D, GLTextureID); // Binding of GLtexture name ilDeleteImages(1, &ilTextureID); return true; }
Image* ImagesLoader::loadFromFile(const std::string& file){ ILuint texture; ilGenImages(1, &texture); ilBindImage(texture); if(!(ilLoadImage(const_cast<ILstring>(file.c_str())))) throw LoadingFailed(file); glm::ivec2 size; size.x = ilGetInteger(IL_IMAGE_WIDTH); size.y = ilGetInteger(IL_IMAGE_HEIGHT); const unsigned char* pix = ilGetData(); Image* img = new Image(size, PXF_A8R8G8B8, pix); img->flip(); return img; }
GLuint Renderer::loadTexture(const std::string &fname) { ILuint imageID; GLuint textureID; ILboolean success; ILenum error; ilGenImages(1, &imageID); ilBindImage(imageID); success = ilLoadImage(fname.c_str()); if (success) { ILinfo ImageInfo; iluGetImageInfo(&ImageInfo); if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT) { iluFlipImage(); } success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); if (!success) { error = ilGetError(); return 0; } glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_FORMAT), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData()); } else { error = ilGetError(); return 0; } ilDeleteImages(1, &imageID); return textureID; }
ILuint CopyImage(Image *src, Image *dest) { ILuint newImageID; ilGenImages(1, &newImageID); ilBindImage(newImageID); if (!ilCopyImage(src->id)) return 0; dest->id = newImageID; dest->rawData = ilGetData(); dest->width = ilGetInteger(IL_IMAGE_WIDTH); dest->height = ilGetInteger(IL_IMAGE_HEIGHT); dest->depth = ilGetInteger(IL_IMAGE_DEPTH); dest->format = ilGetInteger(IL_IMAGE_FORMAT); return 1; }
ILuint ImageManager::GenerateKeeperImage(ILuint TextureDevILID, int16_t BorderColorID) { ILuint NewImageID; if (BorderColorID != -1) { ilGenImages(1, &NewImageID); ilBindImage(NewImageID); ilCopyImage(TextureDevILID); ApplyBorder(NewImageID, BorderColorID); } else { // no reason to copy large amounts of data without changes NewImageID = TextureDevILID; } return NewImageID; }
bool JTexture::loadPixelsFromFile(std::string path) { //deallocate previous texture data freeTexture(); bool pixelsLoaded = false; ILuint imgID = 0; ilGenImages(1, &imgID); ilBindImage(imgID); ILboolean success = ilLoadImage(path.c_str()); if(success == IL_TRUE) { success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); if(success == IL_TRUE) { GLuint imgWidth = (GLuint)ilGetInteger(IL_IMAGE_WIDTH); GLuint imgHeight = (GLuint)ilGetInteger(IL_IMAGE_HEIGHT); GLuint size = imgWidth * imgHeight; mPixels = new GLuint[size]; mTextureWidth = imgWidth; mTextureHeight = imgHeight; memcpy(mPixels, ilGetData(), size * 4); pixelsLoaded = true; } ilDeleteImages(1, &imgID); } if(!pixelsLoaded) { printf("Unable to load %s\n", path.c_str()); } return pixelsLoaded; }
bool CBitmap::LoadGrayscale(const std::string& filename) { type = BitmapTypeStandardAlpha; channels = 1; CFileHandler file(filename); if (!file.FileExists()) { return false; } unsigned char* buffer = new unsigned char[file.FileSize() + 1]; file.Read(buffer, file.FileSize()); boost::mutex::scoped_lock lck(devilMutex); ilOriginFunc(IL_ORIGIN_UPPER_LEFT); ilEnable(IL_ORIGIN_SET); ILuint ImageName = 0; ilGenImages(1, &ImageName); ilBindImage(ImageName); const bool success = !!ilLoadL(IL_TYPE_UNKNOWN, buffer, file.FileSize()); ilDisable(IL_ORIGIN_SET); delete[] buffer; if (success == false) { return false; } ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE); xsize = ilGetInteger(IL_IMAGE_WIDTH); ysize = ilGetInteger(IL_IMAGE_HEIGHT); delete[] mem; mem = NULL; // to prevent a dead-pointer in case of an out-of-memory exception on the next line mem = new unsigned char[xsize * ysize]; memcpy(mem, ilGetData(), xsize * ysize); ilDeleteImages(1, &ImageName); return true; }
bool M_loadImage(const char * filename, void * data) { DevILInit(); // gen image ILuint ImgId = 0; ilGenImages(1, &ImgId); // bind image ilBindImage(ImgId); // load image if(! ilLoadImage(filename)) { ilDeleteImages(1, &ImgId); DevILShutDown(); return false; } // get properties int bytePerPix = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL); int width = ilGetInteger(IL_IMAGE_WIDTH); int height = ilGetInteger(IL_IMAGE_HEIGHT); if(bytePerPix == 4) ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); else ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); // create image MImage * image = (MImage *)data; image->create(M_UBYTE, (unsigned int)width, (unsigned int)height, (unsigned int)bytePerPix); // copy data unsigned int size = image->getSize(); memcpy(image->getData(), ilGetData(), size); ilDeleteImages(1, &ImgId); DevILShutDown(); return true; }
// First part of a 2 stage file loader... bit DevilLoadStart(cstrconst filename,nat32 & handle,nat32 & outWidth,nat32 & outHeight) { ilGenImages(1,(unsigned int *)&handle); ilBindImage(handle); ilEnable(0x0600); ilOriginFunc(0x0601); ilLoadImage(filename); if (ilGetError()) { ilDeleteImages(1,(unsigned int *)&handle); return false; } else { outWidth = ilGetInteger(0x0DE4); outHeight = ilGetInteger(0x0DE5); return true; } }
void Image::loadImage(const char *filename) { ILboolean ok; ilGenImages(1, &image); CHECK_IL_ERROR("ilGenImages") ilBindImage(image); CHECK_IL_ERROR("ilBindImage") ok = ilLoadImage(filename); if (!ok) { CHECK_IL_ERROR("ilLoadImage") } size.x = ilGetInteger(IL_IMAGE_WIDTH); size.y = ilGetInteger(IL_IMAGE_HEIGHT); buffer = new char[(int)size.x * (int)size.y * 4]; ilCopyPixels(0, 0, 0, size.x, size.y, 1, IL_RGBA, IL_UNSIGNED_BYTE, buffer); }
ILuint ImageManager::loadImage(char* filepath, bool ColorKey) { ILuint ImageID; ilGenImages(1, &ImageID); ilBindImage(ImageID); printf("Loading Image file: %s\n", filepath); if(!ilLoadImage(filepath)) { cerr << "Couldn't load image " << filepath << endl; } /* IL_RGB IL_RGBA IL_BGR IL_BGRA IL_LUMINANCE IL_COLOUR_INDEX IL_BYTE IL_UNSIGNED_BYTE IL_SHORT IL_UNSIGNED_SHORT IL_INT IL_UNSIGNED_INT IL_FLOAT IL_DOUBLE */ ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE); if(ColorKey) { //convert color key } ReportDevILErrors(); return ImageID; }
GLuint getTexture( const std::string &filename, int *xsize, int *ysize ) { GLuint texId; // See if the texture is already loaded TextureDB::iterator ti; ti = g_textureDB.find( filename ); if (ti == g_textureDB.end() ) { // Load the font image ILuint ilImgId; ilGenImages( 1, &ilImgId ); ilBindImage( ilImgId ); if (!ilLoadImage( (ILstring)filename.c_str() )) { printf("Loading font image failed\n"); } // printf("Loaded Texture %s\n", filename.c_str() ); // Make a GL texture for it texId = ilutGLBindTexImage(); // and remember it g_textureDB[ filename ] = texId; } else { // found the texture texId = (*ti).second; } // now get the size if they asked for it if ((xsize) && (ysize)) { glBindTexture( GL_TEXTURE_2D, texId ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, xsize ); glGetTexLevelParameteriv( GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, ysize ); } return texId; }
int main(int argc, char **argv) { ILuint image = 0; ILuint reference = 0; // syntax: ILtestAlgoQuant <reference> if (argc < 2) { return -1; } ilInit(); iluInit(); ilEnable(IL_ORIGIN_SET); // flip image on load if necessary ilEnable(IL_FILE_MODE); // overwrite files // load reference image ilGenImages(1, &reference); CHECK(reference != 0); CHECK(testLoadImage(argv[1], reference)); // duplicate image = ilCloneCurImage(); CHECK(image != 0); // quantize ilBindImage(image); ilSetInteger(IL_QUANTIZATION_MODE, IL_WU_QUANT); ilConvertImage(IL_COLOUR_INDEX, IL_UNSIGNED_BYTE); CHECK(testSaveImage("test_quant.png", image)); // compare two images CHECK_GREATER(iluSimilarity(reference), 0.98f); // cleanup ilDeleteImages(1, &image); ilDeleteImages(1, &reference); ilShutDown(); return 0; }
int main(int argc, char *argv[]) { BITMAP *Image; PALETTE Pal; ILuint Id; if (argc != 2) { printf("Please specify a filename.\n"); return 1; } ilInit(); ilGenImages(1, &Id); ilBindImage(Id); ilLoadImage(argv[1]); // if (ilGetInteger(IL_IMAGE_FORMAT) == GL_BGR || // ilGetInteger(IL_IMAGE_FORMAT) == GL_BGRA) ilSwapColours(); Image = (BITMAP*)ilutConvertToAlleg(Pal); allegro_init(); install_keyboard(); if (ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL) == 8) { set_color_depth(8); set_palette(Pal); } else set_color_depth(32); set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); blit(Image, screen, 0, 0, (SCREEN_W - Image->w) / 2, (SCREEN_H - Image->h) / 2, Image->w, Image->h); destroy_bitmap(Image); readkey(); return 0; }
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)); } } }
ILuint LoadImage(const std::string& filename, Image *image) { ILuint newImageID; ilGenImages(1, &newImageID); ilBindImage(newImageID); if (!ilLoadImage(strdup(filename.c_str()))) return 0; ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); image->id = newImageID; image->rawData = ilGetData(); image->width = ilGetInteger(IL_IMAGE_WIDTH); image->height = ilGetInteger(IL_IMAGE_HEIGHT); image->depth = ilGetInteger(IL_IMAGE_DEPTH); image->format = ilGetInteger(IL_IMAGE_FORMAT); return 1; }