21#include <SDL3_image/SDL_image.h>
37 SDL_DestroySurface(this->surface);
90 SDL_IOStream *stream = SDL_IOFromConstMem(bytes, (
int) length);
92 SDL_Surface *surface = IMG_LoadTyped_IO(stream, 0, self->
type);
95 SDL_DestroySurface(surface);
100 self = release(self);
116 self = release(self);
129 self->
type = strrchr(resource->name,
'.') ? strrchr(resource->name,
'.') + 1 : NULL;
132 self = release(self);
144 Resource *resource = $$(Resource, resourceWithName, name);
159 self = (
Image *) super(Object, self,
init);
163 if (surface->format != SDL_PIXELFORMAT_RGBA32) {
164 self->
surface = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA32);
185#pragma mark - Class lifecycle
192 ((ObjectInterface *) clazz->interface)->dealloc =
dealloc;
194 ((ImageInterface *) clazz->interface)->imageWithBytes =
imageWithBytes;
204 ((ImageInterface *) clazz->interface)->
size =
size;
216 clazz = _initialize(&(
const ClassDef) {
218 .superclass = _Object(),
219 .instanceSize =
sizeof(
Image),
220 .interfaceOffset = offsetof(
Image, interface),
221 .interfaceSize =
sizeof(ImageInterface),
static View * init(View *self)
static Image * imageWithResource(const Resource *resource)
static Image * initWithData(Image *self, const Data *data)
static Image * initWithBytes(Image *self, const uint8_t *bytes, size_t length)
static Image * initWithResource(Image *self, const Resource *resource)
static Image * initWithSurface(Image *self, SDL_Surface *surface)
static Image * imageWithSurface(SDL_Surface *surface)
static Image * imageWithBytes(const uint8_t *bytes, size_t length)
static Image * imageWithResourceName(const char *name)
static Image * imageWithData(const Data *data)
static void dealloc(Object *self)
static Image * initWithResourceName(Image *self, const char *name)
static SDL_Size size(const Image *self)
static void initialize(Class *clazz)
View logging facilities via SDL_Log.
SDL_Size size(const Image *self)
const char * type
The image type, inferred if instantiated with a Resource.
Image * initWithData(Image *self, const Data *data)
Initializes this Image with the specified Data.
Image * initWithResourceName(Image *self, const char *name)
Initializes this Image, loading the Resource by the given name.
Image * initWithBytes(Image *self, const uint8_t *bytes, size_t length)
Initializes this Image with the specified bytes.
Image * imageWithResourceName(const char *name)
Instantiates an Image with the specified Resource name.
Image * imageWithData(const Data *data)
Instantiates an Image with the specified Data.
Image * initWithSurface(Image *self, SDL_Surface *surface)
Initializes this Image with the given surface.
SDL_Surface * surface
The backing surface.
Image * imageWithResource(const Resource *resource)
Instantiates an Image with the specified Resource.
Image * imageWithSurface(SDL_Surface *surface)
Instantiates an Image with the specified surface.
Image * initWithResource(Image *self, const Resource *resource)
Initializes this Image with the specified Resource.