dds.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright (C) 2001-2006, William Joseph.
  3. All Rights Reserved.
  4. This file is part of GtkRadiant.
  5. GtkRadiant 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. GtkRadiant 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. You should have received a copy of the GNU General Public License
  14. along with GtkRadiant; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #include "dds.h"
  18. #include <stdlib.h>
  19. #include "ifilesystem.h"
  20. #include "iarchive.h"
  21. #include "idatastream.h"
  22. #include "ddslib.h"
  23. #include "imagelib.h"
  24. Image* LoadDDSBuff(const byte* buffer)
  25. {
  26. int width, height;
  27. ddsPF_t pixelFormat;
  28. if(DDSGetInfo(reinterpret_cast<ddsBuffer_t*>(const_cast<byte*>(buffer)), &width, &height, &pixelFormat) == -1)
  29. {
  30. return 0;
  31. }
  32. RGBAImage* image = new RGBAImage(width, height);
  33. if(DDSDecompress(reinterpret_cast<ddsBuffer_t*>(const_cast<byte*>(buffer)), image->getRGBAPixels()) == -1)
  34. {
  35. image->release();
  36. return 0;
  37. }
  38. return image;
  39. }
  40. Image* LoadDDS(ArchiveFile& file)
  41. {
  42. ScopedArchiveBuffer buffer(file);
  43. return LoadDDSBuff(buffer.buffer);
  44. }