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).
pull/2/merge
HW 13 years ago
parent 10a8d59882
commit 447b9fe2b5

19
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}
};

Loading…
Cancel
Save