PNGReader.h 994 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef PNGREADER_H
  2. #define PNGREADER_H
  3. #include <png.h>
  4. #include "utils/Color.h"
  5. class PNGReader final {
  6. const char* path;
  7. int width;
  8. int height;
  9. int channels;
  10. int bitDepth;
  11. int rowBytes;
  12. FILE* file;
  13. png_structp read;
  14. png_infop info;
  15. ColorChannel** rowPointers;
  16. public:
  17. PNGReader(const char* path);
  18. ~PNGReader();
  19. PNGReader(const PNGReader& other) = delete;
  20. PNGReader(PNGReader&& other) = delete;
  21. PNGReader& operator=(const PNGReader& other) = delete;
  22. PNGReader& operator=(PNGReader&& other) = delete;
  23. int getWidth() const;
  24. int getHeight() const;
  25. int getChannels() const;
  26. int getBufferSize() const;
  27. bool hasError() const;
  28. template<int N>
  29. bool readData(Color<N>* buffer) {
  30. if(channels != N) {
  31. return true;
  32. }
  33. return readData(reinterpret_cast<ColorChannel*> (buffer));
  34. }
  35. private:
  36. bool readData(ColorChannel* buffer);
  37. bool checkSignature();
  38. };
  39. #endif