Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

ImgTex.cpp 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "resource/ImgTex.h"
  19. #include "resource/ImgColor.h"
  20. #include "BinReader.h"
  21. #include "Core.h"
  22. #include "ResourceCache.h"
  23. ImgTex::ImgTex(uint32_t id, const void* data, size_t size) : ResourceImpl{id}
  24. {
  25. BinReader reader(data, size);
  26. uint32_t resourceId = reader.readInt();
  27. assert(resourceId == id);
  28. UNUSED(resourceId);
  29. uint32_t zero = reader.readInt();
  30. assert(zero == 0);
  31. UNUSED(zero);
  32. uint8_t two = reader.readByte();
  33. assert(two == 2);
  34. UNUSED(two);
  35. uint32_t numImgColors = reader.readInt();
  36. assert(numImgColors > 0);
  37. // This seems to be a list of textures by decreasing quality, as the first ones in the list are in highres.dat
  38. // We're just going to pick the first and roll with it
  39. uint32_t imgColorId = reader.readInt();
  40. imgColor = Core::get().resourceCache().get(imgColorId);
  41. assert(imgColor->resourceType() == ResourceType::kImgColor);
  42. for(uint32_t i = 1; i < numImgColors; i++)
  43. {
  44. reader.readInt();
  45. }
  46. assert(reader.remaining() == 0);
  47. }
  48. ImgTex::ImgTex(ResourcePtr imgColor) : ResourceImpl{static_cast<uint32_t>(ResourceType::kImgTex) | 0xFFFF}, imgColor{imgColor}
  49. {
  50. assert(imgColor->resourceType() == ResourceType::kImgColor);
  51. }