TextureHeader.h#

Parent directory (texture)

Information about an Image asset, excluding the actual image pixels and custom metadata.

Includes#

  • PVRCore/texture/MetaData.h

  • PVRCore/texture/PixelFormat.h

  • algorithm

  • cstddef

  • cstdint

  • map

  • string (CompileTimeHash.h)

  • vector

Included By#

Namespaces#

Classes#

Source Code#

#pragma once

#include "PVRCore/texture/PixelFormat.h"
#include "PVRCore/texture/MetaData.h"
#include <map>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <cstddef>
#include <string>

namespace pvr {
enum
{
    pvrTextureAllMipMaps = -1
};

struct TextureHeader
{
public:
    // V3 Header Identifiers.

    enum Constants
    {
        PVRv3 = 0x03525650,
        PVRv3Reversed = 0x50565203,

        // PVR header flags.
        CompressedFlag = (1 << 0),
        PremultipliedFlag = (1 << 1),
        SizeOfHeader = 52
    };

    uint32_t flags;
    PixelFormat pixelFormat;
    ColorSpace colorSpace;
    VariableType channelType;
    uint32_t height;
    uint32_t width;
    uint32_t depth;
    uint32_t numSurfaces;
    uint32_t numFaces;
    uint32_t numMipMaps;
    uint32_t numPlanes;
    uint32_t metaDataSize;

    // Header _header; //!< Texture header as laid out in a file.
    std::map<uint32_t, std::map<uint32_t, TextureMetaData>> _metaDataMap;

    TextureHeader();

    TextureHeader(uint32_t numMetaData, TextureMetaData* metaData);

    TextureHeader(PixelFormat pixelFormat, uint32_t width, uint32_t height, uint32_t depth = 1, uint32_t numMipMaps = 1, ColorSpace colorSpace = ColorSpace::lRGB,
        VariableType channelType = VariableType::UnsignedByteNorm, uint32_t numSurfaces = 1, uint32_t numFaces = 1, uint32_t flags = 0, TextureMetaData* metaData = NULL,
        uint32_t metaDataSize = 0, uint32_t numPlanes = 1);

    PixelFormat getPixelFormat() const { return pixelFormat; }

    uint32_t getBitsPerPixel() const;

    void getMinDimensionsForFormat(uint32_t& minX, uint32_t& minY, uint32_t& minZ) const;

    ColorSpace getColorSpace() const { return static_cast<ColorSpace>(colorSpace); }

    VariableType getChannelType() const { return static_cast<VariableType>(channelType); }

    uint32_t getWidth(uint32_t uiMipMapLevel = 0) const
    {
        // If MipLevel does not exist, return no uiDataSize.
        if (uiMipMapLevel > numMipMaps) { return 0; }
        return std::max<uint32_t>(width >> uiMipMapLevel, 1);
    }

    TextureMetaData::AxisOrientation getOrientation(TextureMetaData::Axis axis) const;

    uint32_t getHeight(uint32_t uiMipMapLevel = 0) const
    {
        // If MipLevel does not exist, return no uiDataSize.
        if (uiMipMapLevel > numMipMaps) { return 0; }
        return std::max<uint32_t>(height >> uiMipMapLevel, 1);
    }

    uint32_t getDepth(uint32_t mipLevel = 0) const
    {
        // If MipLevel does not exist, return no uiDataSize.
        if (mipLevel > numMipMaps) { return 0; }
        return std::max<uint32_t>(depth >> mipLevel, 1);
    }

    uint32_t getTextureSize(int32_t mipMapLevel = pvrTextureAllMipMaps, bool allSurfaces = true, bool allFaces = true, bool allPlanes = true, uint32_t planeIndex = 0) const
    {
        return static_cast<uint32_t>(
            (static_cast<uint64_t>(8) * static_cast<uint64_t>(getDataSize(mipMapLevel, allSurfaces, allFaces, allPlanes, planeIndex))) / static_cast<uint64_t>(getBitsPerPixel()));
    }

    uint32_t getDataSize(int32_t mipLevel = pvrTextureAllMipMaps, bool allSurfaces = true, bool allFaces = true, bool allPlanes = true, uint32_t planeIndex = 0) const;

    ptrdiff_t getDataOffset(uint32_t mipMapLevel = 0, uint32_t arrayMember = 0, uint32_t face = 0, uint32_t plane = 0) const;

    uint32_t getNumArrayMembers() const { return numSurfaces; }

    const std::map<uint32_t, std::map<uint32_t, TextureMetaData>>* getMetaDataMap() const { return &_metaDataMap; }

    uint32_t getNumMipMapLevels() const { return numMipMaps; }

    uint32_t getNumFaces() const { return numFaces; }

    uint32_t getNumPlanes() const { return numPlanes; }

    const std::string getCubeMapOrder() const;

    bool isFileCompressed() const { return (flags & CompressedFlag) != 0; }

    bool isPreMultiplied() const { return (flags & PremultipliedFlag) != 0; }

    uint32_t getMetaDataSize() const { return metaDataSize; }

    bool getDirect3DFormat(uint32_t& outD3dFormat) const;

    bool getDirectXGIFormat(uint32_t& outDxgiFormat, bool& notAlpha) const;

    void setPixelFormat(PixelFormat uPixelFormat) { pixelFormat = uPixelFormat.getPixelTypeId(); }

    void setColorSpace(ColorSpace newColorSpace) { colorSpace = newColorSpace; }

    void setChannelType(VariableType newChannelType) { channelType = newChannelType; }

    void setBumpMap(float bumpScale, std::string bumpOrder);

    bool isBumpMap() const;

    void setWidth(uint32_t newWidth) { width = newWidth; }

    void setHeight(uint32_t newHeight) { height = newHeight; }

    void setDepth(uint32_t newDepth) { depth = newDepth; }

    void setNumArrayMembers(uint32_t numNewMembers) { numSurfaces = numNewMembers; }

    void setNumMipMapLevels(uint32_t numNewMipMapLevels) { numMipMaps = numNewMipMapLevels; }

    void setNumFaces(uint32_t numNewFaces) { numFaces = numNewFaces; }

    void setNumPlanes(uint32_t numNewPlanes) { numPlanes = numNewPlanes; }

    void setOrientation(TextureMetaData::AxisOrientation axisOrientation);

    void setCubeMapOrder(std::string cubeMapOrder);

    void setIsFileCompressed(bool isFileCompressed)
    {
        if (isFileCompressed) { flags |= CompressedFlag; }
        else
        {
            flags &= !static_cast<bool>(static_cast<uint32_t>(CompressedFlag));
        }
    }

    void setIsPreMultiplied(bool isPreMultiplied)
    {
        if (isPreMultiplied) { flags |= PremultipliedFlag; }
        else
        {
            flags &= !static_cast<bool>(static_cast<uint32_t>(PremultipliedFlag));
        }
    }

    void addMetaData(const TextureMetaData& metaData);
};
} // namespace pvr