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


C++ BinaryInput::setPosition方法代码示例

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


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

示例1:

void MD2Model::Part::loadTextureFilenames(BinaryInput& b, int num, int offset) {

    _textureFilenames.resize(num);
    b.setPosition(offset);
    for (int t = 0; t < num; ++t) {
        _textureFilenames[t] = b.readString();
    }
}
开发者ID:jackpoz,项目名称:G3D-backup,代码行数:8,代码来源:MD2Model_load.cpp

示例2: decodeTGA

void GImage::decodeTGA(
    BinaryInput&        input) {

    // This is a simple TGA loader that can handle uncompressed
    // truecolor TGA files (TGA type 2).
    // Verify this is a TGA file by looking for the TRUEVISION tag.
    int pos = input.getPosition();
    input.setPosition(input.size() - 18);
    std::string tag = input.readString(16);
    if (tag != "TRUEVISION-XFILE") {
        throw Error("Not a TGA file", input.getFilename());
    }

    input.setPosition(pos);

    int IDLength     = input.readUInt8();
    int colorMapType = input.readUInt8();
    int imageType    = input.readUInt8();

    (void)colorMapType;

    // 2 is the type supported by this routine.
    if (imageType != 2 && imageType != 10) {
        throw Error("TGA images must be type 2 (Uncompressed truecolor) or 10 (Run-length truecolor)", input.getFilename());
    }

    // Color map specification
    input.skip(5);

    // Image specification

    // Skip x and y offsets
    input.skip(4);

    m_width  = input.readInt16();
    m_height = input.readInt16();

    int colorDepth = input.readUInt8();

    if ((colorDepth != 24) && (colorDepth != 32)) {
        throw Error("TGA files must be 24 or 32 bit.", input.getFilename());
    }

    if (colorDepth == 32) {
        m_channels = 4;
    } else {
        m_channels = 3;
    }

    // Image descriptor contains overlay data as well
    // as data indicating where the origin is
    int imageDescriptor = input.readUInt8();
    (void)imageDescriptor;

    // Image ID
    input.skip(IDLength);

    m_byte = (uint8*)m_memMan->alloc(m_width * m_height * m_channels);
    debugAssert(m_byte);

    // Pixel data
    int x;
    int y;

    if (imageType == 2) {
        // Uncompressed
        if (m_channels == 3) {
            for (y = m_height - 1; y >= 0; --y) {
              for (x = 0; x < m_width; ++x) {
                int i = (x + y * m_width) * 3;
                readBGR(m_byte + i, input);
              }
            }
        } else {
            for (y = m_height - 1; y >= 0; --y) {
              for (x = 0; x < m_width; ++x) {
                 int i = (x + y * m_width) * 4;
                 readBGRA(m_byte + i, input);
              }
            }
        }
    } else if (imageType == 10) {

        // Run-length encoded
        for (y = m_height - 1; y >= 0; --y) {
            for (int x = 0; x < m_width; /* intentionally no x increment */) {
                // The specification guarantees that no packet will wrap past the end of a row
                const uint8 repetitionCount = input.readUInt8();
                const uint8 numValues = (repetitionCount & (~128)) + 1;
                int byteOffset = (x + y * m_width) * 3;

                if (repetitionCount & 128) {
                    // When the high bit is 1, this is a run-length packet
                    if (m_channels == 3) {
                        Color3uint8 value;
                        readBGR((uint8*)(&value), input);
                        for (int i = 0; i < numValues; ++i, ++x) {
                            for (int b = 0; b < 3; ++b, ++byteOffset) {
                                m_byte[byteOffset] = value[b];
                            }
//.........这里部分代码省略.........
开发者ID:Demigodess,项目名称:Darkcore,代码行数:101,代码来源:GImage_tga.cpp

示例3: decodeTGA

void GImage::decodeTGA(
    BinaryInput&        input) {

    // This is a simple TGA loader that can handle uncompressed
    // truecolor TGA files (TGA type 2). 
    // Verify this is a TGA file by looking for the TRUEVISION tag.
    int pos = input.getPosition();
    input.setPosition(input.size() - 18);
    std::string tag = input.readString(16);
    if (tag != "TRUEVISION-XFILE") {
        throw Error("Not a TGA file", input.getFilename());
    }

    input.setPosition(pos);

    int IDLength     = input.readUInt8();
    int colorMapType = input.readUInt8();
    int imageType    = input.readUInt8();

    (void)colorMapType;
	
    // 2 is the type supported by this routine.
    if (imageType != 2) {
        throw Error("TGA images must be type 2 (Uncompressed truecolor)", input.getFilename());
    }
	
    // Color map specification
    input.skip(5);

    // Image specification

    // Skip x and y offsets
    input.skip(4); 

    m_width  = input.readInt16();
    m_height = input.readInt16();

    int colorDepth = input.readUInt8();

    if ((colorDepth != 24) && (colorDepth != 32)) {
        throw Error("TGA files must be 24 or 32 bit.", input.getFilename());
    }

    if (colorDepth == 32) {
        m_channels = 4;
    } else {
        m_channels = 3;
    }

    // Image descriptor contains overlay data as well
    // as data indicating where the origin is
    int imageDescriptor = input.readUInt8();
    (void)imageDescriptor;
	
    // Image ID
    input.skip(IDLength);

    m_byte = (uint8*)m_memMan->alloc(m_width * m_height * m_channels);
    debugAssert(m_byte);
	
    // Pixel data
    int x;
    int y;

    if (m_channels == 3) {
        for (y = m_height - 1; y >= 0; --y) {
          for (x = 0; x < m_width; ++x) {
            int b = input.readUInt8();
            int g = input.readUInt8();
            int r = input.readUInt8();
		    
            int i = (x + y * m_width) * 3;
            m_byte[i + 0] = r;
            m_byte[i + 1] = g;
            m_byte[i + 2] = b;
          }
        }
    } else {
        for (y = m_height - 1; y >= 0; --y) {
          for (x = 0; x < m_width; ++x) {
            int b = input.readUInt8();
            int g = input.readUInt8();
            int r = input.readUInt8();
            int a = input.readUInt8();
		    
            int i = (x + y * m_width) * 4;
            m_byte[i + 0] = r;
            m_byte[i + 1] = g;
            m_byte[i + 2] = b;
            m_byte[i + 3] = a;
          }
        }
    }
}
开发者ID:3raZar3,项目名称:fucked,代码行数:94,代码来源:GImage_tga.cpp


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