Image.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * Copyright (c) 2006-2020 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. #pragma once
  21. // LOVE
  22. #include "common/config.h"
  23. #include "common/StringMap.h"
  24. #include "common/math.h"
  25. #include "Texture.h"
  26. namespace love
  27. {
  28. namespace graphics
  29. {
  30. class Image : public Texture
  31. {
  32. public:
  33. static love::Type type;
  34. enum SettingType
  35. {
  36. SETTING_MIPMAPS,
  37. SETTING_LINEAR,
  38. SETTING_DPI_SCALE,
  39. SETTING_MAX_ENUM
  40. };
  41. struct Settings
  42. {
  43. bool mipmaps = false;
  44. bool linear = false;
  45. float dpiScale = 1.0f;
  46. };
  47. virtual ~Image();
  48. void replacePixels(love::image::ImageDataBase *d, int slice, int mipmap, int x, int y, bool reloadmipmaps);
  49. void replacePixels(const void *data, size_t size, int slice, int mipmap, const Rect &rect, bool reloadmipmaps);
  50. bool isFormatLinear() const;
  51. bool isCompressed() const;
  52. MipmapsType getMipmapsType() const;
  53. static int imageCount;
  54. static bool getConstant(const char *in, SettingType &out);
  55. static bool getConstant(SettingType in, const char *&out);
  56. static const char *getConstant(SettingType in);
  57. static std::vector<std::string> getConstants(SettingType);
  58. protected:
  59. Image(const Slices &data, const Settings &settings);
  60. Image(TextureType textype, PixelFormat format, int width, int height, int slices, const Settings &settings);
  61. void uploadImageData(love::image::ImageDataBase *d, int level, int slice, int x, int y);
  62. virtual void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd = nullptr) = 0;
  63. virtual void generateMipmaps() = 0;
  64. // The settings used to initialize this Image.
  65. Settings settings;
  66. MipmapsType mipmapsType;
  67. bool sRGB;
  68. // True if the image wasn't able to be properly created and it had to fall
  69. // back to a default texture.
  70. bool usingDefaultTexture;
  71. private:
  72. Image(const Slices &data, const Settings &settings, bool validatedata);
  73. void init(PixelFormat fmt, int w, int h, const Settings &settings);
  74. static StringMap<SettingType, SETTING_MAX_ENUM>::Entry settingTypeEntries[];
  75. static StringMap<SettingType, SETTING_MAX_ENUM> settingTypes;
  76. }; // Image
  77. } // graphics
  78. } // love