6#include "common/config.h"
8#include "medialoader/image/PNGHandler.h"
9#include "medialoader/image/STBHandler.h"
10#include "medialoader/image/EXRHandler.h"
12#include "medialoader/image/ddsHandler.h"
13#include "medialoader/image/PVRHandler.h"
14#include "medialoader/image/KTXHandler.h"
15#include "medialoader/image/PKMHandler.h"
16#include "medialoader/image/ASTCHandler.h"
18#include <simplesquirrel/simplesquirrel.hpp>
68 throw eve::Exception(
"Could not load image file: %s", path.c_str());
69 return static_cast<ImageData *
>(resource);
87 if (handler->canParseCompressed((
const char*)
data->getData(),
data->getSize()))
96 return formatHandlers;
104 res->
paste(src, 0, 0, sx, sy,
w,
h);
117 std::vector<eve::ref<ImageData>> faces;
122 if (totalW % 3 == 0 && totalH % 4 == 0 && totalW / 3 == totalH / 4)
132 faces.emplace_back(newPastedImageData(src, 1*
w, 1*
h,
w,
h));
133 faces.emplace_back(newPastedImageData(src, 1*
w, 3*
h,
w,
h));
134 faces.emplace_back(newPastedImageData(src, 1*
w, 0*
h,
w,
h));
135 faces.emplace_back(newPastedImageData(src, 1*
w, 2*
h,
w,
h));
136 faces.emplace_back(newPastedImageData(src, 0*
w, 1*
h,
w,
h));
137 faces.emplace_back(newPastedImageData(src, 2*
w, 1*
h,
w,
h));
139 else if (totalW % 4 == 0 && totalH % 3 == 0 && totalW / 4 == totalH / 3)
148 faces.emplace_back(newPastedImageData(src, 2*
w, 1*
h,
w,
h));
149 faces.emplace_back(newPastedImageData(src, 0*
w, 1*
h,
w,
h));
150 faces.emplace_back(newPastedImageData(src, 1*
w, 0*
h,
w,
h));
151 faces.emplace_back(newPastedImageData(src, 1*
w, 2*
h,
w,
h));
152 faces.emplace_back(newPastedImageData(src, 1*
w, 1*
h,
w,
h));
153 faces.emplace_back(newPastedImageData(src, 3*
w, 1*
h,
w,
h));
155 else if (totalH % 6 == 0 && totalW == totalH / 6)
167 for (
int i = 0; i < 6; i++)
168 faces.emplace_back(newPastedImageData(src, 0, i *
h,
w,
h));
170 else if (totalW % 6 == 0 && totalW / 6 == totalH)
177 for (
int i = 0; i < 6; i++)
178 faces.emplace_back(newPastedImageData(src, i *
w, 0,
w,
h));
188 std::vector<eve::ref<ImageData>> layers;
193 if (totalW % totalH == 0)
195 for (
int i = 0; i < totalW / totalH; i++)
196 layers.emplace_back(newPastedImageData(src, i * totalH, 0, totalH, totalH));
198 else if (totalH % totalW == 0)
200 for (
int i = 0; i < totalH / totalW; i++)
201 layers.emplace_back(newPastedImageData(src, 0, i * totalW, totalW, totalW));
204 throw eve::Exception(
"Cannot extract volume layers from source ImageData.");
209void Image::expose(ssq::Table &table) {
210 auto cls = table.addClass(
name, Image::create,
false);
216 "ImageData", std::function<image::ImageData *()>([]() ->
image::ImageData * {
return nullptr; }),
229 if (!self)
return 0.f;
232 img.addFunc(
"getPixelG", [](image::ImageData *self,
int x,
int y) ->
float {
233 if (!self)
return 0.f;
234 return self->getPixel(
x,
y).g;
236 img.addFunc(
"getPixelB", [](image::ImageData *self,
int x,
int y) ->
float {
237 if (!self)
return 0.f;
238 return self->getPixel(
x,
y).
b;
240 img.addFunc(
"getPixelA", [](image::ImageData *self,
int x,
int y) ->
float {
241 if (!self)
return 0.f;
242 return self->getPixel(
x,
y).
a;
244 img.addFunc(
"setPixel", [](image::ImageData *self,
int x,
int y,
float r,
float g,
float b,
float a) {
250void Image::expose(ssq::Class &
cls) {
254 cls.addFunc(
"newEmptyImageData",
255 [](
Image *self,
int width,
int height,
const std::string &format) -> ImageData * {
256 if (!self)
return nullptr;
#define Module_IMPL(ModuleName, newExpr)
virtual std::string getName() const =0
Resource * get(std::string key)
Get the cached resource for key; on a miss, load it through the registered IAssetReloader providers a...
static ResourceManager & getInstance()
Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or gen...
Represents raw pixel data.
ImageData * clone() const
bool inside(int x, int y) const
Checks whether a position is inside this ImageData. Useful for checking bounds.
void getPixel(int x, int y, Colorf &c) const
Gets the pixel at location (x,y).
medialoader::Colorf Colorf
void paste(ImageData *src, int dx, int dy, int sx, int sy, int sw, int sh)
Paste part of one ImageData onto another. The subregion defined by the top-left corner (sx,...
ImageData * rotate(float radians, std::string filter="nearest", bool expand=true) const
Rotate pixels around the image center and return a new ImageData.
size_t getPixelSize() const
std::string getFormat() const
This module is responsible for decoding files such as PNG, GIF, JPEG into raw pixel data,...
std::vector< ref< ImageData > > newVolumeLayers(ImageData *src)
ImageData * newImageDataFromFile(std::string path)
Loads an image from a VFS path through the unified resource cache. Repeated loads of one path share a...
medialoader::FormatHandler FormatHandler
bool isCompressed(Data *data)
Creates new CompressedImageData from FileData.
const std::list< FormatHandler * > & getFormatHandlers() const
ImageData * newImageData(Data *data)
Creates new ImageData from FileData.
std::vector< ref< ImageData > > newCubeFaces(ImageData *src)