Beispiel #1
0
TTexturePtr LoadFromMemory(TFilePtr& aFile, const char* aLogdata)
{
   LOG_PARAMS(aLogdata);
   if (!ValidateFileHeader(aFile)) {
      LOG_ERROR("Could not load image %s: Invalid file header", aLogdata);
      return TTexturePtr();
   }
   png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
   if (pngPtr == nullptr) {
      LOG_ERROR("Could not initialize png read struct for %s", aLogdata);
      return TTexturePtr();
   }
   TTexturePtr result = LoadPNG(aFile, aLogdata, pngPtr);
   png_destroy_read_struct(&pngPtr, nullptr, nullptr);
   return result;
}
Beispiel #2
0
/**
Loads and checks both bitmap file and info headers.

@param[in] FileStream   The input file stream.
@param[out] FileHeader  The bitmap file header read from the file.
@param[out] InfoHeader  The bitmap info header read from the file.

@return One of #BitmapLoadStatus codes.
*/
static BitmapLoadStatus LoadAndValidateHeaders(std::ifstream& FileStream, BitmapFileHeader* FileHeader,
                                               BitmapInfoHeader* InfoHeader)
{
    FileStream.read(reinterpret_cast<char*>(FileHeader), sizeof(*FileHeader));
    if (FileStream.bad()) {
        return INVALID_FILE_HEADER;
    }

    if (!ValidateFileHeader(*FileHeader)) {
        return INVALID_FILE_HEADER;
    }

    FileStream.read(reinterpret_cast<char*>(InfoHeader), sizeof(*InfoHeader));
    if (FileStream.bad() || !ValidateInfoHeader(*InfoHeader)) {
        return INVALID_INFO_HEADER;
    }

    return LOAD_SUCCESS;
}