void poImage::load(uint w, uint h, uint c, const ubyte *pix) { if(bitmap) { totalAllocatedImageMemorySize -= FreeImage_GetDIBSize(bitmap); FreeImage_Unload(bitmap); } if(pix != NULL) bitmap = FreeImage_ConvertFromRawBits(const_cast<ubyte*>(pix), w, h, w*c, c*8, 0,0,0); else { bitmap = FreeImage_Allocate(w, h, c*8); char black[] = {0,0,0,0}; FreeImage_FillBackground(bitmap, black); } totalAllocatedImageMemorySize += FreeImage_GetDIBSize(bitmap); }
void poImage::load(const std::string &url) { FIBITMAP *bmp = loadDIB(url); if(bmp) { bitmap = bmp; this->url = url; totalAllocatedImageMemorySize += FreeImage_GetDIBSize(bitmap); } }
unsigned char* GLES2Texture::loadImage(const char *filename, int& colorDepth) { //image format FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; //pointer to the image, once loaded FIBITMAP *dib(0); //pointer to the image data BYTE* bits(0); //image width and height unsigned int width(0), height(0); //check the file signature and deduce its format fif = FreeImage_GetFileType(filename, 0); //if still unknown, try to guess the file format from the file extension if(fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilename(filename); //if still unkown, return failure if(fif == FIF_UNKNOWN) return NULL; //check that the plugin has reading capabilities and load the file if(FreeImage_FIFSupportsReading(fif)) dib = FreeImage_Load(fif, filename); //if the image failed to load, return failure if(!dib) return NULL; int datasize = FreeImage_GetDIBSize(dib); //retrieve the image data bits = FreeImage_GetBits(dib); //get the image width and height width = FreeImage_GetWidth(dib); height = FreeImage_GetHeight(dib); //get the image bpp colorDepth = FreeImage_GetBPP(dib); //if this somehow one of these failed (they shouldn't), return failure if((bits == 0) || (width == 0) || (height == 0)) return NULL; mWidth = width; mHeight = height; // BGRA 转成 RGBA unsigned char* buffer = new unsigned char[datasize]; int i=0; for (i=0; i<datasize; i+=4) { (buffer+i)[0] = (bits+i)[2]; (buffer+i)[1] = (bits+i)[1]; (buffer+i)[2] = (bits+i)[0]; (buffer+i)[3] = (bits+i)[3]; } //Free FreeImage's copy of the data FreeImage_Unload(dib); return buffer; }
bool CCubemap::LoadTexture(string filename, BYTE **bmpBytes, int &iWidth, int &iHeight) { FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; FIBITMAP* dib(0); fif = FreeImage_GetFileType(filename.c_str(), 0); // Check the file signature and deduce its format if(fif == FIF_UNKNOWN) // If still unknown, try to guess the file format from the file extension fif = FreeImage_GetFIFFromFilename(filename.c_str()); if(fif == FIF_UNKNOWN) // If still unknown, return failure return false; if(FreeImage_FIFSupportsReading(fif)) // Check if the plugin has reading capabilities and load the file dib = FreeImage_Load(fif, filename.c_str()); if(!dib) { char message[1024]; sprintf_s(message, "Cannot load image\n%s\n", filename.c_str()); MessageBox(NULL, message, "Error", MB_ICONERROR); return false; } iWidth = FreeImage_GetWidth(dib); iHeight = FreeImage_GetWidth(dib); int bpp = FreeImage_GetBPP(dib); BYTE* bDataPointer = FreeImage_GetBits(dib); // Retrieve the image data // If somehow one of these failed (they shouldn't), return failure if(*bDataPointer == NULL || FreeImage_GetWidth(dib) == 0 || FreeImage_GetHeight(dib) == 0) return false; int test = FreeImage_GetDIBSize(dib); *bmpBytes = new BYTE [iWidth*iHeight*bpp/8]; memcpy(*bmpBytes, bDataPointer, iWidth*iHeight*bpp/8); /* GLenum format; FreeImage_GetBPP(dib); if(FreeImage_GetBPP(dib) == 32)format = GL_RGBA; if(FreeImage_GetBPP(dib) == 24)format = GL_BGR; if(FreeImage_GetBPP(dib) == 8)format = GL_LUMINANCE; */ FreeImage_Unload(dib); return true; // Success }
bool Bitmap::loadFile(std::string FileName) { //image format FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; //check the file signature and deduce its format fif = FreeImage_GetFileType(FileName.c_str(), 0); //if still unknown, try to guess the file format from the file extension if(fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilename(FileName.c_str()); //if still unkown, return failure if(fif == FIF_UNKNOWN) { return false; } //check that the plugin has reading capabilities and load the file if(FreeImage_FIFSupportsReading(fif)) m_image = std::shared_ptr<FIBITMAP>(FreeImage_Load(fif, FileName.c_str()), [](FIBITMAP* dib){ FreeImage_Unload(dib); }); //if the image failed to load, return failure if(!m_image) { return false; } //get the image width and height m_width = FreeImage_GetWidth(m_image.get()); m_height = FreeImage_GetHeight(m_image.get()); m_size = FreeImage_GetDIBSize(m_image.get()); //if this somehow one of these failed (they shouldn't), return failure if((FreeImage_GetBits(m_image.get()) == 0) || (m_width == 0) || (m_height == 0) || (m_size == 0)) { return false; } //return success return true; }
LONG fipImage::getImageSize() const { return FreeImage_GetDIBSize(_dib); }
// This is what does the work in the background thread UINT CHexEditDoc::RunAerialThread() { // Keep looping until we are told to die for (;;) { // Signal that we are waiting then wait for start_aerial_event_ to be pulsed { CSingleLock sl(&docdata_, TRUE); aerial_state_ = WAITING; } TRACE1("+++ BGAerial: waiting for %p\n", this); DWORD wait_status = ::WaitForSingleObject(HANDLE(start_aerial_event_), INFINITE); docdata_.Lock(); aerial_state_ = SCANNING; docdata_.Unlock(); start_aerial_event_.ResetEvent(); ASSERT(wait_status == WAIT_OBJECT_0); TRACE1("+++ BGAerial: got event for %p\n", this); if (AerialProcessStop()) continue; // Reset for new scan docdata_.Lock(); aerial_fin_ = false; aerial_addr_ = 0; FILE_ADDRESS file_len = length_; int file_bpe = bpe_; unsigned char *file_dib = FreeImage_GetBits(dib_); unsigned dib_size = FreeImage_GetDIBSize(dib_); docdata_.Unlock(); TRACE("+++ BGAerial: using bitmap at %p\n", file_dib); // Get the file buffer size_t buf_len = (size_t)min(file_len, 65536); ASSERT(aerial_buf_ == NULL); aerial_buf_ = new unsigned char[buf_len]; for (;;) { // First check if we need to stop if (AerialProcessStop()) break; // stop processing and go back to WAITING state // Check if we have finished scanning the file if (aerial_addr_ >= file_len) { TRACE2("+++ BGAerial: finished scan for %p at address %p\n", this, file_dib + 3*size_t(aerial_addr_/file_bpe)); CSingleLock sl(&docdata_, TRUE); // Protect shared data access aerial_fin_ = true; break; // falls out to end_scan } // Get the next buffer full from the file and scan it size_t got = GetData(aerial_buf_, buf_len, aerial_addr_, 3); ASSERT(got <= buf_len); unsigned char *pbm = file_dib + 3*size_t(aerial_addr_/file_bpe); // where we write to bitmap unsigned char *pbuf; // where we read from the file buffer for (pbuf = aerial_buf_; pbuf < aerial_buf_ + got; pbuf += file_bpe, pbm += 3) { int r, g, b; r = g = b = 0; for (unsigned char *pp = pbuf; pp < pbuf + file_bpe; ++pp) { r += GetRValue(kala_[*pp]); g += GetGValue(kala_[*pp]); b += GetBValue(kala_[*pp]); } *pbm = unsigned char(b/file_bpe); *(pbm+1) = unsigned char(g/file_bpe); *(pbm+2) = unsigned char(r/file_bpe); } aerial_addr_ += got; } delete[] aerial_buf_; aerial_buf_ = NULL; } return 0; // never reached }
ImageData::ImageData(const char *filename) { assert(sizeof(BYTE) == sizeof(GLubyte)); // image format FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; // pointer to the image, once loaded FIBITMAP *dib(0); // pointer to the image data BYTE* bits(0); // check the file signature and deduce its format fif = FreeImage_GetFileType(filename, 0); // if still unknown, try to guess the file format from the file extension if (fif == FIF_UNKNOWN){ fif = FreeImage_GetFIFFromFilename(filename); } // if still unkown, return failure if (fif == FIF_UNKNOWN){ std::cerr << "Loading " << filename << " failure. fif unknown." << std::endl; exit(EXIT_FAILURE); } // If image foramt is unsupportable, return failure. if (fif != FIF_BMP && fif != FIF_JPEG && fif != FIF_GIF && fif != FIF_PNG && fif != FIF_TARGA){ std::cerr << "Loading " << filename << " failure. Unsupportable format." << std::endl; exit(EXIT_FAILURE); } // check that the plugin has reading capabilities and load the file if (FreeImage_FIFSupportsReading(fif)) dib = FreeImage_Load(fif, filename); // if the image failed to load, return failure if (!dib){ std::cerr << "Loading " << filename << " failure. dib error." << std::endl; exit(EXIT_FAILURE); } unsigned int bitPerPixel = FreeImage_GetBPP(dib); switch (bitPerPixel) { case 8: internalFormat = GL_RED; format = GL_RED; break; case 24: internalFormat = GL_RGB; format = GL_BGR; break; case 32: internalFormat = GL_RGBA; format = GL_BGRA; break; default: FreeImage_Unload(dib); std::cerr << "Loading " << filename << " failure. Unsupportable format." << std::endl; exit(EXIT_FAILURE); } // retrieve the image data bits = FreeImage_GetBits(dib); // get the image width and height width = FreeImage_GetWidth(dib); height = FreeImage_GetHeight(dib); // if this somehow one of these failed (they shouldn't), return failure if ((bits == 0) || (width == 0) || (height == 0)){ std::cerr << "Loading " << filename << " failure. error unknown." << std::endl; exit(EXIT_FAILURE); } unsigned int dataSize = FreeImage_GetDIBSize(dib); data = new GLubyte[dataSize]; memcpy(data, bits, dataSize); FreeImage_Unload(dib); }
poImage::~poImage() { totalAllocatedImageMemorySize -= FreeImage_GetDIBSize(bitmap); FreeImage_Unload(bitmap); bitmap = NULL; }