diff options
Diffstat (limited to 'src/emu/rendutil.h')
-rw-r--r-- | src/emu/rendutil.h | 109 |
1 files changed, 21 insertions, 88 deletions
diff --git a/src/emu/rendutil.h b/src/emu/rendutil.h index 1824fb0a34a..71e5bdc95c3 100644 --- a/src/emu/rendutil.h +++ b/src/emu/rendutil.h @@ -13,9 +13,13 @@ #pragma once -#include "render.h" +#include "rendertypes.h" -#include <math.h> +#include "utilfwd.h" + +#include <algorithm> +#include <cmath> +#include <utility> /* ----- image formats ----- */ @@ -23,6 +27,8 @@ enum ru_imgformat { RENDUTIL_IMGFORMAT_PNG, + RENDUTIL_IMGFORMAT_JPEG, + RENDUTIL_IMGFORMAT_MSDIB, RENDUTIL_IMGFORMAT_UNKNOWN, RENDUTIL_IMGFORMAT_ERROR @@ -36,13 +42,14 @@ enum ru_imgformat /* ----- render utilities ----- */ -void render_resample_argb_bitmap_hq(bitmap_argb32 &dest, bitmap_argb32 &source, const render_color &color, bool force = false); -bool render_clip_line(render_bounds *bounds, const render_bounds *clip); -bool render_clip_quad(render_bounds *bounds, const render_bounds *clip, render_quad_texuv *texcoords); -void render_line_to_quad(const render_bounds *bounds, float width, float length_extension, render_bounds *bounds0, render_bounds *bounds1); -void render_load_jpeg(bitmap_argb32 &bitmap, emu_file &file, const char *dirname, const char *filename); -bool render_load_png(bitmap_argb32 &bitmap, emu_file &file, const char *dirname, const char *filename, bool load_as_alpha_to_existing = false); -ru_imgformat render_detect_image(emu_file &file, const char *dirname, const char *filename); +void render_resample_argb_bitmap_hq(bitmap_argb32 &dest, bitmap_argb32 &source, const render_color &color, bool force = false) noexcept; +bool render_clip_line(render_bounds &bounds, const render_bounds &clip); +bool render_clip_quad(render_bounds &bounds, const render_bounds &clip, render_quad_texuv *texcoords); +std::pair<render_bounds, render_bounds> render_line_to_quad(const render_bounds &bounds, float width, float length_extension); +void render_load_msdib(bitmap_argb32 &bitmap, util::random_read &file) noexcept; +void render_load_jpeg(bitmap_argb32 &bitmap, util::random_read &file) noexcept; +bool render_load_png(bitmap_argb32 &bitmap, util::random_read &file, bool load_as_alpha_to_existing = false) noexcept; +ru_imgformat render_detect_image(util::random_read &file) noexcept; @@ -57,76 +64,7 @@ ru_imgformat render_detect_image(emu_file &file, const char *dirname, const char static inline float render_round_nearest(float f) { - return floor(f + 0.5f); -} - - -/*------------------------------------------------- - set_render_bounds_xy - cleaner way to set the - bounds --------------------------------------------------*/ - -static inline void set_render_bounds_xy(render_bounds &bounds, float x0, float y0, float x1, float y1) -{ - bounds.x0 = x0; - bounds.y0 = y0; - bounds.x1 = x1; - bounds.y1 = y1; -} - - -/*------------------------------------------------- - set_render_bounds_wh - cleaner way to set the - bounds --------------------------------------------------*/ - -static inline void set_render_bounds_wh(render_bounds &bounds, float x0, float y0, float width, float height) -{ - bounds.x0 = x0; - bounds.y0 = y0; - bounds.x1 = x0 + width; - bounds.y1 = y0 + height; -} - - -/*------------------------------------------------- - sect_render_bounds - compute the intersection - of two render_bounds --------------------------------------------------*/ - -static inline void sect_render_bounds(render_bounds &dest, const render_bounds &src) -{ - dest.x0 = (std::max)(dest.x0, src.x0); - dest.x1 = (std::min)(dest.x1, src.x1); - dest.y0 = (std::max)(dest.y0, src.y0); - dest.y1 = (std::min)(dest.y1, src.y1); -} - - -/*------------------------------------------------- - union_render_bounds - compute the union of two - render_bounds --------------------------------------------------*/ - -static inline void union_render_bounds(render_bounds &dest, const render_bounds &src) -{ - dest.x0 = (std::min)(dest.x0, src.x0); - dest.x1 = (std::max)(dest.x1, src.x1); - dest.y0 = (std::min)(dest.y0, src.y0); - dest.y1 = (std::max)(dest.y1, src.y1); -} - - -/*------------------------------------------------- - set_render_color - cleaner way to set a color --------------------------------------------------*/ - -static inline void set_render_color(render_color *color, float a, float r, float g, float b) -{ - color->a = a; - color->r = r; - color->g = g; - color->b = b; + return floorf(f + 0.5f); } @@ -135,7 +73,7 @@ static inline void set_render_color(render_color *color, float a, float r, float flip flags -------------------------------------------------*/ -static inline int orientation_swap_flips(int orientation) +constexpr int orientation_swap_flips(int orientation) { return (orientation & ORIENTATION_SWAP_XY) | ((orientation & ORIENTATION_FLIP_X) ? ORIENTATION_FLIP_Y : 0) | @@ -148,7 +86,7 @@ static inline int orientation_swap_flips(int orientation) that will undo another orientation -------------------------------------------------*/ -static inline int orientation_reverse(int orientation) +constexpr int orientation_reverse(int orientation) { /* if not swapping X/Y, then just apply the same transform to reverse */ if (!(orientation & ORIENTATION_SWAP_XY)) @@ -165,7 +103,7 @@ static inline int orientation_reverse(int orientation) after applying two subsequent orientations -------------------------------------------------*/ -static inline int orientation_add(int orientation1, int orientation2) +constexpr int orientation_add(int orientation1, int orientation2) { /* if the 2nd transform doesn't swap, just XOR together */ if (!(orientation2 & ORIENTATION_SWAP_XY)) @@ -192,11 +130,7 @@ static inline float apply_brightness_contrast_gamma_fp(float srcval, float brigh srcval = (srcval * contrast) + brightness - 1.0f; /* clamp and return */ - if (srcval < 0.0f) - srcval = 0.0f; - if (srcval > 1.0f) - srcval = 1.0f; - return srcval; + return std::clamp(srcval, 0.0f, 1.0f); } @@ -213,5 +147,4 @@ static inline u8 apply_brightness_contrast_gamma(u8 src, float brightness, float return u8(result * 255.0f); } - #endif // MAME_EMU_RENDUTIL_H |