// Copyright (C) 2022 Jakub Melka // // This file is part of PDF4QT. // // PDF4QT is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // with the written consent of the copyright owner, any later version. // // PDF4QT is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with PDF4QT. If not, see . #ifndef PDF3D_U3D_H #define PDF3D_U3D_H #include "pdfglobal.h" #include namespace pdf { namespace u3d { class PDF3D_U3D { public: static PDF3D_U3D parse(QByteArray data); }; class PDF3D_U3D_ContextManager { public: bool isContextCompressed(uint32_t context) const; bool isContextStaticAndCompressed(uint32_t context) const; uint32_t getTotalSymbolFrequency(uint32_t context) const; uint32_t getSymbolFrequency(uint32_t context, uint32_t symbol) const; uint32_t getCumulativeSymbolFrequency(uint32_t context, uint32_t symbol) const; uint32_t getSymbolFromFrequency(uint32_t context, uint32_t symbolFrequency) const; void addSymbol(uint32_t context, uint32_t symbol); private: struct ContextData { ContextData() { symbols= { { 0, Data{ 1, 1} } }; } struct Data { uint32_t symbolCount = 0; uint32_t cumulativeSymbolCount = 0; }; std::map symbols; }; const ContextData* getContextData(uint32_t context) const; std::map m_contexts; }; class PDF3D_U3D_Constants { public: static constexpr uint32_t S_NOT_THREE_QUARTER_MASK = 0x00003FFF; static constexpr uint32_t S_QUARTER_MASK = 0x00004000; static constexpr uint32_t S_NOT_HALF_MASK = 0x00007FFF; static constexpr uint32_t S_HALF_MASK = 0x00008000; static constexpr uint32_t S_STATIC_FULL = 0x00000400; static constexpr uint32_t S_MAX_RANGE = S_STATIC_FULL + 0x00003FFF; static constexpr uint32_t S_CONTEXT_8 = 0; static constexpr uint32_t S_MAX_CUMULATIVE_SYMBOL_COUNT = 0x00001fff; static constexpr uint32_t S_MAXIMUM_SYMBOL_IN_HISTOGRAM = 0x0000FFFF; }; class PDF3D_U3D_DataReader { public: PDF3D_U3D_DataReader(QByteArray data); ~PDF3D_U3D_DataReader(); uint8_t readU8(); uint16_t readU16(); uint32_t readU32(); uint64_t readU64(); int32_t readI32(); float readF32(); uint8_t readCompressedU8(uint32_t context); uint16_t readCompressedU16(uint32_t context); uint32_t readCompressedU32(uint32_t context); private: uint32_t readSymbol(uint32_t context); uint8_t swapBits8(uint8_t source); uint32_t readBit(); uint32_t read15Bits(); QByteArray m_data; PDF3D_U3D_ContextManager m_contextManager; uint32_t m_high; uint32_t m_low; uint32_t m_underflow; uint32_t m_code; uint32_t m_position; }; } // namespace u3d } // namespace pdf #endif // PDF3D_U3D_H