Advertisement
Guest User

Untitled

a guest
Dec 31st, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. Image2d* MkoFileReader::CreateMkoAsset(const std::string& strId, unsigned uType){
  2.     if (uType != MKO_IMAGE)
  3.         throwError(__FUNCTION__ + std::string(" failed. File does not contain Image2d Data."));
  4.  
  5.     std::string strTextureFilename(128, 0);
  6.     if (!GetString(strTextureFilename, true))
  7.         throwError(__FUNCTION__ + std::string(" invalid mko file. Missing texture filename"));
  8.  
  9.     Image2d* pAsset = nullptr;
  10.  
  11.     if (_uVersion == 1){
  12.         struct ImageData{
  13.             unsigned short width;
  14.             unsigned short height;
  15.             unsigned short scale;
  16.             union{
  17.                 unsigned char bits;
  18.                 struct ImageProperties{
  19.                     unsigned char generateMipMap : 1;
  20.                     unsigned char filterQuality : 2;
  21.                     unsigned char unused : 5;
  22.                 } bitfield;
  23.             };
  24.         } data;
  25.  
  26.         _filestream.read(reinterpret_cast<char*>(&data), sizeof(ImageData));
  27.         if (_filestream.fail())
  28.             throwError(__FUNCTION__ + std::string(" failed. Missing ImageData"));
  29.  
  30.         if (data.scale <= 0)
  31.             throwError(__FUNCTION__ + std::string(" Invalid scale value."));
  32.  
  33.         float fScale = 1.0f / static_cast<float>(data.scale);
  34.         pAsset = new Image2d(data.width*data.scale,
  35.             data.height*data.scale,
  36.             static_cast<TextureInfo::FilterQuality>(data.bitfield.filterQuality),
  37.             data.bitfield.generateMipMap,
  38.             strTextureFilename,
  39.             strId);
  40.     }
  41.  
  42.     return pAsset;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement