这篇教程C++ stbi_image_free函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中stbi_image_free函数的典型用法代码示例。如果您正苦于以下问题:C++ stbi_image_free函数的具体用法?C++ stbi_image_free怎么用?C++ stbi_image_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了stbi_image_free函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: m_openglTextureID//-----------------------------------------------------------------------------------------------Texture::Texture( const std::string& imageFilePath ) : m_openglTextureID( 0 ) , m_size( 0, 0 ){ int numComponents = 0; // Filled in for us to indicate how many color/alpha components the image had (e.g. 3=RGB, 4=RGBA) int numComponentsRequested = 0; // don't care; we support 3 (RGB) or 4 (RGBA) unsigned char* imageData = stbi_load( imageFilePath.c_str(), &m_size.x, &m_size.y, &numComponents, numComponentsRequested ); if( imageData == nullptr ) return; // Enable texturing OpenGLRenderer::EnableTexture2D(); // Tell OpenGL that our pixel data is single-byte aligned OpenGLRenderer::PixelStore(); // Ask OpenGL for an unused texName (ID number) to use for this texture OpenGLRenderer::GenerateTextures( &m_openglTextureID ); // Tell OpenGL to bind (set) this as the currently active texture OpenGLRenderer::BindTexture2D( m_openglTextureID ); // Set texture clamp vs. wrap (repeat) OpenGLRenderer::SetTexture2DWrapS( REPEAT ); // GL_CLAMP or GL_REPEAT OpenGLRenderer::SetTexture2DWrapT( REPEAT ); // GL_CLAMP or GL_REPEAT // Set magnification (texel > pixel) and minification (texel < pixel) filters OpenGLRenderer::SetTexture2DMagnificationFilter( LINEAR ); // one of: GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR OpenGLRenderer::SetTexture2DMinificationFilter( LINEAR_MIPMAP_LINEAR ); // one of: GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR //OpenGLRenderer::SetTexture2DMaxLevel( 5 ); pixelDataFormat bufferFormat = RGBA; // the format our source pixel data is currently in; any of: GL_RGB, GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, ... if( numComponents == 1 ) bufferFormat = LUMINANCE; else if( numComponents == 3 ) bufferFormat = RGB; pixelDataFormat internalFormat = bufferFormat; // the format we want the texture to me on the card; allows us to translate into a different texture format as we upload to OpenGL OpenGLRenderer::SetTexture2DImage( // Upload this pixel data to our new OpenGL texture 0, // Which mipmap level to use as the "root" (0 = the highest-quality, full-res image), if mipmaps are enabled internalFormat, // Type of texel format we want OpenGL to use for this texture internally on the video card m_size.x, // Texel-width of image; for maximum compatibility, use 2^N + 2^B, where N is some integer in the range [3,10], and B is the border thickness [0,1] m_size.y, // Texel-height of image; for maximum compatibility, use 2^M + 2^B, where M is some integer in the range [3,10], and B is the border thickness [0,1] 0, // Border size, in texels (must be 0 or 1) bufferFormat, // Pixel format describing the composition of the pixel data in buffer imageData ); // Location of the actual pixel data bytes/buffer OpenGLRenderer::GenerateMipmapHint(); OpenGLRenderer::GenerateMipmapTexture2D(); stbi_image_free( imageData ); s_textureRegistry[ imageFilePath ] = this;}
开发者ID:MrBowler,项目名称:SD6-A2,代码行数:57,
示例2: HGLT_ASSERTTexture Texture::loadFile(const std::string& fileName, const unsigned int& channelCount){ Texture t; HGLT_ASSERT( channelCount > 0 && channelCount <= 4, "Invalid Image Channel Count." ); if( channelCount <= 0 || channelCount > 4 ) return t; glGenTextures(1, &t.m_nGLId); HGLT_ASSERT( t.m_nGLId != hglt::invalidGLID, "Cannot create an OpenGL Texture ID." ); int x; int y; int comp; unsigned char * data = stbi_load(fileName.c_str(), &x, &y, &comp, channelCount); HGLT_ASSERT(data != nullptr, std::string("Unable to load:" + fileName).c_str()); if( data == nullptr ) { glDeleteTextures(1, &t.m_nGLId); t.m_nGLId = hglt::invalidGLID; return t; } GLint format; switch(channelCount) { case 1: format = GL_RED; break; case 2: format = GL_RG; break; case 3: format = GL_RGB; break; case 4: format = GL_RGBA; break; } t.bind(); glTexImage2D(GL_TEXTURE_2D, 0, format, x, y, 0, format, GL_UNSIGNED_BYTE, data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); t.unbind(); stbi_image_free(data); t.m_filename = fileName; return t;}
开发者ID:Hekiat,项目名称:Book,代码行数:56,
示例3: stbi_loadImage::Image(const String &filename, uint16 hframes, uint16 vframes) { this->filename = filename; this->hframes = hframes; this->vframes = vframes; width = 0; height = 0; handlex = 0; handley = 0; gltex = 0; lastU = 1.0; lastV = 1.0; // TAREA: Cargar el buffer de la imagen int bWidth=0; int bHeight=0; unsigned char* buffer = stbi_load(filename.ToCString(),&bWidth,&bHeight,NULL,4); unsigned char* buffer1 = NULL; width=(uint16)bWidth; height=(uint16)bHeight; int width1=(int)pow(2,ceil(Log2(width))); int height1=(int)pow(2,ceil(Log2(height))); if ((width1!=width)||(height1!=height)) { bWidth = width1; bHeight = height1; buffer1=new unsigned char[bWidth*bHeight*4]; for (int i=0; i<(height);i++) { for (int j=0; j<(width); j++) { for (int k=0; k<4;k++) { buffer1[(j*width1+i)*4 + k]=buffer[(j*width+i)*4 + k]; } } } lastU=(double)width/width1; lastV=(double)height/height1; } // Generamos la textura if ( buffer ) { // TAREA: Generar la textura de OpenGL glGenTextures(1, &gltex); Bind(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); if (buffer1) glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bWidth,bHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,buffer1); else glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bWidth,bHeight,0,GL_RGBA,GL_UNSIGNED_BYTE,buffer); stbi_image_free(buffer); delete[] buffer1; }}
开发者ID:CheVilCode,项目名称:Input_Manager,代码行数:56,
示例4: ImageFont::Font(const String& filename) : Image(filename, 16, 16){ int widthImage = 0; int heightImage = 0; int nComponents = 4; unsigned int nFrames = 16 * 16; uint16 widthFrame = GetWidth(); uint16 heightFrame = GetHeight(); uint16 nLine = -1; unsigned char* pixels = stbi_load( filename.ToCString(), &widthImage, &heightImage, &nComponents, nComponents); for(unsigned int n = 0; n < (unsigned int)nFrames; n++) { Glyph glyph(0, 0, widthFrame, heightFrame); uint16 row = n / 16; uint16 column = n % 16; for(unsigned int posY = (unsigned int) (row * heightFrame); posY < (unsigned int) ((row + 1) * heightFrame) ; posY++ ) { for(unsigned int posX = (unsigned int)( column * widthFrame ); posX < (unsigned int)( (column + 1) * widthFrame ); posX++) { unsigned char pixelR = pixels[(posY * widthImage + posX) * 4 + 0]; unsigned char pixelG = pixels[(posY * widthImage + posX) * 4 + 1]; unsigned char pixelB = pixels[(posY * widthImage + posX) * 4 + 2]; unsigned char* pixelA = &pixels[(posY * widthImage + posX) * 4 + 3]; if( Glyph::IsYellow( pixelR, pixelG, pixelB)) { glyph.SetInitialCoordinates(posX, posY); *pixelA = 0; } else if( Glyph::IsRed( pixelR, pixelG, pixelB)) { glyph.SetFinalCoordinates(posX, posY); *pixelA = 0; } else if( Glyph::IsBlack( pixelR, pixelG, pixelB)) { *pixelA = 0; } } } glyphs.Add(glyph); } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, widthImage, heightImage, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); stbi_image_free(pixels);}
开发者ID:CarlosCasVen,项目名称:UTad,代码行数:56,
示例5: createBackgroundvoid createBackground(HWND hwnd){ int w,h, comp; U8* data = stbi_load("images//drawing.jpg",&w,&h,&comp,4); U8* bmdata;// fprintf(stderr,"loaded %p (%d,%d) %d components/n",data,w,h,comp); //Since we have DI data, use CreateDIBSection BITMAPINFOHEADER bi; bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth=640; bi.biHeight = -480; bi.biPlanes = 1; bi.biBitCount=32; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; HDC screenDC = GetDC(0); HDC bufferDC = CreateCompatibleDC(screenDC); bmBk = CreateDIBSection( bufferDC, (BITMAPINFO*)&bi, DIB_RGB_COLORS, (void**)&bmdata, NULL, 0); union sPixel { U32 value; struct sRGB { U8 r; U8 g; U8 b; U8 a; }rgb; }; DeleteObject(bufferDC); ReleaseDC(hwnd,screenDC); // We need to reverse r and b positions... // memcpy(bmdata,data,640*480*4); sPixel* src=(sPixel*)data; sPixel* dest=(sPixel*)bmdata; int i; for(i=0;i<640*480;i++){ sPixel pixel = *src++; U8 t = pixel.rgb.r; pixel.rgb.r = pixel.rgb.b; pixel.rgb.b = t; *dest++ = pixel; } stbi_image_free(data);// HBITMAP mybm = CreateBitmap(w,h,1,24,data);// fprintf(stderr,"created bitmap %p /n",bmBk); }
开发者ID:anarchitech,项目名称:fpgasm-xcfg,代码行数:56,
示例6: image image( const std::string &filepath ) { unsigned char *stbi_data = stbi_load( filepath.c_str(), &w, &h, &n, 0 ); if ( !stbi_data ) { throw std::runtime_error( "Failed load image from " + filepath ); } data.assign( stbi_data, stbi_data + (w * h * n) ); stbi_image_free( stbi_data ); }
开发者ID:vivichrist,项目名称:Renderer308,代码行数:10,
示例7: Java_com_original_Convert_createBMPJNIEXPORT void JNICALL Java_com_original_Convert_createBMP(JNIEnv * myEnv, jobject obj, jstring jpeg_PathJ, jstring bmp_PathJ){ jpeg_Path = myEnv->GetStringUTFChars(jpeg_PathJ, NULL); bmp_Path = myEnv->GetStringUTFChars(bmp_PathJ, NULL); LOGI("Destination = %s",bmp_Path); init(); stbi_write_bmp(bmp_Path, imageWidth, imageHeight, comp, image); stbi_image_free(image); LOGI("Looking Good");}
开发者ID:msteptoe,项目名称:FURI_Code,代码行数:10,
示例8: loadPicunsigned char* loadPic(char* path){ // load an image unsigned char* image; unsigned char* image0 = stbi_load(path, &width, &height, &comp, 0); //flip image vertically image = (unsigned char*)malloc(sizeof(unsigned char)*width*height*comp); for (int y = 0, stride = width*comp; y < height; y++) memcpy(image + (height - 1 - y)*stride, image0 + y*stride, stride); // vertical flip stbi_image_free(image0); // release the original image return image;}
开发者ID:wutti,项目名称:cgShooterProj,代码行数:10,
示例9: stbi_loadResource* ImageLoader::loadInternal(State* state, string dir){ Image* ret; int width, height, comp; unsigned char* data = stbi_load(dir.c_str(),&width,&height,&comp,0); ret = new Image(dir, width, height, comp, data); stbi_image_free(data); return ret;}
开发者ID:jsmtux,项目名称:Op3nD,代码行数:10,
示例10: test_correctstatic void test_correct(char const *filename){ int x0, y0, n0; int x1, y1, n1; unsigned char *data0 = stbi_load(filename, &x0, &y0, &n0, 0); unsigned char *data1 = stbi_orig_load(filename, &x1, &y1, &n1, 0); printf("%dx%d n=%d/n", x0, y0, n0); if (x0 != x1 || y0 != y1 || n0 != n1) panic("image dimension mismatch!/n"); if (memcmp(data0, data1, x0*y0*n0) != 0) panic("image data mismatch!/n"); stbi_image_free(data0); stbi_image_free(data1); printf("%s decodes correctly./n", filename);}
开发者ID:geekmaster,项目名称:stbopt,代码行数:19,
示例11: stbi_loadvoid Texture::LoadTexture(std::string fileName){ int numComponents; m_data = stbi_load((fileName).c_str(), &m_width, &m_height, &numComponents, 4); if (m_data == NULL){ LOG(FATAL) << "Error: Unable to load texture: " << fileName << std::endl; stbi_image_free(m_data); return; }}
开发者ID:AlexGreulich,项目名称:HRTFVR,代码行数:10,
示例12: stbi_load_from_memoryWaifu2x::eWaifu2xError Waifu2x::LoadMatBySTBI(cv::Mat &float_image, const std::vector<char> &img_data){ int x, y, comp; stbi_uc *data = stbi_load_from_memory((const stbi_uc *)img_data.data(), img_data.size(), &x, &y, &comp, 4); if (!data) return eWaifu2xError_FailedOpenInputFile; int type = 0; switch (comp) { case 1: case 3: case 4: type = CV_MAKETYPE(CV_8U, comp); break; default: return eWaifu2xError_FailedOpenInputFile; } float_image = cv::Mat(cv::Size(x, y), type); const auto LinePixel = float_image.step1() / float_image.channels(); const auto Channel = float_image.channels(); const auto Width = float_image.size().width; const auto Height = float_image.size().height; assert(x == Width); assert(y == Height); assert(Channel == comp); auto ptr = float_image.data; for (int i = 0; i < y; i++) { for (int j = 0; j < x; j++) { for (int ch = 0; ch < Channel; ch++) ptr[(i * LinePixel + j) * comp + ch] = data[(i * x + j) * comp + ch]; } } stbi_image_free(data); if (comp >= 3) { // RGBだからBGRに C++ stbi_load函数代码示例 C++ stbi_failure_reason函数代码示例
|