void ScanGallery::slotUnloadItem(FileTreeViewItem *curr) { if (curr==NULL) return; if (curr->isDir()) // is a directory { for (int i = 0; i<curr->childCount(); ++i) { FileTreeViewItem *child = static_cast<FileTreeViewItem*>(curr->child(i)); slotUnloadItem(child); // recursively unload contents } } else // is a file/image { const KookaImage *image = imageForItem(curr); if (image==NULL) return; // ok, nothing to unload if (image->subImagesCount()>0) // image with subimages { while (curr->childCount()>0) // recursively unload subimages { FileTreeViewItem *child = static_cast<FileTreeViewItem*>(curr->takeChild(0)); slotUnloadItem(child); delete child; } } emit unloadImage(image); delete image; curr->setClientData(NULL); // clear image from item slotDecorate(curr); } }
void ofxBKImage::setFromPixels(ofPixels p) { unloadImage(); unlink(); imageInternal = new ofImage(); isResizedForDraw = false; imageInternal->getPixels() = p; imageInternal->update(); processImageForDrawing(); }
void GuiImage::setImage(std::string path) { if(mPath == path) return; mPath = path; unloadImage(); if(!path.empty()) loadImage(path); }
void MediaServer::unloadMedia(string &path) { if (loadedSources.count(path)) { BaseSource* mediaSource = getSourceByPath(path); if (mediaSource->getType() == SourceType::SOURCE_TYPE_IMAGE) { unloadImage(path); } else if (mediaSource->getType() == SourceType::SOURCE_TYPE_VIDEO) { unloadVideo(path); } else if (mediaSource->getType() == SourceType::SOURCE_TYPE_FBO) { unloadFboSource(path); } else { // Oh my god, what to do!? Relax and exit. ofLogFatalError("MediaServer") << "Attempt to unload media of unknown type"; std::exit(EXIT_FAILURE); } } else { ofLogNotice("MediaServer") << "Nothing to unload"; } }
// 从文件中载入图片 Bool FreeImageImage::loadFromFile(PCStr pszFileName) { unloadImage(); FREE_IMAGE_FORMAT eImgFormat = FIF_UNKNOWN; FIBITMAP* pFIBitmap = 0; eImgFormat = FreeImage_GetFileType(pszFileName); if(eImgFormat == FIF_UNKNOWN) { eImgFormat = FreeImage_GetFIFFromFilename(pszFileName); } if(eImgFormat != FIF_UNKNOWN && FreeImage_FIFSupportsReading(eImgFormat)) { pFIBitmap = FreeImage_Load(eImgFormat, pszFileName, 0); } Bool isSuccess = False; if(pFIBitmap) { // 非 32 位色图片,转换为 32 位 UInt nBPP = FreeImage_GetBPP(pFIBitmap); if(nBPP != 32) { FIBITMAP* pFIBitmap32 = FreeImage_ConvertTo32Bits(pFIBitmap); FreeImage_Unload(pFIBitmap); pFIBitmap = pFIBitmap32; } } if(pFIBitmap) { // 加载到内存数据中 isSuccess = _load(pFIBitmap); FreeImage_Unload(pFIBitmap); // 记录下文件名 _strFileName = pszFileName; } return isSuccess; }
// 从内存中载入图片 Bool FreeImageImage::loadFromMemory(PCVoid pData, UInt nDataSize) { unloadImage(); FREE_IMAGE_FORMAT eImgFormat = FIF_UNKNOWN; FIMEMORY* pFIMemory = FreeImage_OpenMemory((UInt8*) pData, nDataSize); FIBITMAP* pFIBitmap = 0; eImgFormat = FreeImage_GetFileTypeFromMemory(pFIMemory); if(eImgFormat != FIF_UNKNOWN && FreeImage_FIFSupportsReading(eImgFormat)) { pFIBitmap = FreeImage_LoadFromMemory(eImgFormat, pFIMemory, 0); } Bool isSuccess = False; if(pFIBitmap) { // 非 32 位色图片,转换为 32 位 UInt nBPP = FreeImage_GetBPP(pFIBitmap); if(nBPP != 32) { FIBITMAP* pFIBitmap32 = FreeImage_ConvertTo32Bits(pFIBitmap); FreeImage_Unload(pFIBitmap); pFIBitmap = pFIBitmap32; } } if(pFIBitmap) { // 加载到内存数据中 isSuccess = _load(pFIBitmap); FreeImage_Unload(pFIBitmap); } FreeImage_CloseMemory(pFIMemory); return isSuccess; }
FreeImageImage::~FreeImageImage() { unloadImage(); }
void resources_unload() { int id; void * vp; for (id = Resource_SCREENCONGRATS; id >= Resource_PALETTE; --id) { switch (id) { case Resource_PALETTE: { vp = game_colors; unloadRawData(&vp, &game_color_count); game_colors = vp; break; } case Resource_ENTDATA: unloadResourceEntdata(); break; case Resource_SPRSEQ: { vp = ent_sprseq; unloadRawData(&vp, &ent_nbr_sprseq); ent_sprseq = vp; break; } case Resource_MVSTEP: { vp = ent_mvstep; unloadRawData(&vp, &ent_nbr_mvstep); ent_mvstep = vp; break; } case Resource_MAPS: unloadResourceMaps(); break; case Resource_SUBMAPS: unloadResourceSubmaps(); break; case Resource_CONNECT: { vp = map_connect; unloadRawData(&vp, &map_nbr_connect); map_connect = vp; break; } case Resource_BNUMS: { vp = map_bnums; unloadRawData(&vp, &map_nbr_bnums); map_bnums = vp; break; } case Resource_BLOCKS: { vp = map_blocks; unloadRawData(&vp, &map_nbr_blocks); map_blocks = vp; break; } case Resource_MARKS: { vp = map_marks; unloadRawData(&vp, &map_nbr_marks); map_marks = vp; break; } case Resource_EFLGC: { vp = map_eflg_c; unloadRawData(&vp, &map_nbr_eflgc); map_eflg_c = vp; break; } case Resource_IMAPSL: { vp = screen_imapsl; unloadRawData(&vp, &screen_nbr_imapsl); screen_imapsl = vp; break; } case Resource_IMAPSTEPS: unloadResourceImapsteps(); break; case Resource_IMAPSOFS: { vp = screen_imapsofs; unloadRawData(&vp, &screen_nbr_imapsofs); screen_imapsofs = vp; break; } case Resource_IMAPTEXT: unloadResourceImaptext(); break; case Resource_GAMEOVERTXT: unloadString((char **)(&screen_gameovertxt)); break; case Resource_PAUSEDTXT: unloadString((char **)(&screen_pausedtxt)); break; case Resource_SPRITESDATA: unloadResourceSpritesData(); break; case Resource_TILESDATA: unloadResourceTilesData(); break; case Resource_HIGHSCORES: unloadResourceHighScores(); break; case Resource_IMGSPLASH: unloadImage(&img_splash); break; #ifdef GFXST case Resource_PICHAF: unloadPicture(&pic_haf); break; case Resource_PICCONGRATS: unloadPicture(&pic_congrats); break; case Resource_PICSPLASH: unloadPicture(&pic_splash); break; #endif /* GFXST */ #ifdef GFXPC case Resource_IMAINHOFT: unloadString((char **)(&screen_imainhoft)); break; case Resource_IMAINRDT: unloadString((char **)(&screen_imainrdt)); break; case Resource_IMAINCDC: unloadString((char **)(&screen_imaincdc)); break; case Resource_SCREENCONGRATS: unloadString((char **)(&screen_congrats)); break; #endif /* GFXPC */ default: break; } } #ifdef ENABLE_SOUND for (id = Resource_SOUNDWALK; id >= Resource_SOUNDBOMBSHHT; --id) { unloadSound(id); } #endif /* ENABLE_SOUND */ unloadResourceFilelist(); }
ofxBKImage::~ofxBKImage() { //std::cout << "!ofxBKImage!" << this <<"!"; unloadImage(); }
void GuiImage::loadImage(std::string path) { //make sure the file *exists* if(!boost::filesystem::exists(path)) { LOG(LogError) << "File \"" << path << "\" not found!"; return; } //make sure we don't already have an image unloadImage(); FREE_IMAGE_FORMAT format = FIF_UNKNOWN; FIBITMAP* image = NULL; BYTE* imageData = NULL; unsigned int width, height; //detect the filetype format = FreeImage_GetFileType(path.c_str(), 0); if(format == FIF_UNKNOWN) format = FreeImage_GetFIFFromFilename(path.c_str()); if(format == FIF_UNKNOWN) { LOG(LogError) << "Error - could not detect filetype for image \"" << path << "\"!"; return; } //make sure we can read this filetype first, then load it if(FreeImage_FIFSupportsReading(format)) { image = FreeImage_Load(format, path.c_str()); }else{ LOG(LogError) << "Error - file format reading not supported for image \"" << path << "\"!"; return; } //make sure it loaded properly if(!image) { LOG(LogError) << "Error loading image \"" << path << "\"!"; return; } //convert to 32bit FIBITMAP* imgConv = FreeImage_ConvertTo32Bits(image); FreeImage_Unload(image); image = imgConv; //get a pointer to the image data as BGRA imageData = FreeImage_GetBits(image); if(!imageData) { LOG(LogError) << "Error retriving bits from image \"" << path << "\"!"; return; } width = FreeImage_GetWidth(image); height = FreeImage_GetHeight(image); //if width or height are zero then something is clearly wrong if(!width || !height) { LOG(LogError) << "Width or height are zero for image \"" << path << "\"!"; FreeImage_Unload(image); return; } /* //set width/height to powers of 2 for OpenGL for(unsigned int i = 0; i < 22; i++) { unsigned int pwrOf2 = pow(2, i); if(!widthPwrOf2 && pwrOf2 >= width) widthPwrOf2 = pwrOf2; if(!heightPwrOf2 && pwrOf2 >= height) heightPwrOf2 = pwrOf2; if(widthPwrOf2 && heightPwrOf2) break; } if(!widthPwrOf2 || !heightPwrOf2) { LOG(LogError) << "Error assigning power of two for width or height of image!"; FreeImage_Unload(image); return; }*/ //convert from BGRA to RGBA GLubyte* imageRGBA = new GLubyte[4*width*height]; for(unsigned int i = 0; i < width*height; i++) { imageRGBA[i*4+0] = imageData[i*4+2]; imageRGBA[i*4+1] = imageData[i*4+1]; imageRGBA[i*4+2] = imageData[i*4+0]; imageRGBA[i*4+3] = imageData[i*4+3]; } //now for the openGL texture stuff glGenTextures(1, &mTextureID); glBindTexture(GL_TEXTURE_2D, mTextureID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageRGBA); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); mWidth = width; mHeight = height; //free the image data FreeImage_Unload(image); //free the memory from that pointer delete[] imageRGBA; resize(); }
GuiImage::~GuiImage() { unloadImage(); }
void GuiImage::deinit() { unloadImage(); }