Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\kit_lodepng_custom.cpp":
- #include "_kit_common.hpp"
- namespace kit {
- namespace png {
- void* lodepng_malloc(size_t size){
- #ifdef LODEPNG_MAX_ALLOC
- if(size > LODEPNG_MAX_ALLOC) return 0;
- #endif
- return memory::alloc(size);
- }
- // NOTE: when realloc returns NULL, it leaves the original memory untouched
- void* lodepng_realloc(void* ptr, size_t new_size){
- #ifdef LODEPNG_MAX_ALLOC
- if(new_size > LODEPNG_MAX_ALLOC) return 0;
- #endif
- return memory::realloc(&ptr, new_size);
- }
- void lodepng_free(void* ptr){
- memory::free(&ptr);
- }
- //i rewrote lodepng's file io functions to only use SDL functions
- #ifndef LODEPNG_NO_COMPILE_DISK
- #undef LONG_MAX
- #define LONG_MAX (2147483647)
- unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) {
- *out = (unsigned char*)SDL_LoadFile(filename, outsize);
- if(*out == nullptr){
- return 78;
- } else {
- ++numAllocations; //a subsequent call to memory::free should undo this
- return 0;
- }
- }
- // write given buffer to the file, overwriting the file, it doesn't append to it.
- unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename) {
- SDL_RWops* file = SDL_RWFromFile(filename, "wb");
- if(file == nullptr) return 79;
- size_t bytesWritten = SDL_RWwrite(file, buffer, 1, buffersize);
- SDL_RWclose(file);
- if(bytesWritten < buffersize) return 79;
- else return 0;
- }
- /*
- #undef LONG_MAX
- #define LONG_MAX (2147483647)
- #include <stdio.h>
- // returns negative value on error. This should be pure C compatible, so no fstat.
- static long lodepng_filesize(const char* filename) {
- FILE* file;
- long size;
- file = fopen(filename, "rb");
- if(!file) return -1;
- if(fseek(file, 0, SEEK_END) != 0) {
- fclose(file);
- return -1;
- }
- size = ftell(file);
- // It may give LONG_MAX as directory size, this is invalid for us.
- if(size == LONG_MAX) size = -1;
- fclose(file);
- return size;
- }
- // load file into buffer that already has the correct allocated size. Returns error code.
- static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char* filename) {
- FILE* file;
- size_t readsize;
- file = fopen(filename, "rb");
- if(!file) return 78;
- readsize = fread(out, 1, size, file);
- fclose(file);
- if(readsize != size) return 78;
- return 0;
- }
- unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) {
- long size = lodepng_filesize(filename);
- if(size < 0) return 78;
- *outsize = (size_t)size;
- *out = (unsigned char*)lodepng_malloc((size_t)size);
- if(!(*out) && size > 0) return 83; // the above malloc failed
- return lodepng_buffer_file(*out, (size_t)size, filename);
- }
- // write given buffer to the file, overwriting the file, it doesn't append to it.
- unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename) {
- FILE* file;
- file = fopen(filename, "wb" );
- if(!file) return 79;
- fwrite(buffer, 1, buffersize, file);
- fclose(file);
- return 0;
- }
- */
- #endif /* LODEPNG_NO_COMPILE_DISK */
- }; /* namespace png */
- }; /* namespace kit */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\kit_memory.cpp":
- #include "_kit_common.hpp"
- //turns something into a void**
- //(this makes some code here easier for me to read)
- #define VPP(_ptr_p) ((void**)(_ptr_p))
- namespace kit {
- size_t numAllocations = 0;
- void* memory::alloc(size_t size){
- void* newHeapMemory = SDL_malloc(size);
- if(newHeapMemory != nullptr) ++numAllocations;
- return newHeapMemory;
- }
- void memory::free(void* ptr_p){
- if(VPP(ptr_p) != nullptr && *VPP(ptr_p) != nullptr){
- --numAllocations;
- SDL_free(*VPP(ptr_p));
- *VPP(ptr_p) = nullptr;
- }
- }
- void* memory::realloc(void* ptr_p, size_t newSize){
- void* ptr_new = nullptr;
- if(VPP(ptr_p) != nullptr){
- ptr_new = SDL_realloc(*VPP(ptr_p), newSize);
- if(ptr_new != nullptr){
- if(*VPP(ptr_p) == nullptr) ++numAllocations;
- *VPP(ptr_p) = ptr_new;
- }
- }
- return ptr_new;
- }
- void* memory::alloc2(size_t size){
- void* newHeapMemory = SDL_malloc(size);
- if(newHeapMemory == nullptr)
- THROW_ERROR("memory::alloc2(): failed to allocate memory");
- ++numAllocations;
- return newHeapMemory;
- }
- void memory::free2(void* ptr_p){
- if( VPP(ptr_p) == nullptr) THROW_ERROR("memory::free2(): ptr_p == nullptr");
- if(*VPP(ptr_p) == nullptr) THROW_ERROR("memory::free2(): *ptr_p == nullptr");
- --numAllocations;
- SDL_free(*VPP(ptr_p));
- *VPP(ptr_p) = nullptr;
- }
- void* memory::realloc2(void* ptr_p, size_t newSize){
- void* ptr_new = nullptr;
- if(VPP(ptr_p) != nullptr){
- ptr_new = SDL_realloc(*VPP(ptr_p), newSize);
- if(ptr_new != nullptr){
- if(*VPP(ptr_p) == nullptr) ++numAllocations; //if memory is new, not realloc'd
- *VPP(ptr_p) = ptr_new;
- }
- } else {
- THROW_ERROR("memory::realloc2(): ptr_p = nullptr");
- }
- if(ptr_new == nullptr)
- THROW_ERROR("memory::realloc2(): failed to reallocate memory");
- return ptr_new;
- }
- size_t memory::getNumAllocations(){
- return numAllocations;
- }
- //currently just a wrapper, but now i can make my own implementation
- //whenever i want, without replacing every call to memset with it
- void* memory::set(void* ptr, s32 value, size_t size){
- if(ptr == nullptr) return nullptr; //now it's safe to pass nullptr :D
- return memset(ptr, value, size);
- }
- void* memory::set2(void* ptr, s32 value, size_t size){
- if(ptr == nullptr) THROW_ERROR("memory::set2(): ptr = nullptr");
- return memset(ptr, value, size);
- }
- void* memory::copy(void* destination, const void* source, size_t size){
- //tbd: maybe make it so that memcpy is only called if dst&src aren't nullptr
- return memcpy(destination, source, size);
- }
- void* memory::copy2(void* destination, const void* source, size_t size){
- if(destination == nullptr) THROW_ERROR("memory::copy2(): destination = nullptr");
- if(source == nullptr) THROW_ERROR("memory::copy2(): source = nullptr");
- return memcpy(destination, source, size);
- }
- u32 memory::getSystemRAM_MiB(){
- s32 result = SDL_GetSystemRAM();
- if(result < 0) //hopefully this can't happen
- THROW_ERROR("memory::getSystemRAM_MiB(): SDL_GetSystemRAM() < 0");
- return (u32)result;
- }
- u32 memory::getSIMDAlignment(){
- return SDL_SIMDGetAlignment(); //this shouldn't be any more than 64...
- }
- void* memory::allocSIMD(size_t size){
- void* newHeapMemory = SDL_SIMDAlloc(size);
- if(newHeapMemory != nullptr) ++numAllocations;
- return newHeapMemory;
- }
- void memory::freeSIMD(void* ptr_p){
- if(VPP(ptr_p) != nullptr && *VPP(ptr_p) != nullptr){
- --numAllocations;
- SDL_SIMDFree(*VPP(ptr_p));
- *VPP(ptr_p) = nullptr;
- }
- }
- void* memory::reallocSIMD(void* ptr_p, size_t newSize){
- void* ptr_new = nullptr;
- if(VPP(ptr_p) != nullptr){
- ptr_new = SDL_SIMDRealloc(*VPP(ptr_p), newSize);
- if(ptr_new != nullptr){
- if(*VPP(ptr_p) == nullptr) ++numAllocations;
- *VPP(ptr_p) = ptr_new;
- }
- }
- return ptr_new;
- }
- void* memory::allocSIMD2(size_t size){
- void* newHeapMemory = SDL_SIMDAlloc(size);
- if(newHeapMemory == nullptr)
- THROW_ERROR("memory::allocSIMD2(): failed to allocate memory");
- ++numAllocations;
- return newHeapMemory;
- }
- void memory::freeSIMD2(void* ptr_p){
- if( VPP(ptr_p) == nullptr) THROW_ERROR("memory::freeSIMD2(): ptr_p == nullptr");
- if(*VPP(ptr_p) == nullptr) THROW_ERROR("memory::freeSIMD2(): *ptr_p == nullptr");
- --numAllocations;
- SDL_SIMDFree(*VPP(ptr_p));
- *VPP(ptr_p) = nullptr;
- }
- void* memory::reallocSIMD2(void* ptr_p, size_t newSize){
- void* ptr_new = nullptr;
- if(VPP(ptr_p) != nullptr){
- ptr_new = SDL_SIMDRealloc(*VPP(ptr_p), newSize);
- if(ptr_new != nullptr){
- if(*VPP(ptr_p) == nullptr) ++numAllocations; //if memory is new, not realloc'd
- *VPP(ptr_p) = ptr_new;
- }
- } else {
- THROW_ERROR("memory::reallocSIMD2(): ptr_p = nullptr");
- }
- if(ptr_new == nullptr)
- THROW_ERROR("memory::reallocSIMD2(): failed to reallocate memory");
- return ptr_new;
- }
- memory::Wrapper::Wrapper(size_t size){
- ptr = memory::alloc(size);
- if(ptr == nullptr)
- THROW_ERROR("memory::Wrapper::Wrapper() failed to allocate memory");
- }
- memory::WrapperSIMD::WrapperSIMD(size_t size){
- ptr = memory::allocSIMD(size);
- if(ptr == nullptr)
- THROW_ERROR("memory::WrapperSIMD::WrapperSIMD() failed to allocate memory");
- }
- }; /* namespace kit */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\kit_Surface.cpp":
- #include "_kit_common.hpp"
- #define SURF_IS_INVALID (!_valid)
- #define SURF_PTR ((SDL_Surface*)_opq)
- namespace kit {
- Surface::Surface(u32 width, u32 height, u32 pixel_format){
- _type = KIT_CLASSTYPE_SURFACE;
- if(width > KIT_S32_MAX)
- THROW_ERROR("Surface::Surface(new): width > KIT_S32_MAX");
- if(height > KIT_S32_MAX)
- THROW_ERROR("Surface::Surface(new): height > KIT_S32_MAX");
- _opq = SDL_CreateRGBSurfaceWithFormat(0, width, height,
- SDL_BITSPERPIXEL(pixel_format),
- pixel_format);
- if(_opq == nullptr)
- THROW_ERRORF("Surface::Surface(new): \"%s\"", SDL_GetError());
- _valid = true;
- _constructing = false;
- }
- Surface::Surface(const Surface& src, u32 pixel_format){
- _type = KIT_CLASSTYPE_SURFACE;
- if(KIT_GET_CLASS_TYPE(&src) != KIT_CLASSTYPE_SURFACE)
- THROW_ERROR("Surface::Surface(Surface&): src is not a Surface class");
- SDL_Surface* src_surf = (SDL_Surface*)KIT_GET_CLASS_OPAQUE(&src);
- if(src_surf == nullptr)
- THROW_ERROR("Surface::Surface(Surface&): src._opq = nullptr");
- _opq = SDL_ConvertSurfaceFormat(src_surf, pixel_format, 0);
- if(_opq == nullptr)
- THROW_ERRORF("Surface::Surface(Surface&): \"%s\"", SDL_GetError());
- _valid = true;
- _constructing = false;
- }
- Surface::Surface(const Window& src, u32 pixel_format){
- _type = KIT_CLASSTYPE_SURFACE;
- if(KIT_GET_CLASS_TYPE(&src) != KIT_CLASSTYPE_WINDOW)
- THROW_ERROR("Surface::Surface(Window&): src is not a Window class");
- SDL_Window* src_win = (SDL_Window*)KIT_GET_CLASS_OPAQUE(&src);
- SDL_Surface** src_surf_p = (SDL_Surface**)&KIT_GET_CLASS_OPAQUE2(&src);
- bool src_surf_was_nullptr = *src_surf_p == nullptr;
- *src_surf_p = SDL_GetWindowSurface(src_win);
- if(*src_surf_p == nullptr){
- _throw_sdl_error:
- THROW_ERRORF("Surface::Surface(Window&): \"%s\"", SDL_GetError());
- }
- _opq = SDL_ConvertSurfaceFormat(*src_surf_p, pixel_format, 0);
- if(src_surf_was_nullptr){
- if(SDL_DestroyWindowSurface(src_win) < 0){
- if(_opq != nullptr){
- SDL_FreeSurface(SURF_PTR);
- _opq = nullptr;
- }
- goto _throw_sdl_error;
- }
- *src_surf_p = nullptr; //set back
- }
- if(_opq == nullptr) goto _throw_sdl_error;
- _valid = true;
- _constructing = false;
- }
- void Surface::_construct_file(const char* filePath,
- SurfaceLoaderCallback callback,
- const char* fname)
- {
- _type = KIT_CLASSTYPE_SURFACE;
- if(fname == nullptr){
- fname = "Surface::Surface(specific file format)";
- if(filePath == nullptr)
- THROW_ERRORF("%s: filePath = nullptr", fname);
- if(!fileio::exists(filePath)){
- THROW_ERRORF("%s: \"%s\" doesn't exist", fname, filePath);
- }
- }
- if(callback == nullptr){ //load .bmp file
- _opq = SDL_LoadBMP(filePath);
- if(_opq == nullptr){
- _throw_sdl_error:
- THROW_ERRORF("%s: \"%s\"", fname, SDL_GetError());
- }
- } else { //load some other file format
- u32 format;
- s32 width, height;
- void* pixels_src = callback(filePath, format, width, height);
- _opq = SDL_CreateRGBSurfaceWithFormat(0, width, height,
- SDL_BITSPERPIXEL(format), format);
- if(_opq == nullptr){
- _free_src_and_throw_sdl_error:
- memory::free(&pixels_src);
- goto _throw_sdl_error;
- }
- if(SDL_LockSurface(SURF_PTR) < 0)
- goto _free_src_and_throw_sdl_error;
- void* pixels_dst = SURF_PTR->pixels;
- s32 bytesPerRow = SURF_PTR->pitch;
- //s32 height = SURF_PTR->h;
- memory::copy(pixels_dst, pixels_src, bytesPerRow*height);
- SDL_UnlockSurface(SURF_PTR);
- memory::free(&pixels_src);
- }
- _valid = true;
- _constructing = false;
- }
- //(the last constructor can be found in "kit_Surface_LoadAllTypes.cpp")
- Surface::~Surface(){
- if(!_valid) return;
- _valid = false;
- if(SURF_PTR != nullptr){
- SDL_FreeSurface(SURF_PTR);
- _opq = nullptr;
- }
- }
- //this is only used for saveImage, as this exists
- //as a byproduct of both SDL_LockSurface and the
- //SurfaceSaverCallback being able to error.
- //basically what this does is ensure that
- //SDL_UnlockSurface is called, even if the
- //SurfaceSaverCallback throws an exception
- struct _thing_that_locks_surface {
- SDL_Surface* ptr = nullptr;
- bool wasLocked = false;
- _thing_that_locks_surface(SDL_Surface* _ptr){
- if(SDL_LockSurface((ptr = _ptr)) < 0)
- THROW_ERRORF("Surface::saveImage(): \"%s\"", SDL_GetError());
- }
- ~_thing_that_locks_surface(){ SDL_UnlockSurface(ptr); }
- };
- void Surface::saveImage(const char* filePath, SurfaceSaverCallback callback){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::saveImage(): invalid Surface");
- if(filePath == nullptr)
- THROW_ERROR("Surface::saveImage(): filePath = nullptr");
- if(callback == nullptr){ //save .bmp file
- //afaik, you don't need to lock a surface before calling SDL_SaveBMP_RW,
- //(hopefully i'm not wrong about that!)
- if(SDL_SaveBMP(SURF_PTR, filePath) < 0)
- THROW_ERRORF("Surface::saveImage(): \"%s\"", SDL_GetError());
- } else { //save some other file format
- _thing_that_locks_surface surface_locker(SURF_PTR); //LMAOOO
- callback(filePath, *this);
- //(surface should unlock after this code block,
- //or if callback throws an exception)
- }
- }
- /******************************************************************************/
- bool Surface::hasRLE(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::hasRLE(): invalid Surface");
- return SDL_HasSurfaceRLE(SURF_PTR);
- }
- bool Surface::hasLockRequirement(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::hasRLE(): invalid Surface");
- return SDL_MUSTLOCK(SURF_PTR);
- }
- u32 Surface::getPixelFmt(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getPixelFmt(): invalid Surface");
- return SURF_PTR->format->format;
- }
- shape::point Surface::getSize(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getSize(): invalid Surface");
- return shape::point(SURF_PTR->w, SURF_PTR->h);
- }
- u32 Surface::getBytesPerRow(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getBytesPerRow(): invalid Surface");
- return (u32)SURF_PTR->pitch;
- }
- void* Surface::getPixelData(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getPixelData(): invalid Surface");
- return SURF_PTR->pixels;
- }
- void* Surface::getUserdata(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getUserdata(): invalid Surface");
- return SURF_PTR->userdata;
- }
- u32 Surface::getPaletteLen(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getPaletteLen(): invalid Surface");
- SDL_Palette* palette = SURF_PTR->format->palette;
- //idk if this is even possible, but just in case
- if(palette == nullptr) return 0;
- if(!SDL_ISPIXELFORMAT_INDEXED(SURF_PTR->format->format)) return 0;
- return (u32)palette->ncolors;
- }
- const colors::ABGR* Surface::getPaletteColors(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getPaletteColors(): invalid Surface");
- SDL_Palette* palette = SURF_PTR->format->palette;
- //idk if this is even possible, but just in case
- if(palette == nullptr) return nullptr;
- if(!SDL_ISPIXELFORMAT_INDEXED(SURF_PTR->format->format)) return nullptr;
- return (const colors::ABGR*)palette->colors;
- }
- BlendModesEnum Surface::getBlendMode(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getBlendMode(): invalid Surface");
- SDL_BlendMode blendMode;
- if(SDL_GetSurfaceBlendMode(SURF_PTR, &blendMode) < 0)
- THROW_ERRORF("Surface::getBlendMode(): \"%s\"", SDL_GetError());
- return (BlendModesEnum)blendMode;
- }
- u8 Surface::getAlphaMod(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getAlphaMod(): invalid Surface");
- u8 alphaMod;
- if(SDL_GetSurfaceAlphaMod(SURF_PTR, & alphaMod) < 0)
- THROW_ERRORF("Surface::getAlphaMod(): \"%s\"", SDL_GetError());
- return alphaMod;
- }
- colors::BGR Surface::getColorMod(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getColorMod(): invalid Surface");
- u8 r, g, b;
- if(SDL_GetSurfaceColorMod(SURF_PTR, &r, &g, &b) < 0)
- THROW_ERRORF("Surface::getColorMod(): \"%s\"", SDL_GetError());
- return colors::BGR888(r, g, b);
- }
- u32 Surface::getColorKey(){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::getColorKey(): invalid Surface");
- u32 key;
- if(SDL_GetColorKey(SURF_PTR, &key) < 0)
- THROW_ERRORF("Surface::getColorKey(): \"%s\"", SDL_GetError());
- return key;
- }
- /******************************************************************************/
- void Surface::setRLE(bool enable){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::setRLE(): invalid Surface");
- if(SDL_SetSurfaceRLE(SURF_PTR, enable) < 0)
- THROW_ERRORF("Surface::setRLE(): \"%s\"", SDL_GetError());
- }
- void Surface::setUserdata(void* userdata){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::setUserdata(): invalid Surface");
- SURF_PTR->userdata = userdata;
- }
- void Surface::setPaletteColors(const colors::ABGR* newColors,
- u32 numColors, u32 firstColor)
- {
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::setPaletteColors(): invalid Surface");
- if(newColors == nullptr)
- THROW_ERROR("Surface::setPaletteColors(): newColors = nullptr");
- if(numColors > KIT_S32_MAX)
- THROW_ERROR("Surface::setPaletteColors(): numColors > KIT_S32_MAX");
- if(firstColor > KIT_S32_MAX)
- THROW_ERROR("Surface::setPaletteColors(): firstColor > KIT_S32_MAX");
- SDL_Palette* palette = SURF_PTR->format->palette;
- if(!SDL_ISPIXELFORMAT_INDEXED(SURF_PTR->format->format) ||
- palette == nullptr || !palette->ncolors)
- {
- THROW_ERROR("Surface::setPaletteColors(): Surface doesn't use a palette");
- }
- if(SDL_SetPaletteColors(palette, (SDL_Color*)newColors, firstColor, numColors) < 0)
- THROW_ERRORF("Surface::setPaletteColors(): \"%s\"", SDL_GetError());
- }
- void Surface::setBlendMode(BlendModesEnum blendMode){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::setBlendMode(): invalid Surface");
- if(SDL_SetSurfaceBlendMode(SURF_PTR, (SDL_BlendMode)blendMode) < 0)
- THROW_ERRORF("Surface::setBlendMode(): \"%s\"", SDL_GetError());
- }
- void Surface::setAlphaMod(u8 alphaMod){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::setAlphaMod(): invalid Surface");
- if(SDL_SetSurfaceAlphaMod(SURF_PTR, alphaMod) < 0)
- THROW_ERRORF("Surface::setAlphaMod(): \"%s\"", SDL_GetError());
- }
- void Surface::setColorMod(colors::BGR colorMod){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::setColorMod(): invalid Surface");
- if(SDL_SetSurfaceColorMod(SURF_PTR, colorMod.r, colorMod.g, colorMod.b) < 0)
- THROW_ERRORF("Surface::setColorMod(): \"%s\"", SDL_GetError());
- }
- void Surface::setColorKey(bool enable, u32 key){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::setColorKey(): invalid Surface");
- if(SDL_SetColorKey(SURF_PTR, enable, key) < 0)
- THROW_ERRORF("Surface::setColorKey(): \"%s\"", SDL_GetError());
- }
- /******************************************************************************/
- u32 Surface::mapRGB(colors::BGR inputColor){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::mapRGB(): invalid Surface");
- return SDL_MapRGB(SURF_PTR->format, inputColor.r, inputColor.g, inputColor.b);
- }
- u32 Surface::mapRGBA(colors::ABGR inputColor){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::mapRGBA(): invalid Surface");
- return SDL_MapRGBA(SURF_PTR->format, inputColor.r, inputColor.g,
- inputColor.b, inputColor.a);
- }
- void Surface::lock(bool locked){
- if(SURF_IS_INVALID)
- THROW_ERROR("Surface::lock(): invalid Surface");
- if(locked){
- if(SDL_LockSurface(SURF_PTR) < 0)
- THROW_ERRORF("Surface::lock(): \"%s\"", SDL_GetError());
- } else {
- SDL_UnlockSurface(SURF_PTR);
- }
- }
- }; /* namespace kit */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement