mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 07:07:38 +03:00
## Summary * Extract author from XTC/XTCH files ## Additional Context * Based on updated details in https://gist.github.com/CrazyCoder/b125f26d6987c0620058249f59f1327d --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? No
106 lines
2.8 KiB
C++
106 lines
2.8 KiB
C++
/**
|
|
* XtcParser.h
|
|
*
|
|
* XTC file parsing and page data extraction
|
|
* XTC ebook support for CrossPoint Reader
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <SdFat.h>
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "XtcTypes.h"
|
|
|
|
namespace xtc {
|
|
|
|
/**
|
|
* XTC File Parser
|
|
*
|
|
* Reads XTC files from SD card and extracts page data.
|
|
* Designed for ESP32-C3's limited RAM (~380KB) using streaming.
|
|
*/
|
|
class XtcParser {
|
|
public:
|
|
XtcParser();
|
|
~XtcParser();
|
|
|
|
// File open/close
|
|
XtcError open(const char* filepath);
|
|
void close();
|
|
bool isOpen() const { return m_isOpen; }
|
|
|
|
// Header information access
|
|
const XtcHeader& getHeader() const { return m_header; }
|
|
uint16_t getPageCount() const { return m_header.pageCount; }
|
|
uint16_t getWidth() const { return m_defaultWidth; }
|
|
uint16_t getHeight() const { return m_defaultHeight; }
|
|
uint8_t getBitDepth() const { return m_bitDepth; } // 1 = XTC/XTG, 2 = XTCH/XTH
|
|
|
|
// Page information
|
|
bool getPageInfo(uint32_t pageIndex, PageInfo& info) const;
|
|
|
|
/**
|
|
* Load page bitmap (raw 1-bit data, skipping XTG header)
|
|
*
|
|
* @param pageIndex Page index (0-based)
|
|
* @param buffer Output buffer (caller allocated)
|
|
* @param bufferSize Buffer size
|
|
* @return Number of bytes read on success, 0 on failure
|
|
*/
|
|
size_t loadPage(uint32_t pageIndex, uint8_t* buffer, size_t bufferSize);
|
|
|
|
/**
|
|
* Streaming page load
|
|
* Memory-efficient method that reads page data in chunks.
|
|
*
|
|
* @param pageIndex Page index
|
|
* @param callback Callback function to receive data chunks
|
|
* @param chunkSize Chunk size (default: 1024 bytes)
|
|
* @return Error code
|
|
*/
|
|
XtcError loadPageStreaming(uint32_t pageIndex,
|
|
std::function<void(const uint8_t* data, size_t size, size_t offset)> callback,
|
|
size_t chunkSize = 1024);
|
|
|
|
// Get title/author from metadata
|
|
std::string getTitle() const { return m_title; }
|
|
std::string getAuthor() const { return m_author; }
|
|
|
|
bool hasChapters() const { return m_hasChapters; }
|
|
const std::vector<ChapterInfo>& getChapters() const { return m_chapters; }
|
|
|
|
// Validation
|
|
static bool isValidXtcFile(const char* filepath);
|
|
|
|
// Error information
|
|
XtcError getLastError() const { return m_lastError; }
|
|
|
|
private:
|
|
FsFile m_file;
|
|
bool m_isOpen;
|
|
XtcHeader m_header;
|
|
std::vector<PageInfo> m_pageTable;
|
|
std::vector<ChapterInfo> m_chapters;
|
|
std::string m_title;
|
|
std::string m_author;
|
|
uint16_t m_defaultWidth;
|
|
uint16_t m_defaultHeight;
|
|
uint8_t m_bitDepth; // 1 = XTC/XTG (1-bit), 2 = XTCH/XTH (2-bit)
|
|
bool m_hasChapters;
|
|
XtcError m_lastError;
|
|
|
|
// Internal helper functions
|
|
XtcError readHeader();
|
|
XtcError readPageTable();
|
|
XtcError readTitle();
|
|
XtcError readAuthor();
|
|
XtcError readChapters();
|
|
};
|
|
|
|
} // namespace xtc
|