From 654dcfeb281d7ba91752df2a360d596761046e30 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Fri, 4 Jul 2014 23:28:37 +0200 Subject: [PATCH] wrlib: merged both R*FlipImage function into one for the public API It is generally not a good idea to have an API with a high number of functions because it adds complexity for user and for maintainability, so both function have been "merged" into a single RFlipImage with a parameter to specify what flip is expected. As a bonus, the function can perform both flips at once if wanted. Signed-off-by: Christophe CURIS --- wrlib/flip.c | 31 +++++++++++++++++++++++++++++-- wrlib/libwraster.map | 3 +-- wrlib/wraster.h | 12 +++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/wrlib/flip.c b/wrlib/flip.c index ea5aeeef..f233238a 100644 --- a/wrlib/flip.c +++ b/wrlib/flip.c @@ -29,8 +29,35 @@ #include #include "wraster.h" +#include "rotate.h" -RImage *RVerticalFlipImage(RImage *source) + +static RImage *r_flip_vertically(RImage *source); +static RImage *r_flip_horizontally(RImage *source); + +/* Flip an image in the direction(s) specified */ +RImage *RFlipImage(RImage *source, int mode) +{ + /* Security */ + if (source == NULL) + return NULL; + + switch (mode & (RVerticalFlip | RHorizontalFlip)) { + case RHorizontalFlip: + return r_flip_horizontally(source); + + case RVerticalFlip: + return r_flip_vertically(source); + + case RHorizontalFlip | RVerticalFlip: + return wraster_rotate_image_180(source); + + default: + return RRetainImage(source); + } +} + +RImage *r_flip_vertically(RImage *source) { RImage *target; int nwidth, nheight; @@ -82,7 +109,7 @@ RImage *RVerticalFlipImage(RImage *source) return target; } -RImage *RHorizontalFlipImage(RImage *source) +RImage *r_flip_horizontally(RImage *source) { RImage *target; int nwidth, nheight; diff --git a/wrlib/libwraster.map b/wrlib/libwraster.map index cf364014..66b4b9dd 100644 --- a/wrlib/libwraster.map +++ b/wrlib/libwraster.map @@ -72,8 +72,7 @@ LIBWRASTER3 RRetainImage; RRGBtoHSV; RRotateImage; - RVerticalFlipImage; - RHorizontalFlipImage; + RFlipImage; RSaveImage; RScaleImage; RShutdown; diff --git a/wrlib/wraster.h b/wrlib/wraster.h index 974688d1..c5655db1 100644 --- a/wrlib/wraster.h +++ b/wrlib/wraster.h @@ -265,6 +265,14 @@ typedef enum { #define RGRD_DIAGONAL RDiagonalGradient +/* + * How an image can be flipped, for RFlipImage + * + * Values are actually bit-mask which can be OR'd + */ +#define RHorizontalFlip 0x0001 +#define RVerticalFlip 0x0002 + /* error codes */ #define RERR_NONE 0 @@ -366,9 +374,7 @@ RImage *RSmoothScaleImage(RImage *src, unsigned new_width, RImage *RRotateImage(RImage *image, float angle); -RImage *RVerticalFlipImage(RImage *image); - -RImage *RHorizontalFlipImage(RImage *image); +RImage *RFlipImage(RImage *image, int mode); RImage *RMakeTiledImage(RImage *tile, unsigned width, unsigned height);