当前位置: 首页>>代码示例>>C++>>正文


C++ Image::computeNumComponents方法代码示例

本文整理汇总了C++中osg::Image::computeNumComponents方法的典型用法代码示例。如果您正苦于以下问题:C++ Image::computeNumComponents方法的具体用法?C++ Image::computeNumComponents怎么用?C++ Image::computeNumComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在osg::Image的用法示例。


在下文中一共展示了Image::computeNumComponents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: writeEXRStream

    bool writeEXRStream(const osg::Image &img, std::ostream& fout, const std::string &fileName) const
    {
        bool writeOK = true;

        //Obtain data from texture
        int width = img.s();
        int height = img.t();
        unsigned int pixelFormat = img.getPixelFormat();
        int numComponents = img.computeNumComponents(pixelFormat);
        unsigned int dataType = img.getDataType();

        //Validates image data
        //if numbers of components matches
        if (!(    numComponents == 3 ||
                  numComponents == 4))
        {
            writeOK = false;
            return false;
        }
        if (!(    dataType == GL_HALF_FLOAT_ARB ||
                  dataType == GL_FLOAT))
        {
            writeOK = false;
            return false;
        }

        //Create a stream to save to
        C_OStream outStream(&fout);

        //Copy data from texture to rgba pixel format
        Array2D<Rgba> outPixels(height,width);
        //If texture is half format
        if (dataType == GL_HALF_FLOAT_ARB)
        {
            half* pOut = (half*) img.data();
            for (long i = height-1; i >= 0; i--)
            {
                for (long j = 0 ; j < width; j++)
                {
                    outPixels[i][j].r = (*pOut);
                    pOut++;
                    outPixels[i][j].g = (*pOut);
                    pOut++;
                    outPixels[i][j].b = (*pOut);
                    pOut++;
                    if (numComponents >= 4)
                    {
                        outPixels[i][j].a = (*pOut);
                        pOut++;
                    }
                    else {
                        outPixels[i][j].a = 1.0f;
                    }
                }
            }
        }
        else if (dataType == GL_FLOAT)
        {
            float* pOut = (float*) img.data();
            for (long i = height-1; i >= 0; i--)
            {
                for (long j = 0 ; j < width; j++)
                {
                    outPixels[i][j].r = half(*pOut);
                    pOut++;
                    outPixels[i][j].g = half(*pOut);
                    pOut++;
                    outPixels[i][j].b = half(*pOut);
                    pOut++;
                    if (numComponents >= 4)
                    {
                        outPixels[i][j].a = half(*pOut);
                        pOut++;
                    }
                    else
                    {
                        outPixels[i][j].a = 1.0f;
                    }
                }
            }
        }
        else
        {
            //If texture format not supported
            return false;
        }

        try
        {
            //Write to stream
            Header outHeader(width, height);
            RgbaOutputFile rgbaFile (outStream, outHeader, WRITE_RGBA);
            rgbaFile.setFrameBuffer ((&outPixels)[0][0], 1, width);
            rgbaFile.writePixels (height);
        }
        catch( char * str )
        {
            writeOK = false;
        }

//.........这里部分代码省略.........
开发者ID:nsmoooose,项目名称:osg,代码行数:101,代码来源:ReaderWriterEXR.cpp


注:本文中的osg::Image::computeNumComponents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。