filmout_display/include/dxf.hpp

80 lines
2.0 KiB
C++

#include <opencv2/opencv.hpp>
#include <fstream>
#include <vector>
#include <stdexcept>
#include <memory>
#include <string>
using namespace cv;
using namespace std;
struct DXFHeader {
int32_t width;
int32_t height;
uint8_t bitDepth;
uint8_t version;
uint8_t flags;
uint8_t reserved;
};
class DXF {
public:
explicit DXF(const string& filepath) :
_filepath(filepath),
_width(0),
_height(0),
_bitDepth(0) {
analyzeFile();
loadImageData();
}
int getWidth() const { return _width; }
int getHeight() const { return _height; }
int getBitDepth() const { return _bitDepth; }
bool hasDXFHeader() const { return true; }
Mat to8bitBGR() const;
Mat to10bitBGR() const;
private:
string _filepath;
int _width;
int _height;
int _bitDepth;
Mat _imageData;
void analyzeFile();
bool readDXFHeader(ifstream& file);
void analyzeDXFContent(ifstream& file);
int detectBitDepth(const vector<uint8_t>& sample);
void loadImageData();
void unpackBits(const std::vector<uint8_t>& rawData);
void calculateDimensions(streamsize fileSize);
void validateImageProperties();
static uint16_t extractBits(const std::vector<uint8_t>& buffer, size_t bitPos, int bitDepth, uint16_t maxValue);
};
/* Example usage
int main() {
try {
DXF dxf("sample.dxf");
cout << "Image dimensions: " << dxf.getWidth() << "x" <<
dxf.getHeight() << endl;
cout << "Original bit depth: " << dxf.getBitDepth() << endl;
Mat bgr8bit = dxf.to8BitBGR();
Mat bgr10bit = dxf.to10BitBGR();
imwrite("output_8bit_bgr.png", bgr8bit);
imwrite("output_10bit_bgr.png", bgr10bit);
return 0;
}
catch (const exception& e) {
cerr << "Error: " << e.what() << endl;
return 1;
}
}*/