static int raw_init_decoder(AVCodecContext *avctx) { RawVideoContext *context = avctx->priv_data; if (avctx->codec_tag) avctx->pix_fmt = findPixelFormat(avctx->codec_tag); else if (avctx->bits_per_sample){ switch(avctx->bits_per_sample){ case 8: avctx->pix_fmt= PIX_FMT_PAL8 ; break; case 15: avctx->pix_fmt= PIX_FMT_RGB555; break; case 16: avctx->pix_fmt= PIX_FMT_RGB565; break; case 24: avctx->pix_fmt= PIX_FMT_BGR24 ; break; case 32: avctx->pix_fmt= PIX_FMT_RGBA32; break; } } context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); context->buffer = av_malloc(context->length); context->pic.pict_type = FF_I_TYPE; context->pic.key_frame = 1; avctx->coded_frame= &context->pic; if (!context->buffer) return -1; return 0; }
bool Texture::initWithData(int32_t format, const uint8_t * buffer, uint32_t width, uint32_t height, bool mipmaps, int pixelFormat) { destroy(); m_target = GL_TEXTURE_2D; m_format = format; m_pixelFormat = pixelFormat < 0 ? findPixelFormat(format) : pixelFormat; m_width = width; m_height = height; glGenTextures(1, &m_texture); glBindTexture(m_target, m_texture); int mipLevels = mipmaps ? getMipLevelsCount(m_width, m_height) : 1; glTexStorage2D(m_target, mipLevels, m_format, m_width, m_height); glTexSubImage2D(m_target, 0, 0, 0, m_width, m_height, m_pixelFormat, GL_UNSIGNED_BYTE, buffer); setSampling(); if (mipmaps) generateMipmaps(); glBindTexture(m_target, 0); if (glCheckError()) { destroy(); return false; } m_isLoaded = true; return m_isLoaded; }
static av_cold int raw_init_decoder(AVCodecContext *avctx) { RawVideoContext *context = avctx->priv_data; if (avctx->codec_tag == MKTAG('r','a','w',' ')) avctx->pix_fmt = findPixelFormat(pixelFormatBpsMOV, avctx->bits_per_sample); else if (avctx->codec_tag) avctx->pix_fmt = findPixelFormat(ff_raw_pixelFormatTags, avctx->codec_tag); else if (avctx->bits_per_sample) avctx->pix_fmt = findPixelFormat(pixelFormatBpsAVI, avctx->bits_per_sample); context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); context->buffer = av_malloc(context->length); context->pic.pict_type = FF_I_TYPE; context->pic.key_frame = 1; avctx->coded_frame= &context->pic; if (!context->buffer) return -1; return 0; }
/////////////////////////////////////////////////////////////////////////////// // choose pixel format // By default, pdf.dwFlags is set PFD_DRAW_TO_WINDOW, PFD_DOUBLEBUFFER and PFD_SUPPORT_OPENGL. /////////////////////////////////////////////////////////////////////////////// bool OpenGLWindow::setPixelFormat(HDC hdc, int colorBits, int depthBits, int stencilBits) { int pixelFormat; bool returnValue = false; PIXELFORMATDESCRIPTOR pfd; // find out the best matched pixel format pixelFormat = findPixelFormat(hdc, colorBits, depthBits, stencilBits); if ( pixelFormat ) { // set members of PIXELFORMATDESCRIPTOR with given mode ID DescribePixelFormat(hdc, pixelFormat, sizeof(pfd), &pfd); // set the fixel format if( SetPixelFormat(hdc, pixelFormat, &pfd) ) returnValue = true; } return returnValue; };
sageContext * sage_open (int db_flag, int red_size, int green_size, int blue_size, int alpha_size, int depth_size, int stencil_size) { const char *str; sageContext *ctx; if (hardware < 0) { goto exit_error; } /* Create context */ ctx = malloc(sizeof(sageContext)); if (ctx == NULL) { goto exit_error; } ctx->gr_ctx = 0; /* Choose a visual */ ctx->fmt = findPixelFormat(&red_size, &green_size, &blue_size, &alpha_size, &depth_size, &stencil_size); fb_color = red_size + green_size + blue_size; fb_alpha = alpha_size; /* Initialize the core */ if (ctx_init(db_flag, red_size, green_size, blue_size, alpha_size, depth_size, stencil_size) != 0) { goto exit_error1; } /* Set driver capabilities */ allow_texuma = hwext_texuma && !YES("3dfx.disable.texuma"); allow_texmirror = hwext_texmirror && !YES("3dfx.disable.texmirror"); allow_fogcoord = hwext_fogcoord && !YES("3dfx.disable.fogcoord"); allow_32bpt = (fb_color == 24 && hwext_texfmt) && !YES("3dfx.disable.32bpt"); allow_blendsquare = (hardware >= GR_SSTTYPE_Voodoo4) && !YES("3dfx.disable.blendsquare"); allow_combine = GL_TRUE && !YES("3dfx.disable.combine"); allow_multitex = (getInteger(GR_NUM_TMU) > 1) && !YES("3dfx.disable.multitex"); allow_compressed = atoi(cfg_get("3dfx.texture.compression", "3")); if (hardware < GR_SSTTYPE_Voodoo4) { allow_compressed &= ~2; } if (!ctx_texcodec) { allow_compressed &= ~1; } if (hardware < GR_SSTTYPE_Voodoo4) { allow_combine = -allow_combine; } /* Update core with driver capabilities */ ctx_const_max_texture_size = getInteger(GR_MAX_TEXTURE_SIZE); ctx_const_max_texture_units = allow_multitex ? 2 : 1; max_texture_levels = 0; while ((GLuint)(1 << max_texture_levels) < ctx_const_max_texture_size) { max_texture_levels++; } ctx_const_max_lod_bias = max_texture_levels; str = cfg_get("3dfx.maxlod", NULL); if (str != NULL) { ctx_const_max_texture_size = 1 << atoi(str); } /* Finish driver setup */ tex_bound_mask = (hardware < GR_SSTTYPE_Banshee) ? 0x1fffff : -1U; if (tm_init() != 0) { goto exit_error2; } if (vb_init() != 0) { goto exit_error3; } fogtable = malloc(getInteger(GR_FOG_TABLE_ENTRIES) * sizeof(GrFog_t)); if (fogtable == NULL) { goto exit_error4; } /* XXX getInteger(GR_GLIDE_STATE_SIZE) */ drv_multipass = drv_multipass_none; init_tri_pointers(); /* Finish core setup */ ext_set("GL_EXT_texture_env_add", GL_TRUE); ext_set("GL_EXT_texture_edge_clamp", GL_TRUE); ext_set("GL_EXT_compiled_vertex_array", GL_TRUE); ext_set("GL_EXT_blend_func_separate", GL_TRUE); ext_set("GL_EXT_texture_lod_bias", GL_TRUE); if (allow_multitex) { ext_set("GL_ARB_multitexture", GL_TRUE); } if (allow_fogcoord) { ext_set("GL_EXT_fog_coord", GL_TRUE); } if (allow_texmirror) { ext_set("GL_ARB_texture_mirrored_repeat", GL_TRUE); } if (stencil_size) { ext_set("GL_EXT_stencil_wrap", GL_TRUE); } if (allow_blendsquare) { ext_set("GL_NV_blend_square", GL_TRUE); } if (allow_combine) { ext_set("GL_ARB_texture_env_combine", GL_TRUE); ext_set("GL_EXT_texture_env_combine", GL_TRUE); } if (allow_compressed) { ext_set("GL_ARB_texture_compression", GL_TRUE); ext_set("GL_EXT_texture_compression_s3tc", GL_TRUE); ext_set("GL_3DFX_texture_compression_FXT1", GL_TRUE); ext_set("GL_S3_s3tc", GL_TRUE); } /* XXX not really */ ext_set("GL_EXT_separate_specular_color", GL_TRUE); ext_set("GL_EXT_secondary_color", GL_TRUE); return ctx; exit_error4: free_a(vb); exit_error3: tm_fini(); exit_error2: ctx_fini(); exit_error1: free(ctx); exit_error: return NULL; }
bool Texture::initAsArray(const std::vector<std::string> & filenames, bool mipmaps) { destroy(); m_arraySize = (uint32_t)filenames.size(); std::vector<uint8_t *> imageData; imageData.resize(m_arraySize, nullptr); auto cleanFunc = [&]() { for (uint32_t i = 0; i < m_arraySize; i++) if (imageData[i] != 0) stbi_image_free(imageData[i]); }; int width = 0, height = 0, components = 0; for (uint32_t i = 0; i < m_arraySize; i++) { int w, h, c; imageData[i] = stbi_load(filenames[i].c_str(), &w, &h, &c, 0); if (!imageData[i]) { common::Logger::toLogWithFormat("Error: could not load file '%s'.\n", filenames[i].c_str()); cleanFunc(); return false; } if (i > 0 && (width != w || height != h || components != c)) { common::Logger::toLog("Error: could not create a cubemap, files have different properties (width, height, components).\n"); cleanFunc(); return false; } else { width = w; height = h; components = c; } } m_format = findFormat(components); if (m_format == -1) { common::Logger::toLog("Error: texture format is unknown.\n"); cleanFunc(); return false; } m_target = GL_TEXTURE_2D_ARRAY; m_width = width; m_height = height; m_pixelFormat = findPixelFormat(m_format); glGenTextures(1, &m_texture); glBindTexture(m_target, m_texture); int mipLevels = mipmaps ? getMipLevelsCount(m_width, m_height) : 1; glTexStorage3D(m_target, mipLevels, m_format, m_width, m_height, m_arraySize); for (uint32_t i = 0; i < m_arraySize; i++) { glTexSubImage3D(m_target, 0, 0, 0, i, m_width, m_height, 1, m_pixelFormat, GL_UNSIGNED_BYTE, imageData[i]); } setSampling(); if (mipmaps) generateMipmaps(); glBindTexture(m_target, 0); cleanFunc(); if (glCheckError()) { destroy(); return false; } m_isLoaded = true; return m_isLoaded; }
bool Texture::initAsCubemap(const std::string& frontFilename, const std::string& backFilename, const std::string& leftFilename, const std::string& rightFilename, const std::string& topFilename, const std::string& bottomFilename, bool mipmaps) { destroy(); std::string filenames[6] = { rightFilename, leftFilename, topFilename, bottomFilename, frontFilename, backFilename }; uint8_t * imageData[6] = { 0, 0, 0, 0, 0, 0 }; auto cleanFunc = [&]() { for (size_t i = 0; i < 6; i++) if (imageData[i] != 0) stbi_image_free(imageData[i]); }; int width = 0, height = 0, components = 0; for (size_t i = 0; i < 6; i++) { int w, h, c; imageData[i] = stbi_load(filenames[i].c_str(), &w, &h, &c, 0); if (!imageData[i]) { common::Logger::toLogWithFormat("Error: could not load file '%s'.\n", filenames[i].c_str()); cleanFunc(); return false; } if (i > 0 && (width != w || height != h || components != c)) { common::Logger::toLog("Error: could not create a cubemap, files have different properties (width, height, components).\n"); cleanFunc(); return false; } else { width = w; height = h; components = c; } } m_format = findFormat(components); if (m_format == -1) { common::Logger::toLog("Error: texture format is unknown.\n"); cleanFunc(); return false; } m_target = GL_TEXTURE_CUBE_MAP; m_width = width; m_height = height; m_pixelFormat = findPixelFormat(m_format); glGenTextures(1, &m_texture); glBindTexture(m_target, m_texture); int mipLevels = mipmaps ? getMipLevelsCount(m_width, m_height) : 1; glTexStorage2D(m_target, mipLevels, m_format, m_width, m_height); for (uint32_t i = 0; i < 6; i++) { glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, m_width, m_height, m_pixelFormat, GL_UNSIGNED_BYTE, imageData[i]); } setSampling(); if (mipmaps) generateMipmaps(); glBindTexture(m_target, 0); cleanFunc(); if (glCheckError()) { destroy(); return false; } m_isLoaded = true; return m_isLoaded; }