1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-08 12:15:49 +00:00

(SDK) Add libretro-sdk/include/clamping.h

This commit is contained in:
twinaphex 2014-10-26 02:18:56 +01:00
parent 0c4de816f9
commit 288c6941de
5 changed files with 31 additions and 52 deletions

View File

@ -22,6 +22,7 @@
#include <compat/posix_string.h>
#include "input_common.h"
#include <file/file_path.h>
#include <clamping.h>
#include <stddef.h>
#include <math.h>
@ -695,15 +696,6 @@ static bool inside_hitbox(const struct overlay_desc *desc, float x, float y)
return false;
}
static inline float clamp(float val, float lower, float upper)
{
if (val < lower)
return lower;
else if (val > upper)
return upper;
return val;
}
void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out,
int16_t norm_x, int16_t norm_y)
{
@ -757,17 +749,17 @@ void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out,
float y_val_sat = y_val / desc->analog_saturate_pct;
unsigned int base = (desc->type == OVERLAY_TYPE_ANALOG_RIGHT) ? 2 : 0;
out->analog[base + 0] = clamp(x_val_sat, -1.0f, 1.0f) * 32767.0f;
out->analog[base + 1] = clamp(y_val_sat, -1.0f, 1.0f) * 32767.0f;
out->analog[base + 0] = clamp_float(x_val_sat, -1.0f, 1.0f) * 32767.0f;
out->analog[base + 1] = clamp_float(y_val_sat, -1.0f, 1.0f) * 32767.0f;
}
if (desc->movable)
{
float x_dist = x - desc->x;
float y_dist = y - desc->y;
desc->delta_x = clamp(x_dist, -desc->range_x, desc->range_x)
desc->delta_x = clamp_float(x_dist, -desc->range_x, desc->range_x)
* ol->active->mod_w;
desc->delta_y = clamp(y_dist, -desc->range_y, desc->range_y)
desc->delta_y = clamp_float(y_dist, -desc->range_y, desc->range_y)
* ol->active->mod_h;
}
}

View File

@ -0,0 +1,24 @@
#ifndef _LIBRETRO_SDK_CLAMPING_H
#define _LIBRETRO_SDK_CLAMPING_H
#include <stdint.h>
static inline float clamp_float(float val, float lower, float upper)
{
if (val < lower)
return lower;
if (val > upper)
return upper;
return val;
}
static inline uint8_t clamp_8bit(int val)
{
if (val > 255)
return 255;
if (val < 0)
return 0;
return (uint8_t)val;
}
#endif

View File

@ -23,7 +23,7 @@
#ifndef __LIBRETRO_SDK_SCALER_PIXCONV_H__
#define __LIBRETRO_SDK_SCALER_PIXCONV_H__
#include <gfx/scaler/scaler_common.h>
#include <clamping.h>
void conv_0rgb1555_argb8888(void *output, const void *input,
int width, int height,

View File

@ -26,7 +26,7 @@
#include <stdint.h>
#include <stddef.h>
#include <boolean.h>
#include "scaler_common.h"
#include <clamping.h>
#define FILTER_UNITY (1 << 14)

View File

@ -1,37 +0,0 @@
/* Copyright (C) 2010-2014 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (scaler_common.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_SCALER_COMMON_H__
#define __LIBRETRO_SDK_SCALER_COMMON_H__
#include <stdint.h>
static inline uint8_t clamp_8bit(int val)
{
if (val > 255)
return 255;
if (val < 0)
return 0;
return (uint8_t)val;
}
#endif