# Path: modules/sdl2/common/filesystem.py
# def fs_to_rwops(handle):
#     return sdl2.rw_from_object(RWOpsWrapper(handle))


import sdl2
import sdl2.ext
import sdl2.sdlimage as sdl2image
import rave.log
import rave.events
import rave.rendering
import rave.resources
from .common import fs_to_rwops
    for fmt, pattern in FORMAT_PATTERNS.items():
        if _formats & fmt:
            game.resources.register_loader(ImageLoader, pattern)
            _log.debug('Loaded support for {fmt} images.', fmt=FORMAT_NAMES[fmt])
        else:
            _log.warn('Failed to load support for {fmt} images.', fmt=FORMAT_NAMES[fmt])


class ImageData(rave.resources.ImageData):
    __slots__ = ('surface',)

    def __init__(self, surface, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.surface = surface

    def __del__(self):
        sdl2.SDL_FreeSurface(self.surface)

    def get_data(self, amount=None):
        if amount:
            return self.surface.contents.pixels[:amount]
        return self.surface.contents.pixels

class ImageLoader:
    @classmethod
    def can_load(cls, path, fd):
        return True

    @classmethod
    def load(cls, path, fd):

# Path: modules/sdl2/common/filesystem.py
# def fs_to_rwops(handle):
#     return sdl2.rw_from_object(RWOpsWrapper(handle))


# Path: modules/sdl2/image.py
import sdl2
import sdl2.ext
import sdl2.sdlimage as sdl2image
import rave.log
import rave.events
import rave.rendering
import rave.resources
from .common import fs_to_rwops

    for fmt, pattern in FORMAT_PATTERNS.items():
        if _formats & fmt:
            game.resources.register_loader(ImageLoader, pattern)
            _log.debug('Loaded support for {fmt} images.', fmt=FORMAT_NAMES[fmt])
        else:
            _log.warn('Failed to load support for {fmt} images.', fmt=FORMAT_NAMES[fmt])


class ImageData(rave.resources.ImageData):
    __slots__ = ('surface',)

    def __init__(self, surface, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.surface = surface

    def __del__(self):
        sdl2.SDL_FreeSurface(self.surface)

    def get_data(self, amount=None):
        if amount:
            return self.surface.contents.pixels[:amount]
        return self.surface.contents.pixels

class ImageLoader:
    @classmethod
    def can_load(cls, path, fd):
        return True

    @classmethod
    def load(cls, path, fd):

        handle = fs_to_rwops(fd)