mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[ion] IonSimulatorLoadImage returns a Texture (otherwise the pixels data
which needs to be deleted when freeing the surface is hard to retrieve)
This commit is contained in:
committed by
EmilieNumworks
parent
02b648e36d
commit
8b5caeb394
@@ -3,7 +3,7 @@
|
||||
#include <jni.h>
|
||||
#include <android/bitmap.h>
|
||||
|
||||
SDL_Surface * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) {
|
||||
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier, bool withTransparency, uint8_t alpha) {
|
||||
JNIEnv * env = static_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
|
||||
jobject activity = static_cast<jobject>(SDL_AndroidGetActivity());
|
||||
|
||||
@@ -35,7 +35,13 @@ SDL_Surface * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
|
||||
bytesPerPixel * bitmapInfo.width,
|
||||
SDL_PIXELFORMAT_ABGR8888);
|
||||
|
||||
AndroidBitmap_unlockPixels(env, j_bitmap);
|
||||
SDL_SetColorKey(surface, withTransparency, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
|
||||
SDL_SetSurfaceAlphaMod(surface, alpha);
|
||||
|
||||
return surface;
|
||||
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
|
||||
AndroidBitmap_unlockPixels(env, j_bitmap);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <SDL.h>
|
||||
#include <UIKit/UIKit.h>
|
||||
|
||||
SDL_Surface * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) {
|
||||
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier, bool withTransparency, uint8_t alpha) {
|
||||
CGImageRef cgImage = [[UIImage imageNamed:[NSString stringWithUTF8String:identifier]] CGImage];
|
||||
if (cgImage == NULL) {
|
||||
return NULL;
|
||||
@@ -39,7 +39,13 @@ SDL_Surface * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
|
||||
bytesPerRow,
|
||||
SDL_PIXELFORMAT_ABGR8888);
|
||||
|
||||
free(bitmapData);
|
||||
SDL_SetColorKey(surface, withTransparency, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
|
||||
SDL_SetSurfaceAlphaMod(surface, alpha);
|
||||
|
||||
return surface;
|
||||
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
|
||||
free(bitmapData);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ static struct {
|
||||
ASSETS_ADDRESS_RANGES_DEFINITION
|
||||
};
|
||||
|
||||
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) {
|
||||
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier, bool withTransparency, uint8_t alpha) {
|
||||
struct jpeg_decompress_struct info;
|
||||
struct jpeg_error_mgr err;
|
||||
info.err = jpeg_std_error(&err);
|
||||
@@ -70,7 +70,13 @@ SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
|
||||
width * bytesPerPixel,
|
||||
surfacePixelFormat);
|
||||
|
||||
SDL_SetColorKey(surface, withTransparency, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
|
||||
SDL_SetSurfaceAlphaMod(surface, alpha);
|
||||
|
||||
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
|
||||
delete[] bitmapData;
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <SDL.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
SDL_Surface * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) {
|
||||
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier, bool withTransparency, uint8_t alpha) {
|
||||
NSImage * nsImage = [NSImage imageNamed:[NSString stringWithUTF8String:identifier]];
|
||||
CGImageRef cgImage = [nsImage CGImageForProposedRect:NULL
|
||||
context:NULL
|
||||
@@ -41,7 +41,13 @@ SDL_Surface * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
|
||||
bytesPerRow,
|
||||
SDL_PIXELFORMAT_ABGR8888);
|
||||
|
||||
free(bitmapData);
|
||||
SDL_SetColorKey(surface, withTransparency, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
|
||||
SDL_SetSurfaceAlphaMod(surface, alpha);
|
||||
|
||||
return surface;
|
||||
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
|
||||
free(bitmapData);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -202,19 +202,10 @@ static constexpr uint8_t k_blendingRatio = 0x44;
|
||||
static SDL_Texture * sBackgroundTexture = nullptr;
|
||||
static SDL_Texture * sKeyLayoutTextures[KeyLayout::NumberOfShapes];
|
||||
|
||||
SDL_Texture * textureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface, bool transparencyFlag, KDColor transparentColor) {
|
||||
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
SDL_SetColorKey(surface, transparencyFlag, SDL_MapRGB(surface->format, transparentColor.red(), transparentColor.green(), transparentColor.blue()));
|
||||
SDL_FreeSurface(surface);
|
||||
return texture;
|
||||
}
|
||||
|
||||
void init(SDL_Renderer * renderer) {
|
||||
sBackgroundTexture = textureFromSurface(renderer, IonSimulatorLoadImage(renderer, "background.jpg"), false, KDColorWhite);
|
||||
sBackgroundTexture = IonSimulatorLoadImage(renderer, "background.jpg", false, 0xFF);
|
||||
for (size_t i = 0; i < KeyLayout::NumberOfShapes; i++) {
|
||||
sKeyLayoutTextures[i] = textureFromSurface(renderer, IonSimulatorLoadImage(renderer, KeyLayout::imagePathForKey[i]), true, KDColorWhite);
|
||||
SDL_SetTextureBlendMode(sKeyLayoutTextures[i], SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureAlphaMod(sKeyLayoutTextures[i], k_blendingRatio);
|
||||
sKeyLayoutTextures[i] = IonSimulatorLoadImage(renderer, KeyLayout::imagePathForKey[i], true, k_blendingRatio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ extern "C" {
|
||||
/* Those functions should be implemented per-platform.
|
||||
* They are defined as C function for easier interop. */
|
||||
|
||||
SDL_Surface * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier);
|
||||
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier, bool withTransparency, uint8_t alpha);
|
||||
char * IonSimulatorGetLanguageCode();
|
||||
|
||||
#if EPSILON_SDL_SCREEN_ONLY
|
||||
|
||||
@@ -36,7 +36,7 @@ HRESULT CreateStreamOnResource(const char * name, LPSTREAM * stream) {
|
||||
return hr;
|
||||
}
|
||||
|
||||
SDL_Surface * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier) {
|
||||
SDL_Texture * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identifier, bool withTransparency, uint8_t alpha) {
|
||||
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
|
||||
ULONG_PTR gdiplusToken;
|
||||
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
|
||||
@@ -71,10 +71,16 @@ SDL_Surface * IonSimulatorLoadImage(SDL_Renderer * renderer, const char * identi
|
||||
bytesPerPixel*width,
|
||||
SDL_PIXELFORMAT_ABGR8888);
|
||||
|
||||
SDL_SetColorKey(surface, withTransparency, SDL_MapRGB(surface->format, 0xFF, 0xFF, 0xFF));
|
||||
SDL_SetSurfaceAlphaMod(surface, alpha);
|
||||
|
||||
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
|
||||
image->UnlockBits(bitmapData);
|
||||
delete bitmapData;
|
||||
delete image;
|
||||
Gdiplus::GdiplusShutdown(gdiplusToken);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
return surface;
|
||||
return texture;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user