1/**
2 * Copyright (c) 2006-2023 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
21#ifndef LOVE_IMAGE_IMAGE_H
22#define LOVE_IMAGE_IMAGE_H
23
24// LOVE
25#include "common/config.h"
26#include "common/Module.h"
27#include "filesystem/File.h"
28#include "ImageData.h"
29#include "CompressedImageData.h"
30
31// C++
32#include <list>
33
34namespace love
35{
36namespace image
37{
38
39/**
40 * This module is responsible for decoding files such as PNG, GIF, JPEG
41 * into raw pixel data, as well as parsing compressed formats which are designed
42 * to be uploaded to the GPU and rendered without being un-compressed.
43 * This module does not know how to draw images on screen; only love.graphics
44 * knows that.
45 **/
46class Image : public Module
47{
48public:
49
50 static love::Type type;
51
52 Image();
53 virtual ~Image();
54
55 // Implements Module.
56 ModuleType getModuleType() const override { return M_IMAGE; }
57 const char *getName() const override;
58
59 /**
60 * Creates new ImageData from FileData.
61 * @param data The FileData containing the encoded image data.
62 * @return The new ImageData.
63 **/
64 ImageData *newImageData(Data *data);
65
66 /**
67 * Creates empty ImageData with the given size.
68 * @param width The width of the ImageData.
69 * @param height The height of the ImageData.
70 * @return The new ImageData.
71 **/
72 ImageData *newImageData(int width, int height, PixelFormat format = PIXELFORMAT_RGBA8);
73
74 /**
75 * Creates empty ImageData with the given size.
76 * @param width The width of the ImageData.
77 * @param height The height of the ImageData.
78 * @param data The data to load into the ImageData.
79 * @param own Whether the new ImageData should take ownership of the data or
80 * copy it.
81 * @return The new ImageData.
82 **/
83 ImageData *newImageData(int width, int height, PixelFormat format, void *data, bool own = false);
84
85 /**
86 * Creates new CompressedImageData from FileData.
87 * @param data The FileData containing the compressed image data.
88 * @return The new CompressedImageData.
89 **/
90 CompressedImageData *newCompressedData(Data *data);
91
92 /**
93 * Determines whether a FileData is Compressed image data or not.
94 * @param data The FileData to test.
95 **/
96 bool isCompressed(Data *data);
97
98 std::vector<StrongRef<ImageData>> newCubeFaces(ImageData *src);
99 std::vector<StrongRef<ImageData>> newVolumeLayers(ImageData *src);
100
101 const std::list<FormatHandler *> &getFormatHandlers() const;
102
103private:
104
105 ImageData *newPastedImageData(ImageData *src, int sx, int sy, int w, int h);
106
107 // Image format handlers we can use for decoding and encoding ImageData.
108 std::list<FormatHandler *> formatHandlers;
109
110}; // Image
111
112} // image
113} // love
114
115#endif // LOVE_IMAGE_IMAGE_H
116