uint32_t * getImage(std::string name, int & width, int & height, int scale) { std::stringstream name_stream; name_stream << oz::path << "sprite sheets/" << name; stbi_convert_iphone_png_to_rgb(0); uint8_t * pixels = stbi_load(name_stream.str().c_str(), &width, &height, NULL, 4); if ( pixels == NULL ) { pixels = loadRLEBMP(name_stream.str().c_str(), width, height); } if ( pixels == NULL ) { std::cout << "oz::getImage" << "No Image Loaded" << std::endl; return NULL; } if ( width > 0 && height > 0) { int32_t c = 0; int32_t q = 0; int32_t size = width * height; int32_t line = width * 2; uint32_t * dpixels = new uint32_t[size*8]; while ( c < size ) { uint32_t pix = getPixel(pixels, c); if ( pix == 0xFF00FF00 ) /* Little Endian AABBGGRR*/ { pix = 0x00000000; } dpixels[q++] = pix; dpixels[q++] = pix; c++; if ( !(c % width) ) { memcpy( dpixels + q, dpixels + q - line, line*4); q += line; } } width *=2; height *=2; return dpixels; } else { return NULL; } }
bool Image::LoadFile( uint8_t * data, int32_t size ) { this->bpp = 4; stbi_convert_iphone_png_to_rgb(1); this->pixels = stbi_load_from_memory(data, (int)size, (int*)&this->width, (int*)&this->height, (int*)&this->original_bpp, this->bpp); if ( this->pixels == NULL ) { std::cout << "elix::Image:" << stbi_failure_reason() << std::endl; this->length = 0; return false; } if ( this->bpp != 4 ) { std::cout << "this->bpp:" << this->bpp << "-" << stbi_failure_reason() << std::endl; } this->length = this->width * this->height * this->bpp; return true; }
//--------------------------------------------------------------------- void STBIImageCodec::startup(void) { stbi_convert_iphone_png_to_rgb(1); stbi_set_unpremultiply_on_load(1); LogManager::getSingleton().logMessage(LML_NORMAL, "stb_image - v2.12 - public domain JPEG/PNG reader"); // Register codecs String exts = "jpeg,jpg,png,bmp,psd,tga,gif,pic,ppm,pgm"; StringVector extsVector = StringUtil::split(exts, ","); for (StringVector::iterator v = extsVector.begin(); v != extsVector.end(); ++v) { ImageCodec* codec = OGRE_NEW STBIImageCodec(*v); msCodecList.push_back(codec); Codec::registerCodec(codec); } StringStream strExt; strExt << "Supported formats: " << exts; LogManager::getSingleton().logMessage( LML_NORMAL, strExt.str()); }
void ASCGLES2Texture::Load() { #ifdef __OBJC__ stbi_convert_iphone_png_to_rgb(1); #endif //Open the texture file FILE* pFile = NULL; #ifdef ASC_IOS pFile = fopen(m_strTextureName.c_str(), "rb"); #else fopen_s(&pFile, m_strTextureName.c_str(), "rb"); #endif if(NULL == pFile) { assert_nowex("Guts, failed to load texture file: ", m_strTextureName); m_bLoaded = false; return; } UINT32 uForceChannels = 0; SINT32 iChannels; SINT32 iWidth; SINT32 iHeight; //Load in the texture data UINT8* pImg = stbi_load_from_file(pFile, &iWidth, &iHeight, &iChannels, uForceChannels); //Close the texture file fclose( pFile ); if(NULL == pImg) { assert_nowex("Guts, failed to load texture because: ", stbi_failure_reason()); m_bLoaded = false; return; } if( ( uForceChannels >= 1 ) && ( uForceChannels <= 4 ) ) { iChannels = SC_SINT(uForceChannels); } m_uiWidth = iWidth; m_uiHeight = iHeight; //Generate the texture glGenTextures(1, &m_uTextureID); //Bind the texture glBindTexture( GL_TEXTURE_2D, m_uTextureID ); UINT32 uTextureFormat = ( iChannels == 3 ) ? GL_RGB : GL_RGBA; if(uTextureFormat != GL_RGBA) { //assert_now("Guts, Texture is not RGBA, dont realy want this"); } glTexImage2D( GL_TEXTURE_2D, 0, uTextureFormat, m_uiWidth, m_uiHeight, 0, uTextureFormat, GL_UNSIGNED_BYTE, pImg); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glBindTexture( GL_TEXTURE_2D, 0 ); ASCMemoryManagement::ReleaseMemory(pImg, false); m_bLoaded = true; }