Advertisement
Jakzon123

File.h

Jul 13th, 2023
879
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 1 0
  1. #pragma once
  2. #include <string>
  3. #include <fstream>
  4.  
  5. class File {
  6.     public:
  7.  
  8.         // storing file header data
  9.         struct Header {
  10.             char idLength;
  11.             char colorMapType;
  12.             char dataTypeCode;
  13.             short colorMapOrigin;
  14.             short colorMapLength;
  15.             char colorMapDepth;
  16.             short xOrigin;
  17.             short yOrigin;
  18.             short width;
  19.             short height;
  20.             char bitsPerPixel;
  21.             char imageDescriptor;
  22.         };
  23.  
  24.         // storing pixel data
  25.         struct Pixel {
  26.             unsigned char blue;
  27.             unsigned char green;
  28.             unsigned char red;
  29.         };
  30.  
  31.         // constructor and destructor
  32.         File(std::string fileName);
  33.         ~File();
  34.  
  35.         // define essential functions
  36.     bool ReadFile(std::string fileName);
  37.     bool WriteFile(std::string fileName);
  38.  
  39.         Header readHeader(std::ifstream& file);
  40.         void writeHeader(Header header, std::ofstream& file);
  41.  
  42.         Pixel** readPixelArray(std::ifstream& file, int width, int height);
  43.         void writePixelArray(Pixel** pixelArray, std::ofstream& file);
  44.  
  45.     Header getHeader();
  46.  
  47.     private:
  48.         Header header;
  49.         Pixel** pixelArray;
  50. };
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement