WiiDuktape/source/duktape/rgba.c

37 lines
865 B
C
Raw Permalink Normal View History

#include "rgba.h"
duk_ret_t compare_rgba(duk_context * ctx) {
unsigned int color1 = get_color(ctx, 0);
unsigned int color2 = get_color(ctx, 1);
duk_push_boolean(ctx, color1 == color2);
return 1;
}
duk_ret_t rgba(duk_context * ctx) {
int r = duk_get_number(ctx, 0);
int g = duk_get_number(ctx, 1);
int b = duk_get_number(ctx, 2);
int a = duk_get_number(ctx, 3);
if (r > 255 || g > 255 || b > 255 || a > 255) {
return duk_error(ctx, DUK_ERR_ERROR, "You can't use a number bigger then 255.");
}
unsigned char * buffer;
buffer = duk_push_fixed_buffer(ctx, 4);
buffer[0] = r;
buffer[1] = g;
buffer[2] = b;
buffer[3] = a;
return 1;
}
unsigned int get_color(duk_context * ctx, duk_idx_t index) {
size_t rgba_size;
unsigned char * rgba = duk_get_buffer(ctx, index, &rgba_size);
return rgba[0] << 24 | rgba[1] << 16 | rgba[2] << 8 | rgba[3];
}