Made alpha in pixel_value_map actually work.

Forgot to register ctx.get_source, done now.

Originally committed to SVN as r1801.
This commit is contained in:
Niels Martin Hansen 2008-01-21 00:07:58 +00:00
parent 251d6f3a21
commit b33e9c9bff
2 changed files with 29 additions and 14 deletions

View File

@ -999,6 +999,7 @@ LuaCairoContext::LuaCairoContext(lua_State *L, cairo_t *_context) :
CALLABLE_REG(set_source_rgba);
CALLABLE_REG(set_source);
CALLABLE_REG(set_source_surface);
CALLABLE_REG(get_source);
CALLABLE_REG(set_antialias);
CALLABLE_REG(get_antialias);
CALLABLE_REG(set_dash);

View File

@ -692,14 +692,36 @@ static int pixel_value_map(lua_State *L)
cairo_surface_t *surf = CheckSurface(L, 1);
const char *program = luaL_checkstring(L, 2);
// Init image
cairo_surface_flush(surf);
int width = cairo_image_surface_get_width(surf);
int height = cairo_image_surface_get_height(surf);
ptrdiff_t stride = (ptrdiff_t)cairo_image_surface_get_stride(surf);
unsigned char *data = cairo_image_surface_get_data(surf);
cairo_format_t format = cairo_image_surface_get_format(surf);
// Set up engine specs
ExpressionEngine::Specification spec;
if (format == CAIRO_FORMAT_ARGB32) {
spec.registers.resize(6);
spec.registers[0] = "R";
spec.registers[1] = "G";
spec.registers[2] = "B";
spec.registers[3] = "A";
spec.registers[4] = "X";
spec.registers[5] = "Y";
}
else if (format == CAIRO_FORMAT_RGB24) {
spec.registers.resize(5);
spec.registers[0] = "R";
spec.registers[1] = "G";
spec.registers[2] = "B";
spec.registers[3] = "X";
spec.registers[4] = "Y";
}
else {
luaL_error(L, "Unsupported pixel format");
}
// Compile program
ExpressionEngine::Machine machine;
@ -711,14 +733,6 @@ static int pixel_value_map(lua_State *L)
luaL_error(L, "Error in expression program near\"%s\"", e);
}
// Init image
cairo_surface_flush(surf);
int width = cairo_image_surface_get_width(surf);
int height = cairo_image_surface_get_height(surf);
ptrdiff_t stride = (ptrdiff_t)cairo_image_surface_get_stride(surf);
unsigned char *data = cairo_image_surface_get_data(surf);
cairo_format_t format = cairo_image_surface_get_format(surf);
if (format == CAIRO_FORMAT_ARGB32) {
BaseImage<PixelFormat::cairo_argb32> img(width, height, stride, data);
for (int y = 0; y < height; y++) {