CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/ext/basis_universal/basisu_file_headers.h
Views: 1401
// basis_file_headers.h1// Copyright (C) 2019-2020 Binomial LLC. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14#pragma once15#include "basisu_transcoder_internal.h"1617namespace basist18{19// Slice desc header flags20enum basis_slice_desc_flags21{22cSliceDescFlagsHasAlpha = 1,2324// Video only: Frame doesn't refer to previous frame (no usage of conditional replenishment pred symbols)25// Currently the first frame is always an I-Frame, all subsequent frames are P-Frames. This will eventually be changed to periodic I-Frames.26cSliceDescFlagsFrameIsIFrame = 227};2829#pragma pack(push)30#pragma pack(1)31struct basis_slice_desc32{33basisu::packed_uint<3> m_image_index; // The index of the source image provided to the encoder (will always appear in order from first to last, first image index is 0, no skipping allowed)34basisu::packed_uint<1> m_level_index; // The mipmap level index (mipmaps will always appear from largest to smallest)35basisu::packed_uint<1> m_flags; // enum basis_slice_desc_flags3637basisu::packed_uint<2> m_orig_width; // The original image width (may not be a multiple of 4 pixels)38basisu::packed_uint<2> m_orig_height; // The original image height (may not be a multiple of 4 pixels)3940basisu::packed_uint<2> m_num_blocks_x; // The slice's block X dimensions. Each block is 4x4 pixels. The slice's pixel resolution may or may not be a power of 2.41basisu::packed_uint<2> m_num_blocks_y; // The slice's block Y dimensions.4243basisu::packed_uint<4> m_file_ofs; // Offset from the start of the file to the start of the slice's data44basisu::packed_uint<4> m_file_size; // The size of the compressed slice data in bytes4546basisu::packed_uint<2> m_slice_data_crc16; // The CRC16 of the compressed slice data, for extra-paranoid use cases47};4849// File header files50enum basis_header_flags51{52// Always set for ETC1S files. Not set for UASTC files.53cBASISHeaderFlagETC1S = 1,5455// Set if the texture had to be Y flipped before encoding. The actual interpretation of this (is Y up or down?) is up to the user.56cBASISHeaderFlagYFlipped = 2,5758// Set if any slices contain alpha (for ETC1S, if the odd slices contain alpha data)59cBASISHeaderFlagHasAlphaSlices = 4,6061// For ETC1S files, this will be true if the file utilizes a codebook from another .basis file.62cBASISHeaderFlagUsesGlobalCodebook = 8,6364// Set if the texture data is sRGB, otherwise it's linear.65// In reality, we have no idea if the texture data is actually linear or sRGB. This is the m_perceptual parameter passed to the compressor.66cBASISHeaderFlagSRGB = 16,67};6869// The image type field attempts to describe how to interpret the image data in a Basis file.70// The encoder library doesn't really do anything special or different with these texture types, this is mostly here for the benefit of the user.71// We do make sure the various constraints are followed (2DArray/cubemap/videoframes/volume implies that each image has the same resolution and # of mipmap levels, etc., cubemap implies that the # of image slices is a multiple of 6)72enum basis_texture_type73{74cBASISTexType2D = 0, // An arbitrary array of 2D RGB or RGBA images with optional mipmaps, array size = # images, each image may have a different resolution and # of mipmap levels75cBASISTexType2DArray = 1, // An array of 2D RGB or RGBA images with optional mipmaps, array size = # images, each image has the same resolution and mipmap levels76cBASISTexTypeCubemapArray = 2, // an array of cubemap levels, total # of images must be divisable by 6, in X+, X-, Y+, Y-, Z+, Z- order, with optional mipmaps77cBASISTexTypeVideoFrames = 3, // An array of 2D video frames, with optional mipmaps, # frames = # images, each image has the same resolution and # of mipmap levels78cBASISTexTypeVolume = 4, // A 3D texture with optional mipmaps, Z dimension = # images, each image has the same resolution and # of mipmap levels7980cBASISTexTypeTotal81};8283enum84{85cBASISMaxUSPerFrame = 0xFFFFFF86};8788enum class basis_tex_format89{90cETC1S = 0,91cUASTC4x4 = 192};9394struct basis_file_header95{96enum97{98cBASISSigValue = ('B' << 8) | 's',99cBASISFirstVersion = 0x10100};101102basisu::packed_uint<2> m_sig; // 2 byte file signature103basisu::packed_uint<2> m_ver; // Baseline file version104basisu::packed_uint<2> m_header_size; // Header size in bytes, sizeof(basis_file_header)105basisu::packed_uint<2> m_header_crc16; // CRC16 of the remaining header data106107basisu::packed_uint<4> m_data_size; // The total size of all data after the header108basisu::packed_uint<2> m_data_crc16; // The CRC16 of all data after the header109110basisu::packed_uint<3> m_total_slices; // The total # of compressed slices (1 slice per image, or 2 for alpha .basis files)111112basisu::packed_uint<3> m_total_images; // The total # of images113114basisu::packed_uint<1> m_tex_format; // enum basis_tex_format115basisu::packed_uint<2> m_flags; // enum basist::header_flags116basisu::packed_uint<1> m_tex_type; // enum basist::basis_texture_type117basisu::packed_uint<3> m_us_per_frame; // Framerate of video, in microseconds per frame118119basisu::packed_uint<4> m_reserved; // For future use120basisu::packed_uint<4> m_userdata0; // For client use121basisu::packed_uint<4> m_userdata1; // For client use122123basisu::packed_uint<2> m_total_endpoints; // The number of endpoints in the endpoint codebook124basisu::packed_uint<4> m_endpoint_cb_file_ofs; // The compressed endpoint codebook's file offset relative to the start of the file125basisu::packed_uint<3> m_endpoint_cb_file_size; // The compressed endpoint codebook's size in bytes126127basisu::packed_uint<2> m_total_selectors; // The number of selectors in the endpoint codebook128basisu::packed_uint<4> m_selector_cb_file_ofs; // The compressed selectors codebook's file offset relative to the start of the file129basisu::packed_uint<3> m_selector_cb_file_size; // The compressed selector codebook's size in bytes130131basisu::packed_uint<4> m_tables_file_ofs; // The file offset of the compressed Huffman codelength tables, for decompressing slices132basisu::packed_uint<4> m_tables_file_size; // The file size in bytes of the compressed huffman codelength tables133134basisu::packed_uint<4> m_slice_desc_file_ofs; // The file offset to the slice description array, usually follows the header135136basisu::packed_uint<4> m_extended_file_ofs; // The file offset of the "extended" header and compressed data, for future use137basisu::packed_uint<4> m_extended_file_size; // The file size in bytes of the "extended" header and compressed data, for future use138};139#pragma pack (pop)140141} // namespace basist142143144