From 1946c68ef87c88e94887435b445b0ff488ed0a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 17 Sep 2020 11:54:33 +0200 Subject: [PATCH] [ion] Simulator: key layouts assets are PNG instead of JPG III (fix ios) --- ion/src/simulator/ios/images.m | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ion/src/simulator/ios/images.m b/ion/src/simulator/ios/images.m index 1830fc617..8165b0f2b 100644 --- a/ion/src/simulator/ios/images.m +++ b/ion/src/simulator/ios/images.m @@ -3,7 +3,7 @@ #include #include -SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier, bool withTransparency, uint8_t alpha) { +SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) { CGImageRef cgImage = [[UIImage imageNamed:[NSString stringWithUTF8String:identifier]] CGImage]; if (cgImage == NULL) { return NULL; @@ -17,7 +17,9 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi size_t bytesPerRow = bytesPerPixel * width; size_t bitsPerComponent = 8; - void * bitmapData = malloc(height * width * bytesPerPixel); + size_t size = height * width * bytesPerPixel; + void * bitmapData = malloc(size); + memset(bitmapData, 0, size); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef context = CGBitmapContextCreate( @@ -31,21 +33,24 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi CGContextRelease(context); CGColorSpaceRelease(colorSpace); - SDL_Surface * surface = SDL_CreateRGBSurfaceWithFormatFrom( - bitmapData, + SDL_Texture * texture = SDL_CreateTexture( + renderer, + SDL_PIXELFORMAT_ABGR8888, + SDL_TEXTUREACCESS_STATIC, width, - height, - bitsPerPixel, - bytesPerRow, - SDL_PIXELFORMAT_ABGR8888); + height + ); - SDL_SetColorKey(surface, withTransparency, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF)); - SDL_SetSurfaceAlphaMod(surface, alpha); + SDL_UpdateTexture( + texture, + NULL, + bitmapData, + bytesPerPixel * width + ); - SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface); + SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); free(bitmapData); - SDL_FreeSurface(surface); return texture; }