1
0
mirror of https://github.com/libretro/RetroArch synced 2025-03-21 04:21:13 +00:00

Cleanups/style nits

This commit is contained in:
libretroadmin 2023-02-23 13:15:14 +01:00
parent 3f3262fba3
commit 7ebab640d7
121 changed files with 1501 additions and 1765 deletions
audio/drivers
cores/libretro-ffmpeg
ctr
frontend
gfx
input
intl
led/drivers
libretro-common

@ -69,7 +69,7 @@ static void *alsa_qsa_init(const char *device,
goto error; goto error;
} }
if((err = snd_pcm_nonblock_mode(alsa->pcm, 1)) < 0) if ((err = snd_pcm_nonblock_mode(alsa->pcm, 1)) < 0)
{ {
RARCH_ERR("[ALSA QSA]: Can't set blocking mode: %s\n", RARCH_ERR("[ALSA QSA]: Can't set blocking mode: %s\n",
snd_strerror(err)); snd_strerror(err));
@ -313,11 +313,10 @@ static bool alsa_qsa_start(void *data, bool is_shutdown)
static void alsa_qsa_set_nonblock_state(void *data, bool state) static void alsa_qsa_set_nonblock_state(void *data, bool state)
{ {
int err;
alsa_qsa_t *alsa = (alsa_qsa_t*)data; alsa_qsa_t *alsa = (alsa_qsa_t*)data;
int err; if ((err = snd_pcm_nonblock_mode(alsa->pcm, state)) < 0)
if((err = snd_pcm_nonblock_mode(alsa->pcm, state)) < 0)
{ {
RARCH_ERR("Can't set blocking mode to %d: %s\n", state, RARCH_ERR("Can't set blocking mode to %d: %s\n", state,
snd_strerror(err)); snd_strerror(err));

@ -170,14 +170,9 @@ static ssize_t ctr_csnd_audio_write(void *data, const void *buf, size_t size)
const uint16_t *src = buf; const uint16_t *src = buf;
ctr_csnd_audio_t *ctr = (ctr_csnd_audio_t*)data; ctr_csnd_audio_t *ctr = (ctr_csnd_audio_t*)data;
(void)data;
(void)buf;
(void)samples_played;
(void)current_tick;
ctr_csnd_audio_update_playpos(ctr); ctr_csnd_audio_update_playpos(ctr);
if((((ctr->playpos - ctr->pos) & CTR_CSND_AUDIO_COUNT_MASK) < (CTR_CSND_AUDIO_COUNT >> 2)) || if ((((ctr->playpos - ctr->pos) & CTR_CSND_AUDIO_COUNT_MASK) < (CTR_CSND_AUDIO_COUNT >> 2)) ||
(((ctr->pos - ctr->playpos ) & CTR_CSND_AUDIO_COUNT_MASK) < (CTR_CSND_AUDIO_COUNT >> 4)) || (((ctr->pos - ctr->playpos ) & CTR_CSND_AUDIO_COUNT_MASK) < (CTR_CSND_AUDIO_COUNT >> 4)) ||
(((ctr->playpos - ctr->pos) & CTR_CSND_AUDIO_COUNT_MASK) < (size >> 2))) (((ctr->playpos - ctr->pos) & CTR_CSND_AUDIO_COUNT_MASK) < (size >> 2)))
{ {

@ -97,7 +97,7 @@ static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size)
ctr_dsp_audio_t * ctr = (ctr_dsp_audio_t*)data; ctr_dsp_audio_t * ctr = (ctr_dsp_audio_t*)data;
uint32_t sample_pos = ndspChnGetSamplePos(ctr->channel); uint32_t sample_pos = ndspChnGetSamplePos(ctr->channel);
if((((sample_pos - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK) < (CTR_DSP_AUDIO_COUNT >> 2)) || if ((((sample_pos - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK) < (CTR_DSP_AUDIO_COUNT >> 2)) ||
(((ctr->pos - sample_pos ) & CTR_DSP_AUDIO_COUNT_MASK) < (CTR_DSP_AUDIO_COUNT >> 4)) || (((ctr->pos - sample_pos ) & CTR_DSP_AUDIO_COUNT_MASK) < (CTR_DSP_AUDIO_COUNT >> 4)) ||
(((sample_pos - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK) < (size >> 2))) (((sample_pos - ctr->pos) & CTR_DSP_AUDIO_COUNT_MASK) < (size >> 2)))
{ {
@ -105,26 +105,27 @@ static ssize_t ctr_dsp_audio_write(void *data, const void *buf, size_t size)
ctr->pos = (sample_pos + (CTR_DSP_AUDIO_COUNT >> 1)) & CTR_DSP_AUDIO_COUNT_MASK; ctr->pos = (sample_pos + (CTR_DSP_AUDIO_COUNT >> 1)) & CTR_DSP_AUDIO_COUNT_MASK;
else else
{ {
do{ do
{
svcSleepThread(100000); svcSleepThread(100000);
/* Run aptMainLoop to update APT state if DSP state /* Run aptMainLoop to update APT state if DSP state
* changed, this prevents a hang on sleep. */ * changed, this prevents a hang on sleep. */
if(!aptMainLoop()) if (!aptMainLoop())
{ {
command_event(CMD_EVENT_QUIT, NULL); command_event(CMD_EVENT_QUIT, NULL);
return true; return true;
} }
sample_pos = ndspChnGetSamplePos(ctr->channel); sample_pos = ndspChnGetSamplePos(ctr->channel);
}while (((sample_pos - (ctr->pos + (size >>2))) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1) }while ( ((sample_pos - (ctr->pos + (size >>2))) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)
|| (((ctr->pos - (CTR_DSP_AUDIO_COUNT >> 4) - sample_pos) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1))); || (((ctr->pos - (CTR_DSP_AUDIO_COUNT >> 4) - sample_pos) & CTR_DSP_AUDIO_COUNT_MASK) > (CTR_DSP_AUDIO_COUNT >> 1)));
} }
} }
pos = ctr->pos << 2; pos = ctr->pos << 2;
if((pos + size) > CTR_DSP_AUDIO_SIZE) if ((pos + size) > CTR_DSP_AUDIO_SIZE)
{ {
memcpy(ctr->dsp_buf.data_pcm8 + pos, buf, memcpy(ctr->dsp_buf.data_pcm8 + pos, buf,
(CTR_DSP_AUDIO_SIZE - pos)); (CTR_DSP_AUDIO_SIZE - pos));

@ -110,7 +110,7 @@ static void *ps3_audio_init(const char *device,
params.param_attrib = 0; params.param_attrib = 0;
#if 0 #if 0
#ifdef HAVE_HEADSET #ifdef HAVE_HEADSET
if(global->console.sound.mode == SOUND_MODE_HEADSET) if (global->console.sound.mode == SOUND_MODE_HEADSET)
params.param_attrib = CELL_AUDIO_PORTATTR_OUT_SECONDARY; params.param_attrib = CELL_AUDIO_PORTATTR_OUT_SECONDARY;
#endif #endif
#endif #endif

@ -166,22 +166,23 @@ static void *psp_audio_init(const char *device,
static void psp_audio_free(void *data) static void psp_audio_free(void *data)
{ {
psp_audio_t* psp = (psp_audio_t*)data; psp_audio_t* psp = (psp_audio_t*)data;
if(!psp) if (!psp)
return; return;
if(psp->running){ if (psp->running)
{
if (psp->worker_thread) if (psp->worker_thread)
{ {
psp->running = false; psp->running = false;
sthread_join(psp->worker_thread); sthread_join(psp->worker_thread);
} }
if (psp->cond) if (psp->cond)
scond_free(psp->cond); scond_free(psp->cond);
if (psp->fifo_lock) if (psp->fifo_lock)
slock_free(psp->fifo_lock); slock_free(psp->fifo_lock);
if (psp->cond_lock) if (psp->cond_lock)
slock_free(psp->cond_lock); slock_free(psp->cond_lock);
} }
free(psp->buffer); free(psp->buffer);
psp->worker_thread = NULL; psp->worker_thread = NULL;
@ -222,7 +223,7 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
slock_unlock(psp->cond_lock); slock_unlock(psp->cond_lock);
slock_lock(psp->fifo_lock); slock_lock(psp->fifo_lock);
if((write_pos + sampleCount) > AUDIO_BUFFER_SIZE) if ((write_pos + sampleCount) > AUDIO_BUFFER_SIZE)
{ {
memcpy(psp->buffer + write_pos, buf, memcpy(psp->buffer + write_pos, buf,
(AUDIO_BUFFER_SIZE - write_pos) * sizeof(uint32_t)); (AUDIO_BUFFER_SIZE - write_pos) * sizeof(uint32_t));
@ -274,13 +275,13 @@ static bool psp_audio_start(void *data, bool is_shutdown)
{ {
psp_audio_t* psp = (psp_audio_t*)data; psp_audio_t* psp = (psp_audio_t*)data;
if(psp && psp->running) if (psp && !psp->running)
return true;
if (!psp->worker_thread)
{ {
psp->running = true; if (!psp->worker_thread)
psp->worker_thread = sthread_create(audioMainLoop, psp); {
psp->running = true;
psp->worker_thread = sthread_create(audioMainLoop, psp);
}
} }
return true; return true;
@ -295,7 +296,6 @@ static void psp_audio_set_nonblock_state(void *data, bool toggle)
static bool psp_audio_use_float(void *data) static bool psp_audio_use_float(void *data)
{ {
(void)data;
return false; return false;
} }
@ -315,7 +315,7 @@ static size_t psp_write_avail(void *data)
static size_t psp_buffer_size(void *data) static size_t psp_buffer_size(void *data)
{ {
/* TODO */ /* TODO/FIXME - implement? */
return AUDIO_BUFFER_SIZE /** sizeof(uint32_t)*/; return AUDIO_BUFFER_SIZE /** sizeof(uint32_t)*/;
} }

@ -1675,7 +1675,7 @@ static void decode_thread_seek(double time)
decode_last_audio_time = time; decode_last_audio_time = time;
if(avformat_seek_file(fctx, -1, INT64_MIN, seek_to, INT64_MAX, 0) < 0) if (avformat_seek_file(fctx, -1, INT64_MIN, seek_to, INT64_MAX, 0) < 0)
log_cb(RETRO_LOG_ERROR, "[FFMPEG] av_seek_frame() failed.\n"); log_cb(RETRO_LOG_ERROR, "[FFMPEG] av_seek_frame() failed.\n");
if (video_stream_index >= 0) if (video_stream_index >= 0)

@ -264,17 +264,17 @@ const u8 GPU_TEVID[]={0xC0,0xC8,0xD0,0xD8,0xF0,0xF8};
void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16 alphaOperands, GPU_COMBINEFUNC rgbCombine, GPU_COMBINEFUNC alphaCombine, u32 constantColor) void GPU_SetTexEnv(u8 id, u16 rgbSources, u16 alphaSources, u16 rgbOperands, u16 alphaOperands, GPU_COMBINEFUNC rgbCombine, GPU_COMBINEFUNC alphaCombine, u32 constantColor)
{ {
u32 param[0x5]; u32 param[0x5];
if(id > 6) if (id > 6)
return; return;
param[0x0] = (alphaSources << 16) | (rgbSources); param[0x0] = (alphaSources << 16) | (rgbSources);
param[0x1] = (alphaOperands << 12) | (rgbOperands); param[0x1] = (alphaOperands << 12) | (rgbOperands);
param[0x2] = (alphaCombine << 16) | (rgbCombine); param[0x2] = (alphaCombine << 16) | (rgbCombine);
param[0x3] = constantColor; param[0x3] = constantColor;
param[0x4] = 0x00000000; /* ? */ param[0x4] = 0x00000000; /* ? */
GPUCMD_AddIncrementalWrites(GPUREG_0000|GPU_TEVID[id], param, 0x00000005); GPUCMD_AddIncrementalWrites(GPUREG_0000|GPU_TEVID[id], param, 0x00000005);
} }
void GPU_DrawArray(GPU_Primitive_t primitive, u32 first, u32 count) void GPU_DrawArray(GPU_Primitive_t primitive, u32 first, u32 count)

@ -377,7 +377,7 @@ u8* gfxBottomFramebuffers[2];
void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id) void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id)
{ {
if(screen==GFX_TOP) if (screen==GFX_TOP)
{ {
u8 enable3d = 0; u8 enable3d = 0;
u8 bit5=(enable3d != 0); u8 bit5=(enable3d != 0);
@ -387,7 +387,9 @@ void gfxSetFramebufferInfo(gfxScreen_t screen, u8 id)
enable3d ? (u32*)gfxTopRightFramebuffers[id] : (u32*)gfxTopLeftFramebuffers[id], enable3d ? (u32*)gfxTopRightFramebuffers[id] : (u32*)gfxTopLeftFramebuffers[id],
240 * 3, 240 * 3,
((1)<<8)|((1^bit5)<<6)|((bit5)<<5)|GSP_BGR8_OES); ((1)<<8)|((1^bit5)<<6)|((bit5)<<5)|GSP_BGR8_OES);
} else { }
else
{
gspPresentBuffer(GFX_BOTTOM, gspPresentBuffer(GFX_BOTTOM,
id, id,
(u32*)gfxBottomFramebuffers[id], (u32*)gfxBottomFramebuffers[id],

@ -123,19 +123,17 @@ static void CFSearchPathForDirectoriesInDomains(
#else #else
NSSearchPathDirectory dir = NSDocumentDirectory; NSSearchPathDirectory dir = NSDocumentDirectory;
#endif #endif
CFStringRef array_val;
#if __has_feature(objc_arc) #if __has_feature(objc_arc)
array_val = (__bridge CFStringRef)[ CFStringRef array_val = (__bridge CFStringRef)[
NSSearchPathForDirectoriesInDomains(dir, NSSearchPathForDirectoriesInDomains(dir,
NSUserDomainMask, YES) firstObject]; NSUserDomainMask, YES) firstObject];
#else #else
NSArray *arr = NSSearchPathForDirectoriesInDomains(dir, CFStringRef array_val = nil;
NSUserDomainMask, YES); NSArray *arr =
if ([arr count] == 0) { NSSearchPathForDirectoriesInDomains(dir,
array_val = nil; NSUserDomainMask, YES);
} else{ if ([arr count] != 0)
array_val = (CFStringRef)[arr objectAtIndex:0]; array_val = (CFStringRef)[arr objectAtIndex:0];
}
#endif #endif
if (array_val) if (array_val)
CFStringGetCString(array_val, s, len, kCFStringEncodingUTF8); CFStringGetCString(array_val, s, len, kCFStringEncodingUTF8);
@ -160,9 +158,15 @@ void get_ios_version(int *major, int *minor);
#define PMGMT_STRMATCH(a,b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo) #define PMGMT_STRMATCH(a,b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo)
#define PMGMT_GETVAL(k,v) CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **) v) #define PMGMT_GETVAL(k,v) CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **) v)
/* Note that AC power sources also include a laptop battery it is charging. */ /* Note that AC power sources also include a
static void checkps(CFDictionaryRef dict, bool * have_ac, bool * have_battery, * laptop battery it is charging. */
bool * charging, int *seconds, int *percent) static void darwin_check_power_source(
CFDictionaryRef dict,
bool *have_ac,
bool *have_battery,
bool *charging,
int *seconds,
int *percent)
{ {
CFStringRef strval; /* don't CFRelease() this. */ CFStringRef strval; /* don't CFRelease() this. */
CFBooleanRef bval; CFBooleanRef bval;
@ -183,7 +187,7 @@ static void checkps(CFDictionaryRef dict, bool * have_ac, bool * have_battery,
if (PMGMT_STRMATCH(strval, CFSTR(kIOPSACPowerValue))) if (PMGMT_STRMATCH(strval, CFSTR(kIOPSACPowerValue)))
is_ac = *have_ac = true; is_ac = *have_ac = true;
else if (!PMGMT_STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue))) else if (!PMGMT_STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue)))
return; /* not a battery? */ return; /* Not a battery? */
if ((PMGMT_GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue)) if ((PMGMT_GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue))
charge = true; charge = true;
@ -195,7 +199,7 @@ static void checkps(CFDictionaryRef dict, bool * have_ac, bool * have_battery,
if (val > 0) if (val > 0)
{ {
*have_battery = true; *have_battery = true;
maxpct = (int) val; maxpct = (int)val;
} }
} }
@ -206,7 +210,7 @@ static void checkps(CFDictionaryRef dict, bool * have_ac, bool * have_battery,
if (val > 0) if (val > 0)
{ {
*have_battery = true; *have_battery = true;
maxpct = (int) val; maxpct = (int)val;
} }
} }
@ -216,12 +220,12 @@ static void checkps(CFDictionaryRef dict, bool * have_ac, bool * have_battery,
CFNumberGetValue(numval, kCFNumberSInt32Type, &val); CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
/* Mac OS X reports 0 minutes until empty if you're plugged in. :( */ /* Mac OS X reports 0 minutes until empty if you're plugged in. :( */
if ((val == 0) && (is_ac)) if ((val == 0) && is_ac)
val = -1; /* !!! FIXME: calc from timeToFull and capacity? */ val = -1; /* !!! FIXME: calc from timeToFull and capacity? */
secs = (int) val; secs = (int)val;
if (secs > 0) if (secs > 0)
secs *= 60; /* value is in minutes, so convert to seconds. */ secs *= 60; /* value is in minutes, so convert to seconds. */
} }
if (PMGMT_GETVAL(kIOPSCurrentCapacityKey, &numval)) if (PMGMT_GETVAL(kIOPSCurrentCapacityKey, &numval))
@ -264,11 +268,8 @@ static void frontend_darwin_get_name(char *s, size_t len)
{ {
#if defined(IOS) #if defined(IOS)
struct utsname buffer; struct utsname buffer;
if (uname(&buffer) == 0)
if (uname(&buffer) != 0) strlcpy(s, buffer.machine, len);
return;
strlcpy(s, buffer.machine, len);
#elif defined(OSX) #elif defined(OSX)
size_t length = 0; size_t length = 0;
sysctlbyname("hw.model", NULL, &length, NULL, 0); sysctlbyname("hw.model", NULL, &length, NULL, 0);
@ -348,10 +349,10 @@ static void frontend_darwin_get_env(int *argc, char *argv[],
if (!bundle) if (!bundle)
return; return;
bundle_url = CFBundleCopyBundleURL(bundle); bundle_url = CFBundleCopyBundleURL(bundle);
bundle_path = CFURLCopyPath(bundle_url); bundle_path = CFURLCopyPath(bundle_url);
resource_url = CFBundleCopyResourcesDirectoryURL(bundle); resource_url = CFBundleCopyResourcesDirectoryURL(bundle);
resource_path = CFURLCopyPath(resource_url); resource_path = CFURLCopyPath(resource_url);
CFRelease(resource_url); CFRelease(resource_url);
@ -379,8 +380,8 @@ static void frontend_darwin_get_env(int *argc, char *argv[],
strlcat(home_dir_buf, "/RetroArch", sizeof(home_dir_buf)); strlcat(home_dir_buf, "/RetroArch", sizeof(home_dir_buf));
#ifdef HAVE_METAL #ifdef HAVE_METAL
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SHADER], fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SHADER],
home_dir_buf, "shaders_slang", home_dir_buf, "shaders_slang",
sizeof(g_defaults.dirs[DEFAULT_DIR_SHADER])); sizeof(g_defaults.dirs[DEFAULT_DIR_SHADER]));
#else #else
fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SHADER], fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_SHADER],
home_dir_buf, "shaders_glsl", home_dir_buf, "shaders_glsl",
@ -450,14 +451,18 @@ static void frontend_darwin_get_env(int *argc, char *argv[],
int major, minor; int major, minor;
get_ios_version(&major, &minor); get_ios_version(&major, &minor);
if (major > 8) if (major > 8)
strlcpy(g_defaults.path_buildbot_server_url, "http://buildbot.libretro.com/nightly/apple/ios9/latest/", sizeof(g_defaults.path_buildbot_server_url)); strlcpy(g_defaults.path_buildbot_server_url,
"http://buildbot.libretro.com/nightly/apple/ios9/latest/",
sizeof(g_defaults.path_buildbot_server_url));
} }
#endif #endif
#if TARGET_OS_IOS #if TARGET_OS_IOS
fill_pathname_join_special(assets_zip_path, bundle_path_buf, "assets.zip", sizeof(assets_zip_path)); fill_pathname_join_special(assets_zip_path,
bundle_path_buf, "assets.zip", sizeof(assets_zip_path));
#else #else
fill_pathname_join_special(assets_zip_path, full_resource_path_buf, "assets.zip", sizeof(assets_zip_path)); fill_pathname_join_special(assets_zip_path,
full_resource_path_buf, "assets.zip", sizeof(assets_zip_path));
#endif #endif
if (path_is_valid(assets_zip_path)) if (path_is_valid(assets_zip_path))
@ -616,7 +621,8 @@ static int frontend_darwin_get_rating(void)
return -1; return -1;
} }
static enum frontend_powerstate frontend_darwin_get_powerstate(int *seconds, int *percent) static enum frontend_powerstate frontend_darwin_get_powerstate(
int *seconds, int *percent)
{ {
enum frontend_powerstate ret = FRONTEND_POWERSTATE_NONE; enum frontend_powerstate ret = FRONTEND_POWERSTATE_NONE;
#if defined(OSX) #if defined(OSX)
@ -629,12 +635,13 @@ static enum frontend_powerstate frontend_darwin_get_powerstate(int *seconds, int
*percent = -1; *percent = -1;
if (!blob) if (!blob)
goto end; return FRONTEND_POWERSTATE_NONE
list = IOPSCopyPowerSourcesList(blob); if (!(list = IOPSCopyPowerSourcesList(blob)))
{
if (!list) CFRelease(blob);
goto end; return FRONTEND_POWERSTATE_NONE;
}
/* don't CFRelease() the list items, or dictionaries! */ /* don't CFRelease() the list items, or dictionaries! */
have_ac = false; have_ac = false;
@ -647,7 +654,7 @@ static enum frontend_powerstate frontend_darwin_get_powerstate(int *seconds, int
CFTypeRef ps = (CFTypeRef)CFArrayGetValueAtIndex(list, i); CFTypeRef ps = (CFTypeRef)CFArrayGetValueAtIndex(list, i);
CFDictionaryRef dict = IOPSGetPowerSourceDescription(blob, ps); CFDictionaryRef dict = IOPSGetPowerSourceDescription(blob, ps);
if (dict) if (dict)
checkps(dict, &have_ac, &have_battery, &charging, darwin_check_power_source(dict, &have_ac, &have_battery, &charging,
seconds, percent); seconds, percent);
} }
@ -661,38 +668,35 @@ static enum frontend_powerstate frontend_darwin_get_powerstate(int *seconds, int
ret = FRONTEND_POWERSTATE_ON_POWER_SOURCE; ret = FRONTEND_POWERSTATE_ON_POWER_SOURCE;
CFRelease(list); CFRelease(list);
end: CFRelease(blob);
if (blob)
CFRelease(blob);
#elif TARGET_OS_IOS #elif TARGET_OS_IOS
float level; float level;
UIDevice *uidev = [UIDevice currentDevice]; UIDevice *uidev = [UIDevice currentDevice];
if (uidev)
if (!uidev)
return ret;
[uidev setBatteryMonitoringEnabled:true];
switch (uidev.batteryState)
{ {
case UIDeviceBatteryStateCharging: [uidev setBatteryMonitoringEnabled:true];
ret = FRONTEND_POWERSTATE_CHARGING;
break; switch (uidev.batteryState)
case UIDeviceBatteryStateFull: {
ret = FRONTEND_POWERSTATE_CHARGED; case UIDeviceBatteryStateCharging:
break; ret = FRONTEND_POWERSTATE_CHARGING;
case UIDeviceBatteryStateUnplugged: break;
ret = FRONTEND_POWERSTATE_ON_POWER_SOURCE; case UIDeviceBatteryStateFull:
break; ret = FRONTEND_POWERSTATE_CHARGED;
case UIDeviceBatteryStateUnknown: break;
break; case UIDeviceBatteryStateUnplugged:
ret = FRONTEND_POWERSTATE_ON_POWER_SOURCE;
break;
case UIDeviceBatteryStateUnknown:
break;
}
level = uidev.batteryLevel;
*percent = ((level < 0.0f) ? -1 : ((int)((level * 100) + 0.5f)));
[uidev setBatteryMonitoringEnabled:false];
} }
level = uidev.batteryLevel;
*percent = ((level < 0.0f) ? -1 : ((int)((level * 100) + 0.5f)));
[uidev setBatteryMonitoringEnabled:false];
#endif #endif
return ret; return ret;
} }
@ -778,26 +782,24 @@ static int frontend_darwin_parse_drive_list(void *data, bool load_content)
CFRelease(bundle_url); CFRelease(bundle_url);
#endif #endif
#endif #endif
return ret; return ret;
} }
/* TODO/FIXME - is adding iOS/tvOS support possible here? */
static uint64_t frontend_darwin_get_total_mem(void) static uint64_t frontend_darwin_get_total_mem(void)
{ {
#if defined(OSX) #if defined(OSX)
uint64_t size; uint64_t size;
int mib[2] = { CTL_HW, HW_MEMSIZE }; int mib[2] = { CTL_HW, HW_MEMSIZE };
u_int namelen = sizeof(mib) / sizeof(mib[0]); u_int namelen = ARRAY_SIZE(mib);
size_t len = sizeof(size); size_t len = sizeof(size);
if (sysctl(mib, namelen, &size, &len, NULL, 0) >= 0)
if (sysctl(mib, namelen, &size, &len, NULL, 0) < 0) return size;
return 0;
return size;
#else
return 0;
#endif #endif
return 0;
} }
/* TODO/FIXME - is adding iOS/tvOS support possible here? */
static uint64_t frontend_darwin_get_free_mem(void) static uint64_t frontend_darwin_get_free_mem(void)
{ {
#if (defined(OSX) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101200)) #if (defined(OSX) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 101200))
@ -808,12 +810,12 @@ static uint64_t frontend_darwin_get_free_mem(void)
if (KERN_SUCCESS == host_page_size(mach_port, &page_size) && if (KERN_SUCCESS == host_page_size(mach_port, &page_size) &&
KERN_SUCCESS == host_statistics64(mach_port, HOST_VM_INFO, KERN_SUCCESS == host_statistics64(mach_port, HOST_VM_INFO,
(host_info64_t)&vm_stats, &count)) (host_info64_t)&vm_stats, &count))
{ {
long long used_memory = (
long long used_memory = ((int64_t)vm_stats.active_count + (int64_t)vm_stats.active_count +
(int64_t)vm_stats.inactive_count + (int64_t)vm_stats.inactive_count +
(int64_t)vm_stats.wire_count) * (int64_t)page_size; (int64_t)vm_stats.wire_count) * (int64_t)page_size;
return used_memory; return used_memory;
} }
#endif #endif
@ -822,7 +824,8 @@ static uint64_t frontend_darwin_get_free_mem(void)
static const char* frontend_darwin_get_cpu_model_name(void) static const char* frontend_darwin_get_cpu_model_name(void)
{ {
cpu_features_get_model_name(darwin_cpu_model_name, sizeof(darwin_cpu_model_name)); cpu_features_get_model_name(darwin_cpu_model_name,
sizeof(darwin_cpu_model_name));
return darwin_cpu_model_name; return darwin_cpu_model_name;
} }
@ -851,7 +854,8 @@ static char* accessibility_mac_language_code(const char* language)
return "Ioana"; return "Ioana";
else if (string_is_equal(language,"pt_pt")) else if (string_is_equal(language,"pt_pt"))
return "Joana"; return "Joana";
else if (string_is_equal(language,"pt_bt") || string_is_equal(language,"pt")) else if (string_is_equal(language,"pt_bt")
|| string_is_equal(language,"pt"))
return "Luciana"; return "Luciana";
else if (string_is_equal(language,"th")) else if (string_is_equal(language,"th"))
return "Kanya"; return "Kanya";
@ -865,7 +869,8 @@ static char* accessibility_mac_language_code(const char* language)
return "Maged"; return "Maged";
else if (string_is_equal(language,"hu")) else if (string_is_equal(language,"hu"))
return "Mariska"; return "Mariska";
else if (string_is_equal(language,"zh_tw") || string_is_equal(language,"zh")) else if (string_is_equal(language,"zh_tw")
|| string_is_equal(language,"zh"))
return "Mei-Jia"; return "Mei-Jia";
else if (string_is_equal(language,"el")) else if (string_is_equal(language,"el"))
return "Melina"; return "Melina";
@ -889,8 +894,7 @@ static char* accessibility_mac_language_code(const char* language)
return "Zosia"; return "Zosia";
else if (string_is_equal(language,"cs")) else if (string_is_equal(language,"cs"))
return "Zuzana"; return "Zuzana";
else return "";
return "";
} }
static bool is_narrator_running_macos(void) static bool is_narrator_running_macos(void)
@ -904,12 +908,12 @@ static bool accessibility_speak_macos(int speed,
int pid; int pid;
const char *voice = get_user_language_iso639_1(false); const char *voice = get_user_language_iso639_1(false);
char* language_speaker = accessibility_mac_language_code(voice); char* language_speaker = accessibility_mac_language_code(voice);
char* speeds[10] = {"80", "100", "125", "150", "170", "210", "260", "310", "380", "450"}; char* speeds[10] = {"80", "100", "125", "150", "170", "210",
"260", "310", "380", "450"};
if (speed < 1) if (speed < 1)
speed = 1; speed = 1;
else if (speed > 10) else if (speed > 10)
speed = 10; speed = 10;
if (priority < 10 && speak_pid > 0) if (priority < 10 && speak_pid > 0)
{ {
@ -952,8 +956,8 @@ static bool accessibility_speak_macos(int speed,
else else
{ {
char* cmd[] = {"say", NULL, "-r", NULL, NULL}; char* cmd[] = {"say", NULL, "-r", NULL, NULL};
cmd[1] = (char*) speak_text; cmd[1] = (char*) speak_text;
cmd[3] = speeds[speed-1]; cmd[3] = speeds[speed-1];
execvp("say",cmd); execvp("say",cmd);
} }
} }

@ -274,11 +274,10 @@ static void frontend_psp_init(void *data)
memset(&appUtilBootParam, 0, sizeof(SceAppUtilBootParam)); memset(&appUtilBootParam, 0, sizeof(SceAppUtilBootParam));
sceAppUtilInit(&appUtilParam, &appUtilBootParam); sceAppUtilInit(&appUtilParam, &appUtilBootParam);
#if defined(HAVE_VITAGLES) #if defined(HAVE_VITAGLES)
if(pibInit(PIB_SHACCCG|PIB_ENABLE_MSAA|PIB_GET_PROC_ADDR_CORE)) if (pibInit(PIB_SHACCCG|PIB_ENABLE_MSAA|PIB_GET_PROC_ADDR_CORE))
return; return;
#endif #endif
#else #else
(void)data;
/* initialize debug screen */ /* initialize debug screen */
pspDebugScreenInit(); pspDebugScreenInit();
pspDebugScreenClear(); pspDebugScreenClear();

@ -163,29 +163,30 @@ enum frontend_powerstate frontend_uwp_get_powerstate(
int *seconds, int *percent) int *seconds, int *percent)
{ {
SYSTEM_POWER_STATUS status; SYSTEM_POWER_STATUS status;
enum frontend_powerstate ret = FRONTEND_POWERSTATE_NONE; enum frontend_powerstate
ret = FRONTEND_POWERSTATE_NONE;
if (!GetSystemPowerStatus(&status)) if (GetSystemPowerStatus(&status))
return ret; {
if (status.BatteryFlag == 0xFF)
ret = FRONTEND_POWERSTATE_NONE;
else if (status.BatteryFlag & (1 << 7))
ret = FRONTEND_POWERSTATE_NO_SOURCE;
else if (status.BatteryFlag & (1 << 3))
ret = FRONTEND_POWERSTATE_CHARGING;
else if (status.ACLineStatus == 1)
ret = FRONTEND_POWERSTATE_CHARGED;
else
ret = FRONTEND_POWERSTATE_ON_POWER_SOURCE;
if (status.BatteryFlag == 0xFF) *percent = (int)status.BatteryLifePercent;
ret = FRONTEND_POWERSTATE_NONE; *seconds = (int)status.BatteryLifeTime;
else if (status.BatteryFlag & (1 << 7))
ret = FRONTEND_POWERSTATE_NO_SOURCE;
else if (status.BatteryFlag & (1 << 3))
ret = FRONTEND_POWERSTATE_CHARGING;
else if (status.ACLineStatus == 1)
ret = FRONTEND_POWERSTATE_CHARGED;
else
ret = FRONTEND_POWERSTATE_ON_POWER_SOURCE;
*percent = (int)status.BatteryLifePercent;
*seconds = (int)status.BatteryLifeTime;
#ifdef _WIN32 #ifdef _WIN32
if (*percent == 255) if (*percent == 255)
*percent = 0; *percent = 0;
#endif #endif
}
return ret; return ret;
} }
@ -259,8 +260,10 @@ static int frontend_uwp_parse_drive_list(void *data, bool load_content)
if (string_is_equal(uwp_device_family, "Windows.Desktop")) if (string_is_equal(uwp_device_family, "Windows.Desktop"))
{ {
menu_entries_append(list, menu_entries_append(list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FILE_BROWSER_OPEN_UWP_PERMISSIONS), msg_hash_to_str(
msg_hash_to_str(MENU_ENUM_LABEL_FILE_BROWSER_OPEN_UWP_PERMISSIONS), MENU_ENUM_LABEL_VALUE_FILE_BROWSER_OPEN_UWP_PERMISSIONS),
msg_hash_to_str(
MENU_ENUM_LABEL_FILE_BROWSER_OPEN_UWP_PERMISSIONS),
MENU_ENUM_LABEL_FILE_BROWSER_OPEN_UWP_PERMISSIONS, MENU_ENUM_LABEL_FILE_BROWSER_OPEN_UWP_PERMISSIONS,
MENU_SETTING_ACTION, 0, 0, NULL); MENU_SETTING_ACTION, 0, 0, NULL);
} }

@ -469,7 +469,8 @@ static void init_nvda(void)
/* The above code is executed on each accessibility speak event, so /* The above code is executed on each accessibility speak event, so
* we should only revert to powershell if nvda_lib wasn't loaded previously, * we should only revert to powershell if nvda_lib wasn't loaded previously,
* and we weren't able to load it on this call, or we don't HAVE_DYLIB */ * and we weren't able to load it on this call, or we don't HAVE_DYLIB */
if ((g_plat_win32_flags & PLAT_WIN32_FLAG_USE_NVDA) && !nvda_lib) { if ((g_plat_win32_flags & PLAT_WIN32_FLAG_USE_NVDA) && !nvda_lib)
{
g_plat_win32_flags &= ~PLAT_WIN32_FLAG_USE_NVDA; g_plat_win32_flags &= ~PLAT_WIN32_FLAG_USE_NVDA;
g_plat_win32_flags |= PLAT_WIN32_FLAG_USE_POWERSHELL; g_plat_win32_flags |= PLAT_WIN32_FLAG_USE_POWERSHELL;
} }

@ -582,7 +582,7 @@ void frontend_driver_attach_console(void)
For now, we do this hack, but this absolutely should be redesigned For now, we do this hack, but this absolutely should be redesigned
as soon as possible. as soon as possible.
*/ */
if( frontend_driver_st.current_frontend_ctx if ( frontend_driver_st.current_frontend_ctx
&& frontend_driver_st.current_frontend_ctx->attach_console) && frontend_driver_st.current_frontend_ctx->attach_console)
frontend_driver_st.current_frontend_ctx->attach_console(); frontend_driver_st.current_frontend_ctx->attach_console();
} }

@ -167,7 +167,7 @@ d3d10_get_closest_match(D3D10Device device,
DXGI_FORMAT default_list[] = {desired_format, DXGI_FORMAT_UNKNOWN}; DXGI_FORMAT default_list[] = {desired_format, DXGI_FORMAT_UNKNOWN};
DXGI_FORMAT* format = dxgi_get_format_fallback_list(desired_format); DXGI_FORMAT* format = dxgi_get_format_fallback_list(desired_format);
if(!format) if (!format)
format = default_list; format = default_list;
while (*format != DXGI_FORMAT_UNKNOWN) while (*format != DXGI_FORMAT_UNKNOWN)

@ -188,7 +188,7 @@ d3d11_get_closest_match(D3D11Device device, DXGI_FORMAT desired_format, UINT des
DXGI_FORMAT default_list[] = {desired_format, DXGI_FORMAT_UNKNOWN}; DXGI_FORMAT default_list[] = {desired_format, DXGI_FORMAT_UNKNOWN};
DXGI_FORMAT* format = dxgi_get_format_fallback_list(desired_format); DXGI_FORMAT* format = dxgi_get_format_fallback_list(desired_format);
if(!format) if (!format)
format = default_list; format = default_list;
while (*format != DXGI_FORMAT_UNKNOWN) while (*format != DXGI_FORMAT_UNKNOWN)

@ -57,8 +57,7 @@ bool d3d8_initialize_symbols(enum gfx_ctx_api api)
return true; return true;
#if defined(DEBUG) || defined(_DEBUG) #if defined(DEBUG) || defined(_DEBUG)
g_d3d8_dll = dylib_load("d3d8d.dll"); if (!(g_d3d8_dll = dylib_load("d3d8d.dll")))
if(!g_d3d8_dll)
#endif #endif
g_d3d8_dll = dylib_load("d3d8.dll"); g_d3d8_dll = dylib_load("d3d8.dll");

@ -592,7 +592,7 @@ static void d3d9_get_video_size(d3d9_video_t *d3d,
d3d->resolution_hd_enable = false; d3d->resolution_hd_enable = false;
if(video_mode.fIsHiDef) if (video_mode.fIsHiDef)
{ {
*width = 1280; *width = 1280;
*height = 720; *height = 720;
@ -1196,17 +1196,15 @@ static void d3d9_video_texture_load_d3d(
if (!ti) if (!ti)
return; return;
if((info->type == TEXTURE_FILTER_MIPMAP_LINEAR) || if ( (info->type == TEXTURE_FILTER_MIPMAP_LINEAR)
(info->type == TEXTURE_FILTER_MIPMAP_NEAREST)) || (info->type == TEXTURE_FILTER_MIPMAP_NEAREST))
want_mipmap = true; want_mipmap = true;
tex = (LPDIRECT3DTEXTURE9)d3d9_texture_new(d3d->dev, if (!(tex = (LPDIRECT3DTEXTURE9)d3d9_texture_new(d3d->dev,
ti->width, ti->height, 0, ti->width, ti->height, 0,
usage, D3D9_ARGB8888_FORMAT, usage, D3D9_ARGB8888_FORMAT,
D3DPOOL_MANAGED, 0, 0, 0, D3DPOOL_MANAGED, 0, 0, 0,
NULL, NULL, want_mipmap); NULL, NULL, want_mipmap)))
if (!tex)
return; return;
IDirect3DTexture9_LockRect(tex, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); IDirect3DTexture9_LockRect(tex, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);

@ -734,14 +734,14 @@ void dxgi_set_hdr_metadata(
hdr10_meta_data.MaxFrameAverageLightLevel = hdr10_meta_data.MaxFrameAverageLightLevel =
(UINT16)(max_fall); (UINT16)(max_fall);
if(g_hdr10_meta_data.RedPrimary != hdr10_meta_data.RedPrimary || if (g_hdr10_meta_data.RedPrimary != hdr10_meta_data.RedPrimary ||
g_hdr10_meta_data.GreenPrimary != hdr10_meta_data.GreenPrimary || g_hdr10_meta_data.GreenPrimary != hdr10_meta_data.GreenPrimary ||
g_hdr10_meta_data.BluePrimary != hdr10_meta_data.BluePrimary || g_hdr10_meta_data.BluePrimary != hdr10_meta_data.BluePrimary ||
g_hdr10_meta_data.WhitePoint != hdr10_meta_data.WhitePoint || g_hdr10_meta_data.WhitePoint != hdr10_meta_data.WhitePoint ||
g_hdr10_meta_data.MaxContentLightLevel != hdr10_meta_data.MaxContentLightLevel || g_hdr10_meta_data.MaxContentLightLevel != hdr10_meta_data.MaxContentLightLevel ||
g_hdr10_meta_data.MaxMasteringLuminance != hdr10_meta_data.MaxMasteringLuminance || g_hdr10_meta_data.MaxMasteringLuminance != hdr10_meta_data.MaxMasteringLuminance ||
g_hdr10_meta_data.MinMasteringLuminance != hdr10_meta_data.MinMasteringLuminance || g_hdr10_meta_data.MinMasteringLuminance != hdr10_meta_data.MinMasteringLuminance ||
g_hdr10_meta_data.MaxFrameAverageLightLevel != hdr10_meta_data.MaxFrameAverageLightLevel) g_hdr10_meta_data.MaxFrameAverageLightLevel != hdr10_meta_data.MaxFrameAverageLightLevel)
{ {
#ifdef __cplusplus #ifdef __cplusplus
if (FAILED(handle->SetHDRMetaData( if (FAILED(handle->SetHDRMetaData(

@ -206,7 +206,7 @@ fragment float4 bokeh_fragment(FontFragmentIn in [[ stage_in ]],
float rad = 0.1 + 0.5 * siz + sin(pha + siz) / 4.0; float rad = 0.1 + 0.5 * siz + sin(pha + siz) / 4.0;
float2 pos = float2(pox + sin(speed / 15. + pha + siz), - 1.0 - rad + (2.0 + 2.0 * rad) * fract(pha + 0.3 * (speed / 7.) * (0.2 + 0.8 * siz))); float2 pos = float2(pox + sin(speed / 15. + pha + siz), - 1.0 - rad + (2.0 + 2.0 * rad) * fract(pha + 0.3 * (speed / 7.) * (0.2 + 0.8 * siz)));
float dis = length(uv - pos); float dis = length(uv - pos);
if(dis < rad) if (dis < rad)
{ {
float3 col = mix(float3(0.194 * sin(speed / 6.0) + 0.3, 0.2, 0.3 * pha), float3(1.1 * sin(speed / 9.0) + 0.3, 0.2 * pha, 0.4), 0.5 + 0.5 * sin(float(i))); float3 col = mix(float3(0.194 * sin(speed / 6.0) + 0.3, 0.2, 0.3 * pha), float3(1.1 * sin(speed / 9.0) + 0.3, 0.2 * pha, 0.4), 0.5 + 0.5 * sin(float(i)));
color += col.zyx * (1.0 - smoothstep(rad * 0.15, rad, dis)); color += col.zyx * (1.0 - smoothstep(rad * 0.15, rad, dis));
@ -225,22 +225,18 @@ float rand_float(float x)
float snow(float3 pos, float2 uv, float o, float atime) float snow(float3 pos, float2 uv, float o, float atime)
{ {
float2 d = (pos.xy - uv); float2 d = (pos.xy - uv);
float a = atan(d.y / d.x) + sin(atime*1.0 + o) * 10.0; float a = atan(d.y / d.x) + sin(atime*1.0 + o) * 10.0;
float dist = d.x*d.x + d.y*d.y; float dist = d.x*d.x + d.y*d.y;
if(dist < pos.z/400.0) if (dist < pos.z/400.0)
{ {
float col = 0.0; float col = 0.0;
if(sin(a * 8.0) < 0.0) if (sin(a * 8.0) < 0.0)
{ col = 1.0;
col=1.0; if (dist < pos.z/800.0)
} col += 1.0;
if(dist < pos.z/800.0)
{
col+=1.0;
}
return col * pos.z; return col * pos.z;
} }

@ -660,7 +660,7 @@ bool x11_alive(void *data)
* is a key press of the same key combination, * is a key press of the same key combination,
* then it's auto-repeat and the key wasn't * then it's auto-repeat and the key wasn't
* actually released. */ * actually released. */
if(XEventsQueued(g_x11_dpy, QueuedAfterReading)) if (XEventsQueued(g_x11_dpy, QueuedAfterReading))
{ {
XEvent next_event; XEvent next_event;
XPeekEvent(g_x11_dpy, &next_event); XPeekEvent(g_x11_dpy, &next_event);

@ -573,14 +573,14 @@ static void d3d8_get_video_size(d3d8_video_t *d3d,
/* Only valid in PAL mode, not valid for HDTV modes! */ /* Only valid in PAL mode, not valid for HDTV modes! */
if(XGetVideoStandard() == XC_VIDEO_STANDARD_PAL_I) if (XGetVideoStandard() == XC_VIDEO_STANDARD_PAL_I)
{ {
/* Check for 16:9 mode (PAL REGION) */ /* Check for 16:9 mode (PAL REGION) */
if(video_mode & XC_VIDEO_FLAGS_WIDESCREEN) if (video_mode & XC_VIDEO_FLAGS_WIDESCREEN)
{ {
*width = 720; *width = 720;
/* 60 Hz, 720x480i */ /* 60 Hz, 720x480i */
if(video_mode & XC_VIDEO_FLAGS_PAL_60Hz) if (video_mode & XC_VIDEO_FLAGS_PAL_60Hz)
*height = 480; *height = 480;
else /* 50 Hz, 720x576i */ else /* 50 Hz, 720x576i */
*height = 576; *height = 576;
@ -590,7 +590,7 @@ static void d3d8_get_video_size(d3d8_video_t *d3d,
else else
{ {
/* Check for 16:9 mode (NTSC REGIONS) */ /* Check for 16:9 mode (NTSC REGIONS) */
if(video_mode & XC_VIDEO_FLAGS_WIDESCREEN) if (video_mode & XC_VIDEO_FLAGS_WIDESCREEN)
{ {
*width = 720; *width = 720;
*height = 480; *height = 480;
@ -598,23 +598,23 @@ static void d3d8_get_video_size(d3d8_video_t *d3d,
} }
} }
if(XGetAVPack() == XC_AV_PACK_HDTV) if (XGetAVPack() == XC_AV_PACK_HDTV)
{ {
if(video_mode & XC_VIDEO_FLAGS_HDTV_480p) if (video_mode & XC_VIDEO_FLAGS_HDTV_480p)
{ {
*width = 640; *width = 640;
*height = 480; *height = 480;
d3d->widescreen_mode = false; d3d->widescreen_mode = false;
d3d->resolution_hd_enable = true; d3d->resolution_hd_enable = true;
} }
else if(video_mode & XC_VIDEO_FLAGS_HDTV_720p) else if (video_mode & XC_VIDEO_FLAGS_HDTV_720p)
{ {
*width = 1280; *width = 1280;
*height = 720; *height = 720;
d3d->widescreen_mode = true; d3d->widescreen_mode = true;
d3d->resolution_hd_enable = true; d3d->resolution_hd_enable = true;
} }
else if(video_mode & XC_VIDEO_FLAGS_HDTV_1080i) else if (video_mode & XC_VIDEO_FLAGS_HDTV_1080i)
{ {
*width = 1920; *width = 1920;
*height = 1080; *height = 1080;

@ -924,12 +924,12 @@ static bool gl1_gfx_frame(void *data, const void *frame,
#ifdef VITA #ifdef VITA
glUseProgram(0); glUseProgram(0);
bool enabled = glIsEnabled(GL_DEPTH_TEST); bool enabled = glIsEnabled(GL_DEPTH_TEST);
if(enabled) if (enabled)
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
#endif #endif
menu_driver_frame(menu_is_alive, video_info); menu_driver_frame(menu_is_alive, video_info);
#ifdef VITA #ifdef VITA
if(enabled) if (enabled)
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
#endif #endif
} }

@ -690,7 +690,7 @@ static void wiiu_free_shader_preset(wiiu_video_t *wiiu)
MEM2_free(wiiu->pass[i].vs_ubos[1]); MEM2_free(wiiu->pass[i].vs_ubos[1]);
MEM2_free(wiiu->pass[i].ps_ubos[0]); MEM2_free(wiiu->pass[i].ps_ubos[0]);
MEM2_free(wiiu->pass[i].ps_ubos[1]); MEM2_free(wiiu->pass[i].ps_ubos[1]);
if(wiiu->pass[i].mem1) if (wiiu->pass[i].mem1)
MEM1_free(wiiu->pass[i].texture.surface.image); MEM1_free(wiiu->pass[i].texture.surface.image);
else else
MEM2_free(wiiu->pass[i].texture.surface.image); MEM2_free(wiiu->pass[i].texture.surface.image);
@ -779,7 +779,7 @@ static bool wiiu_init_frame_textures(wiiu_video_t *wiiu, unsigned width, unsigne
{ {
for (i = 0; i < wiiu->shader_preset->passes; i++) for (i = 0; i < wiiu->shader_preset->passes; i++)
{ {
if(wiiu->pass[i].mem1) if (wiiu->pass[i].mem1)
MEM1_free(wiiu->pass[i].texture.surface.image); MEM1_free(wiiu->pass[i].texture.surface.image);
else else
MEM2_free(wiiu->pass[i].texture.surface.image); MEM2_free(wiiu->pass[i].texture.surface.image);
@ -932,17 +932,17 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu,
unsigned i; unsigned i;
for (i = 0; i < uniformVarCount; i++) for (i = 0; i < uniformVarCount; i++)
{ {
int k;
float *dst;
const char *id = NULL;
if (uniformVars[i].block != id) if (uniformVars[i].block != id)
continue; continue;
if (!(id = strrchr(uniformVars[i].name, '.')))
const char *id = strrchr(uniformVars[i].name, '.');
if (!id)
continue; continue;
id++; id++;
float *dst = ubo + uniformVars[i].offset; dst = ubo + uniformVars[i].offset;
if (string_is_equal(id, "OutputSize")) if (string_is_equal(id, "OutputSize"))
{ {
@ -964,7 +964,7 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu,
if (string_is_equal(id, "FrameCount")) if (string_is_equal(id, "FrameCount"))
{ {
*dst = wiiu->shader_preset->pass[pass].frame_count_mod ? *dst = wiiu->shader_preset->pass[pass].frame_count_mod ?
frame_count % wiiu->shader_preset->pass[pass].frame_count_mod : frame_count % wiiu->shader_preset->pass[pass].frame_count_mod :
frame_count; frame_count;
*(u32 *)dst = __builtin_bswap32(*(u32 *)dst); *(u32 *)dst = __builtin_bswap32(*(u32 *)dst);
@ -973,7 +973,7 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu,
if (string_is_equal(id, "FrameDirection")) if (string_is_equal(id, "FrameDirection"))
{ {
*dst = frame_direction; *dst = frame_direction;
*(u32 *)dst = __builtin_bswap32(*(u32 *)dst); *(u32 *)dst = __builtin_bswap32(*(u32 *)dst);
continue; continue;
} }
@ -989,7 +989,7 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu,
if (string_is_equal(id, "SourceSize")) if (string_is_equal(id, "SourceSize"))
{ {
GX2Surface *source = (pass > 0) ? &wiiu->pass[pass - 1].texture.surface : &wiiu->texture.surface; GX2Surface *source = (pass > 0) ? &wiiu->pass[pass - 1].texture.surface : &wiiu->texture.surface;
((GX2_vec4 *)dst)->x = source->width; ((GX2_vec4 *)dst)->x = source->width;
((GX2_vec4 *)dst)->y = source->height; ((GX2_vec4 *)dst)->y = source->height;
((GX2_vec4 *)dst)->z = 1.0f / source->width; ((GX2_vec4 *)dst)->z = 1.0f / source->width;
@ -1000,15 +1000,16 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu,
if (!strncmp(id, "OriginalHistorySize", if (!strncmp(id, "OriginalHistorySize",
STRLEN_CONST("OriginalHistorySize"))) STRLEN_CONST("OriginalHistorySize")))
{ {
unsigned index = strtoul(id + STRLEN_CONST("OriginalHistorySize"), GX2Surface *source;
unsigned index = strtoul(id + STRLEN_CONST("OriginalHistorySize"),
NULL, 0); NULL, 0);
if(index > pass) if (index > pass)
index = 0; index = 0;
if(index) if (index)
index = pass - index; index = pass - index;
GX2Surface *source = (index > 0) ? &wiiu->pass[index - 1].texture.surface : &wiiu->texture.surface; source = (index > 0) ? &wiiu->pass[index - 1].texture.surface : &wiiu->texture.surface;
((GX2_vec4 *)dst)->x = source->width; ((GX2_vec4 *)dst)->x = source->width;
((GX2_vec4 *)dst)->y = source->height; ((GX2_vec4 *)dst)->y = source->height;
((GX2_vec4 *)dst)->z = 1.0f / source->width; ((GX2_vec4 *)dst)->z = 1.0f / source->width;
@ -1019,10 +1020,11 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu,
if ((pass > 0 ) && !strncmp(id, "PassOutputSize", if ((pass > 0 ) && !strncmp(id, "PassOutputSize",
STRLEN_CONST("PassOutputSize"))) STRLEN_CONST("PassOutputSize")))
{ {
unsigned index = strtoul(id + STRLEN_CONST("PassOutputSize"), NULL, 0); GX2Surface *output;
if(index > pass - 1) unsigned index = strtoul(id + STRLEN_CONST("PassOutputSize"), NULL, 0);
index = pass - 1; if (index > pass - 1)
GX2Surface *output = &wiiu->pass[index].texture.surface; index = pass - 1;
output = &wiiu->pass[index].texture.surface;
((GX2_vec4 *)dst)->x = output->width; ((GX2_vec4 *)dst)->x = output->width;
((GX2_vec4 *)dst)->y = output->height; ((GX2_vec4 *)dst)->y = output->height;
((GX2_vec4 *)dst)->z = 1.0f / output->width; ((GX2_vec4 *)dst)->z = 1.0f / output->width;
@ -1033,10 +1035,11 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu,
/* feedback not supported yet */ /* feedback not supported yet */
if (!strncmp(id, "PassFeedbackSize", STRLEN_CONST("PassFeedbackSize"))) if (!strncmp(id, "PassFeedbackSize", STRLEN_CONST("PassFeedbackSize")))
{ {
unsigned index = strtoul(id + STRLEN_CONST("PassFeedbackSize"), NULL, 0); GX2Surface *output;
if(index > wiiu->shader_preset->passes - 1) unsigned index = strtoul(id + STRLEN_CONST("PassFeedbackSize"), NULL, 0);
index = wiiu->shader_preset->passes - 1; if (index > wiiu->shader_preset->passes - 1)
GX2Surface *output = &wiiu->pass[index].texture.surface; index = wiiu->shader_preset->passes - 1;
output = &wiiu->pass[index].texture.surface;
((GX2_vec4 *)dst)->x = output->width; ((GX2_vec4 *)dst)->x = output->width;
((GX2_vec4 *)dst)->y = output->height; ((GX2_vec4 *)dst)->y = output->height;
((GX2_vec4 *)dst)->z = 1.0f / output->width; ((GX2_vec4 *)dst)->z = 1.0f / output->width;
@ -1044,13 +1047,13 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu,
continue; continue;
} }
for (int k = 0; k < wiiu->shader_preset->luts; k++) for (k = 0; k < wiiu->shader_preset->luts; k++)
{ {
size_t lut_id_size = strlen(wiiu->shader_preset->lut[k].id); size_t lut_id_size = strlen(wiiu->shader_preset->lut[k].id);
if (!strncmp(id, wiiu->shader_preset->lut[k].id, lut_id_size) if ( !strncmp(id, wiiu->shader_preset->lut[k].id, lut_id_size)
&& !!strcmp(id + lut_id_size, "Size")) && !!strcmp(id + lut_id_size, "Size"))
{ {
GX2Surface *surface = &wiiu->luts[k].surface; GX2Surface *surface = &wiiu->luts[k].surface;
((GX2_vec4 *)dst)->x = surface->width; ((GX2_vec4 *)dst)->x = surface->width;
((GX2_vec4 *)dst)->y = surface->height; ((GX2_vec4 *)dst)->y = surface->height;
((GX2_vec4 *)dst)->z = 1.0f / surface->width; ((GX2_vec4 *)dst)->z = 1.0f / surface->width;
@ -1064,16 +1067,15 @@ static void wiiu_gfx_update_uniform_block(wiiu_video_t *wiiu,
continue; continue;
} }
for (int k = 0; k < wiiu->shader_preset->num_parameters; k++) for (k = 0; k < wiiu->shader_preset->num_parameters; k++)
{ {
if (string_is_equal(id, wiiu->shader_preset->parameters[k].id)) if (string_is_equal(id, wiiu->shader_preset->parameters[k].id))
{ {
*dst = wiiu->shader_preset->parameters[k].current; *dst = wiiu->shader_preset->parameters[k].current;
*(u32 *)dst = __builtin_bswap32(*(u32 *)dst); *(u32 *)dst = __builtin_bswap32(*(u32 *)dst);
break; break;
} }
} }
} }
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, ubo, size); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, ubo, size);
@ -1122,13 +1124,13 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
wiiu_gfx_update_viewport(wiiu); wiiu_gfx_update_viewport(wiiu);
GX2ClearColor(&wiiu->color_buffer, 0.0f, 0.0f, 0.0f, 1.0f); GX2ClearColor(&wiiu->color_buffer, 0.0f, 0.0f, 0.0f, 1.0f);
/* can't call GX2ClearColor after GX2SetContextState for whatever reason */ /* Can't call GX2ClearColor after GX2SetContextState for whatever reason */
GX2SetContextState(wiiu->ctx_state); GX2SetContextState(wiiu->ctx_state);
if (frame) if (frame)
{ {
if ((width != wiiu->texture.surface.width) || if ( (width != wiiu->texture.surface.width)
(height != wiiu->texture.surface.height)) || (height != wiiu->texture.surface.height))
wiiu_init_frame_textures(wiiu, width, height); wiiu_init_frame_textures(wiiu, width, height);
wiiu->width = width; wiiu->width = width;
@ -1221,6 +1223,7 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
for (j = 0; j < wiiu->pass[i].gfd->ps->samplerVarCount; j++) for (j = 0; j < wiiu->pass[i].gfd->ps->samplerVarCount; j++)
{ {
int k;
if (string_is_equal(wiiu->pass[i].gfd->ps->samplerVars[j].name, "Source")) if (string_is_equal(wiiu->pass[i].gfd->ps->samplerVars[j].name, "Source"))
{ {
GX2SetPixelTexture(texture, wiiu->pass[i].gfd->ps->samplerVars[j].location); GX2SetPixelTexture(texture, wiiu->pass[i].gfd->ps->samplerVars[j].location);
@ -1243,14 +1246,14 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
if (!strncmp(wiiu->pass[i].gfd->ps->samplerVars[j].name, "OriginalHistory", STRLEN_CONST("OriginalHistory"))) if (!strncmp(wiiu->pass[i].gfd->ps->samplerVars[j].name, "OriginalHistory", STRLEN_CONST("OriginalHistory")))
{ {
unsigned index = strtoul(wiiu->pass[i].gfd->ps->samplerVars[j].name + STRLEN_CONST("OriginalHistory"), NULL, 0); GX2Texture *source;
if(index > i) unsigned index = strtoul(wiiu->pass[i].gfd->ps->samplerVars[j].name + STRLEN_CONST("OriginalHistory"), NULL, 0);
index = 0; if (index > i)
index = 0;
if (index)
index = i - index;
if(index) source = (index > 0) ? &wiiu->pass[index - 1].texture : &wiiu->texture;
index = i - index;
GX2Texture *source = (index > 0) ? &wiiu->pass[index - 1].texture : &wiiu->texture;
GX2SetPixelTexture(source, wiiu->pass[i].gfd->ps->samplerVars[j].location); GX2SetPixelTexture(source, wiiu->pass[i].gfd->ps->samplerVars[j].location);
GX2SetPixelSampler(wiiu->shader_preset->pass[index].filter ? GX2SetPixelSampler(wiiu->shader_preset->pass[index].filter ?
&wiiu->sampler_linear[wiiu->shader_preset->pass[index].wrap] : &wiiu->sampler_linear[wiiu->shader_preset->pass[index].wrap] :
@ -1262,8 +1265,8 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
if ((i > 0) && !strncmp(wiiu->pass[i].gfd->ps->samplerVars[j].name, "PassOutput", STRLEN_CONST("PassOutput"))) if ((i > 0) && !strncmp(wiiu->pass[i].gfd->ps->samplerVars[j].name, "PassOutput", STRLEN_CONST("PassOutput")))
{ {
unsigned index = strtoul(wiiu->pass[i].gfd->ps->samplerVars[j].name + STRLEN_CONST("PassOutput"), NULL, 0); unsigned index = strtoul(wiiu->pass[i].gfd->ps->samplerVars[j].name + STRLEN_CONST("PassOutput"), NULL, 0);
if(index > i - 1) if (index > i - 1)
index = i - 1; index = i - 1;
GX2SetPixelTexture(&wiiu->pass[index].texture, wiiu->pass[i].gfd->ps->samplerVars[j].location); GX2SetPixelTexture(&wiiu->pass[index].texture, wiiu->pass[i].gfd->ps->samplerVars[j].location);
GX2SetPixelSampler(wiiu->shader_preset->pass[index].filter ? GX2SetPixelSampler(wiiu->shader_preset->pass[index].filter ?
&wiiu->sampler_linear[wiiu->shader_preset->pass[index].wrap] : &wiiu->sampler_linear[wiiu->shader_preset->pass[index].wrap] :
@ -1276,8 +1279,8 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
if (!strncmp(wiiu->pass[i].gfd->ps->samplerVars[j].name, "PassFeedback", STRLEN_CONST("PassFeedback"))) if (!strncmp(wiiu->pass[i].gfd->ps->samplerVars[j].name, "PassFeedback", STRLEN_CONST("PassFeedback")))
{ {
unsigned index = strtoul(wiiu->pass[i].gfd->ps->samplerVars[j].name + STRLEN_CONST("PassFeedback"), NULL, 0); unsigned index = strtoul(wiiu->pass[i].gfd->ps->samplerVars[j].name + STRLEN_CONST("PassFeedback"), NULL, 0);
if(index > wiiu->shader_preset->passes - 1) if (index > wiiu->shader_preset->passes - 1)
index = wiiu->shader_preset->passes - 1; index = wiiu->shader_preset->passes - 1;
GX2SetPixelTexture(&wiiu->pass[index].texture, wiiu->pass[i].gfd->ps->samplerVars[j].location); GX2SetPixelTexture(&wiiu->pass[index].texture, wiiu->pass[i].gfd->ps->samplerVars[j].location);
GX2SetPixelSampler(wiiu->shader_preset->pass[i].filter ? GX2SetPixelSampler(wiiu->shader_preset->pass[i].filter ?
@ -1287,7 +1290,7 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
continue; continue;
} }
for (int k = 0; k < wiiu->shader_preset->luts; k++) for (k = 0; k < wiiu->shader_preset->luts; k++)
{ {
if (wiiu->luts[k].surface.image if (wiiu->luts[k].surface.image
&& string_is_equal(wiiu->pass[i].gfd->ps->samplerVars[j].name, wiiu->shader_preset->lut[k].id)) && string_is_equal(wiiu->pass[i].gfd->ps->samplerVars[j].name, wiiu->shader_preset->lut[k].id))
@ -1300,7 +1303,6 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
} }
} }
} }
if (wiiu->pass[i].color_buffer.surface.image) if (wiiu->pass[i].color_buffer.surface.image)
@ -1440,22 +1442,10 @@ static void wiiu_gfx_set_nonblock_state(void *data, bool toggle,
GX2SetSwapInterval(!toggle); /* do we need this ? */ GX2SetSwapInterval(!toggle); /* do we need this ? */
} }
static bool wiiu_gfx_alive(void *data) static bool wiiu_gfx_alive(void *data) { return true; }
{ static bool wiiu_gfx_focus(void *data) { return true; }
(void)data;
return true;
}
static bool wiiu_gfx_focus(void *data)
{
(void)data;
return true;
}
static bool wiiu_gfx_suppress_screensaver(void *data, bool enable) static bool wiiu_gfx_suppress_screensaver(void *data, bool enable)
{ {
(void)data;
(void)enable;
return false; return false;
} }
@ -1471,100 +1461,100 @@ static bool wiiu_gfx_set_shader(void *data,
GX2DrawDone(); GX2DrawDone();
wiiu_free_shader_preset(wiiu); wiiu_free_shader_preset(wiiu);
if (string_is_empty(path)) if (!string_is_empty(path))
return true;
if (type != RARCH_SHADER_SLANG)
{ {
RARCH_WARN("[GX2] Only Slang shaders are supported. Falling back to stock.\n"); if (type != RARCH_SHADER_SLANG)
return false;
}
wiiu->shader_preset = calloc(1, sizeof(*wiiu->shader_preset));
if (!video_shader_load_preset_into_shader(path, wiiu->shader_preset))
{
free(wiiu->shader_preset);
wiiu->shader_preset = NULL;
return false;
}
for (i = 0; i < wiiu->shader_preset->passes; i++)
{
unsigned j;
char *ptr;
char gfdpath[PATH_MAX_LENGTH];
struct video_shader_pass *pass = &wiiu->shader_preset->pass[i];
strlcpy(gfdpath, pass->source.path, sizeof(gfdpath));
if (!(ptr = strrchr(gfdpath, '.')))
ptr = gfdpath + strlen(gfdpath);
*ptr++ = '.';
*ptr++ = 'g';
*ptr++ = 's';
*ptr++ = 'h';
*ptr++ = '\0';
wiiu->pass[i].gfd = gfd_open(gfdpath);
if (!wiiu->pass[i].gfd)
{ {
wiiu_free_shader_preset(wiiu); RARCH_WARN("[GX2] Only Slang shaders are supported. Falling back to stock.\n");
return false; return false;
} }
for (j = 0; j < 2 && j < wiiu->pass[i].gfd->vs->uniformBlockCount; j++) wiiu->shader_preset = calloc(1, sizeof(*wiiu->shader_preset));
if (!video_shader_load_preset_into_shader(path, wiiu->shader_preset))
{ {
wiiu->pass[i].vs_ubos[j] = MEM2_alloc(wiiu->pass[i].gfd->vs->uniformBlocks[j].size, free(wiiu->shader_preset);
GX2_UNIFORM_BLOCK_ALIGNMENT); wiiu->shader_preset = NULL;
memset(wiiu->pass[i].vs_ubos[j], 0, wiiu->pass[i].gfd->vs->uniformBlocks[j].size); return false;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->pass[i].vs_ubos[j],
wiiu->pass[i].gfd->vs->uniformBlocks[j].size);
} }
for (j = 0; j < 2 && j < wiiu->pass[i].gfd->ps->uniformBlockCount; j++) for (i = 0; i < wiiu->shader_preset->passes; i++)
{
wiiu->pass[i].ps_ubos[j] = MEM2_alloc(wiiu->pass[i].gfd->ps->uniformBlocks[j].size,
GX2_UNIFORM_BLOCK_ALIGNMENT);
memset(wiiu->pass[i].ps_ubos[j], 0, wiiu->pass[i].gfd->ps->uniformBlocks[j].size);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->pass[i].ps_ubos[j],
wiiu->pass[i].gfd->ps->uniformBlocks[j].size);
}
}
for (i = 0; i < wiiu->shader_preset->luts; i++)
{
struct texture_image image = {};
if (image_texture_load(&image, wiiu->shader_preset->lut[i].path))
{ {
unsigned j; unsigned j;
char *ptr;
char gfdpath[PATH_MAX_LENGTH];
struct video_shader_pass *pass = &wiiu->shader_preset->pass[i];
wiiu->luts[i].surface.width = image.width; strlcpy(gfdpath, pass->source.path, sizeof(gfdpath));
wiiu->luts[i].surface.height = image.height;
wiiu->luts[i].surface.depth = 1;
wiiu->luts[i].surface.dim = GX2_SURFACE_DIM_TEXTURE_2D;
wiiu->luts[i].surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED;
wiiu->luts[i].viewNumSlices = 1;
wiiu->luts[i].surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8; if (!(ptr = strrchr(gfdpath, '.')))
wiiu->luts[i].compMap = GX2_COMP_SEL(_G, _B, _A, _R); ptr = gfdpath + strlen(gfdpath);
GX2CalcSurfaceSizeAndAlignment(&wiiu->luts[i].surface); *ptr++ = '.';
GX2InitTextureRegs(&wiiu->luts[i]); *ptr++ = 'g';
wiiu->luts[i].surface.image = MEM2_alloc(wiiu->luts[i].surface.imageSize, *ptr++ = 's';
wiiu->luts[i].surface.alignment); *ptr++ = 'h';
*ptr++ = '\0';
for (j = 0; (j < image.height) && (j < wiiu->luts[i].surface.height); j++) wiiu->pass[i].gfd = gfd_open(gfdpath);
memcpy((uint32_t *)wiiu->luts[i].surface.image + (j * wiiu->luts[i].surface.pitch),
image.pixels + (j * image.width), image.width * sizeof(image.pixels));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->luts[i].surface.image, if (!wiiu->pass[i].gfd)
wiiu->luts[i].surface.imageSize); {
wiiu_free_shader_preset(wiiu);
return false;
}
image_texture_free(&image); for (j = 0; j < 2 && j < wiiu->pass[i].gfd->vs->uniformBlockCount; j++)
{
wiiu->pass[i].vs_ubos[j] = MEM2_alloc(wiiu->pass[i].gfd->vs->uniformBlocks[j].size,
GX2_UNIFORM_BLOCK_ALIGNMENT);
memset(wiiu->pass[i].vs_ubos[j], 0, wiiu->pass[i].gfd->vs->uniformBlocks[j].size);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->pass[i].vs_ubos[j],
wiiu->pass[i].gfd->vs->uniformBlocks[j].size);
}
for (j = 0; j < 2 && j < wiiu->pass[i].gfd->ps->uniformBlockCount; j++)
{
wiiu->pass[i].ps_ubos[j] = MEM2_alloc(wiiu->pass[i].gfd->ps->uniformBlocks[j].size,
GX2_UNIFORM_BLOCK_ALIGNMENT);
memset(wiiu->pass[i].ps_ubos[j], 0, wiiu->pass[i].gfd->ps->uniformBlocks[j].size);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_UNIFORM_BLOCK, wiiu->pass[i].ps_ubos[j],
wiiu->pass[i].gfd->ps->uniformBlocks[j].size);
}
}
for (i = 0; i < wiiu->shader_preset->luts; i++)
{
struct texture_image image = {};
if (image_texture_load(&image, wiiu->shader_preset->lut[i].path))
{
unsigned j;
wiiu->luts[i].surface.width = image.width;
wiiu->luts[i].surface.height = image.height;
wiiu->luts[i].surface.depth = 1;
wiiu->luts[i].surface.dim = GX2_SURFACE_DIM_TEXTURE_2D;
wiiu->luts[i].surface.tileMode = GX2_TILE_MODE_LINEAR_ALIGNED;
wiiu->luts[i].viewNumSlices = 1;
wiiu->luts[i].surface.format = GX2_SURFACE_FORMAT_UNORM_R8_G8_B8_A8;
wiiu->luts[i].compMap = GX2_COMP_SEL(_G, _B, _A, _R);
GX2CalcSurfaceSizeAndAlignment(&wiiu->luts[i].surface);
GX2InitTextureRegs(&wiiu->luts[i]);
wiiu->luts[i].surface.image = MEM2_alloc(wiiu->luts[i].surface.imageSize,
wiiu->luts[i].surface.alignment);
for (j = 0; (j < image.height) && (j < wiiu->luts[i].surface.height); j++)
memcpy((uint32_t *)wiiu->luts[i].surface.image + (j * wiiu->luts[i].surface.pitch),
image.pixels + (j * image.width), image.width * sizeof(image.pixels));
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->luts[i].surface.image,
wiiu->luts[i].surface.imageSize);
image_texture_free(&image);
}
} }
} }
@ -1712,13 +1702,13 @@ static void wiiu_gfx_set_texture_frame(void *data,
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->menu.texture.surface.image, GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, wiiu->menu.texture.surface.image,
wiiu->menu.texture.surface.imageSize); wiiu->menu.texture.surface.imageSize);
wiiu->menu.v->pos.x = wiiu->vp.x; wiiu->menu.v->pos.x = wiiu->vp.x;
wiiu->menu.v->pos.y = wiiu->vp.y; wiiu->menu.v->pos.y = wiiu->vp.y;
wiiu->menu.v->pos.width = wiiu->vp.width; wiiu->menu.v->pos.width = wiiu->vp.width;
wiiu->menu.v->pos.height = wiiu->vp.height; wiiu->menu.v->pos.height = wiiu->vp.height;
wiiu->menu.v->coord.u = 0.0f; wiiu->menu.v->coord.u = 0.0f;
wiiu->menu.v->coord.v = 0.0f; wiiu->menu.v->coord.v = 0.0f;
wiiu->menu.v->coord.width = (float)width / wiiu->menu.texture.surface.width; wiiu->menu.v->coord.width = (float)width / wiiu->menu.texture.surface.width;
wiiu->menu.v->coord.height = (float)height / wiiu->menu.texture.surface.height; wiiu->menu.v->coord.height = (float)height / wiiu->menu.texture.surface.height;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->menu.v, 4 * sizeof(*wiiu->menu.v)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->menu.v, 4 * sizeof(*wiiu->menu.v));
@ -1784,18 +1774,13 @@ static const video_poke_interface_t wiiu_poke_interface = {
}; };
static void wiiu_gfx_get_poke_interface(void *data, static void wiiu_gfx_get_poke_interface(void *data,
const video_poke_interface_t **iface) const video_poke_interface_t **iface)
{ {
(void)data;
*iface = &wiiu_poke_interface; *iface = &wiiu_poke_interface;
} }
#ifdef HAVE_GFX_WIDGETS #ifdef HAVE_GFX_WIDGETS
static bool wiiu_gfx_widgets_enabled(void *data) static bool wiiu_gfx_widgets_enabled(void *data) { return true; }
{
(void)data;
return true;
}
#endif #endif
video_driver_t video_wiiu = video_driver_t video_wiiu =

@ -118,13 +118,13 @@ static u32 __VISendI2CData(u8 addr,void *val,u32 len)
s32 i,j; s32 i,j;
u32 level,ret; u32 level,ret;
if(i2cIdentFirst==0) if (i2cIdentFirst==0)
{ {
__viOpenI2C(0); __viOpenI2C(0);
udelay(4); udelay(4);
i2cIdentFlag = 0; i2cIdentFlag = 0;
if(__viGetSDA()!=0) if (__viGetSDA()!=0)
i2cIdentFlag = 1; i2cIdentFlag = 1;
i2cIdentFirst = 1; i2cIdentFirst = 1;
} }
@ -137,9 +137,7 @@ static u32 __VISendI2CData(u8 addr,void *val,u32 len)
__viSetSDA(i2cIdentFlag); __viSetSDA(i2cIdentFlag);
udelay(4); udelay(4);
ret = __sendSlaveAddress(addr); if ((ret = __sendSlaveAddress(addr)) == 0)
if(ret == 0)
{ {
_CPU_ISR_Restore(level); _CPU_ISR_Restore(level);
return 0; return 0;
@ -151,7 +149,7 @@ static u32 __VISendI2CData(u8 addr,void *val,u32 len)
c = ((u8*)val)[i]; c = ((u8*)val)[i];
for(j=0;j<8;j++) for(j=0;j<8;j++)
{ {
if(c&0x80) if (c&0x80)
__viSetSDA(i2cIdentFlag); __viSetSDA(i2cIdentFlag);
else else
__viSetSDA(i2cIdentFlag^1); __viSetSDA(i2cIdentFlag^1);
@ -168,7 +166,7 @@ static u32 __VISendI2CData(u8 addr,void *val,u32 len)
__viSetSCL(1); __viSetSCL(1);
udelay(2); udelay(2);
if(i2cIdentFlag == 1 && __viGetSDA()!=0) if (i2cIdentFlag == 1 && __viGetSDA()!=0)
{ {
_CPU_ISR_Restore(level); _CPU_ISR_Restore(level);
return 0; return 0;
@ -407,7 +405,8 @@ static const u8 gamma_coeffs[][33] =
void VIDEO_SetGamma(int gamma) void VIDEO_SetGamma(int gamma)
{ {
gamma = MAX(0,MIN(30,gamma)); u8 *data;
u8 *data = (u8 *)&gamma_coeffs[gamma][0]; gamma = MAX(0,MIN(30,gamma));
data = (u8 *)&gamma_coeffs[gamma][0];
__VIWriteI2CRegisterBuf(0x10, 0x21, data); __VIWriteI2CRegisterBuf(0x10, 0x21, data);
} }

@ -402,7 +402,7 @@ static void *psp_init(const video_info_t *video,
psp->vsync = video->vsync; psp->vsync = video->vsync;
psp->rgb32 = video->rgb32; psp->rgb32 = video->rgb32;
if(psp->rgb32) if (psp->rgb32)
{ {
u32 i; u32 i;
uint32_t* LUT_r_local = (uint32_t*)(SCEGU_VRAM_BP32_2); uint32_t* LUT_r_local = (uint32_t*)(SCEGU_VRAM_BP32_2);
@ -620,7 +620,7 @@ static bool psp_frame(void *data, const void *frame,
menu_driver_frame(menu_is_alive, video_info); menu_driver_frame(menu_is_alive, video_info);
#endif #endif
if(psp->menu.active) if (psp->menu.active)
{ {
sceGuSendList(GU_TAIL, psp->menu.dList, &(psp->menu.context_storage)); sceGuSendList(GU_TAIL, psp->menu.dList, &(psp->menu.context_storage));
sceGuSync(0, 0); sceGuSync(0, 0);
@ -646,7 +646,7 @@ static void psp_free(void *data)
{ {
psp1_video_t *psp = (psp1_video_t*)data; psp1_video_t *psp = (psp1_video_t*)data;
if(!(psp) || !(psp->main_dList)) if (!(psp) || !(psp->main_dList))
return; return;
sceDisplayWaitVblankStart(); sceDisplayWaitVblankStart();

@ -777,7 +777,7 @@ static void rsx_unload_texture(void *data,
{ {
#if 0 #if 0
/* TODO fix crash on loading core */ /* TODO fix crash on loading core */
if(texture->data) if (texture->data)
rsxFree(texture->data); rsxFree(texture->data);
#endif #endif
free(texture); free(texture);
@ -1177,7 +1177,7 @@ static bool rsx_frame(void* data, const void* frame,
vp.offset[3] = 0.0f; vp.offset[3] = 0.0f;
rsxSetViewport(gcm->context, vp.x, vp.y, vp.w, vp.h, vp.min, vp.max, vp.scale, vp.offset); rsxSetViewport(gcm->context, vp.x, vp.y, vp.w, vp.h, vp.min, vp.max, vp.scale, vp.offset);
if(frame && width && height) if (frame && width && height)
{ {
gcm->tex_index = ((gcm->tex_index + 1) % RSX_MAX_TEXTURES); gcm->tex_index = ((gcm->tex_index + 1) % RSX_MAX_TEXTURES);
rsx_load_texture_data(gcm, &gcm->texture[gcm->tex_index], frame, width, height, pitch, gcm->rgb32, false, rsx_load_texture_data(gcm, &gcm->texture[gcm->tex_index], frame, width, height, pitch, gcm->rgb32, false,
@ -1324,7 +1324,7 @@ static void rsx_set_aspect_ratio(void* data, unsigned aspect_ratio_idx)
{ {
rsx_t* gcm = (rsx_t*)data; rsx_t* gcm = (rsx_t*)data;
if(!gcm) if (!gcm)
return; return;
gcm->keep_aspect = true; gcm->keep_aspect = true;

@ -174,10 +174,10 @@ static bool switch_frame(void *data, const void *frame,
for (x = 0; x < 1280; x++) for (x = 0; x < 1280; x++)
sw->image[y*1280+x] = 0xFF000000; sw->image[y*1280+x] = 0xFF000000;
if(width > 0 && height > 0) if (width > 0 && height > 0)
{ {
if(sw->last_width != width || if ( (sw->last_width != width)
sw->last_height != height) || (sw->last_height != height))
{ {
scaler_ctx_gen_reset(&sw->scaler); scaler_ctx_gen_reset(&sw->scaler);
@ -193,7 +193,7 @@ static bool switch_frame(void *data, const void *frame,
sw->scaler.scaler_type = SCALER_TYPE_POINT; sw->scaler.scaler_type = SCALER_TYPE_POINT;
if(!scaler_ctx_gen_filter(&sw->scaler)) if (!scaler_ctx_gen_filter(&sw->scaler))
{ {
RARCH_ERR("failed to generate scaler for main image\n"); RARCH_ERR("failed to generate scaler for main image\n");
return false; return false;
@ -245,11 +245,11 @@ static bool switch_frame(void *data, const void *frame,
#endif #endif
r = surface_dequeue_buffer(&sw->surface, &out_buffer); r = surface_dequeue_buffer(&sw->surface, &out_buffer);
if(r != RESULT_OK) if (r != RESULT_OK)
return true; /* just skip the frame */ return true; /* just skip the frame */
r = surface_wait_buffer(&sw->surface); r = surface_wait_buffer(&sw->surface);
if(r != RESULT_OK) if (r != RESULT_OK)
return true; return true;
gfx_slow_swizzling_blit(out_buffer, sw->image, 1280, 720, 0, 0); gfx_slow_swizzling_blit(out_buffer, sw->image, 1280, 720, 0, 0);

@ -171,7 +171,7 @@ static bool vita2d_gfx_frame(void *data, const void *frame,
if (frame) if (frame)
{ {
if(!(vita->texture&&vita2d_texture_get_datap(vita->texture)==frame)) if (!(vita->texture&&vita2d_texture_get_datap(vita->texture)==frame))
{ {
unsigned i; unsigned i;
unsigned int stride; unsigned int stride;
@ -252,7 +252,7 @@ static bool vita2d_gfx_frame(void *data, const void *frame,
menu_driver_frame(menu_is_alive, video_info); menu_driver_frame(menu_is_alive, video_info);
#endif #endif
if(vita->menu.texture) if (vita->menu.texture)
{ {
if (vita->fullscreen) if (vita->fullscreen)
vita2d_draw_texture_scale(vita->menu.texture, vita2d_draw_texture_scale(vita->menu.texture,
@ -297,7 +297,7 @@ static bool vita2d_gfx_frame(void *data, const void *frame,
gfx_widgets_frame(video_info); gfx_widgets_frame(video_info);
#endif #endif
if(!string_is_empty(msg)) if (!string_is_empty(msg))
font_driver_render_msg(vita, msg, NULL, NULL); font_driver_render_msg(vita, msg, NULL, NULL);
vita2d_end_drawing(); vita2d_end_drawing();
@ -782,7 +782,7 @@ static bool vita_get_current_sw_framebuffer(void *data,
if (!vita->texture || vita->width != framebuffer->width || if (!vita->texture || vita->width != framebuffer->width ||
vita->height != framebuffer->height) vita->height != framebuffer->height)
{ {
if(vita->texture) if (vita->texture)
{ {
vita2d_wait_rendering_done(); vita2d_wait_rendering_done();
vita2d_free_texture(vita->texture); vita2d_free_texture(vita->texture);

@ -24,7 +24,7 @@ vec3 InverseTonemap(vec3 sdr)
{ {
vec3 hdr; vec3 hdr;
if(global.inverse_tonemap > 0.0f) if (global.inverse_tonemap > 0.0f)
{ {
sdr = pow(abs(sdr), vec3(global.contrast / 2.2f)); /* Display Gamma - needs to be determined by calibration screen */ sdr = pow(abs(sdr), vec3(global.contrast / 2.2f)); /* Display Gamma - needs to be determined by calibration screen */
@ -83,23 +83,19 @@ vec3 Hdr10(vec3 hdr)
{ {
vec3 hdr10; vec3 hdr10;
if(global.hdr10 > 0.0f) if (global.hdr10 > 0.0f)
{ {
/* Now convert into HDR10 */ /* Now convert into HDR10 */
vec3 rec2020 = hdr * k709to2020; vec3 rec2020 = hdr * k709to2020;
if(global.expand_gamut > 0.0f) if (global.expand_gamut > 0.0f)
{ rec2020 = hdr * kExpanded709to2020;
rec2020 = hdr * kExpanded709to2020;
}
vec3 linearColour = rec2020 * (global.paper_white_nits / kMaxNitsFor2084); vec3 linearColour = rec2020 * (global.paper_white_nits / kMaxNitsFor2084);
hdr10 = LinearToST2084(linearColour); hdr10 = LinearToST2084(linearColour);
} }
else else
{
hdr10 = hdr; hdr10 = hdr;
}
return hdr10; return hdr10;
} }

@ -28,7 +28,7 @@ for( int i=0; i < 8; i++ )
float rad = 0.1 + 0.5 * siz + sin(pha + siz) / 4.0; float rad = 0.1 + 0.5 * siz + sin(pha + siz) / 4.0;
vec2 pos = vec2(pox + sin(speed / 15. + pha + siz), - 1.0 - rad + (2.0 + 2.0 * rad) * fract(pha + 0.3 * (speed / 7.) * (0.2 + 0.8 * siz))); vec2 pos = vec2(pox + sin(speed / 15. + pha + siz), - 1.0 - rad + (2.0 + 2.0 * rad) * fract(pha + 0.3 * (speed / 7.) * (0.2 + 0.8 * siz)));
float dis = length(uv - pos); float dis = length(uv - pos);
if(dis < rad) if (dis < rad)
{ {
vec3 col = mix(vec3(0.194 * sin(speed / 6.0) + 0.3, 0.2, 0.3 * pha), vec3(1.1 * sin(speed / 9.0) + 0.3, 0.2 * pha, 0.4), 0.5 + 0.5 * sin(float(i))); vec3 col = mix(vec3(0.194 * sin(speed / 6.0) + 0.3, 0.2, 0.3 * pha), vec3(1.1 * sin(speed / 9.0) + 0.3, 0.2 * pha, 0.4), 0.5 + 0.5 * sin(float(i)));
color += col.zyx * (1.0 - smoothstep(rad * 0.15, rad, dis)); color += col.zyx * (1.0 - smoothstep(rad * 0.15, rad, dis));

@ -132,7 +132,7 @@ static void *gfx_ctx_qnx_init(void *video_driver)
goto error; goto error;
#endif #endif
if(!screen_win) if (!screen_win)
{ {
if (screen_create_window(&screen_win, screen_ctx)) if (screen_create_window(&screen_win, screen_ctx))
{ {
@ -308,7 +308,7 @@ static int dpi_get_density(qnx_ctx_data_t *qnx)
{ {
int screen_dpi[2]; int screen_dpi[2];
if(!qnx) if (!qnx)
return -1; return -1;
if (screen_get_display_property_iv(qnx->screen_disp, if (screen_get_display_property_iv(qnx->screen_disp,

@ -216,7 +216,7 @@ static void d3d12_font_render_line(
font->atlas->dirty = false; font->atlas->dirty = false;
} }
if(font->texture.dirty) if (font->texture.dirty)
d3d12_upload_texture(d3d12->queue.cmd, &font->texture, d3d12_upload_texture(d3d12->queue.cmd, &font->texture,
d3d12); d3d12);

@ -213,7 +213,7 @@ static void wiiu_font_render_line(
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.v + wiiu->vertex_cache.current, count * sizeof(wiiu->vertex_cache.v)); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.v + wiiu->vertex_cache.current, count * sizeof(wiiu->vertex_cache.v));
if(font->atlas->dirty) if (font->atlas->dirty)
{ {
for (i = 0; (i < font->atlas->height) && (i < font->texture.surface.height); i++) for (i = 0; (i < font->atlas->height) && (i < font->texture.surface.height); i++)
memcpy(font->texture.surface.image + (i * font->texture.surface.pitch), memcpy(font->texture.surface.image + (i * font->texture.surface.pitch),

@ -300,11 +300,11 @@ static bool gl_glsl_load_binary_shader(GLuint shader, char *save_path)
GLint status; GLint status;
FILE *shader_binary = fopen(save_path, "rb" ); FILE *shader_binary = fopen(save_path, "rb" );
if(shader_binary) if (shader_binary)
{ {
char *shader_data = NULL; char *shader_data = NULL;
fseek (shader_binary, 0, SEEK_END); fseek(shader_binary, 0, SEEK_END);
shader_size=ftell (shader_binary); shader_size=ftell (shader_binary);
fseek(shader_binary, 0, SEEK_SET); fseek(shader_binary, 0, SEEK_SET);
@ -414,7 +414,7 @@ static bool gl_glsl_compile_shader(glsl_shader_data_t *glsl,
gl_glsl_hash_shader(source, ARRAY_SIZE(source)); gl_glsl_hash_shader(source, ARRAY_SIZE(source));
snprintf(save_path, sizeof(save_path), snprintf(save_path, sizeof(save_path),
"/data/retroarch/temp/%lx.sb", hash); "/data/retroarch/temp/%lx.sb", hash);
if(gl_glsl_load_binary_shader(shader, save_path)) if (gl_glsl_load_binary_shader(shader, save_path))
return true; return true;
} }
#endif #endif
@ -427,7 +427,7 @@ static bool gl_glsl_compile_shader(glsl_shader_data_t *glsl,
#if 0 #if 0
#if defined(ORBIS) #if defined(ORBIS)
if(status == GL_TRUE) if (status == GL_TRUE)
gl_glsl_dump_shader(shader, save_path); gl_glsl_dump_shader(shader, save_path);
#endif #endif
#endif #endif

@ -68,21 +68,18 @@ static void *twoxsai_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
(void)config;
(void)userdata;
if (!filt) if (!filt)
return NULL; return NULL;
filt->workers = (struct softfilter_thread_data*) if (!(filt->workers = (struct softfilter_thread_data*)
calloc(threads, sizeof(struct softfilter_thread_data)); calloc(threads, sizeof(struct softfilter_thread_data))))
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
return filt; return filt;
} }
@ -90,7 +87,7 @@ static void twoxsai_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width * TWOXSAI_SCALE; *out_width = width * TWOXSAI_SCALE;
*out_height = height * TWOXSAI_SCALE; *out_height = height * TWOXSAI_SCALE;
} }
@ -143,30 +140,22 @@ static void twoxsai_generic_destroy(void *data)
if ((colorA == colorE && colorB == colorL) || (colorA == colorC && colorA == colorF && colorB != colorE && colorB == colorJ)) \ if ((colorA == colorE && colorB == colorL) || (colorA == colorC && colorA == colorF && colorB != colorE && colorB == colorJ)) \
product = colorA; \ product = colorA; \
else \ else \
{ \
product = interpolate_cb(colorA, colorB); \ product = interpolate_cb(colorA, colorB); \
} \
if ((colorA == colorG && colorC == colorO) || (colorA == colorB && colorA == colorH && colorG != colorC && colorC == colorM)) \ if ((colorA == colorG && colorC == colorO) || (colorA == colorB && colorA == colorH && colorG != colorC && colorC == colorM)) \
product1 = colorA; \ product1 = colorA; \
else \ else \
{ \
product1 = interpolate_cb(colorA, colorC); \ product1 = interpolate_cb(colorA, colorC); \
} \
product2 = colorA; \ product2 = colorA; \
} else if (colorB == colorC && colorA != colorD) \ } else if (colorB == colorC && colorA != colorD) \
{ \ { \
if ((colorB == colorF && colorA == colorH) || (colorB == colorE && colorB == colorD && colorA != colorF && colorA == colorI)) \ if ((colorB == colorF && colorA == colorH) || (colorB == colorE && colorB == colorD && colorA != colorF && colorA == colorI)) \
product = colorB; \ product = colorB; \
else \ else \
{ \
product = interpolate_cb(colorA, colorB); \ product = interpolate_cb(colorA, colorB); \
} \
if ((colorC == colorH && colorA == colorF) || (colorC == colorG && colorC == colorD && colorA != colorH && colorA == colorI)) \ if ((colorC == colorH && colorA == colorF) || (colorC == colorG && colorC == colorD && colorA != colorH && colorA == colorI)) \
product1 = colorC; \ product1 = colorC; \
else \ else \
{ \
product1 = interpolate_cb(colorA, colorC); \ product1 = interpolate_cb(colorA, colorC); \
} \
product2 = colorB; \ product2 = colorB; \
} \ } \
else if (colorA == colorD && colorB == colorC) \ else if (colorA == colorD && colorB == colorC) \
@ -179,21 +168,19 @@ static void twoxsai_generic_destroy(void *data)
} \ } \
else \ else \
{ \ { \
int r = 0; \ int r = 0; \
product1 = interpolate_cb(colorA, colorC); \ product1 = interpolate_cb(colorA, colorC); \
product = interpolate_cb(colorA, colorB); \ product = interpolate_cb(colorA, colorB); \
r += result_cb(colorA, colorB, colorG, colorE); \ r += result_cb(colorA, colorB, colorG, colorE); \
r += result_cb(colorB, colorA, colorK, colorF); \ r += result_cb(colorB, colorA, colorK, colorF); \
r += result_cb(colorB, colorA, colorH, colorN); \ r += result_cb(colorB, colorA, colorH, colorN); \
r += result_cb(colorA, colorB, colorL, colorO); \ r += result_cb(colorA, colorB, colorL, colorO); \
if (r > 0) \ if (r > 0) \
product2 = colorA; \ product2 = colorA; \
else if (r < 0) \ else if (r < 0) \
product2 = colorB; \ product2 = colorB; \
else \ else \
{ \
product2 = interpolate2_cb(colorA, colorB, colorC, colorD); \ product2 = interpolate2_cb(colorA, colorB, colorC, colorD); \
} \
} \ } \
} \ } \
else \ else \
@ -204,21 +191,17 @@ static void twoxsai_generic_destroy(void *data)
else if (colorB == colorE && colorB == colorD && colorA != colorF && colorA == colorI) \ else if (colorB == colorE && colorB == colorD && colorA != colorF && colorA == colorI) \
product = colorB; \ product = colorB; \
else \ else \
{ \
product = interpolate_cb(colorA, colorB); \ product = interpolate_cb(colorA, colorB); \
} \
if (colorA == colorB && colorA == colorH && colorG != colorC && colorC == colorM) \ if (colorA == colorB && colorA == colorH && colorG != colorC && colorC == colorM) \
product1 = colorA; \ product1 = colorA; \
else if (colorC == colorG && colorC == colorD && colorA != colorH && colorA == colorI) \ else if (colorC == colorG && colorC == colorD && colorA != colorH && colorA == colorI) \
product1 = colorC; \ product1 = colorC; \
else \ else \
{ \
product1 = interpolate_cb(colorA, colorC); \ product1 = interpolate_cb(colorA, colorC); \
} \
} \ } \
out[0] = colorA; \ out[0] = colorA; \
out[1] = product; \ out[1] = product; \
out[dst_stride] = product1; \ out[dst_stride] = product1; \
out[dst_stride + 1] = product2; \ out[dst_stride + 1] = product2; \
++in; \ ++in; \
out += 2 out += 2
@ -292,11 +275,10 @@ static void twoxsai_work_cb_rgb565(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)thread_data; (struct softfilter_thread_data*)thread_data;
uint16_t *input = (uint16_t*)thr->in_data; uint16_t *input = (uint16_t*)thr->in_data;
uint16_t *output = (uint16_t*)thr->out_data; uint16_t *output = (uint16_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
twoxsai_generic_rgb565(width, height, twoxsai_generic_rgb565(width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565),
@ -308,11 +290,10 @@ static void twoxsai_work_cb_xrgb8888(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)thread_data; (struct softfilter_thread_data*)thread_data;
uint32_t *input = (uint32_t*)thr->in_data; uint32_t *input = (uint32_t*)thr->in_data;
uint32_t *output = (uint32_t*)thr->out_data; uint32_t *output = (uint32_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
twoxsai_generic_xrgb8888(width, height, twoxsai_generic_xrgb8888(width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888),
@ -327,37 +308,38 @@ static void twoxsai_generic_packets(void *data,
unsigned height, size_t input_stride) unsigned height, size_t input_stride)
{ {
unsigned i; unsigned i;
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
for (i = 0; i < filt->threads; i++) for (i = 0; i < filt->threads; i++)
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)&filt->workers[i]; (struct softfilter_thread_data*)&filt->workers[i];
unsigned y_start = (height * i) / filt->threads; unsigned y_start = (height * i) / filt->threads;
unsigned y_end = (height * (i + 1)) / filt->threads; unsigned y_end = (height * (i + 1)) / filt->threads;
thr->out_data = (uint8_t*)output + y_start *
thr->out_data = (uint8_t*)output + y_start *
TWOXSAI_SCALE * output_stride; TWOXSAI_SCALE * output_stride;
thr->in_data = (const uint8_t*)input + y_start * input_stride; thr->in_data = (const uint8_t*)input + y_start * input_stride;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = y_end - y_start; thr->height = y_end - y_start;
/* Workers need to know if they can access pixels /* Workers need to know if they can access pixels
* outside their given buffer. * outside their given buffer.
*/ */
thr->first = y_start; thr->first = y_start;
thr->last = y_end == height; thr->last = y_end == height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[i].work = twoxsai_work_cb_rgb565; packets[i].work = twoxsai_work_cb_rgb565;
#if 0 #if 0
else if (filt->in_fmt == SOFTFILTER_FMT_RGB4444) else if (filt->in_fmt == SOFTFILTER_FMT_RGB4444)
packets[i].work = twoxsai_work_cb_rgb4444; packets[i].work = twoxsai_work_cb_rgb4444;
#endif #endif
else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[i].work = twoxsai_work_cb_xrgb8888; packets[i].work = twoxsai_work_cb_xrgb8888;
packets[i].thread_data = thr; packets[i].thread_data = thr;
} }
} }
@ -380,7 +362,6 @@ static const struct softfilter_implementation twoxsai_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &twoxsai_generic; return &twoxsai_generic;
} }

@ -46,10 +46,10 @@ struct softfilter_thread_data
struct filter_data struct filter_data
{ {
unsigned threads;
struct softfilter_thread_data *workers; struct softfilter_thread_data *workers;
unsigned in_fmt;
struct snes_ntsc_t *ntsc; struct snes_ntsc_t *ntsc;
unsigned threads;
unsigned in_fmt;
int burst; int burst;
int burst_toggle; int burst_toggle;
}; };
@ -162,18 +162,18 @@ static void *blargg_ntsc_snes_generic_create(const struct softfilter_config *con
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
if (!filt) if (!filt)
return NULL; return NULL;
filt->workers = (struct softfilter_thread_data*) if (!(filt->workers = (struct softfilter_thread_data*)
calloc(threads, sizeof(struct softfilter_thread_data)); calloc(threads, sizeof(struct softfilter_thread_data))))
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
blargg_ntsc_snes_initialize(filt, config, userdata); blargg_ntsc_snes_initialize(filt, config, userdata);
@ -195,7 +195,7 @@ static void blargg_ntsc_snes_generic_destroy(void *data)
if (!filt) if (!filt)
return; return;
if(filt->ntsc) if (filt->ntsc)
free(filt->ntsc); free(filt->ntsc);
free(filt->workers); free(filt->workers);
@ -207,7 +207,7 @@ static void blargg_ntsc_snes_render_rgb565(void *data, int width, int height,
uint16_t *input, int pitch, uint16_t *output, int outpitch) uint16_t *input, int pitch, uint16_t *output, int outpitch)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if(width <= 256 || !hires_blit) if (width <= 256 || !hires_blit)
retroarch_snes_ntsc_blit(filt->ntsc, input, pitch, filt->burst, retroarch_snes_ntsc_blit(filt->ntsc, input, pitch, filt->burst,
width, height, output, outpitch * 2, first, last); width, height, output, outpitch * 2, first, last);
else else
@ -225,18 +225,16 @@ static void blargg_ntsc_snes_rgb565(void *data, unsigned width, unsigned height,
first, last, first, last,
src, src_stride, src, src_stride,
dst, dst_stride); dst, dst_stride);
} }
static void blargg_ntsc_snes_work_cb_rgb565(void *data, void *thread_data) static void blargg_ntsc_snes_work_cb_rgb565(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)thread_data; (struct softfilter_thread_data*)thread_data;
uint16_t *input = (uint16_t*)thr->in_data; uint16_t *input = (uint16_t*)thr->in_data;
uint16_t *output = (uint16_t*)thr->out_data; uint16_t *output = (uint16_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
blargg_ntsc_snes_rgb565(data, width, height, blargg_ntsc_snes_rgb565(data, width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565),
@ -249,30 +247,31 @@ static void blargg_ntsc_snes_generic_packets(void *data,
void *output, size_t output_stride, void *output, size_t output_stride,
const void *input, unsigned width, unsigned height, size_t input_stride) const void *input, unsigned width, unsigned height, size_t input_stride)
{ {
struct filter_data *filt = (struct filter_data*)data;
unsigned i; unsigned i;
struct filter_data *filt = (struct filter_data*)data;
for (i = 0; i < filt->threads; i++) for (i = 0; i < filt->threads; i++)
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)&filt->workers[i]; (struct softfilter_thread_data*)&filt->workers[i];
unsigned y_start = (height * i) / filt->threads; unsigned y_start = (height * i) / filt->threads;
unsigned y_end = (height * (i + 1)) / filt->threads; unsigned y_end = (height * (i + 1)) / filt->threads;
thr->out_data = (uint8_t*)output + y_start * output_stride; thr->out_data = (uint8_t*)output + y_start * output_stride;
thr->in_data = (const uint8_t*)input + y_start * input_stride; thr->in_data = (const uint8_t*)input + y_start * input_stride;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = y_end - y_start; thr->height = y_end - y_start;
/* Workers need to know if they can /* Workers need to know if they can
* access pixels outside their given buffer. */ * access pixels outside their given buffer. */
thr->first = y_start; thr->first = y_start;
thr->last = y_end == height; thr->last = y_end == height;
/* TODO/FIXME - no XRGB8888 codepath? */
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[i].work = blargg_ntsc_snes_work_cb_rgb565; packets[i].work = blargg_ntsc_snes_work_cb_rgb565;
packets[i].thread_data = thr; packets[i].thread_data = thr;
} }
} }
@ -294,7 +293,6 @@ static const struct softfilter_implementation blargg_ntsc_snes_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &blargg_ntsc_snes_generic; return &blargg_ntsc_snes_generic;
} }

@ -40,8 +40,8 @@ struct softfilter_thread_data
struct filter_data struct filter_data
{ {
unsigned threads;
struct softfilter_thread_data *workers; struct softfilter_thread_data *workers;
unsigned threads;
unsigned in_fmt; unsigned in_fmt;
}; };
@ -67,27 +67,23 @@ static void *darken_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
(void)config;
(void)userdata;
if (!filt) if (!filt)
return NULL; return NULL;
filt->workers = (struct softfilter_thread_data*) if (!(filt->workers = (struct softfilter_thread_data*)
calloc(threads, sizeof(struct softfilter_thread_data)); calloc(threads, sizeof(struct softfilter_thread_data))))
filt->threads = threads;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
filt->threads = threads;
filt->in_fmt = in_fmt;
return filt; return filt;
} }
static void darken_output(void *data, unsigned *out_width, unsigned *out_height, static void darken_output(void *data, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width; *out_width = width;
*out_height = height; *out_height = height;
} }
@ -104,14 +100,13 @@ static void darken_destroy(void *data)
static void darken_work_cb_xrgb8888(void *data, void *thread_data) static void darken_work_cb_xrgb8888(void *data, void *thread_data)
{ {
unsigned x, y;
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)thread_data; (struct softfilter_thread_data*)thread_data;
const uint32_t *input = (const uint32_t*)thr->in_data; const uint32_t *input = (const uint32_t*)thr->in_data;
uint32_t *output = (uint32_t*)thr->out_data; uint32_t *output = (uint32_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
unsigned x, y;
for (y = 0; y < height; for (y = 0; y < height;
y++, input += thr->in_pitch >> 2, output += thr->out_pitch >> 2) y++, input += thr->in_pitch >> 2, output += thr->out_pitch >> 2)
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
@ -120,14 +115,13 @@ static void darken_work_cb_xrgb8888(void *data, void *thread_data)
static void darken_work_cb_rgb565(void *data, void *thread_data) static void darken_work_cb_rgb565(void *data, void *thread_data)
{ {
unsigned x, y;
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)thread_data; (struct softfilter_thread_data*)thread_data;
const uint16_t *input = (const uint16_t*)thr->in_data; const uint16_t *input = (const uint16_t*)thr->in_data;
uint16_t *output = (uint16_t*)thr->out_data; uint16_t *output = (uint16_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
unsigned x, y;
for (y = 0; y < height; for (y = 0; y < height;
y++, input += thr->in_pitch >> 1, output += thr->out_pitch >> 1) y++, input += thr->in_pitch >> 1, output += thr->out_pitch >> 1)
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
@ -145,20 +139,21 @@ static void darken_packets(void *data,
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)&filt->workers[i]; (struct softfilter_thread_data*)&filt->workers[i];
unsigned y_start = (height * i) / filt->threads; unsigned y_start = (height * i) / filt->threads;
unsigned y_end = (height * (i + 1)) / filt->threads; unsigned y_end = (height * (i + 1)) / filt->threads;
thr->out_data = (uint8_t*)output + y_start * output_stride;
thr->in_data = (const uint8_t*)input + y_start * input_stride; thr->out_data = (uint8_t*)output + y_start * output_stride;
thr->out_pitch = output_stride; thr->in_data = (const uint8_t*)input + y_start * input_stride;
thr->in_pitch = input_stride; thr->out_pitch = output_stride;
thr->width = width; thr->in_pitch = input_stride;
thr->height = y_end - y_start; thr->width = width;
thr->height = y_end - y_start;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[i].work = darken_work_cb_xrgb8888; packets[i].work = darken_work_cb_xrgb8888;
else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[i].work = darken_work_cb_rgb565; packets[i].work = darken_work_cb_rgb565;
packets[i].thread_data = thr; packets[i].thread_data = thr;
} }
} }
@ -180,7 +175,6 @@ static const struct softfilter_implementation darken = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &darken; return &darken;
} }

@ -87,9 +87,9 @@ static void dot_matrix_3x_initialize(struct filter_data *filt,
/* Convert to RGB565 */ /* Convert to RGB565 */
filt->grid_color.rgb565 = filt->grid_color.rgb565 =
(((grid_color >> 19) & 0x1F) << 11) | ( ((grid_color >> 19) & 0x1F) << 11)
(((grid_color >> 11) & 0x1F) << 6) | | (((grid_color >> 11) & 0x1F) << 6)
((grid_color >> 3) & 0x1F); | ((grid_color >> 3) & 0x1F);
} }
static void *dot_matrix_3x_generic_create(const struct softfilter_config *config, static void *dot_matrix_3x_generic_create(const struct softfilter_config *config,
@ -103,16 +103,16 @@ static void *dot_matrix_3x_generic_create(const struct softfilter_config *config
if (!filt) if (!filt)
return NULL; return NULL;
/* Apparently the code is not thread-safe, if (!(filt->workers = (struct softfilter_thread_data*)
* so force single threaded operation... */ calloc(1, sizeof(struct softfilter_thread_data))))
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
/* Initialise colour lookup tables */ /* Initialise colour lookup tables */
dot_matrix_3x_initialize(filt, config, userdata); dot_matrix_3x_initialize(filt, config, userdata);
@ -131,9 +131,8 @@ static void dot_matrix_3x_generic_output(void *data,
static void dot_matrix_3x_generic_destroy(void *data) static void dot_matrix_3x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -290,22 +289,22 @@ static void dot_matrix_3x_generic_packets(void *data,
/* We are guaranteed single threaded operation /* We are guaranteed single threaded operation
* (filt->threads = 1) so we don't need to loop * (filt->threads = 1) so we don't need to loop
* over threads and can cull some code */ * over threads and can cull some code */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = dot_matrix_3x_work_cb_rgb565; packets[0].work = dot_matrix_3x_work_cb_rgb565;
else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = dot_matrix_3x_work_cb_xrgb8888; packets[0].work = dot_matrix_3x_work_cb_xrgb8888;
packets[0].thread_data = thr; packets[0].thread_data = thr;
} }
static const struct softfilter_implementation dot_matrix_3x_generic = { static const struct softfilter_implementation dot_matrix_3x_generic = {
@ -327,7 +326,6 @@ static const struct softfilter_implementation dot_matrix_3x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &dot_matrix_3x_generic; return &dot_matrix_3x_generic;
} }

@ -50,10 +50,10 @@ struct softfilter_thread_data
struct filter_data struct filter_data
{ {
unsigned threads;
struct softfilter_thread_data *workers; struct softfilter_thread_data *workers;
dot_matrix_4x_grid_color_t grid_color; /* uint32_t alignment */
unsigned threads;
unsigned in_fmt; unsigned in_fmt;
dot_matrix_4x_grid_color_t grid_color;
}; };
static unsigned dot_matrix_4x_generic_input_fmts(void) static unsigned dot_matrix_4x_generic_input_fmts(void)
@ -87,9 +87,9 @@ static void dot_matrix_4x_initialize(struct filter_data *filt,
/* Convert to RGB565 */ /* Convert to RGB565 */
filt->grid_color.rgb565 = filt->grid_color.rgb565 =
(((grid_color >> 19) & 0x1F) << 11) | (((grid_color >> 19) & 0x1F) << 11)
(((grid_color >> 11) & 0x1F) << 6) | | (((grid_color >> 11) & 0x1F) << 6)
((grid_color >> 3) & 0x1F); | ((grid_color >> 3) & 0x1F);
} }
static void *dot_matrix_4x_generic_create(const struct softfilter_config *config, static void *dot_matrix_4x_generic_create(const struct softfilter_config *config,
@ -98,21 +98,18 @@ static void *dot_matrix_4x_generic_create(const struct softfilter_config *config
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
if (!filt) if (!filt)
return NULL; return NULL;
if (!(filt->workers = (struct softfilter_thread_data*)
/* Apparently the code is not thread-safe, calloc(1, sizeof(struct softfilter_thread_data))))
* so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
/* Initialise colour lookup tables */ /* Initialise colour lookup tables */
dot_matrix_4x_initialize(filt, config, userdata); dot_matrix_4x_initialize(filt, config, userdata);
@ -131,9 +128,8 @@ static void dot_matrix_4x_generic_output(void *data,
static void dot_matrix_4x_generic_destroy(void *data) static void dot_matrix_4x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -330,22 +326,22 @@ static void dot_matrix_4x_generic_packets(void *data,
/* We are guaranteed single threaded operation /* We are guaranteed single threaded operation
* (filt->threads = 1) so we don't need to loop * (filt->threads = 1) so we don't need to loop
* over threads and can cull some code */ * over threads and can cull some code */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = dot_matrix_4x_work_cb_rgb565; packets[0].work = dot_matrix_4x_work_cb_rgb565;
else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = dot_matrix_4x_work_cb_xrgb8888; packets[0].work = dot_matrix_4x_work_cb_xrgb8888;
packets[0].thread_data = thr; packets[0].thread_data = thr;
} }
static const struct softfilter_implementation dot_matrix_4x_generic = { static const struct softfilter_implementation dot_matrix_4x_generic = {
@ -367,7 +363,6 @@ static const struct softfilter_implementation dot_matrix_4x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &dot_matrix_4x_generic; return &dot_matrix_4x_generic;
} }

@ -70,20 +70,17 @@ static void *epx_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
(void)config;
(void)userdata;
if (!filt) if (!filt)
return NULL; return NULL;
filt->workers = (struct softfilter_thread_data*) filt->workers = (struct softfilter_thread_data*)
calloc(threads, sizeof(struct softfilter_thread_data)); calloc(threads, sizeof(struct softfilter_thread_data));
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers) if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
filt->threads = 1;
filt->in_fmt = in_fmt;
return filt; return filt;
} }
@ -91,7 +88,7 @@ static void epx_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width * EPX_SCALE; *out_width = width * EPX_SCALE;
*out_height = height * EPX_SCALE; *out_height = height * EPX_SCALE;
} }
@ -110,35 +107,32 @@ static void epx_generic_rgb565 (unsigned width, unsigned height,
int first, int lsat, uint16_t *src, int first, int lsat, uint16_t *src,
unsigned src_stride, uint16_t *dst, unsigned dst_stride) unsigned src_stride, uint16_t *dst, unsigned dst_stride)
{ {
uint16_t colorX, colorA, colorB, colorC, colorD; uint16_t colorA;
uint16_t *sP, *uP, *lP;
uint32_t*dP1, *dP2;
int w; int w;
for (; height; height--) for (; height; height--)
{ {
sP = (uint16_t *) src; uint16_t *sP = (uint16_t *) src;
uP = (uint16_t *) (src - src_stride); uint16_t *uP = (uint16_t *) (src - src_stride);
lP = (uint16_t *) (src + src_stride); uint16_t *lP = (uint16_t *) (src + src_stride);
dP1 = (uint32_t *) dst; uint32_t *dP1 = (uint32_t *) dst;
dP2 = (uint32_t *) (dst + dst_stride); uint32_t *dP2 = (uint32_t *) (dst + dst_stride);
/* left edge */ /* left edge */
uint16_t colorX = *sP;
colorX = *sP; uint16_t colorC = *++sP;
colorC = *++sP; uint16_t colorB = *lP++;
colorB = *lP++; uint16_t colorD = *uP++;
colorD = *uP++;
if ((colorX != colorC) && (colorB != colorD)) if ((colorX != colorC) && (colorB != colorD))
{ {
#ifdef MSB_FIRST #ifdef MSB_FIRST
*dP1 = (colorX << 16) + ((colorC == colorD) ? colorC : colorX); *dP1 = (colorX << 16) + ((colorC == colorD) ? colorC : colorX);
*dP2 = (colorX << 16) + ((colorB == colorC) ? colorB : colorX); *dP2 = (colorX << 16) + ((colorB == colorC) ? colorB : colorX);
#else #else
*dP1 = colorX + (((colorC == colorD) ? colorC : colorX) << 16); *dP1 = colorX + (((colorC == colorD) ? colorC : colorX) << 16);
*dP2 = colorX + (((colorB == colorC) ? colorB : colorX) << 16); *dP2 = colorX + (((colorB == colorC) ? colorB : colorX) << 16);
#endif #endif
} }
else else
*dP1 = *dP2 = (colorX << 16) + colorX; *dP1 = *dP2 = (colorX << 16) + colorX;
@ -172,7 +166,6 @@ static void epx_generic_rgb565 (unsigned width, unsigned height,
} }
/* right edge */ /* right edge */
colorA = colorX; colorA = colorX;
colorX = colorC; colorX = colorC;
colorB = *lP; colorB = *lP;
@ -200,10 +193,10 @@ static void epx_work_cb_rgb565(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)thread_data; (struct softfilter_thread_data*)thread_data;
uint16_t *input = (uint16_t*)thr->in_data; uint16_t *input = (uint16_t*)thr->in_data;
uint16_t *output = (uint16_t*)thr->out_data; uint16_t *output = (uint16_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
epx_generic_rgb565(width, height, epx_generic_rgb565(width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
@ -225,19 +218,19 @@ static void epx_generic_packets(void *data,
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)&filt->workers[i]; (struct softfilter_thread_data*)&filt->workers[i];
unsigned y_start = (height * i) / filt->threads; unsigned y_start = (height * i) / filt->threads;
unsigned y_end = (height * (i + 1)) / filt->threads; unsigned y_end = (height * (i + 1)) / filt->threads;
thr->out_data = (uint8_t*)output + y_start * EPX_SCALE * output_stride; thr->out_data = (uint8_t*)output + y_start * EPX_SCALE * output_stride;
thr->in_data = (const uint8_t*)input + y_start * input_stride; thr->in_data = (const uint8_t*)input + y_start * input_stride;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = y_end - y_start; thr->height = y_end - y_start;
/* Workers need to know if they can /* Workers need to know if they can
* access pixels outside their given buffer. */ * access pixels outside their given buffer. */
thr->first = y_start; thr->first = y_start;
thr->last = y_end == height; thr->last = y_end == height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[i].work = epx_work_cb_rgb565; packets[i].work = epx_work_cb_rgb565;
@ -263,7 +256,6 @@ static const struct softfilter_implementation epx_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &epx_generic; return &epx_generic;
} }

@ -139,10 +139,10 @@ static void gameboy3x_initialize(struct filter_data *filt,
filt->colors.xrgb8888.pixel_lut[i] = palette[i]; filt->colors.xrgb8888.pixel_lut[i] = palette[i];
/* Populate grid lookup tables */ /* Populate grid lookup tables */
grid_color = gameboy3x_get_grid_colour(palette[i], palette_grid); grid_color = gameboy3x_get_grid_colour(palette[i], palette_grid);
filt->colors.rgb565.grid_lut[i] = GAMEBOY_3X_RGB24_TO_RGB565(grid_color); filt->colors.rgb565.grid_lut[i] = GAMEBOY_3X_RGB24_TO_RGB565(grid_color);
filt->colors.xrgb8888.grid_lut[i] = grid_color; filt->colors.xrgb8888.grid_lut[i] = grid_color;
} }
} }
@ -152,22 +152,19 @@ static void *gameboy3x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
if (!filt) if (!filt)
return NULL; return NULL;
if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
/* Initialise colour lookup tables */ /* Initialise colour lookup tables */
gameboy3x_initialize(filt, config, userdata); gameboy3x_initialize(filt, config, userdata);
@ -185,9 +182,8 @@ static void gameboy3x_generic_output(void *data,
static void gameboy3x_generic_destroy(void *data) static void gameboy3x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -230,8 +226,8 @@ static void gameboy3x_work_cb_rgb565(void *data, void *thread_data)
/* Convert to lookup table index /* Convert to lookup table index
* > This can never be greater than 3, * > This can never be greater than 3,
* but check anyway... */ * but check anyway... */
lut_index = in_rgb_mean >> 3; lut_index = in_rgb_mean >> 3;
lut_index = (lut_index > 3) ? 3 : lut_index; lut_index = (lut_index > 3) ? 3 : lut_index;
/* Get output pixel and grid colours */ /* Get output pixel and grid colours */
out_pixel_color = *(pixel_lut + lut_index); out_pixel_color = *(pixel_lut + lut_index);
@ -307,8 +303,8 @@ static void gameboy3x_work_cb_xrgb8888(void *data, void *thread_data)
/* Convert to lookup table index /* Convert to lookup table index
* > This can never be greater than 3, * > This can never be greater than 3,
* but check anyway... */ * but check anyway... */
lut_index = in_rgb_mean >> 6; lut_index = in_rgb_mean >> 6;
lut_index = (lut_index > 3) ? 3 : lut_index; lut_index = (lut_index > 3) ? 3 : lut_index;
/* Get output pixel and grid colours */ /* Get output pixel and grid colours */
out_pixel_color = *(pixel_lut + lut_index); out_pixel_color = *(pixel_lut + lut_index);
@ -354,22 +350,22 @@ static void gameboy3x_generic_packets(void *data,
/* We are guaranteed single threaded operation /* We are guaranteed single threaded operation
* (filt->threads = 1) so we don't need to loop * (filt->threads = 1) so we don't need to loop
* over threads and can cull some code */ * over threads and can cull some code */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = gameboy3x_work_cb_rgb565; packets[0].work = gameboy3x_work_cb_rgb565;
else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = gameboy3x_work_cb_xrgb8888; packets[0].work = gameboy3x_work_cb_xrgb8888;
packets[0].thread_data = thr; packets[0].thread_data = thr;
} }
static const struct softfilter_implementation gameboy3x_generic = { static const struct softfilter_implementation gameboy3x_generic = {
@ -391,7 +387,6 @@ static const struct softfilter_implementation gameboy3x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &gameboy3x_generic; return &gameboy3x_generic;
} }

@ -170,21 +170,18 @@ static void *gameboy4x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
if (!filt) if (!filt)
return NULL; return NULL;
if (!(filt->workers = (struct softfilter_thread_data*)
/* Apparently the code is not thread-safe, calloc(1, sizeof(struct softfilter_thread_data))))
* so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
/* Initialise colour lookup tables */ /* Initialise colour lookup tables */
gameboy4x_initialize(filt, config, userdata); gameboy4x_initialize(filt, config, userdata);
@ -203,9 +200,8 @@ static void gameboy4x_generic_output(void *data,
static void gameboy4x_generic_destroy(void *data) static void gameboy4x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -412,22 +408,22 @@ static void gameboy4x_generic_packets(void *data,
/* We are guaranteed single threaded operation /* We are guaranteed single threaded operation
* (filt->threads = 1) so we don't need to loop * (filt->threads = 1) so we don't need to loop
* over threads and can cull some code */ * over threads and can cull some code */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = gameboy4x_work_cb_rgb565; packets[0].work = gameboy4x_work_cb_rgb565;
else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = gameboy4x_work_cb_xrgb8888; packets[0].work = gameboy4x_work_cb_xrgb8888;
packets[0].thread_data = thr; packets[0].thread_data = thr;
} }
static const struct softfilter_implementation gameboy4x_generic = { static const struct softfilter_implementation gameboy4x_generic = {
@ -449,7 +445,6 @@ static const struct softfilter_implementation gameboy4x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &gameboy4x_generic; return &gameboy4x_generic;
} }

@ -68,22 +68,17 @@ static void *grid2x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data)); filt->threads = 1;
filt->threads = 1; filt->in_fmt = in_fmt;
filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -91,16 +86,15 @@ static void grid2x_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width << 1; *out_width = width << 1;
*out_height = height << 1; *out_height = height << 1;
} }
static void grid2x_generic_destroy(void *data) static void grid2x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -127,7 +121,7 @@ static void grid2x_work_cb_xrgb8888(void *data, void *thread_data)
uint32_t scanline_color = (color + (color & 0x1010101)) >> 1; uint32_t scanline_color = (color + (color & 0x1010101)) >> 1;
/* > Second pass: 50:50 mix of color:(color:0) /* > Second pass: 50:50 mix of color:(color:0)
* => Gives ((1 + 0.5) / 2) = 0.75 */ * => Gives ((1 + 0.5) / 2) = 0.75 */
scanline_color = (color + scanline_color + ((color ^ scanline_color) & 0x1010101)) >> 1; scanline_color = (color + scanline_color + ((color ^ scanline_color) & 0x1010101)) >> 1;
/* c.f "Mixing Packed RGB Pixels Efficiently" /* c.f "Mixing Packed RGB Pixels Efficiently"
* http://blargg.8bitalley.com/info/rgb_mixing.html */ * http://blargg.8bitalley.com/info/rgb_mixing.html */
@ -171,7 +165,7 @@ static void grid2x_work_cb_rgb565(void *data, void *thread_data)
uint16_t scanline_color = (color + (color & 0x821)) >> 1; uint16_t scanline_color = (color + (color & 0x821)) >> 1;
/* > Second pass: 50:50 mix of color:(color:0) /* > Second pass: 50:50 mix of color:(color:0)
* => Gives ((1 + 0.5) / 2) = 0.75 */ * => Gives ((1 + 0.5) / 2) = 0.75 */
scanline_color = (color + scanline_color + ((color ^ scanline_color) & 0x821)) >> 1; scanline_color = (color + scanline_color + ((color ^ scanline_color) & 0x821)) >> 1;
/* c.f "Mixing Packed RGB Pixels Efficiently" /* c.f "Mixing Packed RGB Pixels Efficiently"
* http://blargg.8bitalley.com/info/rgb_mixing.html */ * http://blargg.8bitalley.com/info/rgb_mixing.html */
@ -203,22 +197,21 @@ static void grid2x_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) { if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = grid2x_work_cb_xrgb8888; packets[0].work = grid2x_work_cb_xrgb8888;
} else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = grid2x_work_cb_rgb565; packets[0].work = grid2x_work_cb_rgb565;
} packets[0].thread_data = thr;
packets[0].thread_data = thr;
} }
static const struct softfilter_implementation grid2x_generic = { static const struct softfilter_implementation grid2x_generic = {
@ -240,7 +233,6 @@ static const struct softfilter_implementation grid2x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &grid2x_generic; return &grid2x_generic;
} }

@ -68,22 +68,17 @@ static void *grid3x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -98,9 +93,8 @@ static void grid3x_generic_output(void *data,
static void grid3x_generic_destroy(void *data) static void grid3x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -127,7 +121,7 @@ static void grid3x_work_cb_xrgb8888(void *data, void *thread_data)
uint32_t scanline_color = (color + (color & 0x1010101)) >> 1; uint32_t scanline_color = (color + (color & 0x1010101)) >> 1;
/* > Second pass: 50:50 mix of color:(color:0) /* > Second pass: 50:50 mix of color:(color:0)
* => Gives ((1 + 0.5) / 2) = 0.75 */ * => Gives ((1 + 0.5) / 2) = 0.75 */
scanline_color = (color + scanline_color + ((color ^ scanline_color) & 0x1010101)) >> 1; scanline_color = (color + scanline_color + ((color ^ scanline_color) & 0x1010101)) >> 1;
/* c.f "Mixing Packed RGB Pixels Efficiently" /* c.f "Mixing Packed RGB Pixels Efficiently"
* http://blargg.8bitalley.com/info/rgb_mixing.html */ * http://blargg.8bitalley.com/info/rgb_mixing.html */
@ -179,7 +173,7 @@ static void grid3x_work_cb_rgb565(void *data, void *thread_data)
uint16_t scanline_color = (color + (color & 0x821)) >> 1; uint16_t scanline_color = (color + (color & 0x821)) >> 1;
/* > Second pass: 50:50 mix of color:(color:0) /* > Second pass: 50:50 mix of color:(color:0)
* => Gives ((1 + 0.5) / 2) = 0.75 */ * => Gives ((1 + 0.5) / 2) = 0.75 */
scanline_color = (color + scanline_color + ((color ^ scanline_color) & 0x821)) >> 1; scanline_color = (color + scanline_color + ((color ^ scanline_color) & 0x821)) >> 1;
/* c.f "Mixing Packed RGB Pixels Efficiently" /* c.f "Mixing Packed RGB Pixels Efficiently"
* http://blargg.8bitalley.com/info/rgb_mixing.html */ * http://blargg.8bitalley.com/info/rgb_mixing.html */
@ -219,21 +213,20 @@ static void grid3x_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) { if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = grid3x_work_cb_xrgb8888; packets[0].work = grid3x_work_cb_xrgb8888;
} else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = grid3x_work_cb_rgb565; packets[0].work = grid3x_work_cb_rgb565;
}
packets[0].thread_data = thr; packets[0].thread_data = thr;
} }
@ -256,7 +249,6 @@ static const struct softfilter_implementation grid3x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &grid3x_generic; return &grid3x_generic;
} }

@ -67,20 +67,18 @@ static void *lq2x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
(void)config;
(void)userdata;
if (!filt) if (!filt)
return NULL; return NULL;
filt->workers = (struct softfilter_thread_data*) if (!(filt->workers = (struct softfilter_thread_data*)
calloc(threads, sizeof(struct softfilter_thread_data)); calloc(threads, sizeof(struct softfilter_thread_data))))
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
return filt; return filt;
} }
@ -88,7 +86,7 @@ static void lq2x_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width * LQ2X_SCALE; *out_width = width * LQ2X_SCALE;
*out_height = height * LQ2X_SCALE; *out_height = height * LQ2X_SCALE;
} }
@ -195,11 +193,10 @@ static void lq2x_work_cb_rgb565(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)thread_data; (struct softfilter_thread_data*)thread_data;
uint16_t *input = (uint16_t*)thr->in_data; uint16_t *input = (uint16_t*)thr->in_data;
uint16_t *output = (uint16_t*)thr->out_data; uint16_t *output = (uint16_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
lq2x_generic_rgb565(width, height, lq2x_generic_rgb565(width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565),
@ -211,13 +208,10 @@ static void lq2x_work_cb_xrgb8888(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)thread_data; (struct softfilter_thread_data*)thread_data;
uint32_t *input = (uint32_t*)thr->in_data; uint32_t *input = (uint32_t*)thr->in_data;
uint32_t *output = (uint32_t*)thr->out_data; uint32_t *output = (uint32_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
(void)data;
lq2x_generic_xrgb8888(width, height, lq2x_generic_xrgb8888(width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888),
@ -238,28 +232,28 @@ static void lq2x_generic_packets(void *data,
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)&filt->workers[i]; (struct softfilter_thread_data*)&filt->workers[i];
unsigned y_start = (height * i) / filt->threads; unsigned y_start = (height * i) / filt->threads;
unsigned y_end = (height * (i + 1)) / filt->threads; unsigned y_end = (height * (i + 1)) / filt->threads;
thr->out_data = (uint8_t*)output + y_start * LQ2X_SCALE * output_stride; thr->out_data = (uint8_t*)output + y_start * LQ2X_SCALE * output_stride;
thr->in_data = (const uint8_t*)input + y_start * input_stride; thr->in_data = (const uint8_t*)input + y_start * input_stride;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = y_end - y_start; thr->height = y_end - y_start;
/* Workers need to know if they can access pixels /* Workers need to know if they can access pixels
* outside their given buffer. */ * outside their given buffer. */
thr->first = y_start; thr->first = y_start;
thr->last = y_end == height; thr->last = y_end == height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[i].work = lq2x_work_cb_rgb565; packets[i].work = lq2x_work_cb_rgb565;
#if 0 #if 0
else if (filt->in_fmt == SOFTFILTER_FMT_RGB4444) else if (filt->in_fmt == SOFTFILTER_FMT_RGB4444)
packets[i].work = lq2x_work_cb_rgb4444; packets[i].work = lq2x_work_cb_rgb4444;
#endif #endif
else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[i].work = lq2x_work_cb_xrgb8888; packets[i].work = lq2x_work_cb_xrgb8888;
packets[i].thread_data = thr; packets[i].thread_data = thr;
} }
} }
@ -282,7 +276,6 @@ static const struct softfilter_implementation lq2x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &lq2x_generic; return &lq2x_generic;
} }

@ -68,22 +68,17 @@ static void *normal2x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -91,16 +86,15 @@ static void normal2x_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width << 1; *out_width = width << 1;
*out_height = height << 1; *out_height = height << 1;
} }
static void normal2x_generic_destroy(void *data) static void normal2x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -119,16 +113,16 @@ static void normal2x_work_cb_xrgb8888(void *data, void *thread_data)
uint32_t *out_ptr = output; uint32_t *out_ptr = output;
for (x = 0; x < thr->width; ++x) for (x = 0; x < thr->width; ++x)
{ {
uint32_t row_color[2];
uint32_t *out_line_ptr = out_ptr; uint32_t *out_line_ptr = out_ptr;
uint32_t color = *(input + x); uint32_t color = *(input + x);
uint32_t row_color[2];
row_color[0] = color; row_color[0] = color;
row_color[1] = color; row_color[1] = color;
/* Row 1 */ /* Row 1 */
memcpy(out_line_ptr, row_color, sizeof(row_color)); memcpy(out_line_ptr, row_color, sizeof(row_color));
out_line_ptr += out_stride; out_line_ptr += out_stride;
/* Row 2 */ /* Row 2 */
memcpy(out_line_ptr, row_color, sizeof(row_color)); memcpy(out_line_ptr, row_color, sizeof(row_color));
@ -155,25 +149,25 @@ static void normal2x_work_cb_rgb565(void *data, void *thread_data)
uint16_t *out_ptr = output; uint16_t *out_ptr = output;
for (x = 0; x < thr->width; ++x) for (x = 0; x < thr->width; ++x)
{ {
uint16_t row_color[2];
uint16_t *out_line_ptr = out_ptr; uint16_t *out_line_ptr = out_ptr;
uint16_t color = *(input + x); uint16_t color = *(input + x);
uint16_t row_color[2];
row_color[0] = color; row_color[0] = color;
row_color[1] = color; row_color[1] = color;
/* Row 1 */ /* Row 1 */
memcpy(out_line_ptr, row_color, sizeof(row_color)); memcpy(out_line_ptr, row_color, sizeof(row_color));
out_line_ptr += out_stride; out_line_ptr += out_stride;
/* Row 2 */ /* Row 2 */
memcpy(out_line_ptr, row_color, sizeof(row_color)); memcpy(out_line_ptr, row_color, sizeof(row_color));
out_ptr += 2; out_ptr += 2;
} }
input += in_stride; input += in_stride;
output += out_stride << 1; output += out_stride << 1;
} }
} }
@ -187,22 +181,21 @@ static void normal2x_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) { if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = normal2x_work_cb_xrgb8888; packets[0].work = normal2x_work_cb_xrgb8888;
} else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = normal2x_work_cb_rgb565; packets[0].work = normal2x_work_cb_rgb565;
} packets[0].thread_data = thr;
packets[0].thread_data = thr;
} }
static const struct softfilter_implementation normal2x_generic = { static const struct softfilter_implementation normal2x_generic = {
@ -224,7 +217,6 @@ static const struct softfilter_implementation normal2x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &normal2x_generic; return &normal2x_generic;
} }

@ -68,22 +68,17 @@ static void *normal2x_height_generic_create(const struct softfilter_config *conf
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -91,16 +86,15 @@ static void normal2x_height_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width; *out_width = width;
*out_height = height << 1; *out_height = height << 1;
} }
static void normal2x_height_generic_destroy(void *data) static void normal2x_height_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -171,22 +165,21 @@ static void normal2x_height_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) { if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = normal2x_height_work_cb_xrgb8888; packets[0].work = normal2x_height_work_cb_xrgb8888;
} else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = normal2x_height_work_cb_rgb565; packets[0].work = normal2x_height_work_cb_rgb565;
} packets[0].thread_data = thr;
packets[0].thread_data = thr;
} }
static const struct softfilter_implementation normal2x_height_generic = { static const struct softfilter_implementation normal2x_height_generic = {
@ -208,7 +201,6 @@ static const struct softfilter_implementation normal2x_height_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &normal2x_height_generic; return &normal2x_height_generic;
} }

@ -41,8 +41,8 @@ struct softfilter_thread_data
struct filter_data struct filter_data
{ {
unsigned threads;
struct softfilter_thread_data *workers; struct softfilter_thread_data *workers;
unsigned threads;
unsigned in_fmt; unsigned in_fmt;
}; };
@ -68,22 +68,17 @@ static void *normal2x_width_generic_create(const struct softfilter_config *confi
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -91,16 +86,15 @@ static void normal2x_width_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width << 1; *out_width = width << 1;
*out_height = height; *out_height = height;
} }
static void normal2x_width_generic_destroy(void *data) static void normal2x_width_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -173,22 +167,21 @@ static void normal2x_width_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) { if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = normal2x_width_work_cb_xrgb8888; packets[0].work = normal2x_width_work_cb_xrgb8888;
} else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = normal2x_width_work_cb_rgb565; packets[0].work = normal2x_width_work_cb_rgb565;
} packets[0].thread_data = thr;
packets[0].thread_data = thr;
} }
static const struct softfilter_implementation normal2x_width_generic = { static const struct softfilter_implementation normal2x_width_generic = {
@ -210,7 +203,6 @@ static const struct softfilter_implementation normal2x_width_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &normal2x_width_generic; return &normal2x_width_generic;
} }

@ -68,22 +68,17 @@ static void *normal4x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -91,16 +86,15 @@ static void normal4x_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width << 2; *out_width = width << 2;
*out_height = height << 2; *out_height = height << 2;
} }
static void normal4x_generic_destroy(void *data) static void normal4x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -165,9 +159,9 @@ static void normal4x_work_cb_rgb565(void *data, void *thread_data)
uint16_t *out_ptr = output; uint16_t *out_ptr = output;
for (x = 0; x < thr->width; ++x) for (x = 0; x < thr->width; ++x)
{ {
uint16_t row_color[4];
uint16_t *out_line_ptr = out_ptr; uint16_t *out_line_ptr = out_ptr;
uint16_t color = *(input + x); uint16_t color = *(input + x);
uint16_t row_color[4];
row_color[0] = color; row_color[0] = color;
row_color[1] = color; row_color[1] = color;
@ -207,22 +201,21 @@ static void normal4x_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) { if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = normal4x_work_cb_xrgb8888; packets[0].work = normal4x_work_cb_xrgb8888;
} else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = normal4x_work_cb_rgb565; packets[0].work = normal4x_work_cb_rgb565;
} packets[0].thread_data = thr;
packets[0].thread_data = thr;
} }
static const struct softfilter_implementation normal4x_generic = { static const struct softfilter_implementation normal4x_generic = {
@ -244,7 +237,6 @@ static const struct softfilter_implementation normal4x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &normal4x_generic; return &normal4x_generic;
} }

@ -44,8 +44,8 @@ struct softfilter_thread_data
struct filter_data struct filter_data
{ {
unsigned threads;
struct softfilter_thread_data *workers; struct softfilter_thread_data *workers;
unsigned threads;
unsigned in_fmt; unsigned in_fmt;
float phosphor_bleed; float phosphor_bleed;
float scale_add; float scale_add;
@ -234,30 +234,23 @@ static void *phosphor2x_generic_create(const struct softfilter_config *config,
{ {
unsigned i; unsigned i;
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
(void)out_fmt;
(void)max_width;
(void)max_height;
(void)config;
(void)userdata;
if (!filt) if (!filt)
return NULL; return NULL;
filt->workers = (struct softfilter_thread_data*) if (!(filt->workers = (struct softfilter_thread_data*)
calloc(threads, sizeof(struct softfilter_thread_data)); calloc(threads, sizeof(struct softfilter_thread_data))))
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
filt->phosphor_bleed = 0.78; filt->phosphor_bleed = 0.78;
filt->scale_add = 1.0; filt->scale_add = 1.0;
filt->scale_times = 0.8; filt->scale_times = 0.8;
filt->scanrange_low = 0.5; filt->scanrange_low = 0.5;
filt->scanrange_high = 0.65; filt->scanrange_high = 0.65;
#if 0 #if 0
@ -271,7 +264,7 @@ static void *phosphor2x_generic_create(const struct softfilter_config *config,
filt->phosphor_bloom_8888[i] = filt->phosphor_bloom_8888[i] =
filt->scale_times * powf((float)i / 255.0f, 1.0f/2.2f) + filt->scale_times * powf((float)i / 255.0f, 1.0f/2.2f) +
filt->scale_add; filt->scale_add;
filt->scan_range_8888[i] = filt->scan_range_8888[i] =
filt->scanrange_low + i * filt->scanrange_low + i *
(filt->scanrange_high - filt->scanrange_low) / 255.0f; (filt->scanrange_high - filt->scanrange_low) / 255.0f;
} }
@ -280,7 +273,7 @@ static void *phosphor2x_generic_create(const struct softfilter_config *config,
filt->phosphor_bloom_565[i] = filt->phosphor_bloom_565[i] =
filt->scale_times * powf((float)i / 31.0f, 1.0f/2.2f) filt->scale_times * powf((float)i / 31.0f, 1.0f/2.2f)
+ filt->scale_add; + filt->scale_add;
filt->scan_range_565[i] = filt->scan_range_565[i] =
filt->scanrange_low + i * filt->scanrange_low + i *
(filt->scanrange_high - filt->scanrange_low) / 31.0f; (filt->scanrange_high - filt->scanrange_low) / 31.0f;
} }
@ -292,8 +285,7 @@ static void phosphor2x_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
(void)data; *out_width = width * PHOSPHOR2X_SCALE;
*out_width = width * PHOSPHOR2X_SCALE;
*out_height = height * PHOSPHOR2X_SCALE; *out_height = height * PHOSPHOR2X_SCALE;
} }
@ -316,9 +308,6 @@ static void phosphor2x_generic_xrgb8888(void *data,
unsigned y; unsigned y;
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
(void)first;
(void)last;
memset(dst, 0, height * dst_stride); memset(dst, 0, height * dst_stride);
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
@ -364,9 +353,6 @@ static void phosphor2x_generic_rgb565(void *data,
unsigned y; unsigned y;
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
(void)first;
(void)last;
memset(dst, 0, height * dst_stride); memset(dst, 0, height * dst_stride);
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
@ -410,7 +396,6 @@ static void phosphor2x_work_cb_xrgb8888(void *data, void *thread_data)
uint32_t *output = (uint32_t*)thr->out_data; uint32_t *output = (uint32_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
phosphor2x_generic_xrgb8888(data, width, height, phosphor2x_generic_xrgb8888(data, width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888),
@ -422,11 +407,10 @@ static void phosphor2x_work_cb_rgb565(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)thread_data; (struct softfilter_thread_data*)thread_data;
uint16_t *input = (uint16_t*)thr->in_data; uint16_t *input = (uint16_t*)thr->in_data;
uint16_t *output = (uint16_t*)thr->out_data; uint16_t *output = (uint16_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
phosphor2x_generic_rgb565(data, width, height, phosphor2x_generic_rgb565(data, width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565),
@ -446,28 +430,28 @@ static void phosphor2x_generic_packets(void *data,
struct softfilter_thread_data *thr = struct softfilter_thread_data *thr =
(struct softfilter_thread_data*)&filt->workers[i]; (struct softfilter_thread_data*)&filt->workers[i];
unsigned y_start = (height * i) / filt->threads; unsigned y_start = (height * i) / filt->threads;
unsigned y_end = (height * (i + 1)) / filt->threads; unsigned y_end = (height * (i + 1)) / filt->threads;
thr->out_data = (uint8_t*)output + y_start * PHOSPHOR2X_SCALE * output_stride; thr->out_data = (uint8_t*)output + y_start * PHOSPHOR2X_SCALE * output_stride;
thr->in_data = (const uint8_t*)input + y_start * input_stride; thr->in_data = (const uint8_t*)input + y_start * input_stride;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = y_end - y_start; thr->height = y_end - y_start;
/* Workers need to know if they can access pixels /* Workers need to know if they can access pixels
* outside their given buffer. */ * outside their given buffer. */
thr->first = y_start; thr->first = y_start;
thr->last = y_end == height; thr->last = y_end == height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[i].work = phosphor2x_work_cb_rgb565; packets[i].work = phosphor2x_work_cb_rgb565;
#if 0 #if 0
else if (filt->in_fmt == SOFTFILTER_FMT_RGB4444) else if (filt->in_fmt == SOFTFILTER_FMT_RGB4444)
packets[i].work = phosphor2x_work_cb_rgb4444; packets[i].work = phosphor2x_work_cb_rgb4444;
#endif #endif
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[i].work = phosphor2x_work_cb_xrgb8888; packets[i].work = phosphor2x_work_cb_xrgb8888;
packets[i].thread_data = thr; packets[i].thread_data = thr;
} }
} }
@ -490,7 +474,6 @@ static const struct softfilter_implementation phosphor2x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &phosphor2x_generic; return &phosphor2x_generic;
} }

@ -63,10 +63,10 @@ struct softfilter_thread_data
struct filter_data struct filter_data
{ {
unsigned threads;
struct softfilter_thread_data *workers;
unsigned in_fmt;
picoscale_functions_t functions; picoscale_functions_t functions;
struct softfilter_thread_data *workers;
unsigned threads;
unsigned in_fmt;
}; };
/******************************************************************* /*******************************************************************
@ -391,16 +391,15 @@ static void *picoscale_256x_320x240_generic_create(const struct softfilter_confi
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
if (!filt) if (!filt)
return NULL; return NULL;
/* Apparently the code is not thread-safe, if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
* so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
/* Assign scaling functions */ /* Assign scaling functions */
picoscale_256x_320x240_initialize(filt, config, userdata); picoscale_256x_320x240_initialize(filt, config, userdata);
@ -507,16 +506,17 @@ static void picoscale_256x_320x240_generic_packets(void *data,
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
/* TODO/FIXME - no XRGB8888 codepath? */
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = picoscale_256x_320x240_work_cb_rgb565; packets[0].work = picoscale_256x_320x240_work_cb_rgb565;
packets[0].thread_data = thr; packets[0].thread_data = thr;
} }
static const struct softfilter_implementation picoscale_256x_320x240_generic = { static const struct softfilter_implementation picoscale_256x_320x240_generic = {
@ -538,7 +538,6 @@ static const struct softfilter_implementation picoscale_256x_320x240_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &picoscale_256x_320x240_generic; return &picoscale_256x_320x240_generic;
} }

@ -68,22 +68,17 @@ static void *scale2x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -91,16 +86,15 @@ static void scale2x_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width << 1; *out_width = width << 1;
*out_height = height << 1; *out_height = height << 1;
} }
static void scale2x_generic_destroy(void *data) static void scale2x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -211,22 +205,21 @@ static void scale2x_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) { if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = scale2x_work_cb_xrgb8888; packets[0].work = scale2x_work_cb_xrgb8888;
} else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = scale2x_work_cb_rgb565; packets[0].work = scale2x_work_cb_rgb565;
} packets[0].thread_data = thr;
packets[0].thread_data = thr;
} }
static const struct softfilter_implementation scale2x_generic = { static const struct softfilter_implementation scale2x_generic = {
@ -248,7 +241,6 @@ static const struct softfilter_implementation scale2x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &scale2x_generic; return &scale2x_generic;
} }

@ -68,22 +68,17 @@ static void *scanline2x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -91,16 +86,15 @@ static void scanline2x_generic_output(void *data,
unsigned *out_width, unsigned *out_height, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width << 1; *out_width = width << 1;
*out_height = height << 1; *out_height = height << 1;
} }
static void scanline2x_generic_destroy(void *data) static void scanline2x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -203,22 +197,21 @@ static void scanline2x_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) { if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = scanline2x_work_cb_xrgb8888; packets[0].work = scanline2x_work_cb_xrgb8888;
} else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = scanline2x_work_cb_rgb565; packets[0].work = scanline2x_work_cb_rgb565;
} packets[0].thread_data = thr;
packets[0].thread_data = thr;
} }
static const struct softfilter_implementation scanline2x_generic = { static const struct softfilter_implementation scanline2x_generic = {
@ -240,7 +233,6 @@ static const struct softfilter_implementation scanline2x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &scanline2x_generic; return &scanline2x_generic;
} }

@ -72,26 +72,23 @@ static void *supertwoxsai_generic_create(const struct softfilter_config *config,
if (!filt) if (!filt)
return NULL; return NULL;
(void)simd; if (!(filt->workers = (struct softfilter_thread_data*)calloc(threads, sizeof(struct softfilter_thread_data))))
(void)config;
(void)userdata;
filt->workers = (struct softfilter_thread_data*)calloc(threads, sizeof(struct softfilter_thread_data));
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe,
* so force single threaded operation... */
filt->threads = 1;
filt->in_fmt = in_fmt;
return filt; return filt;
} }
static void supertwoxsai_generic_output(void *data, unsigned *out_width, unsigned *out_height, static void supertwoxsai_generic_output(void *data, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width * SUPERTWOXSAI_SCALE; *out_width = width * SUPERTWOXSAI_SCALE;
*out_height = height * SUPERTWOXSAI_SCALE; *out_height = height * SUPERTWOXSAI_SCALE;
} }
@ -265,11 +262,10 @@ static void supertwoxsai_generic_rgb565(unsigned width, unsigned height,
static void supertwoxsai_work_cb_rgb565(void *data, void *thread_data) static void supertwoxsai_work_cb_rgb565(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data;
uint16_t *input = (uint16_t*)thr->in_data; uint16_t *input = (uint16_t*)thr->in_data;
uint16_t *output = (uint16_t*)thr->out_data; uint16_t *output = (uint16_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
supertwoxsai_generic_rgb565(width, height, supertwoxsai_generic_rgb565(width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565),
@ -280,16 +276,15 @@ static void supertwoxsai_work_cb_rgb565(void *data, void *thread_data)
static void supertwoxsai_work_cb_xrgb8888(void *data, void *thread_data) static void supertwoxsai_work_cb_xrgb8888(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data;
uint32_t *input = (uint32_t*)thr->in_data; uint32_t *input = (uint32_t*)thr->in_data;
uint32_t *output = (uint32_t*)thr->out_data; uint32_t *output = (uint32_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
supertwoxsai_generic_xrgb8888(width, height, supertwoxsai_generic_xrgb8888(width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888),
output, output,
(unsigned)(thr->out_pitch / SOFTFILTER_BPP_XRGB8888)); (unsigned)(thr->out_pitch / SOFTFILTER_BPP_XRGB8888));
} }
static void supertwoxsai_generic_packets(void *data, static void supertwoxsai_generic_packets(void *data,
@ -304,24 +299,24 @@ static void supertwoxsai_generic_packets(void *data,
{ {
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[i]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[i];
unsigned y_start = (height * i) / filt->threads; unsigned y_start = (height * i) / filt->threads;
unsigned y_end = (height * (i + 1)) / filt->threads; unsigned y_end = (height * (i + 1)) / filt->threads;
thr->out_data = (uint8_t*)output + y_start * SUPERTWOXSAI_SCALE * output_stride; thr->out_data = (uint8_t*)output + y_start * SUPERTWOXSAI_SCALE * output_stride;
thr->in_data = (const uint8_t*)input + y_start * input_stride; thr->in_data = (const uint8_t*)input + y_start * input_stride;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = y_end - y_start; thr->height = y_end - y_start;
/* Workers need to know if they can access pixels /* Workers need to know if they can access pixels
* outside their given buffer. */ * outside their given buffer. */
thr->first = y_start; thr->first = y_start;
thr->last = y_end == height; thr->last = y_end == height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[i].work = supertwoxsai_work_cb_rgb565; packets[i].work = supertwoxsai_work_cb_rgb565;
else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[i].work = supertwoxsai_work_cb_xrgb8888; packets[i].work = supertwoxsai_work_cb_xrgb8888;
packets[i].thread_data = thr; packets[i].thread_data = thr;
} }
} }
@ -343,7 +338,6 @@ static const struct softfilter_implementation supertwoxsai_generic = {
const struct softfilter_implementation *softfilter_get_implementation(softfilter_simd_mask_t simd) const struct softfilter_implementation *softfilter_get_implementation(softfilter_simd_mask_t simd)
{ {
(void)simd;
return &supertwoxsai_generic; return &supertwoxsai_generic;
} }

@ -69,26 +69,22 @@ static void *supereagle_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd;
(void)config;
(void)userdata;
if (!filt) if (!filt)
return NULL; return NULL;
filt->workers = (struct softfilter_thread_data*)calloc(threads, sizeof(struct softfilter_thread_data)); if (!(filt->workers = (struct softfilter_thread_data*)calloc(threads, sizeof(struct softfilter_thread_data))))
filt->threads = 1;
filt->in_fmt = in_fmt;
if (!filt->workers)
{ {
free(filt); free(filt);
return NULL; return NULL;
} }
filt->threads = 1;
filt->in_fmt = in_fmt;
return filt; return filt;
} }
static void supereagle_generic_output(void *data, unsigned *out_width, unsigned *out_height, static void supereagle_generic_output(void *data, unsigned *out_width, unsigned *out_height,
unsigned width, unsigned height) unsigned width, unsigned height)
{ {
*out_width = width * SUPEREAGLE_SCALE; *out_width = width * SUPEREAGLE_SCALE;
*out_height = height * SUPEREAGLE_SCALE; *out_height = height * SUPEREAGLE_SCALE;
} }
@ -229,7 +225,6 @@ static void supereagle_generic_xrgb8888(unsigned width, unsigned height,
for (finish = width; finish; finish -= 1) for (finish = width; finish; finish -= 1)
{ {
supereagle_declare_variables(uint32_t, in, nextline); supereagle_declare_variables(uint32_t, in, nextline);
supereagle_function(supereagle_result, supereagle_interpolate_xrgb8888, supereagle_interpolate2_xrgb8888); supereagle_function(supereagle_result, supereagle_interpolate_xrgb8888, supereagle_interpolate2_xrgb8888);
} }
@ -253,7 +248,6 @@ static void supereagle_generic_rgb565(unsigned width, unsigned height,
for (finish = width; finish; finish -= 1) for (finish = width; finish; finish -= 1)
{ {
supereagle_declare_variables(uint16_t, in, nextline); supereagle_declare_variables(uint16_t, in, nextline);
supereagle_function(supereagle_result, supereagle_interpolate_rgb565, supereagle_interpolate2_rgb565); supereagle_function(supereagle_result, supereagle_interpolate_rgb565, supereagle_interpolate2_rgb565);
} }
@ -265,31 +259,31 @@ static void supereagle_generic_rgb565(unsigned width, unsigned height,
static void supereagle_work_cb_rgb565(void *data, void *thread_data) static void supereagle_work_cb_rgb565(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data;
uint16_t *input = (uint16_t*)thr->in_data; uint16_t *input = (uint16_t*)thr->in_data;
uint16_t *output = (uint16_t*)thr->out_data; uint16_t *output = (uint16_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
supereagle_generic_rgb565(width, height, supereagle_generic_rgb565(width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_RGB565),
output, output,
(unsigned)(thr->out_pitch / SOFTFILTER_BPP_RGB565)); (unsigned)(thr->out_pitch / SOFTFILTER_BPP_RGB565));
} }
static void supereagle_work_cb_xrgb8888(void *data, void *thread_data) static void supereagle_work_cb_xrgb8888(void *data, void *thread_data)
{ {
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)thread_data;
uint32_t *input = (uint32_t*)thr->in_data; uint32_t *input = (uint32_t*)thr->in_data;
uint32_t *output = (uint32_t*)thr->out_data; uint32_t *output = (uint32_t*)thr->out_data;
unsigned width = thr->width; unsigned width = thr->width;
unsigned height = thr->height; unsigned height = thr->height;
supereagle_generic_xrgb8888(width, height, supereagle_generic_xrgb8888(width, height,
thr->first, thr->last, input, thr->first, thr->last, input,
(unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888), (unsigned)(thr->in_pitch / SOFTFILTER_BPP_XRGB8888),
output, output,
(unsigned)(thr->out_pitch / SOFTFILTER_BPP_XRGB8888)); (unsigned)(thr->out_pitch / SOFTFILTER_BPP_XRGB8888));
} }
static void supereagle_generic_packets(void *data, static void supereagle_generic_packets(void *data,
@ -304,23 +298,23 @@ static void supereagle_generic_packets(void *data,
{ {
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[i]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[i];
unsigned y_start = (height * i) / filt->threads; unsigned y_start = (height * i) / filt->threads;
unsigned y_end = (height * (i + 1)) / filt->threads; unsigned y_end = (height * (i + 1)) / filt->threads;
thr->out_data = (uint8_t*)output + y_start * SUPEREAGLE_SCALE * output_stride; thr->out_data = (uint8_t*)output + y_start * SUPEREAGLE_SCALE * output_stride;
thr->in_data = (const uint8_t*)input + y_start * input_stride; thr->in_data = (const uint8_t*)input + y_start * input_stride;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = y_end - y_start; thr->height = y_end - y_start;
/* Workers need to know if they can access pixels outside their given buffer. */ /* Workers need to know if they can access pixels outside their given buffer. */
thr->first = y_start; thr->first = y_start;
thr->last = y_end == height; thr->last = y_end == height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[i].work = supereagle_work_cb_rgb565; packets[i].work = supereagle_work_cb_rgb565;
else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) else if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[i].work = supereagle_work_cb_xrgb8888; packets[i].work = supereagle_work_cb_xrgb8888;
packets[i].thread_data = thr; packets[i].thread_data = thr;
} }
} }
@ -342,7 +336,6 @@ static const struct softfilter_implementation supereagle_generic = {
const struct softfilter_implementation *softfilter_get_implementation(softfilter_simd_mask_t simd) const struct softfilter_implementation *softfilter_get_implementation(softfilter_simd_mask_t simd)
{ {
(void)simd;
return &supereagle_generic; return &supereagle_generic;
} }

@ -68,22 +68,17 @@ static void *upscale_1_5x_generic_create(const struct softfilter_config *config,
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -98,9 +93,8 @@ static void upscale_1_5x_generic_output(void *data,
static void upscale_1_5x_generic_destroy(void *data) static void upscale_1_5x_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -139,34 +133,34 @@ static void upscale_1_5x_work_cb_xrgb8888(void *data, void *thread_data)
const uint32_t *in_line_ptr = input + (x << 1); const uint32_t *in_line_ptr = input + (x << 1);
uint32_t *out_line_ptr = out_ptr; uint32_t *out_line_ptr = out_ptr;
color_a = *in_line_ptr; color_a = *in_line_ptr;
color_b = *(in_line_ptr + 1); color_b = *(in_line_ptr + 1);
in_line_ptr += in_stride; in_line_ptr += in_stride;
color_c = *in_line_ptr; color_c = *in_line_ptr;
color_d = *(in_line_ptr + 1); color_d = *(in_line_ptr + 1);
color_ab = (color_a + color_b + ((color_a ^ color_b) & 0x1010101)) >> 1; color_ab = (color_a + color_b + ((color_a ^ color_b) & 0x1010101)) >> 1;
color_cd = (color_c + color_d + ((color_c ^ color_d) & 0x1010101)) >> 1; color_cd = (color_c + color_d + ((color_c ^ color_d) & 0x1010101)) >> 1;
/* Row 1 */ /* Row 1 */
*out_line_ptr = color_a; *out_line_ptr = color_a;
*(out_line_ptr + 1) = color_ab; *(out_line_ptr + 1) = color_ab;
*(out_line_ptr + 2) = color_b; *(out_line_ptr + 2) = color_b;
out_line_ptr += out_stride; out_line_ptr += out_stride;
/* Row 2 */ /* Row 2 */
*out_line_ptr = (color_a + color_c + ((color_a ^ color_c) & 0x1010101)) >> 1; *out_line_ptr = (color_a + color_c + ((color_a ^ color_c) & 0x1010101)) >> 1;
*(out_line_ptr + 1) = (color_ab + color_cd + ((color_ab ^ color_cd) & 0x1010101)) >> 1; *(out_line_ptr + 1) = (color_ab + color_cd + ((color_ab ^ color_cd) & 0x1010101)) >> 1;
*(out_line_ptr + 2) = (color_b + color_d + ((color_b ^ color_d) & 0x1010101)) >> 1; *(out_line_ptr + 2) = (color_b + color_d + ((color_b ^ color_d) & 0x1010101)) >> 1;
out_line_ptr += out_stride; out_line_ptr += out_stride;
/* Row 3 */ /* Row 3 */
*out_line_ptr = color_c; *out_line_ptr = color_c;
*(out_line_ptr + 1) = color_cd; *(out_line_ptr + 1) = color_cd;
*(out_line_ptr + 2) = color_d; *(out_line_ptr + 2) = color_d;
out_ptr += 3; out_ptr += 3;
} }
input += in_stride << 1; input += in_stride << 1;
@ -253,22 +247,21 @@ static void upscale_1_5x_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888) { if (filt->in_fmt == SOFTFILTER_FMT_XRGB8888)
packets[0].work = upscale_1_5x_work_cb_xrgb8888; packets[0].work = upscale_1_5x_work_cb_xrgb8888;
} else if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { else if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
packets[0].work = upscale_1_5x_work_cb_rgb565; packets[0].work = upscale_1_5x_work_cb_rgb565;
} packets[0].thread_data = thr;
packets[0].thread_data = thr;
} }
static const struct softfilter_implementation upscale_1_5x_generic = { static const struct softfilter_implementation upscale_1_5x_generic = {
@ -290,7 +283,6 @@ static const struct softfilter_implementation upscale_1_5x_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &upscale_1_5x_generic; return &upscale_1_5x_generic;
} }

@ -333,22 +333,17 @@ static void *upscale_240x160_320x240_generic_create(const struct softfilter_conf
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
/* Assign scaling functions */ /* Assign scaling functions */
upscale_240x160_320x240_initialize(filt, config, userdata); upscale_240x160_320x240_initialize(filt, config, userdata);
@ -375,9 +370,8 @@ static void upscale_240x160_320x240_generic_output(void *data,
static void upscale_240x160_320x240_generic_destroy(void *data) static void upscale_240x160_320x240_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -429,20 +423,20 @@ static void upscale_240x160_320x240_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { /* TODO/FIXME - no XRGB8888 codepath? */
packets[0].work = upscale_240x160_320x240_work_cb_rgb565; if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
} packets[0].work = upscale_240x160_320x240_work_cb_rgb565;
packets[0].thread_data = thr; packets[0].thread_data = thr;
} }
static const struct softfilter_implementation upscale_240x160_320x240_generic = { static const struct softfilter_implementation upscale_240x160_320x240_generic = {
@ -464,7 +458,6 @@ static const struct softfilter_implementation upscale_240x160_320x240_generic =
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &upscale_240x160_320x240_generic; return &upscale_240x160_320x240_generic;
} }

@ -574,22 +574,17 @@ static void *upscale_256x_320x240_generic_create(const struct softfilter_config
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
return filt; return filt;
} }
@ -613,9 +608,8 @@ static void upscale_256x_320x240_generic_output(void *data,
static void upscale_256x_320x240_generic_destroy(void *data) static void upscale_256x_320x240_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -679,20 +673,20 @@ static void upscale_256x_320x240_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { /* TODO/FIXME - no XRGB8888 codepath? */
packets[0].work = upscale_256x_320x240_work_cb_rgb565; if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
} packets[0].work = upscale_256x_320x240_work_cb_rgb565;
packets[0].thread_data = thr; packets[0].thread_data = thr;
} }
static const struct softfilter_implementation upscale_256x_320x240_generic = { static const struct softfilter_implementation upscale_256x_320x240_generic = {
@ -714,7 +708,6 @@ static const struct softfilter_implementation upscale_256x_320x240_generic = {
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &upscale_256x_320x240_generic; return &upscale_256x_320x240_generic;
} }

@ -89,18 +89,14 @@ void upscale_mix_240x160_to_320x240(uint16_t *dst, const uint16_t *src,
for (block_x = 0; block_x < 80; block_x++) for (block_x = 0; block_x < 80; block_x++)
{ {
const uint16_t *block_src_ptr = block_src; uint16_t _4, _5, _6;
uint16_t *block_dst_ptr = block_dst;
uint16_t _1, _2, _3,
_4, _5, _6;
uint16_t _1_2_weight_1_3; uint16_t _1_2_weight_1_3;
uint16_t _2_3_weight_1_1; uint16_t _2_3_weight_1_1;
uint16_t _4_5_weight_1_3; uint16_t _4_5_weight_1_3;
uint16_t _5_6_weight_1_1; uint16_t _5_6_weight_1_1;
uint16_t tmp; uint16_t tmp;
const uint16_t *block_src_ptr = block_src;
uint16_t *block_dst_ptr = block_dst;
/* Horizontally: /* Horizontally:
* Before(3): * Before(3):
@ -116,9 +112,9 @@ void upscale_mix_240x160_to_320x240(uint16_t *dst, const uint16_t *src,
*/ */
/* -- Row 1 -- */ /* -- Row 1 -- */
_1 = *(block_src_ptr ); uint16_t _1 = *(block_src_ptr );
_2 = *(block_src_ptr + 1); uint16_t _2 = *(block_src_ptr + 1);
_3 = *(block_src_ptr + 2); uint16_t _3 = *(block_src_ptr + 2);
*(block_dst_ptr ) = _1; *(block_dst_ptr ) = _1;
UPSCALE_240__WEIGHT_1_3(_1, _2, block_dst_ptr + 1, tmp); UPSCALE_240__WEIGHT_1_3(_1, _2, block_dst_ptr + 1, tmp);
@ -277,12 +273,10 @@ void upscale_mix_240x160_to_320x240_aspect(uint16_t *dst, const uint16_t *src,
for (block_x = 0; block_x < 80; block_x++) for (block_x = 0; block_x < 80; block_x++)
{ {
uint16_t tmp;
const uint16_t *block_src_ptr = block_src; const uint16_t *block_src_ptr = block_src;
uint16_t *block_dst_ptr = block_dst; uint16_t *block_dst_ptr = block_dst;
uint16_t _1, _2, _3;
uint16_t tmp;
/* Horizontally: /* Horizontally:
* Before(3): * Before(3):
* (a)(b)(c) * (a)(b)(c)
@ -291,17 +285,17 @@ void upscale_mix_240x160_to_320x240_aspect(uint16_t *dst, const uint16_t *src,
*/ */
/* -- Row 1 -- */ /* -- Row 1 -- */
_1 = *(block_src_ptr ); uint16_t _1 = *(block_src_ptr );
_2 = *(block_src_ptr + 1); uint16_t _2 = *(block_src_ptr + 1);
_3 = *(block_src_ptr + 2); uint16_t _3 = *(block_src_ptr + 2);
*(block_dst_ptr ) = _1; *(block_dst_ptr ) = _1;
UPSCALE_240__WEIGHT_1_3(_1, _2, block_dst_ptr + 1, tmp); UPSCALE_240__WEIGHT_1_3(_1, _2, block_dst_ptr + 1, tmp);
UPSCALE_240__WEIGHT_1_1(_2, _3, block_dst_ptr + 2, tmp); UPSCALE_240__WEIGHT_1_1(_2, _3, block_dst_ptr + 2, tmp);
*(block_dst_ptr + 3) = _3; *(block_dst_ptr + 3) = _3;
block_src += 3; block_src += 3;
block_dst += 4; block_dst += 4;
} }
/* Letterboxing - zero out last 14 rows */ /* Letterboxing - zero out last 14 rows */
@ -337,8 +331,7 @@ static void upscale_mix_240x160_320x240_initialize(struct filter_data *filt,
filt->function.upscale_mix_240x160_320x240 = upscale_mix_240x160_to_320x240_aspect; filt->function.upscale_mix_240x160_320x240 = upscale_mix_240x160_to_320x240_aspect;
/* Read aspect ratio correction setting */ /* Read aspect ratio correction setting */
if (config->get_int(userdata, "keep_aspect", &keep_aspect, 1) && if (config->get_int(userdata, "keep_aspect", &keep_aspect, 1) && !keep_aspect)
!keep_aspect)
filt->function.upscale_mix_240x160_320x240 = upscale_mix_240x160_to_320x240; filt->function.upscale_mix_240x160_320x240 = upscale_mix_240x160_to_320x240;
} }
@ -348,23 +341,17 @@ static void *upscale_mix_240x160_320x240_generic_create(const struct softfilter_
unsigned threads, softfilter_simd_mask_t simd, void *userdata) unsigned threads, softfilter_simd_mask_t simd, void *userdata)
{ {
struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt)); struct filter_data *filt = (struct filter_data*)calloc(1, sizeof(*filt));
(void)simd; if (!filt)
(void)config; return NULL;
(void)userdata; if (!(filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data))))
{
if (!filt) { free(filt);
return NULL; return NULL;
} }
/* Apparently the code is not thread-safe, /* Apparently the code is not thread-safe,
* so force single threaded operation... */ * so force single threaded operation... */
filt->workers = (struct softfilter_thread_data*)calloc(1, sizeof(struct softfilter_thread_data));
filt->threads = 1; filt->threads = 1;
filt->in_fmt = in_fmt; filt->in_fmt = in_fmt;
if (!filt->workers) {
free(filt);
return NULL;
}
/* Assign scaling functions */ /* Assign scaling functions */
upscale_mix_240x160_320x240_initialize(filt, config, userdata); upscale_mix_240x160_320x240_initialize(filt, config, userdata);
@ -390,9 +377,8 @@ static void upscale_mix_240x160_320x240_generic_output(void *data,
static void upscale_mix_240x160_320x240_generic_destroy(void *data) static void upscale_mix_240x160_320x240_generic_destroy(void *data)
{ {
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
if (!filt) { if (!filt)
return; return;
}
free(filt->workers); free(filt->workers);
free(filt); free(filt);
} }
@ -444,20 +430,20 @@ static void upscale_mix_240x160_320x240_generic_packets(void *data,
* over threads and can cull some code. This only * over threads and can cull some code. This only
* makes the tiniest performance difference, but * makes the tiniest performance difference, but
* every little helps when running on an o3DS... */ * every little helps when running on an o3DS... */
struct filter_data *filt = (struct filter_data*)data; struct filter_data *filt = (struct filter_data*)data;
struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0]; struct softfilter_thread_data *thr = (struct softfilter_thread_data*)&filt->workers[0];
thr->out_data = (uint8_t*)output; thr->out_data = (uint8_t*)output;
thr->in_data = (const uint8_t*)input; thr->in_data = (const uint8_t*)input;
thr->out_pitch = output_stride; thr->out_pitch = output_stride;
thr->in_pitch = input_stride; thr->in_pitch = input_stride;
thr->width = width; thr->width = width;
thr->height = height; thr->height = height;
if (filt->in_fmt == SOFTFILTER_FMT_RGB565) { /* TODO/FIXME - no XRGB8888 codepath? */
packets[0].work = upscale_mix_240x160_320x240_work_cb_rgb565; if (filt->in_fmt == SOFTFILTER_FMT_RGB565)
} packets[0].work = upscale_mix_240x160_320x240_work_cb_rgb565;
packets[0].thread_data = thr; packets[0].thread_data = thr;
} }
static const struct softfilter_implementation upscale_mix_240x160_320x240_generic = { static const struct softfilter_implementation upscale_mix_240x160_320x240_generic = {
@ -479,7 +465,6 @@ static const struct softfilter_implementation upscale_mix_240x160_320x240_generi
const struct softfilter_implementation *softfilter_get_implementation( const struct softfilter_implementation *softfilter_get_implementation(
softfilter_simd_mask_t simd) softfilter_simd_mask_t simd)
{ {
(void)simd;
return &upscale_mix_240x160_320x240_generic; return &upscale_mix_240x160_320x240_generic;
} }

@ -134,7 +134,7 @@ void scope_repeat(scope_t *scope)
else else
{ {
gen->value.val_int += gen->increment.val_int; gen->value.val_int += gen->increment.val_int;
if(gen->shift > 0) if (gen->shift > 0)
gen->value.val_int <<= gen->shift; gen->value.val_int <<= gen->shift;
else if (gen->shift < 0) else if (gen->shift < 0)
gen->value.val_int >>= -gen->shift; gen->value.val_int >>= -gen->shift;

@ -92,7 +92,7 @@ static void hidpad_retrode_get_buttons(void *pad_data, input_bits_t *state)
retrode_pad_data_t *pad = (retrode_pad_data_t *)pad_data; retrode_pad_data_t *pad = (retrode_pad_data_t *)pad_data;
if (pad) if (pad)
{ {
if(pad->datatype == RETRODE_TYPE_PAD) if (pad->datatype == RETRODE_TYPE_PAD)
{ {
BITS_COPY16_PTR(state, pad->buttons); BITS_COPY16_PTR(state, pad->buttons);
} }
@ -117,7 +117,7 @@ static int16_t hidpad_retrode_get_axis(void *pad_data, unsigned axis)
if (!pad || axis >= 2) if (!pad || axis >= 2)
return 0; return 0;
if(pad->datatype == RETRODE_TYPE_PAD) if (pad->datatype == RETRODE_TYPE_PAD)
val = pad->data[2 + axis]; val = pad->data[2 + axis];
else else
val = device->pad_data[0].data[2 + axis]; val = device->pad_data[0].data[2 + axis];
@ -228,7 +228,7 @@ static void *hidpad_retrode_pad_init(void *device_data, int pad_index, joypad_co
{ {
retrode_device_data_t *device = (retrode_device_data_t *)device_data; retrode_device_data_t *device = (retrode_device_data_t *)device_data;
if(!device || pad_index < 0 || pad_index >= RETRODE_MAX_PAD || !joypad || device->pad_data[pad_index].joypad) if (!device || pad_index < 0 || pad_index >= RETRODE_MAX_PAD || !joypad || device->pad_data[pad_index].joypad)
return NULL; return NULL;
device->pad_data[pad_index].joypad = joypad; device->pad_data[pad_index].joypad = joypad;
@ -238,11 +238,8 @@ static void *hidpad_retrode_pad_init(void *device_data, int pad_index, joypad_co
static void hidpad_retrode_pad_deinit(void *pad_data) static void hidpad_retrode_pad_deinit(void *pad_data)
{ {
retrode_pad_data_t *pad = (retrode_pad_data_t *)pad_data; retrode_pad_data_t *pad = (retrode_pad_data_t *)pad_data;
if (pad)
if(!pad) pad->joypad = NULL;
return;
pad->joypad = NULL;
} }
static int8_t hidpad_retrode_status(void *device_data, int pad_index) static int8_t hidpad_retrode_status(void *device_data, int pad_index)
@ -250,7 +247,7 @@ static int8_t hidpad_retrode_status(void *device_data, int pad_index)
retrode_device_data_t *device = (retrode_device_data_t *)device_data; retrode_device_data_t *device = (retrode_device_data_t *)device_data;
int8_t result = 0; int8_t result = 0;
if(!device || pad_index < 0 || pad_index >= RETRODE_MAX_PAD) if (!device || pad_index < 0 || pad_index >= RETRODE_MAX_PAD)
return 0; return 0;
result |= PAD_CONNECT_READY; result |= PAD_CONNECT_READY;
@ -265,7 +262,7 @@ static joypad_connection_t *hidpad_retrode_joypad(void *device_data, int pad_ind
{ {
retrode_device_data_t *device = (retrode_device_data_t *)device_data; retrode_device_data_t *device = (retrode_device_data_t *)device_data;
if(!device || pad_index < 0 || pad_index >= RETRODE_MAX_PAD) if (!device || pad_index < 0 || pad_index >= RETRODE_MAX_PAD)
return 0; return 0;
return device->pad_data[pad_index].joypad; return device->pad_data[pad_index].joypad;
} }

@ -420,8 +420,7 @@ static int wiimote_handshake(struct connect_wii_wiimote_t* wm,
/* estamos haciendo handshake o bien se necesita iniciar un /* estamos haciendo handshake o bien se necesita iniciar un
* nuevo handshake ya que se inserta(quita una expansion. */ * nuevo handshake ya que se inserta(quita una expansion. */
int attachment = 0; int attachment = 0;
if (event != WM_RPT_CTRL_STATUS)
if(event != WM_RPT_CTRL_STATUS)
return 0; return 0;
/* Is an attachment connected to /* Is an attachment connected to
@ -440,7 +439,7 @@ static int wiimote_handshake(struct connect_wii_wiimote_t* wm,
/* Send the initialization code for the attachment */ /* Send the initialization code for the attachment */
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_HANDSHAKE_COMPLETE)) if (WIIMOTE_IS_SET(wm,WIIMOTE_STATE_HANDSHAKE_COMPLETE))
{ {
/* Rehandshake. */ /* Rehandshake. */
@ -481,7 +480,7 @@ static int wiimote_handshake(struct connect_wii_wiimote_t* wm,
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP);
wm->exp.type = EXP_NONE; wm->exp.type = EXP_NONE;
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_HANDSHAKE_COMPLETE)) if (WIIMOTE_IS_SET(wm,WIIMOTE_STATE_HANDSHAKE_COMPLETE))
{ {
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
/* forzamos un handshake por si venimos /* forzamos un handshake por si venimos
@ -490,7 +489,7 @@ static int wiimote_handshake(struct connect_wii_wiimote_t* wm,
} }
} }
if(!attachment && WIIMOTE_IS_SET(wm,WIIMOTE_STATE_HANDSHAKE)) if (!attachment && WIIMOTE_IS_SET(wm,WIIMOTE_STATE_HANDSHAKE))
{ {
wm->handshake_state = 2; wm->handshake_state = 2;
continue; continue;
@ -536,7 +535,7 @@ static int wiimote_handshake(struct connect_wii_wiimote_t* wm,
} }
return 0; return 0;
case 5: case 5:
if(event != WM_RPT_READ) if (event != WM_RPT_READ)
return 0; return 0;
wiimote_classic_ctrl_handshake(wm, &wm->exp.cc.classic, data,len); wiimote_classic_ctrl_handshake(wm, &wm->exp.cc.classic, data,len);

@ -108,7 +108,7 @@ static void hidpad_wiiugca_get_buttons(void *pad_data, input_bits_t *state)
gca_pad_data_t *pad = (gca_pad_data_t *)pad_data; gca_pad_data_t *pad = (gca_pad_data_t *)pad_data;
if (pad) if (pad)
{ {
if(pad->datatype == GCA_TYPE_PAD) if (pad->datatype == GCA_TYPE_PAD)
{ {
BITS_COPY16_PTR(state, pad->buttons); BITS_COPY16_PTR(state, pad->buttons);
} }
@ -134,10 +134,8 @@ static int16_t hidpad_wiiugca_get_axis(void *pad_data, unsigned axis)
if (!pad || axis_data.axis >= 4) if (!pad || axis_data.axis >= 4)
return 0; return 0;
if (pad->datatype == GCA_TYPE_PAD)
if(pad->datatype == GCA_TYPE_PAD)
return gamepad_get_axis_value(pad->analog, &axis_data); return gamepad_get_axis_value(pad->analog, &axis_data);
return gamepad_get_axis_value(device->pad_data[0].analog, &axis_data); return gamepad_get_axis_value(device->pad_data[0].analog, &axis_data);
} }
@ -244,7 +242,7 @@ static void hidpad_wiiugca_set_rumble(void *data,
const char *hidpad_wiiugca_get_name(void *pad_data) const char *hidpad_wiiugca_get_name(void *pad_data)
{ {
gca_pad_data_t *pad = (gca_pad_data_t *)pad_data; gca_pad_data_t *pad = (gca_pad_data_t *)pad_data;
if(!pad || pad->datatype != GCA_TYPE_PAD) if (!pad || pad->datatype != GCA_TYPE_PAD)
return DEVICE_NAME; return DEVICE_NAME;
switch(pad->device_data->connected[pad->pad_index]) switch(pad->device_data->connected[pad->pad_index])
@ -284,7 +282,7 @@ static void *hidpad_wiiugca_pad_init(void *device_data, int pad_index, joypad_co
{ {
gca_device_data_t *device = (gca_device_data_t *)device_data; gca_device_data_t *device = (gca_device_data_t *)device_data;
if(!device || pad_index < 0 || pad_index >= GCA_MAX_PAD || !joypad || device->pad_data[pad_index].joypad || !device->connected[pad_index]) if (!device || pad_index < 0 || pad_index >= GCA_MAX_PAD || !joypad || device->pad_data[pad_index].joypad || !device->connected[pad_index])
return NULL; return NULL;
device->pad_data[pad_index].joypad = joypad; device->pad_data[pad_index].joypad = joypad;
@ -295,18 +293,16 @@ static void hidpad_wiiugca_pad_deinit(void *pad_data)
{ {
gca_pad_data_t *pad = (gca_pad_data_t *)pad_data; gca_pad_data_t *pad = (gca_pad_data_t *)pad_data;
if(!pad) if (pad)
return; pad->joypad = NULL;
pad->joypad = NULL;
} }
static int8_t hidpad_wiiugca_status(void *device_data, int pad_index) static int8_t hidpad_wiiugca_status(void *device_data, int pad_index)
{ {
gca_device_data_t *device = (gca_device_data_t *)device_data;
int8_t result = 0; int8_t result = 0;
gca_device_data_t *device = (gca_device_data_t *)device_data;
if(!device || pad_index < 0 || pad_index >= GCA_MAX_PAD) if (!device || pad_index < 0 || pad_index >= GCA_MAX_PAD)
return 0; return 0;
if (device->connected[pad_index]) if (device->connected[pad_index])
@ -321,10 +317,8 @@ static int8_t hidpad_wiiugca_status(void *device_data, int pad_index)
static joypad_connection_t *hidpad_wiiugca_joypad(void *device_data, int pad_index) static joypad_connection_t *hidpad_wiiugca_joypad(void *device_data, int pad_index)
{ {
gca_device_data_t *device = (gca_device_data_t *)device_data; gca_device_data_t *device = (gca_device_data_t *)device_data;
if (!device || pad_index < 0 || pad_index >= GCA_MAX_PAD)
if(!device || pad_index < 0 || pad_index >= GCA_MAX_PAD)
return 0; return 0;
return device->pad_data[pad_index].joypad; return device->pad_data[pad_index].joypad;
} }

@ -219,7 +219,7 @@ static void hidpad_wiiupro_packet_handler(void *data,
device->data.btn.home = (packet[0x0C] & 0x8) ? 1 : 0; device->data.btn.home = (packet[0x0C] & 0x8) ? 1 : 0;
if(device->calib.calib_round < 5) if (device->calib.calib_round < 5)
{ {
device->calib.hatvalue_calib[0] = (packet[4] | (packet[4 + 1] << 8)); device->calib.hatvalue_calib[0] = (packet[4] | (packet[4 + 1] << 8));
device->calib.hatvalue_calib[1] = (packet[8] | (packet[8 + 1] << 8)); device->calib.hatvalue_calib[1] = (packet[8] | (packet[8 + 1] << 8));

@ -1132,7 +1132,7 @@ static void handle_hotplug(android_input_t *android,
* This device is composed of two hid devices * This device is composed of two hid devices
* We make it look like one device * We make it look like one device
*/ */
else if( else if (
( (
string_starts_with_size(device_model, "R800", STRLEN_CONST("R800")) || string_starts_with_size(device_model, "R800", STRLEN_CONST("R800")) ||
strstr(device_model, "Xperia Play") || strstr(device_model, "Xperia Play") ||
@ -1326,17 +1326,17 @@ static void engine_handle_touchpad(
int action = AMOTION_EVENT_ACTION_MASK int action = AMOTION_EVENT_ACTION_MASK
& AMotionEvent_getAction(event); & AMotionEvent_getAction(event);
int raw_action = AMotionEvent_getAction(event); int raw_action = AMotionEvent_getAction(event);
if( action == AMOTION_EVENT_ACTION_POINTER_DOWN if ( action == AMOTION_EVENT_ACTION_POINTER_DOWN
|| action == AMOTION_EVENT_ACTION_POINTER_UP ) || action == AMOTION_EVENT_ACTION_POINTER_UP )
{ {
int pointer_index = (AMotionEvent_getAction( event ) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; int pointer_index = (AMotionEvent_getAction( event ) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
pointer_id = AMotionEvent_getPointerId( event, pointer_index); pointer_id = AMotionEvent_getPointerId( event, pointer_index);
} }
if( action == AMOTION_EVENT_ACTION_DOWN if ( action == AMOTION_EVENT_ACTION_DOWN
|| action == AMOTION_EVENT_ACTION_POINTER_DOWN ) || action == AMOTION_EVENT_ACTION_POINTER_DOWN )
touchstate[pointer_id].down = 1; touchstate[pointer_id].down = 1;
else if( action == AMOTION_EVENT_ACTION_UP else if (action == AMOTION_EVENT_ACTION_UP
|| action == AMOTION_EVENT_ACTION_POINTER_UP || action == AMOTION_EVENT_ACTION_POINTER_UP
|| action == AMOTION_EVENT_ACTION_CANCEL ) || action == AMOTION_EVENT_ACTION_CANCEL )
touchstate[pointer_id].down = 0; touchstate[pointer_id].down = 0;
@ -1669,8 +1669,9 @@ static int16_t android_input_state(
case RETRO_DEVICE_MOUSE: case RETRO_DEVICE_MOUSE:
{ {
int val = 0; int val = 0;
if(port > 0) if (port > 0)
break; /* TODO: implement mouse for additional ports/players */ break; /* TODO: implement mouse for additional ports/players */
switch (id) switch (id)
{ {
case RETRO_DEVICE_ID_MOUSE_LEFT: case RETRO_DEVICE_ID_MOUSE_LEFT:
@ -1703,7 +1704,7 @@ static int16_t android_input_state(
case RETRO_DEVICE_LIGHTGUN: case RETRO_DEVICE_LIGHTGUN:
{ {
int val = 0; int val = 0;
if(port > 0) if (port > 0)
break; /* TODO: implement lightgun for additional ports/players */ break; /* TODO: implement lightgun for additional ports/players */
switch (id) switch (id)
{ {

@ -1004,7 +1004,7 @@ bool dinput_handle_message(void *data,
wParam == DBT_DEVICEREMOVECOMPLETE) wParam == DBT_DEVICEREMOVECOMPLETE)
{ {
PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam; PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam;
if(pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) if (pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
{ {
#if 0 #if 0
PDEV_BROADCAST_DEVICEINTERFACE pDevInf = PDEV_BROADCAST_DEVICEINTERFACE pDevInf =

@ -325,7 +325,7 @@ static bool psp_input_set_sensor_state(void *data, unsigned port,
return true; return true;
case RETRO_SENSOR_ACCELEROMETER_DISABLE: case RETRO_SENSOR_ACCELEROMETER_DISABLE:
case RETRO_SENSOR_GYROSCOPE_DISABLE: case RETRO_SENSOR_GYROSCOPE_DISABLE:
if(psp->sensors_enabled) if (psp->sensors_enabled)
{ {
psp->sensors_enabled = false; psp->sensors_enabled = false;
sceMotionMagnetometerOff(); sceMotionMagnetometerOff();
@ -334,7 +334,7 @@ static bool psp_input_set_sensor_state(void *data, unsigned port,
return true; return true;
case RETRO_SENSOR_ACCELEROMETER_ENABLE: case RETRO_SENSOR_ACCELEROMETER_ENABLE:
case RETRO_SENSOR_GYROSCOPE_ENABLE: case RETRO_SENSOR_GYROSCOPE_ENABLE:
if(!psp->sensors_enabled) if (!psp->sensors_enabled)
{ {
psp->sensors_enabled = true; psp->sensors_enabled = true;
sceMotionStartSampling(); sceMotionStartSampling();
@ -357,10 +357,10 @@ static float psp_input_get_sensor_input(void *data,
psp_input_t *psp = (psp_input_t*)data; psp_input_t *psp = (psp_input_t*)data;
if(!psp || !psp->sensors_enabled) if (!psp || !psp->sensors_enabled)
return 0.0f; return 0.0f;
if(id >= RETRO_SENSOR_ACCELEROMETER_X && id <= RETRO_SENSOR_GYROSCOPE_Z) if (id >= RETRO_SENSOR_ACCELEROMETER_X && id <= RETRO_SENSOR_GYROSCOPE_Z)
{ {
sceMotionGetSensorState(&sixaxis, port); sceMotionGetSensorState(&sixaxis, port);

@ -412,7 +412,7 @@ static int16_t udev_mouse_get_pointer_x(const udev_input_mouse_t *mouse, bool sc
if (x < -0x7fff) if (x < -0x7fff)
return -0x7fff; return -0x7fff;
else if(x > 0x7fff) else if (x > 0x7fff)
return 0x7fff; return 0x7fff;
return x; return x;
@ -457,7 +457,7 @@ static int16_t udev_mouse_get_pointer_y(const udev_input_mouse_t *mouse, bool sc
if (y < -0x7fff) if (y < -0x7fff)
return -0x7fff; return -0x7fff;
else if(y > 0x7fff) else if (y > 0x7fff)
return 0x7fff; return 0x7fff;
return y; return y;
@ -1064,7 +1064,7 @@ static int16_t udev_pointer_state(udev_input_t *udev,
case RETRO_DEVICE_ID_POINTER_Y: case RETRO_DEVICE_ID_POINTER_Y:
return udev_mouse_get_pointer_y(mouse, screen); return udev_mouse_get_pointer_y(mouse, screen);
case RETRO_DEVICE_ID_POINTER_PRESSED: case RETRO_DEVICE_ID_POINTER_PRESSED:
if(mouse->abs == 1) if (mouse->abs == 1)
return mouse->pp; return mouse->pp;
return mouse->l; return mouse->l;
} }

@ -174,7 +174,7 @@ static int16_t input_wl_state(
} }
} }
if(!keyboard_mapping_blocked) if (!keyboard_mapping_blocked)
{ {
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{ {
@ -194,14 +194,14 @@ static int16_t input_wl_state(
{ {
if (binds[port][id].valid && binds[port][id].key < RETROK_LAST) if (binds[port][id].valid && binds[port][id].key < RETROK_LAST)
{ {
if(id != RARCH_GAME_FOCUS_TOGGLE && !keyboard_mapping_blocked) if (id != RARCH_GAME_FOCUS_TOGGLE && !keyboard_mapping_blocked)
{ {
if(BIT_GET(wl->key_state, rarch_keysym_lut[binds[port][id].key])) if (BIT_GET(wl->key_state, rarch_keysym_lut[binds[port][id].key]))
return 1; return 1;
} }
else if(id == RARCH_GAME_FOCUS_TOGGLE) else if (id == RARCH_GAME_FOCUS_TOGGLE)
{ {
if(BIT_GET(wl->key_state, rarch_keysym_lut[binds[port][id].key])) if (BIT_GET(wl->key_state, rarch_keysym_lut[binds[port][id].key]))
return 1; return 1;
} }

@ -1390,7 +1390,7 @@ static int16_t btstack_hid_joypad_axis(void *data,
if (val < 0) if (val < 0)
return val; return val;
} }
else if(AXIS_POS_GET(joyaxis) < 4) else if (AXIS_POS_GET(joyaxis) < 4)
{ {
int16_t val = pad_connection_get_axis( int16_t val = pad_connection_get_axis(
&slots[port], port, AXIS_POS_GET(joyaxis)); &slots[port], port, AXIS_POS_GET(joyaxis));

@ -340,7 +340,7 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result,
if (range == 3) if (range == 3)
val *= 2; val *= 2;
if(min == 1) if (min == 1)
val--; val--;
switch(val) switch(val)

@ -493,7 +493,7 @@ static int16_t libusb_hid_joypad_axis(void *data,
if (val < 0) if (val < 0)
return val; return val;
} }
else if(AXIS_POS_GET(joyaxis) < 4) else if (AXIS_POS_GET(joyaxis) < 4)
{ {
int16_t val = pad_connection_get_axis(&hid->slots[port], int16_t val = pad_connection_get_axis(&hid->slots[port],
port, AXIS_POS_GET(joyaxis)); port, AXIS_POS_GET(joyaxis));

@ -227,7 +227,7 @@ static void check_port0_active(uint8_t pad_count)
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
int idx = settings->uints.input_joypad_index[0]; int idx = settings->uints.input_joypad_index[0];
if(pad_count < 2 && idx != 0) if (pad_count < 2 && idx != 0)
{ {
#ifdef HW_RVL #ifdef HW_RVL
pad_type[0] = WPAD_EXP_NONE; pad_type[0] = WPAD_EXP_NONE;
@ -588,7 +588,7 @@ static void gx_joypad_poll(void)
#endif #endif
/* Count active controllers */ /* Count active controllers */
if(gx_joypad_query_pad(port)) if (gx_joypad_query_pad(port))
pad_count++; pad_count++;
/* Always enable 1 pad in port 0 if there's only 1 controller connected. /* Always enable 1 pad in port 0 if there's only 1 controller connected.

@ -535,7 +535,7 @@ static int16_t apple_gamecontroller_joypad_axis(
if (val < 0) if (val < 0)
return val; return val;
} }
else if(AXIS_POS_GET(joyaxis) < 4) else if (AXIS_POS_GET(joyaxis) < 4)
{ {
int16_t axis = AXIS_POS_GET(joyaxis); int16_t axis = AXIS_POS_GET(joyaxis);
int16_t val = mfi_axes[port][axis]; int16_t val = mfi_axes[port][axis];

@ -80,8 +80,7 @@ static void *ps2_joypad_init(void *data)
Port 0,3 -> Connector 7 Port 0,3 -> Connector 7
Port 1,3 -> Connector 8 Port 1,3 -> Connector 8
*/ */
if ((ret = padPortOpen(port, slot, padBuf[port][slot])) == 0)
if((ret = padPortOpen(port, slot, padBuf[port][slot])) == 0)
return NULL; return NULL;
} }
} }

@ -368,7 +368,7 @@ static bool psp_joypad_rumble(unsigned pad,
#ifdef VITA #ifdef VITA
if (psp2_model != SCE_KERNEL_MODEL_VITATV) if (psp2_model != SCE_KERNEL_MODEL_VITATV)
return false; return false;
if(pad >= DEFAULT_MAX_PADS) if (pad >= DEFAULT_MAX_PADS)
return false; return false;
switch (effect) switch (effect)
{ {

@ -68,7 +68,7 @@ static void *switch_joypad_init(void *data)
for (i = 0; i < DEFAULT_MAX_PADS; i++) for (i = 0; i < DEFAULT_MAX_PADS; i++)
{ {
if(i == 0) if (i == 0)
padInitializeDefault(&pad_states[0]); padInitializeDefault(&pad_states[0]);
else else
padInitialize(&pad_states[i], i); padInitialize(&pad_states[i], i);

@ -4776,7 +4776,7 @@ void bsv_movie_handle_push_key_event(bsv_movie_t *movie, uint8_t down, uint16_t
void bsv_movie_finish_rewind(input_driver_state_t *input_st) void bsv_movie_finish_rewind(input_driver_state_t *input_st)
{ {
bsv_movie_t *handle = input_st->bsv_movie_state_handle; bsv_movie_t *handle = input_st->bsv_movie_state_handle;
if(!handle) if (!handle)
return; return;
handle->frame_ptr = (handle->frame_ptr + 1) & handle->frame_mask; handle->frame_ptr = (handle->frame_ptr + 1) & handle->frame_mask;
handle->first_rewind = !handle->did_rewind; handle->first_rewind = !handle->did_rewind;
@ -4803,7 +4803,7 @@ void bsv_movie_next_frame(input_driver_state_t *input_st)
if (input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_PLAYBACK) if (input_st->bsv_movie_state.flags & BSV_FLAG_MOVIE_PLAYBACK)
{ {
/* read next key events, a frame happened for sure? but don't apply them yet */ /* read next key events, a frame happened for sure? but don't apply them yet */
if(handle->key_event_count != 0) if (handle->key_event_count != 0)
{ {
RARCH_ERR("[Movie] BSV keyboard replay reading next frame while some unused keys still in queue\n"); RARCH_ERR("[Movie] BSV keyboard replay reading next frame while some unused keys still in queue\n");
} }
@ -5289,7 +5289,7 @@ void input_driver_poll(void)
runloop_state_t *runloop_st = runloop_state_get_ptr(); runloop_state_t *runloop_st = runloop_state_get_ptr();
retro_keyboard_event_t *key_event = &runloop_st->key_event; retro_keyboard_event_t *key_event = &runloop_st->key_event;
if(*key_event && *key_event == runloop_st->frontend_key_event) if (*key_event && *key_event == runloop_st->frontend_key_event)
{ {
int i; int i;
bsv_key_data_t k; bsv_key_data_t k;
@ -6301,7 +6301,7 @@ void input_keyboard_event(bool down, unsigned code,
if (*key_event) if (*key_event)
{ {
if(*key_event == runloop_st->frontend_key_event) if (*key_event == runloop_st->frontend_key_event)
{ {
#ifdef HAVE_BSV_MOVIE #ifdef HAVE_BSV_MOVIE
/* Save input to BSV record, if recording */ /* Save input to BSV record, if recording */

@ -403,7 +403,8 @@ static const char *menu_hash_to_str_el_label_enum(enum msg_hash_enums msg)
} }
#endif #endif
const char *msg_hash_to_str_el(enum msg_hash_enums msg) { const char *msg_hash_to_str_el(enum msg_hash_enums msg)
{
#ifdef HAVE_MENU #ifdef HAVE_MENU
const char *ret = menu_hash_to_str_el_label_enum(msg); const char *ret = menu_hash_to_str_el_label_enum(msg);
@ -411,7 +412,8 @@ const char *msg_hash_to_str_el(enum msg_hash_enums msg) {
return ret; return ret;
#endif #endif
switch (msg) { switch (msg)
{
#include "msg_hash_el.h" #include "msg_hash_el.h"
default: default:
#if 0 #if 0

@ -2373,7 +2373,8 @@ static const char *menu_hash_to_str_pt_br_label_enum(enum msg_hash_enums msg)
} }
#endif #endif
const char *msg_hash_to_str_pt_br(enum msg_hash_enums msg) { const char *msg_hash_to_str_pt_br(enum msg_hash_enums msg)
{
#ifdef HAVE_MENU #ifdef HAVE_MENU
const char *ret = menu_hash_to_str_pt_br_label_enum(msg); const char *ret = menu_hash_to_str_pt_br_label_enum(msg);
@ -2381,7 +2382,8 @@ const char *msg_hash_to_str_pt_br(enum msg_hash_enums msg) {
return ret; return ret;
#endif #endif
switch (msg) { switch (msg)
{
#include "msg_hash_pt_br.h" #include "msg_hash_pt_br.h"
default: default:
#if 0 #if 0

@ -1911,7 +1911,8 @@ static const char *menu_hash_to_str_tr_label_enum(enum msg_hash_enums msg)
} }
#endif #endif
const char *msg_hash_to_str_tr(enum msg_hash_enums msg) { const char *msg_hash_to_str_tr(enum msg_hash_enums msg)
{
#ifdef HAVE_MENU #ifdef HAVE_MENU
const char *ret = menu_hash_to_str_tr_label_enum(msg); const char *ret = menu_hash_to_str_tr_label_enum(msg);
@ -1919,7 +1920,8 @@ const char *msg_hash_to_str_tr(enum msg_hash_enums msg) {
return ret; return ret;
#endif #endif
switch (msg) { switch (msg)
{
#include "msg_hash_tr.h" #include "msg_hash_tr.h"
default: default:
#if 0 #if 0

@ -106,16 +106,16 @@ static void rpi_set(int led, int state)
int gpio = 0; int gpio = 0;
/* Invalid LED? */ /* Invalid LED? */
if((led < 0) || (led >= MAX_LEDS)) if ((led < 0) || (led >= MAX_LEDS))
return; return;
gpio = rpi_cur->map[led]; gpio = rpi_cur->map[led];
if(gpio <= 0) if (gpio <= 0)
return; return;
if(rpi_cur->setup[led] == 0) if (rpi_cur->setup[led] == 0)
rpi_cur->setup[led] = setup_gpio(gpio); rpi_cur->setup[led] = setup_gpio(gpio);
if(rpi_cur->setup[led] > 0) if (rpi_cur->setup[led] > 0)
set_gpio(gpio, state); set_gpio(gpio, state);
} }

@ -93,16 +93,16 @@ static void sys_led_set(int led, int state)
int sysled = 0; int sysled = 0;
/* Invalid LED? */ /* Invalid LED? */
if((led < 0) || (led >= MAX_LEDS)) if ((led < 0) || (led >= MAX_LEDS))
return; return;
sysled = sys_cur->map[led]; sysled = sys_cur->map[led];
if(sysled < 0) if (sysled < 0)
return; return;
if(sys_cur->setup[led] == 0) if (sys_cur->setup[led] == 0)
sys_cur->setup[led] = setup_sysled(sysled); sys_cur->setup[led] = setup_sysled(sysled);
if(sys_cur->setup[led] > 0) if (sys_cur->setup[led] > 0)
set_sysled(sysled, state); set_sysled(sysled, state);
} }

@ -923,7 +923,7 @@ audio_mixer_voice_t* audio_mixer_play(audio_mixer_sound_t* sound,
} }
else else
{ {
if(i < AUDIO_MIXER_MAX_VOICES) if (i < AUDIO_MIXER_MAX_VOICES)
{ {
audio_mixer_release(voice); audio_mixer_release(voice);
AUDIO_MIXER_UNLOCK(voice); AUDIO_MIXER_UNLOCK(voice);

@ -33,13 +33,12 @@
struct chorus_data struct chorus_data
{ {
float old[2][CHORUS_MAX_DELAY]; float old[2][CHORUS_MAX_DELAY];
unsigned old_ptr;
float delay; float delay;
float depth; float depth;
float input_rate; float input_rate;
float mix_dry; float mix_dry;
float mix_wet; float mix_wet;
unsigned old_ptr;
unsigned lfo_ptr; unsigned lfo_ptr;
unsigned lfo_period; unsigned lfo_period;
}; };
@ -66,37 +65,37 @@ static void chorus_process(void *data, struct dspfilter_output *output,
unsigned delay_int; unsigned delay_int;
float delay_frac, l_a, l_b, r_a, r_b; float delay_frac, l_a, l_b, r_a, r_b;
float chorus_l, chorus_r; float chorus_l, chorus_r;
float in[2] = { out[0], out[1] }; float in[2] = { out[0], out[1] };
float delay = ch->delay + ch->depth * sin((2.0 * M_PI * ch->lfo_ptr++) / ch->lfo_period); float delay = ch->delay + ch->depth * sin((2.0 * M_PI * ch->lfo_ptr++) / ch->lfo_period);
delay *= ch->input_rate; delay *= ch->input_rate;
if (ch->lfo_ptr >= ch->lfo_period) if (ch->lfo_ptr >= ch->lfo_period)
ch->lfo_ptr = 0; ch->lfo_ptr = 0;
delay_int = (unsigned)delay; delay_int = (unsigned)delay;
if (delay_int >= CHORUS_MAX_DELAY - 1) if (delay_int >= CHORUS_MAX_DELAY - 1)
delay_int = CHORUS_MAX_DELAY - 2; delay_int = CHORUS_MAX_DELAY - 2;
delay_frac = delay - delay_int; delay_frac = delay - delay_int;
ch->old[0][ch->old_ptr] = in[0]; ch->old[0][ch->old_ptr] = in[0];
ch->old[1][ch->old_ptr] = in[1]; ch->old[1][ch->old_ptr] = in[1];
l_a = ch->old[0][(ch->old_ptr - delay_int - 0) & CHORUS_DELAY_MASK]; l_a = ch->old[0][(ch->old_ptr - delay_int - 0) & CHORUS_DELAY_MASK];
l_b = ch->old[0][(ch->old_ptr - delay_int - 1) & CHORUS_DELAY_MASK]; l_b = ch->old[0][(ch->old_ptr - delay_int - 1) & CHORUS_DELAY_MASK];
r_a = ch->old[1][(ch->old_ptr - delay_int - 0) & CHORUS_DELAY_MASK]; r_a = ch->old[1][(ch->old_ptr - delay_int - 0) & CHORUS_DELAY_MASK];
r_b = ch->old[1][(ch->old_ptr - delay_int - 1) & CHORUS_DELAY_MASK]; r_b = ch->old[1][(ch->old_ptr - delay_int - 1) & CHORUS_DELAY_MASK];
/* Lerp introduces aliasing of the chorus component, /* Lerp introduces aliasing of the chorus component,
* but doing full polyphase here is probably overkill. */ * but doing full polyphase here is probably overkill. */
chorus_l = l_a * (1.0f - delay_frac) + l_b * delay_frac; chorus_l = l_a * (1.0f - delay_frac) + l_b * delay_frac;
chorus_r = r_a * (1.0f - delay_frac) + r_b * delay_frac; chorus_r = r_a * (1.0f - delay_frac) + r_b * delay_frac;
out[0] = ch->mix_dry * in[0] + ch->mix_wet * chorus_l; out[0] = ch->mix_dry * in[0] + ch->mix_wet * chorus_l;
out[1] = ch->mix_dry * in[1] + ch->mix_wet * chorus_r; out[1] = ch->mix_dry * in[1] + ch->mix_wet * chorus_r;
ch->old_ptr = (ch->old_ptr + 1) & CHORUS_DELAY_MASK; ch->old_ptr = (ch->old_ptr + 1) & CHORUS_DELAY_MASK;
} }
} }
@ -113,24 +112,24 @@ static void *chorus_init(const struct dspfilter_info *info,
config->get_float(userdata, "lfo_freq", &lfo_freq, 0.5f); config->get_float(userdata, "lfo_freq", &lfo_freq, 0.5f);
config->get_float(userdata, "drywet", &drywet, 0.8f); config->get_float(userdata, "drywet", &drywet, 0.8f);
delay /= 1000.0f; delay /= 1000.0f;
depth /= 1000.0f; depth /= 1000.0f;
if (depth > delay) if (depth > delay)
depth = delay; depth = delay;
if (drywet < 0.0f) if (drywet < 0.0f)
drywet = 0.0f; drywet = 0.0f;
else if (drywet > 1.0f) else if (drywet > 1.0f)
drywet = 1.0f; drywet = 1.0f;
ch->mix_dry = 1.0f - 0.5f * drywet; ch->mix_dry = 1.0f - 0.5f * drywet;
ch->mix_wet = 0.5f * drywet; ch->mix_wet = 0.5f * drywet;
ch->delay = delay; ch->delay = delay;
ch->depth = depth; ch->depth = depth;
ch->lfo_period = (1.0f / lfo_freq) * info->input_rate; ch->lfo_period = (1.0f / lfo_freq) * info->input_rate;
ch->input_rate = info->input_rate; ch->input_rate = info->input_rate;
if (!ch->lfo_period) if (!ch->lfo_period)
ch->lfo_period = 1; ch->lfo_period = 1;
return ch; return ch;
@ -151,10 +150,6 @@ static const struct dspfilter_implementation chorus_plug = {
#endif #endif
const struct dspfilter_implementation * const struct dspfilter_implementation *
dspfilter_get_implementation(dspfilter_simd_mask_t mask) dspfilter_get_implementation(dspfilter_simd_mask_t mask) { return &chorus_plug; }
{
(void)mask;
return &chorus_plug;
}
#undef dspfilter_get_implementation #undef dspfilter_get_implementation

@ -42,7 +42,7 @@ static void delta_process(void *data, struct dspfilter_output *output,
const struct dspfilter_input *input) const struct dspfilter_input *input)
{ {
unsigned i, c; unsigned i, c;
struct delta_data *d = (struct delta_data*)data; struct delta_data *d = (struct delta_data*)data;
float *out = output->samples; float *out = output->samples;
output->samples = input->samples; output->samples = input->samples;
output->frames = input->frames; output->frames = input->frames;
@ -51,9 +51,9 @@ static void delta_process(void *data, struct dspfilter_output *output,
{ {
for (c = 0; c < 2; c++) for (c = 0; c < 2; c++)
{ {
float current = *out; float current = *out;
*out++ = current + (current - d->old[c]) * d->intensity; *out++ = current + (current - d->old[c]) * d->intensity;
d->old[c] = current; d->old[c] = current;
} }
} }
} }
@ -83,7 +83,6 @@ static const struct dspfilter_implementation delta_plug = {
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask) const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{ {
(void)mask;
return &delta_plug; return &delta_plug;
} }

@ -75,11 +75,11 @@ static void echo_process(void *data, struct dspfilter_output *output,
echo_right += echo->channels[c].buffer[(echo->channels[c].ptr << 1) + 1]; echo_right += echo->channels[c].buffer[(echo->channels[c].ptr << 1) + 1];
} }
echo_left *= echo->amp; echo_left *= echo->amp;
echo_right *= echo->amp; echo_right *= echo->amp;
left = out[0] + echo_left; left = out[0] + echo_left;
right = out[1] + echo_right; right = out[1] + echo_right;
for (c = 0; c < echo->num_channels; c++) for (c = 0; c < echo->num_channels; c++)
{ {
@ -121,28 +121,25 @@ static void *echo_init(const struct dspfilter_info *info,
&num_feedback, default_feedback, 1); &num_feedback, default_feedback, 1);
config->get_float(userdata, "amp", &echo->amp, 0.2f); config->get_float(userdata, "amp", &echo->amp, 0.2f);
channels = num_feedback = num_delay = MIN(num_delay, num_feedback); channels = num_feedback = num_delay = MIN(num_delay, num_feedback);
echo_channels = (struct echo_channel*)calloc(channels, if (!(echo_channels = (struct echo_channel*)calloc(channels,
sizeof(*echo_channels)); sizeof(*echo_channels))))
if (!echo_channels)
goto error; goto error;
echo->channels = echo_channels; echo->channels = echo_channels;
echo->num_channels = channels; echo->num_channels = channels;
for (i = 0; i < channels; i++) for (i = 0; i < channels; i++)
{ {
unsigned frames = (unsigned)(delay[i] * info->input_rate / 1000.0f + 0.5f); unsigned frames = (unsigned)(delay[i] * info->input_rate / 1000.0f + 0.5f);
if (!frames) if (!frames)
goto error; goto error;
echo->channels[i].buffer = (float*)calloc(frames, 2 * sizeof(float)); if (!(echo->channels[i].buffer = (float*)calloc(frames, 2 * sizeof(float))))
if (!echo->channels[i].buffer)
goto error; goto error;
echo->channels[i].frames = frames; echo->channels[i].frames = frames;
echo->channels[i].feedback = feedback[i]; echo->channels[i].feedback = feedback[i];
} }
@ -173,7 +170,6 @@ static const struct dspfilter_implementation echo_plug = {
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask) const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{ {
(void)mask;
return &echo_plug; return &echo_plug;
} }

@ -34,12 +34,11 @@
struct eq_data struct eq_data
{ {
fft_t *fft; fft_t *fft;
float buffer[8 * 1024];
float *save; float *save;
float *block; float *block;
fft_complex_t *filter; fft_complex_t *filter;
fft_complex_t *fftblock; fft_complex_t *fftblock;
float buffer[8 * 1024];
unsigned block_size; unsigned block_size;
unsigned block_ptr; unsigned block_ptr;
}; };
@ -88,11 +87,11 @@ static void eq_process(void *data, struct dspfilter_output *output,
memcpy(eq->block + eq->block_ptr * 2, in, write_avail * 2 * sizeof(float)); memcpy(eq->block + eq->block_ptr * 2, in, write_avail * 2 * sizeof(float));
in += write_avail * 2; in += write_avail * 2;
input_frames -= write_avail; input_frames -= write_avail;
eq->block_ptr += write_avail; eq->block_ptr += write_avail;
// Convolve a new block. /* Convolve a new block. */
if (eq->block_ptr == eq->block_size) if (eq->block_ptr == eq->block_size)
{ {
unsigned i, c; unsigned i, c;
@ -105,16 +104,16 @@ static void eq_process(void *data, struct dspfilter_output *output,
fft_process_inverse(eq->fft, out + c, eq->fftblock, 2); fft_process_inverse(eq->fft, out + c, eq->fftblock, 2);
} }
// Overlap add method, so add in saved block now. /* Overlap add method, so add in saved block now. */
for (i = 0; i < 2 * eq->block_size; i++) for (i = 0; i < 2 * eq->block_size; i++)
out[i] += eq->save[i]; out[i] += eq->save[i];
// Save block for later. /* Save block for later. */
memcpy(eq->save, out + 2 * eq->block_size, 2 * eq->block_size * sizeof(float)); memcpy(eq->save, out + 2 * eq->block_size, 2 * eq->block_size * sizeof(float));
out += eq->block_size * 2; out += eq->block_size * 2;
output->frames += eq->block_size; output->frames += eq->block_size;
eq->block_ptr = 0; eq->block_ptr = 0;
} }
} }
} }
@ -184,8 +183,8 @@ static void generate_response(fft_complex_t *response,
lerp = (freq - start_freq) / (end_freq - start_freq); lerp = (freq - start_freq) / (end_freq - start_freq);
gain = (1.0f - lerp) * start_gain + lerp * end_gain; gain = (1.0f - lerp) * start_gain + lerp * end_gain;
response[i].real = gain; response[i].real = gain;
response[i].imag = 0.0f; response[i].imag = 0.0f;
response[2 * samples - i].real = gain; response[2 * samples - i].real = gain;
response[2 * samples - i].imag = 0.0f; response[2 * samples - i].imag = 0.0f;
} }
@ -196,10 +195,9 @@ static void create_filter(struct eq_data *eq, unsigned size_log2,
{ {
int i; int i;
int half_block_size = eq->block_size >> 1; int half_block_size = eq->block_size >> 1;
double window_mod = 1.0 / kaiser_window_function(0.0, beta); double window_mod = 1.0 / kaiser_window_function(0.0, beta);
fft_t *fft = fft_new(size_log2);
fft_t *fft = fft_new(size_log2); float *time_filter = (float*)calloc(eq->block_size * 2 + 1, sizeof(*time_filter));
float *time_filter = (float*)calloc(eq->block_size * 2 + 1, sizeof(*time_filter));
if (!fft || !time_filter) if (!fft || !time_filter)
goto end; goto end;
@ -228,8 +226,8 @@ static void create_filter(struct eq_data *eq, unsigned size_log2,
for (i = 0; i < (int)eq->block_size; i++) for (i = 0; i < (int)eq->block_size; i++)
{ {
/* Kaiser window. */ /* Kaiser window. */
double phase = (double)i / eq->block_size; double phase = (double)i / eq->block_size;
phase = 2.0 * (phase - 0.5); phase = 2.0 * (phase - 0.5);
time_filter[i] *= window_mod * kaiser_window_function(phase, beta); time_filter[i] *= window_mod * kaiser_window_function(phase, beta);
} }
@ -261,15 +259,15 @@ end:
static void *eq_init(const struct dspfilter_info *info, static void *eq_init(const struct dspfilter_info *info,
const struct dspfilter_config *config, void *userdata) const struct dspfilter_config *config, void *userdata)
{ {
float *frequencies, *gain;
unsigned num_freq, num_gain, i, size;
int size_log2; int size_log2;
float beta; float beta;
struct eq_gain *gains = NULL; float *frequencies, *gain;
char *filter_path = NULL; unsigned num_freq, num_gain, i, size;
struct eq_gain *gains = NULL;
char *filter_path = NULL;
const float default_freq[] = { 0.0f, info->input_rate }; const float default_freq[] = { 0.0f, info->input_rate };
const float default_gain[] = { 0.0f, 0.0f }; const float default_gain[] = { 0.0f, 0.0f };
struct eq_data *eq = (struct eq_data*)calloc(1, sizeof(*eq)); struct eq_data *eq = (struct eq_data*)calloc(1, sizeof(*eq));
if (!eq) if (!eq)
return NULL; return NULL;
@ -289,8 +287,7 @@ static void *eq_init(const struct dspfilter_info *info,
num_gain = num_freq = MIN(num_gain, num_freq); num_gain = num_freq = MIN(num_gain, num_freq);
gains = (struct eq_gain*)calloc(num_gain, sizeof(*gains)); if (!(gains = (struct eq_gain*)calloc(num_gain, sizeof(*gains))))
if (!gains)
goto error; goto error;
for (i = 0; i < num_gain; i++) for (i = 0; i < num_gain; i++)
@ -303,15 +300,15 @@ static void *eq_init(const struct dspfilter_info *info,
eq->block_size = size; eq->block_size = size;
eq->save = (float*)calloc( size, 2 * sizeof(*eq->save)); eq->save = (float*)calloc( size, 2 * sizeof(*eq->save));
eq->block = (float*)calloc(2 * size, 2 * sizeof(*eq->block)); eq->block = (float*)calloc(2 * size, 2 * sizeof(*eq->block));
eq->fftblock = (fft_complex_t*)calloc(2 * size, sizeof(*eq->fftblock)); eq->fftblock = (fft_complex_t*)calloc(2 * size, sizeof(*eq->fftblock));
eq->filter = (fft_complex_t*)calloc(2 * size, sizeof(*eq->filter)); eq->filter = (fft_complex_t*)calloc(2 * size, sizeof(*eq->filter));
/* Use an FFT which is twice the block size with zero-padding /* Use an FFT which is twice the block size with zero-padding
* to make circular convolution => proper convolution. * to make circular convolution => proper convolution.
*/ */
eq->fft = fft_new(size_log2 + 1); eq->fft = fft_new(size_log2 + 1);
if (!eq->fft || !eq->fftblock || !eq->save || !eq->block || !eq->filter) if (!eq->fft || !eq->fftblock || !eq->save || !eq->block || !eq->filter)
goto error; goto error;
@ -345,7 +342,6 @@ static const struct dspfilter_implementation eq_plug = {
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask) const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{ {
(void)mask;
return &eq_plug; return &eq_plug;
} }

@ -364,7 +364,6 @@ static const struct dspfilter_implementation iir_plug = {
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask) const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{ {
(void)mask;
return &iir_plug; return &iir_plug;
} }

@ -104,7 +104,6 @@ static const struct dspfilter_implementation panning = {
const struct dspfilter_implementation * const struct dspfilter_implementation *
dspfilter_get_implementation(dspfilter_simd_mask_t mask) dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{ {
(void)mask;
return &panning; return &panning;
} }

@ -27,8 +27,8 @@
#include <retro_miscellaneous.h> #include <retro_miscellaneous.h>
#include <libretro_dspfilter.h> #include <libretro_dspfilter.h>
#define phaserlfoshape 4.0 #define PHASER_LFO_SHAPE 4.0
#define phaserlfoskipsamples 20 #define PHASER_LFO_SKIP_SAMPLES 20
struct phaser_data struct phaser_data
{ {
@ -71,10 +71,10 @@ static void phaser_process(void *data, struct dspfilter_output *output,
for (c = 0; c < 2; c++) for (c = 0; c < 2; c++)
m[c] = in[c] + ph->fbout[c] * ph->fb * 0.01f; m[c] = in[c] + ph->fbout[c] * ph->fb * 0.01f;
if ((ph->skipcount++ % phaserlfoskipsamples) == 0) if ((ph->skipcount++ % PHASER_LFO_SKIP_SAMPLES) == 0)
{ {
ph->gain = 0.5 * (1.0 + cos(ph->skipcount * ph->lfoskip + ph->phase)); ph->gain = 0.5 * (1.0 + cos(ph->skipcount * ph->lfoskip + ph->phase));
ph->gain = (exp(ph->gain * phaserlfoshape) - 1.0) / (exp(phaserlfoshape) - 1); ph->gain = (exp(ph->gain * PHASER_LFO_SHAPE) - 1.0) / (exp(PHASER_LFO_SHAPE) - 1);
ph->gain = 1.0 - ph->gain * ph->depth; ph->gain = 1.0 - ph->gain * ph->depth;
} }
@ -138,7 +138,6 @@ static const struct dspfilter_implementation phaser_plug = {
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask) const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{ {
(void)mask;
return &phaser_plug; return &phaser_plug;
} }

@ -127,7 +127,7 @@ static float revmodel_process(struct revmodel *rev, float in)
static void revmodel_update(struct revmodel *rev) static void revmodel_update(struct revmodel *rev)
{ {
int i; int i;
rev->wet1 = rev->wet * (rev->width / 2.0f + 0.5f); rev->wet1 = rev->wet * (rev->width / 2.0f + 0.5f);
if (rev->mode >= freezemode) if (rev->mode >= freezemode)
{ {
@ -138,15 +138,15 @@ static void revmodel_update(struct revmodel *rev)
else else
{ {
rev->roomsize1 = rev->roomsize; rev->roomsize1 = rev->roomsize;
rev->damp1 = rev->damp; rev->damp1 = rev->damp;
rev->gain = fixedgain; rev->gain = fixedgain;
} }
for (i = 0; i < NUMCOMBS; i++) for (i = 0; i < NUMCOMBS; i++)
{ {
rev->combL[i].feedback = rev->roomsize1; rev->combL[i].feedback = rev->roomsize1;
rev->combL[i].damp1 = rev->damp1; rev->combL[i].damp1 = rev->damp1;
rev->combL[i].damp2 = 1.0f - rev->damp1; rev->combL[i].damp2 = 1.0f - rev->damp1;
} }
} }
@ -186,7 +186,7 @@ static void revmodel_setmode(struct revmodel *rev, float value)
revmodel_update(rev); revmodel_update(rev);
} }
static void revmodel_init(struct revmodel *rev,int srate, bool right) static void revmodel_init(struct revmodel *rev, int srate, bool right)
{ {
unsigned c; unsigned c;
static const int comb_lengths[8] = { 1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 }; static const int comb_lengths[8] = { 1116, 1188, 1277, 1356, 1422, 1491, 1557, 1617 };
@ -196,19 +196,19 @@ static void revmodel_init(struct revmodel *rev,int srate, bool right)
for (c = 0; c < NUMCOMBS; ++c) for (c = 0; c < NUMCOMBS; ++c)
{ {
rev->bufcomb[c] = malloc(r*comb_lengths[c]+stereosep*sizeof(float)); rev->bufcomb[c] = malloc(r * comb_lengths[c] + stereosep * sizeof(float));
rev->combL[c].buffer = rev->bufcomb[c]; rev->combL[c].buffer = rev->bufcomb[c];
memset(rev->combL[c].buffer,0,r*comb_lengths[c]+stereosep*sizeof(float)); memset(rev->combL[c].buffer, 0, r * comb_lengths[c] + stereosep * sizeof(float));
rev->combL[c].bufsize=r*comb_lengths[c]+stereosep; rev->combL[c].bufsize = r * comb_lengths[c] + stereosep;
} }
for (c = 0; c < NUMALLPASSES; ++c) for (c = 0; c < NUMALLPASSES; ++c)
{ {
rev->bufallpass[c] = malloc(r*allpass_lengths[c]+stereosep*sizeof(float)); rev->bufallpass[c] = malloc(r * allpass_lengths[c] + stereosep * sizeof(float));
rev->allpassL[c].buffer = rev->bufallpass[c]; rev->allpassL[c].buffer = rev->bufallpass[c];
memset(rev->allpassL[c].buffer,0,r*allpass_lengths[c]+stereosep*sizeof(float)); memset(rev->allpassL[c].buffer, 0, r * allpass_lengths[c] + stereosep * sizeof(float));
rev->allpassL[c].bufsize=r*allpass_lengths[c]+stereosep; rev->allpassL[c].bufsize = r * allpass_lengths[c] + stereosep;
rev->allpassL[c].feedback = 0.5f; rev->allpassL[c].feedback = 0.5f;
} }
revmodel_setwet(rev, initialwet); revmodel_setwet(rev, initialwet);
@ -226,8 +226,8 @@ struct reverb_data
static void reverb_free(void *data) static void reverb_free(void *data)
{ {
struct reverb_data *rev = (struct reverb_data*)data;
unsigned i; unsigned i;
struct reverb_data *rev = (struct reverb_data*)data;
for (i = 0; i < NUMCOMBS; i++) for (i = 0; i < NUMCOMBS; i++)
{ {

@ -32,11 +32,11 @@
struct tremolo_core struct tremolo_core
{ {
float freq; float *wavetable;
float depth; float freq;
float* wavetable; float depth;
int index; int index;
int maxindex; int maxindex;
}; };
struct tremolo struct tremolo
@ -54,24 +54,25 @@ static void tremolo_free(void *data)
static void tremolocore_init(struct tremolo_core *core,float depth,int samplerate,float freq) static void tremolocore_init(struct tremolo_core *core,float depth,int samplerate,float freq)
{ {
const double offset = 1. - depth / 2.; double env;
unsigned i; unsigned i;
double env; const double offset = 1. - depth / 2.;
core->index = 0; core->index = 0;
core->maxindex = samplerate/freq; core->maxindex = samplerate / freq;
core->wavetable = malloc(core->maxindex*sizeof(float)); core->wavetable = malloc(core->maxindex * sizeof(float));
memset(core->wavetable, 0, core->maxindex * sizeof(float)); memset(core->wavetable, 0, core->maxindex * sizeof(float));
for (i = 0; i < core->maxindex; i++) { for (i = 0; i < core->maxindex; i++)
env = freq * i / samplerate; {
env = sin((M_PI*2) * fmod(env + 0.25, 1.0)); env = freq * i / samplerate;
core->wavetable[i] = env * (1 - fabs(offset)) + offset; env = sin((M_PI*2) * fmod(env + 0.25, 1.0));
} core->wavetable[i] = env * (1 - fabs(offset)) + offset;
}
} }
float tremolocore_core(struct tremolo_core *core,float in) float tremolocore_core(struct tremolo_core *core,float in)
{ {
core->index = core->index % core->maxindex; core->index = core->index % core->maxindex;
return in * core->wavetable[core->index++]; return in * core->wavetable[core->index++];
} }
static void tremolo_process(void *data, struct dspfilter_output *output, static void tremolo_process(void *data, struct dspfilter_output *output,
@ -81,16 +82,15 @@ static void tremolo_process(void *data, struct dspfilter_output *output,
float *out; float *out;
struct tremolo *tre = (struct tremolo*)data; struct tremolo *tre = (struct tremolo*)data;
output->samples = input->samples; output->samples = input->samples;
output->frames = input->frames; output->frames = input->frames;
out = output->samples; out = output->samples;
for (i = 0; i < input->frames; i++, out += 2) for (i = 0; i < input->frames; i++, out += 2)
{ {
float in[2] = { out[0], out[1] }; float in[2] = { out[0], out[1] };
out[0] = tremolocore_core(&tre->left, in[0]);
out[0] = tremolocore_core(&tre->left, in[0]); out[1] = tremolocore_core(&tre->right, in[1]);
out[1] = tremolocore_core(&tre->right, in[1]);
} }
} }
@ -98,7 +98,7 @@ static void *tremolo_init(const struct dspfilter_info *info,
const struct dspfilter_config *config, void *userdata) const struct dspfilter_config *config, void *userdata)
{ {
float freq, depth; float freq, depth;
struct tremolo *tre = (struct tremolo*)calloc(1, sizeof(*tre)); struct tremolo *tre = (struct tremolo*)calloc(1, sizeof(*tre));
if (!tre) if (!tre)
return NULL; return NULL;
@ -125,7 +125,6 @@ static const struct dspfilter_implementation tremolo_plug = {
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask) const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{ {
(void)mask;
return &tremolo_plug; return &tremolo_plug;
} }

@ -30,31 +30,30 @@
#define sqr(a) ((a) * (a)) #define sqr(a) ((a) * (a))
const float BASE_DELAY_SEC = 0.002; // 2 ms static const float BASE_DELAY_SEC = 0.002; /* 2 ms */
const float VIBRATO_FREQUENCY_DEFAULT_HZ = 2; static const float VIBRATO_FREQUENCY_DEFAULT_HZ = 2;
const float VIBRATO_FREQUENCY_MAX_HZ = 14; static const float VIBRATO_FREQUENCY_MAX_HZ = 14;
const float VIBRATO_DEPTH_DEFAULT_PERCENT = 50; static const float VIBRATO_DEPTH_DEFAULT_PERCENT = 50;
const int add_delay = 3; static const int add_delay = 3;
float hermite_interp(float x, float *y) static float hermite_interp(float x, float *y)
{ {
float c0, c1, c2, c3; float c0 = y[1];
c0 = y[1]; float c1 = (1.0f / 2.0f) * (y[2] - y[0]);
c1 = (1.0 / 2.0)*(y[2] - y[0]); float c2 = (y[0] - (5.0f / 2.0f) * y[1]) + (2.0f * y[2] - (1.0f / 2.0f) * y[3]);
c2 = (y[0] - (5.0 / 2.0)*y[1]) + (2.0*y[2] - (1.0 / 2.0)*y[3]); float c3 = (1.0f / 2.0f) * (y[3] - y[0]) + (3.0f / 2.0f) * (y[1] - y[2]);
c3 = (1.0 / 2.0)*(y[3] - y[0]) + (3.0 / 2.0)*(y[1] - y[2]); return ((c3 * x + c2) * x + c1) * x + c0;
return ((c3*x + c2)*x + c1)*x + c0;
} }
struct vibrato_core struct vibrato_core
{ {
float freq; float* buffer;
float samplerate; float freq;
int phase; float samplerate;
float depth; float depth;
float* buffer; int phase;
int writeindex; int writeindex;
int size; int size;
}; };
struct vibrato struct vibrato
@ -72,60 +71,62 @@ static void vibrato_free(void *data)
static void vibratocore_init(struct vibrato_core *core,float depth,int samplerate,float freq) static void vibratocore_init(struct vibrato_core *core,float depth,int samplerate,float freq)
{ {
core->size = BASE_DELAY_SEC * samplerate * 2; core->size = BASE_DELAY_SEC * samplerate * 2;
core->buffer = malloc((core->size + add_delay)*sizeof(float)); core->buffer = malloc((core->size + add_delay) * sizeof(float));
memset(core->buffer, 0, (core->size + add_delay) * sizeof(float)); memset(core->buffer, 0, (core->size + add_delay) * sizeof(float));
core->samplerate = samplerate; core->samplerate = samplerate;
core->freq = freq; core->freq = freq;
core->depth = depth; core->depth = depth;
core->phase = 0; core->phase = 0;
core->writeindex = 0; core->writeindex = 0;
} }
float vibratocore_core(struct vibrato_core *core,float in) float vibratocore_core(struct vibrato_core *core,float in)
{ {
float M = core->freq / core->samplerate; int ipart;
int maxphase = core->samplerate / core->freq; float delay, readindex, fpart, value;
float lfo = sin(M * 2. * M_PI * core->phase++); float M = core->freq / core->samplerate;
core->phase = core->phase % maxphase; int maxphase = core->samplerate / core->freq;
lfo = (lfo + 1) * 1.; // transform from [-1; 1] to [0; 1] float lfo = sin(M * 2. * M_PI * core->phase++);
int maxdelay = BASE_DELAY_SEC * core->samplerate; int maxdelay = BASE_DELAY_SEC * core->samplerate;
float delay = lfo * core->depth * maxdelay; core->phase = core->phase % maxphase;
delay += add_delay; lfo = (lfo + 1) * 1.; // transform from [-1; 1] to [0; 1]
float readindex = core->writeindex - 1 - delay; delay = lfo * core->depth * maxdelay;
while (readindex < 0)readindex += core->size; delay += add_delay;
while (readindex >= core->size)readindex -= core->size; readindex = core->writeindex - 1 - delay;
int ipart = (int)readindex; // integer part of the delay while (readindex < 0)
float fpart = readindex - ipart; // fractional part of the delay readindex += core->size;
float value = hermite_interp(fpart, &(core->buffer[ipart])); while (readindex >= core->size)
core->buffer[core->writeindex] = in; readindex -= core->size;
if (core->writeindex < add_delay){ ipart = (int)readindex; /* Integer part of the delay */
core->buffer[core->size + core->writeindex] = in; fpart = readindex - ipart; /* fractional part of the delay */
} value = hermite_interp(fpart, &(core->buffer[ipart]));
core->writeindex++; core->buffer[core->writeindex] = in;
if (core->writeindex == core->size) { if (core->writeindex < add_delay)
core->writeindex = 0; core->buffer[core->size + core->writeindex] = in;
} core->writeindex++;
return value; if (core->writeindex == core->size)
core->writeindex = 0;
return value;
} }
static void vibrato_process(void *data, struct dspfilter_output *output, static void vibrato_process(void *data,
struct dspfilter_output *output,
const struct dspfilter_input *input) const struct dspfilter_input *input)
{ {
unsigned i; unsigned i;
float *out; float *out;
struct vibrato *vib = (struct vibrato*)data; struct vibrato *vib = (struct vibrato*)data;
output->samples = input->samples; output->samples = input->samples;
output->frames = input->frames; output->frames = input->frames;
out = output->samples; out = output->samples;
for (i = 0; i < input->frames; i++, out += 2) for (i = 0; i < input->frames; i++, out += 2)
{ {
float in[2] = { out[0], out[1] }; float in[2] = { out[0], out[1] };
out[0] = vibratocore_core(&vib->left, in[0]);
out[0] = vibratocore_core(&vib->left, in[0]); out[1] = vibratocore_core(&vib->right, in[1]);
out[1] = vibratocore_core(&vib->right, in[1]);
} }
} }
@ -133,7 +134,7 @@ static void *vibrato_init(const struct dspfilter_info *info,
const struct dspfilter_config *config, void *userdata) const struct dspfilter_config *config, void *userdata)
{ {
float freq, depth; float freq, depth;
struct vibrato *vib = (struct vibrato*)calloc(1, sizeof(*vib)); struct vibrato *vib = (struct vibrato*)calloc(1, sizeof(*vib));
if (!vib) if (!vib)
return NULL; return NULL;
@ -160,7 +161,6 @@ static const struct dspfilter_implementation vibrato_plug = {
const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask) const struct dspfilter_implementation *dspfilter_get_implementation(dspfilter_simd_mask_t mask)
{ {
(void)mask;
return &vibrato_plug; return &vibrato_plug;
} }

@ -68,39 +68,39 @@ static void wahwah_process(void *data, struct dspfilter_output *output,
if ((wah->skipcount++ % WAHWAH_LFO_SKIP_SAMPLES) == 0) if ((wah->skipcount++ % WAHWAH_LFO_SKIP_SAMPLES) == 0)
{ {
float omega, sn, cs, alpha; float omega, sn, cs, alpha;
float frequency = (1.0 + cos(wah->skipcount * wah->lfoskip + wah->phase)) / 2.0; float frequency = (1.0f + cos(wah->skipcount * wah->lfoskip + wah->phase)) / 2.0f;
frequency = frequency * wah->depth * (1.0 - wah->freqofs) + wah->freqofs; frequency = frequency * wah->depth * (1.0f - wah->freqofs) + wah->freqofs;
frequency = exp((frequency - 1.0) * 6.0); frequency = exp((frequency - 1.0f) * 6.0f);
omega = M_PI * frequency; omega = M_PI * frequency;
sn = sin(omega); sn = sin(omega);
cs = cos(omega); cs = cos(omega);
alpha = sn / (2.0 * wah->res); alpha = sn / (2.0f * wah->res);
wah->b0 = (1.0 - cs) / 2.0; wah->b0 = (1.0f - cs) / 2.0f;
wah->b1 = 1.0 - cs; wah->b1 = 1.0f - cs;
wah->b2 = (1.0 - cs) / 2.0; wah->b2 = (1.0f - cs) / 2.0f;
wah->a0 = 1.0 + alpha; wah->a0 = 1.0f + alpha;
wah->a1 = -2.0 * cs; wah->a1 = -2.0f * cs;
wah->a2 = 1.0 - alpha; wah->a2 = 1.0f - alpha;
} }
out_l = (wah->b0 * in[0] + wah->b1 * wah->l.xn1 + wah->b2 * wah->l.xn2 - wah->a1 * wah->l.yn1 - wah->a2 * wah->l.yn2) / wah->a0; out_l = (wah->b0 * in[0] + wah->b1 * wah->l.xn1 + wah->b2 * wah->l.xn2 - wah->a1 * wah->l.yn1 - wah->a2 * wah->l.yn2) / wah->a0;
out_r = (wah->b0 * in[1] + wah->b1 * wah->r.xn1 + wah->b2 * wah->r.xn2 - wah->a1 * wah->r.yn1 - wah->a2 * wah->r.yn2) / wah->a0; out_r = (wah->b0 * in[1] + wah->b1 * wah->r.xn1 + wah->b2 * wah->r.xn2 - wah->a1 * wah->r.yn1 - wah->a2 * wah->r.yn2) / wah->a0;
wah->l.xn2 = wah->l.xn1; wah->l.xn2 = wah->l.xn1;
wah->l.xn1 = in[0]; wah->l.xn1 = in[0];
wah->l.yn2 = wah->l.yn1; wah->l.yn2 = wah->l.yn1;
wah->l.yn1 = out_l; wah->l.yn1 = out_l;
wah->r.xn2 = wah->r.xn1; wah->r.xn2 = wah->r.xn1;
wah->r.xn1 = in[1]; wah->r.xn1 = in[1];
wah->r.yn2 = wah->r.yn1; wah->r.yn2 = wah->r.yn1;
wah->r.yn1 = out_r; wah->r.yn1 = out_r;
out[0] = out_l; out[0] = out_l;
out[1] = out_r; out[1] = out_r;
} }
} }
@ -117,8 +117,8 @@ static void *wahwah_init(const struct dspfilter_info *info,
config->get_float(userdata, "depth", &wah->depth, 0.7f); config->get_float(userdata, "depth", &wah->depth, 0.7f);
config->get_float(userdata, "resonance", &wah->res, 2.5f); config->get_float(userdata, "resonance", &wah->res, 2.5f);
wah->lfoskip = wah->freq * 2.0 * M_PI / info->input_rate; wah->lfoskip = wah->freq * 2.0f * M_PI / info->input_rate;
wah->phase = wah->startphase * M_PI / 180.0; wah->phase = wah->startphase * M_PI / 180.0f;
return wah; return wah;
} }

@ -68,24 +68,17 @@ const static unsigned char unb64[]={
*/ */
char* base64(const void* binaryData, int len, int *flen) char* base64(const void* binaryData, int len, int *flen)
{ {
const unsigned char* bin = (const unsigned char*) binaryData;
char* res; char* res;
int rc = 0; /* result counter */
int byteNo; /* I need this after the loop */ int byteNo; /* I need this after the loop */
const unsigned char* bin = (const unsigned char*) binaryData;
int modulusLen = len % 3 ; int rc = 0; /* result counter */
int modulusLen = len % 3 ;
/* 2 gives 1 and 1 gives 2, but 0 gives 0. */ /* 2 gives 1 and 1 gives 2, but 0 gives 0. */
int pad = ((modulusLen&1)<<1) + ((modulusLen&2)>>1); int pad = ((modulusLen&1)<<1) + ((modulusLen&2)>>1);
*flen = 4*(len + pad)/3; *flen = 4*(len + pad)/3;
res = (char*) malloc(*flen + 1); /* and one for the null */ if (!(res = (char*) malloc(*flen + 1))) /* and one for the NULL */
if (!res)
{
/* ERROR: base64 could not allocate enough memory. */
return 0; return 0;
}
for (byteNo=0; byteNo <= len-3; byteNo+=3) for (byteNo=0; byteNo <= len-3; byteNo+=3)
{ {
@ -120,34 +113,29 @@ char* base64(const void* binaryData, int len, int *flen)
unsigned char* unbase64(const char* ascii, int len, int *flen) unsigned char* unbase64(const char* ascii, int len, int *flen)
{ {
const unsigned char *safeAsciiPtr = (const unsigned char*) ascii;
unsigned char *bin;
int cb = 0;
int charNo; int charNo;
unsigned char *bin;
const unsigned char *safeAsciiPtr = (const unsigned char*) ascii;
int cb = 0;
int pad = 0; int pad = 0;
if (len < 2) { /* 2 accesses below would be OOB. */ if (len < 2) /* 2 accesses below would be OOB (Out Of Bounds). */
{
/* catch empty string, return NULL as result. */ /* catch empty string, return NULL as result. */
/* ERROR: You passed an invalid base64 string (too short). /* ERROR: You passed an invalid base64 string (too short).
* You get NULL back. */ * You get NULL back. */
*flen = 0; *flen = 0;
return 0; return 0;
} }
if(safeAsciiPtr[len-1]=='=') if (safeAsciiPtr[len-1]=='=')
++pad; ++pad;
if(safeAsciiPtr[len-2]=='=') if (safeAsciiPtr[len-2]=='=')
++pad; ++pad;
*flen = 3*len/4 - pad; *flen = 3*len/4 - pad;
bin = (unsigned char*)malloc(*flen); if (!(bin = (unsigned char*)malloc(*flen)))
if (!bin)
{
/* ERROR: unbase64 could not allocate enough memory. */
return 0; return 0;
}
for (charNo=0; charNo <= len-4-pad; charNo+=4) for (charNo=0; charNo <= len-4-pad; charNo+=4)
{ {

@ -165,12 +165,12 @@ static void dump_content(RFILE *file, const void *frame,
{ {
/* BGR24 byte order input matches output. Can directly copy, but... need to make sure we pad it. */ /* BGR24 byte order input matches output. Can directly copy, but... need to make sure we pad it. */
uint32_t zeros = 0; uint32_t zeros = 0;
int pad = (int)(line_size-pitch); int padding = (int)(line_size-pitch);
for (j = 0; j < height; j++, u.u8 += pitch) for (j = 0; j < height; j++, u.u8 += pitch)
{ {
filestream_write(file, u.u8, pitch); filestream_write(file, u.u8, pitch);
if(pad != 0) if (padding != 0)
filestream_write(file, &zeros, pad); filestream_write(file, &zeros, padding);
} }
} }
break; break;
@ -184,8 +184,7 @@ static void dump_content(RFILE *file, const void *frame,
} }
/* allocate line buffer, and initialize the final four bytes to zero, for deterministic padding */ /* allocate line buffer, and initialize the final four bytes to zero, for deterministic padding */
line = (uint8_t*)malloc(line_size); if (!(line = (uint8_t*)malloc(line_size)))
if (!line)
return; return;
*(uint32_t*)(line + line_size - 4) = 0; *(uint32_t*)(line + line_size - 4) = 0;

@ -118,7 +118,7 @@ rxml_document_t *rxml_load_document(const char *path)
error: error:
free(memory_buffer); free(memory_buffer);
if(file) if (file)
filestream_close(file); filestream_close(file);
return NULL; return NULL;
} }

@ -75,22 +75,22 @@ static INLINE int16_t tofloat16(float f)
e = ((i >> 23) & 0x000000ff) - (127 - 15); e = ((i >> 23) & 0x000000ff) - (127 - 15);
m = i & 0x007fffff; m = i & 0x007fffff;
if(e <= 0) if (e <= 0)
{ {
if(e < -10) if (e < -10)
return (int16_t)(s); return (int16_t)(s);
m = (m | 0x00800000) >> (1 - e); m = (m | 0x00800000) >> (1 - e);
if(m & 0x00001000) if (m & 0x00001000)
m += 0x00002000; m += 0x00002000;
return (int16_t)(s | (m >> 13)); return (int16_t)(s | (m >> 13));
} }
if(e == 0xff - (127 - 15)) if (e == 0xff - (127 - 15))
{ {
if(m == 0) if (m == 0)
return (int16_t)(s | 0x7c00); return (int16_t)(s | 0x7c00);
m >>= 13; m >>= 13;
@ -98,11 +98,11 @@ static INLINE int16_t tofloat16(float f)
return (int16_t)(s | 0x7c00 | m | (m == 0)); return (int16_t)(s | 0x7c00 | m | (m == 0));
} }
if(m & 0x00001000) if (m & 0x00001000)
{ {
m += 0x00002000; m += 0x00002000;
if(m & 0x00800000) if (m & 0x00800000)
{ {
m = 0; m = 0;
e += 1; e += 1;

@ -66,19 +66,20 @@ static void crash(void)
cothread_t co_create(unsigned int size, void (*entrypoint)(void)) cothread_t co_create(unsigned int size, void (*entrypoint)(void))
{ {
size = (size + 1023) & ~1023; uint64_t *ptr = NULL;
cothread_t handle = 0; cothread_t handle = 0;
size = (size + 1023) & ~1023;
#if HAVE_POSIX_MEMALIGN >= 1 #if HAVE_POSIX_MEMALIGN >= 1
if (posix_memalign(&handle, 1024, size + 512) < 0) if (posix_memalign(&handle, 1024, size + 512) < 0)
return 0; return 0;
#else #else
handle = memalign(1024, size + 512); handle = memalign(1024, size + 512);
#endif #endif
if (!handle) if (!handle)
return handle; return handle;
uint64_t *ptr = (uint64_t*)handle; ptr = (uint64_t*)handle;
/* Non-volatiles. */ /* Non-volatiles. */
ptr[0] = 0; /* x8 */ ptr[0] = 0; /* x8 */
ptr[1] = 0; /* x9 */ ptr[1] = 0; /* x9 */

Some files were not shown because too many files have changed in this diff Show More