/*****************************************************************************\ file:SetPalette(pal) \*****************************************************************************/ static int imluaFileSetPalette (lua_State *L) { imFile *ifile = imlua_checkfile(L, 1); imluaPalette *pal = imlua_checkpalette(L, 2); imFileSetPalette(ifile, pal->color, pal->count); return 0; }
/*****************************************************************************\ im.PaletteFindNearest \*****************************************************************************/ static int imluaPaletteFindNearest (lua_State *L) { imluaPalette *pal = imlua_checkpalette(L, 1); long color = (long int) lua_touserdata(L, 1); lua_pushnumber(L, imPaletteFindNearest(pal->color, pal->count, color)); return 1; }
/*****************************************************************************\ im.PaletteFindColor \*****************************************************************************/ static int imluaPaletteFindColor (lua_State *L) { imluaPalette *pal = imlua_checkpalette(L, 1); long color = (long) lua_touserdata(L, 2); unsigned char tol = (unsigned char)luaL_checkint(L, 3); lua_pushnumber(L, imPaletteFindColor(pal->color, pal->count, color, tol)); return 1; }
/*****************************************************************************\ image:SetPalette \*****************************************************************************/ static int imluaImageSetPalette (lua_State *L) { imImage *image = imlua_checkimage(L, 1); imluaPalette *pal = imlua_checkpalette(L, 2); long* palette = (long*)malloc(sizeof(long)*256); memcpy(palette, pal->color, pal->count*sizeof(long)); imImageSetPalette(image, palette, pal->count); return 0; }
/***************************************************************************\ * color = palette[i] * \***************************************************************************/ static int imluaPalette_index(lua_State *L) { imluaPalette *pal = imlua_checkpalette(L, 1); int index_i = luaL_checkint(L, 2); if (index_i < 0 || index_i >= pal->count) luaL_argerror(L, 2, "index is out of bounds"); lua_pushlightuserdata(L, (void*) pal->color[index_i]); return 1; }
/***************************************************************************\ * palette[i] = color * \***************************************************************************/ static int imluaPalette_newindex(lua_State *L) { long color_i; imluaPalette *pal = imlua_checkpalette(L, 1); int index_i = luaL_checkint(L, 2); if (index_i < 0 || index_i >= pal->count) luaL_argerror(L, 2, "index is out of bounds"); if (!lua_islightuserdata(L, 3)) luaL_argerror(L, 3, "color must be a light user data"); color_i = (long int) lua_touserdata(L, 3); pal->color[index_i] = color_i; return 0; }