Skip to content

Commit

Permalink
wrlib: add explicit type definition in API to allow compiler Type Che…
Browse files Browse the repository at this point in the history
…cks (1/3)

When defining enums as types instead of simple enums allows to use these
types at the places where the corresponding enum values are expected, then
allowing the compiler to check that, potentially reporting incorrect use
of values to the user.

This patch adds types for the configuration fields in the RContextAttributes
structure.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
  • Loading branch information
Christophe CURIS authored and crmafra committed Jun 15, 2014
1 parent 96a6e4d commit eb3f0b1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 32 deletions.
3 changes: 2 additions & 1 deletion util/wmsetbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,8 @@ int main(int argc, char **argv)
char *back_color = "gray20";
char *image_name = NULL;
char *domain = "WindowMaker";
int update = 0, cpc = 4, render_mode = RDitheredRendering, obey_user = 0;
int update = 0, cpc = 4, obey_user = 0;
RRenderingMode render_mode = RDitheredRendering;
char *texture = NULL;
int workspace = -1;

Expand Down
2 changes: 1 addition & 1 deletion wrlib/scale.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static double Mitchell_filter(double t)
static double (*filterf)(double) = Mitchell_filter;
static double fwidth = Mitchell_support;

void wraster_change_filter(int type)
void wraster_change_filter(RScalingFilter type)
{
switch (type) {
case RBoxFilter:
Expand Down
2 changes: 1 addition & 1 deletion wrlib/scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/*
* Function to change the smoothing filter used for image scaling (RSmoothScaleImage)
*/
void wraster_change_filter(int type);
void wraster_change_filter(RScalingFilter type);


#endif
52 changes: 23 additions & 29 deletions wrlib/wraster.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,43 @@ extern "C" {




/* image display modes */
typedef enum {
RDitheredRendering = 0,
RBestMatchRendering = 1
} RRenderingMode;


/* std colormap usage/creation modes */
enum {
RUseStdColormap, /* default. fallbacks to RIgnore.. if
there is none defined */
RCreateStdColormap,
RIgnoreStdColormap
};
typedef enum {
RUseStdColormap, /* default: fallbacks to RIgnore if there is none defined */
RCreateStdColormap,
RIgnoreStdColormap
} RStdColormapMode;


/* smoothed scaling filter types */
typedef enum {
RBoxFilter,
RTriangleFilter,
RBellFilter,
RBSplineFilter,
RLanczos3Filter,
RMitchellFilter
} RScalingFilter;


typedef struct RContextAttributes {
int flags;
int render_mode;
RRenderingMode render_mode;
int colors_per_channel; /* for PseudoColor */
float rgamma; /* gamma correction for red, */
float ggamma; /* green, */
float bgamma; /* and blue */
VisualID visualid; /* visual ID to use */
int use_shared_memory; /* True of False */
int scaling_filter;
int standard_colormap_mode; /* what to do with std cma */
RScalingFilter scaling_filter;
RStdColormapMode standard_colormap_mode; /* what to do with std cma */
} RContextAttributes;


Expand Down Expand Up @@ -211,24 +224,6 @@ typedef struct RXImage {
} RXImage;


/* image display modes */
enum {
RDitheredRendering = 0,
RBestMatchRendering = 1
};


/* smoothed scaling filter types */
enum {
RBoxFilter,
RTriangleFilter,
RBellFilter,
RBSplineFilter,
RLanczos3Filter,
RMitchellFilter
};


/* note that not all operations are supported in all functions */
enum {
RClearOperation, /* clear with 0 */
Expand Down Expand Up @@ -481,4 +476,3 @@ extern int RErrorCode;
#endif /* __cplusplus */

#endif

0 comments on commit eb3f0b1

Please sign in to comment.