CompressedImageData.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Copyright (c) 2006-2017 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "CompressedImageData.h"
  21. namespace love
  22. {
  23. namespace image
  24. {
  25. namespace magpie
  26. {
  27. CompressedImageData::CompressedImageData(std::list<CompressedFormatHandler *> formats, love::filesystem::FileData *filedata)
  28. {
  29. CompressedFormatHandler *parser = nullptr;
  30. for (CompressedFormatHandler *handler : formats)
  31. {
  32. if (handler->canParse(filedata))
  33. {
  34. parser = handler;
  35. break;
  36. }
  37. }
  38. if (parser == nullptr)
  39. throw love::Exception("Could not parse compressed data: Unknown format.");
  40. memory = parser->parse(filedata, dataImages, format, sRGB);
  41. if (memory == nullptr)
  42. throw love::Exception("Could not parse compressed data.");
  43. if (format == PIXELFORMAT_UNKNOWN)
  44. throw love::Exception("Could not parse compressed data: Unknown format.");
  45. if (dataImages.size() == 0 || memory->size == 0)
  46. throw love::Exception("Could not parse compressed data: No valid data?");
  47. }
  48. CompressedImageData::CompressedImageData(const CompressedImageData &c)
  49. {
  50. format = c.format;
  51. sRGB = c.sRGB;
  52. memory.set(new Memory(c.memory->size), Acquire::NORETAIN);
  53. memcpy(memory->data, c.memory->data, memory->size);
  54. for (const auto &i : c.dataImages)
  55. {
  56. Slice *slice = new Slice(i->getFormat(), i->getWidth(), i->getHeight(), memory, i->getOffset(), i->getSize());
  57. dataImages.push_back(slice);
  58. slice->release();
  59. }
  60. }
  61. CompressedImageData *CompressedImageData::clone() const
  62. {
  63. return new CompressedImageData(*this);
  64. }
  65. CompressedImageData::~CompressedImageData()
  66. {
  67. }
  68. } // magpie
  69. } // image
  70. } // love