From 447b9fe2b5041ab28980c81ecf5a5cf0e0c52b5f Mon Sep 17 00:00:00 2001 From: HW Date: Wed, 16 Nov 2011 01:56:37 +0100 Subject: [PATCH] added gamma setting to drawcontext usage in Lua: dc:setGamma(1.5) print(dc:getGamma()) set it to a negative value to disable gamma correction (since gamma correction will always imply calculations over the full buffer data). --- pdf.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pdf.c b/pdf.c index 0e3290d9b..a7f2f5944 100644 --- a/pdf.c +++ b/pdf.c @@ -39,6 +39,7 @@ typedef struct PdfPage { typedef struct DrawContext { int rotate; double zoom; + double gamma; int offset_x; int offset_y; } DrawContext; @@ -78,6 +79,7 @@ static int newDrawContext(lua_State *L) { double zoom = luaL_optnumber(L, 2, (double) 1.0); int offset_x = luaL_optint(L, 3, 0); int offset_y = luaL_optint(L, 4, 0); + double gamma = luaL_optnumber(L, 5, (double) -1.0); DrawContext *dc = (DrawContext*) lua_newuserdata(L, sizeof(DrawContext)); dc->rotate = rotate; @@ -129,6 +131,18 @@ static int dcGetZoom(lua_State *L) { return 1; } +static int dcSetGamma(lua_State *L) { + DrawContext *dc = (DrawContext*) luaL_checkudata(L, 1, "drawcontext"); + dc->gamma = luaL_checknumber(L, 2); + return 0; +} + +static int dcGetGamma(lua_State *L) { + DrawContext *dc = (DrawContext*) luaL_checkudata(L, 1, "drawcontext"); + lua_pushnumber(L, dc->gamma); + return 1; +} + static int openPage(lua_State *L) { fz_error error; fz_device *dev; @@ -233,6 +247,9 @@ static int drawPage(lua_State *L) { #else pdf_run_page(page->doc->xref, page->page, dev, ctm); #endif + if(dc->gamma >= 0.0) { + fz_gamma_pixmap(pix, dc->gamma); + } fz_free_device(dev); fz_drop_pixmap(pix); @@ -266,6 +283,8 @@ static const struct luaL_reg drawcontext_meth[] = { {"getZoom", dcGetZoom}, {"setOffset", dcSetOffset}, {"getOffset", dcGetOffset}, + {"setGamma", dcSetGamma}, + {"getGamma", dcGetGamma}, {NULL, NULL} };