Advertisement
Zgragselus

Untitled

Jul 25th, 2023
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. /// <summary>
  2. /// Loads sctex file into loaded helper structure
  3. /// </summary>
  4. /// <param name="filename">Filename</param>
  5. /// <returns>Pointer to HelperImageData </returns>
  6. LoaderSctex::HelperImageData* LoaderSctex::Load(const std::string& filename)
  7. {
  8.     if (!Files::Exists(filename))
  9.     {
  10.         mLog->Print("LoaderSctex", std::string("File ") + filename + std::string(" does not exist!"));
  11.         return nullptr;
  12.     }
  13.  
  14.     HelperImageData* image = new HelperImageData();
  15.  
  16.     FILE* f = fopen(filename.c_str(), "rb");
  17.  
  18.     fread(&image->mHeader, sizeof(Header), 1, f);
  19.  
  20.     image->mImageRecord = new ImageRecord[image->mHeader.mNumImages];
  21.  
  22.     fread(image->mImageRecord, sizeof(ImageRecord), image->mHeader.mNumImages, f);
  23.  
  24.     image->mImageData = new ImageData[image->mHeader.mNumImages];
  25.  
  26.     for (size_t i = 0; i < image->mHeader.mNumImages; i++)
  27.     {
  28.         image->mImageData[i].mData = new unsigned char[image->mImageRecord[i].mSize];
  29.  
  30.         fseek(f, (long)image->mImageRecord[i].mOffset, SEEK_SET);
  31.         fread(image->mImageData[i].mData, sizeof(char), image->mImageRecord[i].mSize, f);
  32.     }
  33.  
  34.     fclose(f);
  35.  
  36.     return image;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement