66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
|
#ifndef DPX_HPP
|
||
|
#define DPX_HPP
|
||
|
|
||
|
#include <opencv2/opencv.hpp>
|
||
|
#include <string>
|
||
|
#include <fstream>
|
||
|
#include <vector>
|
||
|
#include <stdexcept>
|
||
|
|
||
|
using namespace std;
|
||
|
using namespace cv;
|
||
|
|
||
|
class DPX {
|
||
|
public:
|
||
|
DPX();
|
||
|
|
||
|
bool read(const string& filename);
|
||
|
Mat getMat() const;
|
||
|
Mat getMatBitDepth(int targetBitDepth) const;
|
||
|
|
||
|
int getWidth() const;
|
||
|
int getHeight() const;
|
||
|
int getBitDepth() const;
|
||
|
|
||
|
private:
|
||
|
struct DPXHeader {
|
||
|
uint32_t magic; // Magic number (0x53445058 "SDPX" or 0x58504453 "XPDS")
|
||
|
uint32_t imageOffset; // Offset to image data
|
||
|
uint16_t width;
|
||
|
uint16_t height;
|
||
|
uint8_t descriptor; // Image descriptor
|
||
|
uint8_t bitDepth; // Bits per component
|
||
|
uint8_t imageElements; // Number of image elements
|
||
|
bool isBigEndian; // File endianness
|
||
|
};
|
||
|
|
||
|
DPXHeader header;
|
||
|
Mat image;
|
||
|
|
||
|
bool readHeader(ifstream& file);
|
||
|
void readImageData(ifstream& file);
|
||
|
uint32_t swapEndian(uint32_t value);
|
||
|
uint16_t swapEndian(uint16_t value);
|
||
|
};
|
||
|
|
||
|
#endif
|
||
|
|
||
|
/* Example usage
|
||
|
int main() {
|
||
|
try {
|
||
|
DPX dpx;
|
||
|
dpx.read("image.dpx");
|
||
|
|
||
|
// Get the original 16-bit Mat
|
||
|
Mat mat16 = dpx.getMat();
|
||
|
|
||
|
// Get 8-bit version
|
||
|
Mat mat8 = dpx.getMatBitDepth(8);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
catch (const exception& e) {
|
||
|
cerr << "Error: " << e.what() << endl;
|
||
|
return 1;
|
||
|
}
|
||
|
}*/
|