Initial commit of picviewer.

Tigran Aivazian 12 years ago
parent fe77be4830
commit 30de5e0a23

@ -110,7 +110,7 @@ POPENNSLIB := $(POPENNSDIR)/libpopen_noshell.a
all: kpdfview
VERSION?=$(shell git describe HEAD)
kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o $(POPENNSLIB) util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS)
kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o $(POPENNSLIB) util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS) pic.o
echo $(VERSION) > git-rev
$(CC) \
$(CFLAGS) \
@ -130,6 +130,7 @@ kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o $(POPENNS
$(LUALIB) \
djvu.o \
$(DJVULIBS) \
pic.o \
cre.o \
$(CRENGINELIBS) \
$(STATICLIBSTDCPP) \
@ -154,6 +155,9 @@ kpdfview.o pdf.o blitbuffer.o util.o drawcontext.o einkfb.o input.o mupdfimg.o:
djvu.o: %.o: %.c
$(CC) -c $(KPDFREADER_CFLAGS) -I$(DJVUDIR)/ $< -o $@
pic.o: %.o: %.c
$(CC) -c $(KPDFREADER_CFLAGS) $< -o $@
cre.o: %.o: %.cpp
$(CC) -c $(CFLAGS) -I$(CRENGINEDIR)/crengine/include/ -I$(LUADIR)/src $< -o $@

@ -3,7 +3,8 @@
ext = {
djvuRead = ";djvu;",
pdfRead = ";pdf;xps;cbz;",
creRead = ";epub;txt;rtf;htm;html;mobi;prc;azw;fb2;chm;pdb;doc;tcr;zip;"
creRead = ";epub;txt;rtf;htm;html;mobi;prc;azw;fb2;chm;pdb;doc;tcr;zip;",
picRead = ";jpg;"
-- seems to accept pdb-files for PalmDoc only
}
@ -16,6 +17,8 @@ function ext:getReader(ftype)
return PDFReader
elseif string.find(self.djvuRead,s..ftype..s) then
return DJVUReader
elseif string.find(self.picRead,s..ftype..s) then
return PICViewer
elseif FileChooser.filemanager_expert_mode > FileChooser.BEGINNERS_MODE
or string.find(self.creRead,s..ftype..s) then
return CREReader

@ -28,6 +28,7 @@
#include "pdf.h"
#include "mupdfimg.h"
#include "djvu.h"
#include "pic.h"
#include "cre.h"
#include "einkfb.h"
#include "input.h"
@ -56,6 +57,7 @@ int main(int argc, char **argv) {
luaopen_einkfb(L);
luaopen_pdf(L);
luaopen_djvu(L);
luaopen_pic(L);
luaopen_cre(L);
luaopen_input(L);
luaopen_util(L);

171
pic.c

@ -0,0 +1,171 @@
/*
KindlePDFViewer: Picture viewer abstraction for Lua
Copyright (C) 2012 Tigran Aivazian <tigran@bibles.org.uk>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "blitbuffer.h"
#include "drawcontext.h"
#include "pic.h"
typedef struct PicDocument {
int width, height;
} PicDocument;
typedef struct PicPage {
int width, height;
PicDocument *doc;
} PicPage;
static int openDocument(lua_State *L) {
const char *filename = luaL_checkstring(L, 1);
printf("openDocument(%s)\n", filename);
PicDocument *doc = (PicDocument*) lua_newuserdata(L, sizeof(PicDocument));
luaL_getmetatable(L, "picdocument");
lua_setmetatable(L, -2);
doc->width = 600;
doc->height = 800;
return 1;
}
static int openPage(lua_State *L) {
PicDocument *doc = (PicDocument*) luaL_checkudata(L, 1, "picdocument");
int pageno = luaL_checkint(L, 2);
printf("openPage(%d)\n", pageno);
PicPage *page = (PicPage*) lua_newuserdata(L, sizeof(PicPage));
luaL_getmetatable(L, "picpage");
lua_setmetatable(L, -2);
page->width = doc->width;
page->height = doc->height;
page->doc = doc;
return 1;
}
static const struct luaL_Reg pic_func[] = {
{"openDocument", openDocument},
{NULL, NULL}
};
static int getNumberOfPages(lua_State *L) {
lua_pushinteger(L, 1);
return 1;
}
static int getOriginalPageSize(lua_State *L) {
PicDocument *doc = (PicDocument*) luaL_checkudata(L, 1, "picdocument");
lua_pushnumber(L, doc->width);
lua_pushnumber(L, doc->height);
return 2;
}
static int closeDocument(lua_State *L) {
PicDocument *doc = (PicDocument*) luaL_checkudata(L, 1, "picdocument");
return 0;
}
static int drawPage(lua_State *L) {
printf("drawPage()\n");
PicPage *page = (PicPage*) luaL_checkudata(L, 1, "picpage");
DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext");
BlitBuffer *bb = (BlitBuffer*) luaL_checkudata(L, 3, "blitbuffer");
uint8_t *imagebuffer = malloc((bb->w)*(bb->h)+1);
/* fill pixel map with white color */
memset(imagebuffer, 0xFF, (bb->w)*(bb->h)+1);
free(imagebuffer);
return 0;
}
static int getCacheSize(lua_State *L) {
lua_pushnumber(L, 8192);
return 1;
}
static int cleanCache(lua_State *L) {
return 0;
}
static int getPageSize(lua_State *L) {
PicPage *page = (PicPage*) luaL_checkudata(L, 1, "picpage");
DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext");
lua_pushnumber(L, dc->zoom * page->width);
lua_pushnumber(L, dc->zoom * page->height);
return 2;
}
static int closePage(lua_State *L) {
PicPage *page = (PicPage*) luaL_checkudata(L, 1, "picpage");
printf("closePage()\n");
return 0;
}
/* unsupported so fake it */
static int getUsedBBox(lua_State *L) {
lua_pushnumber(L, (double)0.01);
lua_pushnumber(L, (double)0.01);
lua_pushnumber(L, (double)-0.01);
lua_pushnumber(L, (double)-0.01);
return 4;
}
static const struct luaL_Reg picdocument_meth[] = {
{"openPage", openPage},
{"getPages", getNumberOfPages},
{"getOriginalPageSize", getOriginalPageSize},
{"close", closeDocument},
{"cleanCache", cleanCache},
{"__gc", closeDocument},
{NULL, NULL}
};
static const struct luaL_Reg picpage_meth[] = {
{"getSize", getPageSize},
{"getUsedBBox", getUsedBBox},
{"close", closePage},
{"__gc", closePage},
{"draw", drawPage},
{NULL, NULL}
};
int luaopen_pic(lua_State *L) {
luaL_newmetatable(L, "picdocument");
lua_pushstring(L, "__index");
lua_pushvalue(L, -2);
lua_settable(L, -3);
luaL_register(L, NULL, picdocument_meth);
lua_pop(L, 1);
luaL_newmetatable(L, "picpage");
lua_pushstring(L, "__index");
lua_pushvalue(L, -2);
lua_settable(L, -3);
luaL_register(L, NULL, picpage_meth);
lua_pop(L, 1);
luaL_register(L, "pic", pic_func);
return 1;
}

27
pic.h

@ -0,0 +1,27 @@
/*
KindlePDFViewer: JPEG Picture viewer abstraction for Lua
Copyright (C) 2012 Tigran Aivazian <tigran@bibles.org.uk>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _JPG_H
#define _JPG_H
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
int luaopen_pic(lua_State *L);
#endif

@ -0,0 +1,11 @@
require "unireader"
PICViewer = UniReader:new{}
function PICViewer:open(filename)
ok, self.doc = pcall(pic.openDocument, filename)
if not ok then
return ok, self.doc
end
return ok
end

@ -19,6 +19,7 @@
require "alt_getopt"
require "pdfreader"
require "djvureader"
require "picviewer"
require "crereader"
require "filechooser"
require "settings"
@ -156,6 +157,7 @@ UniReader:initGlobalSettings(G_reader_settings)
-- initialize specific readers
PDFReader:init()
DJVUReader:init()
PICViewer:init()
CREReader:init()
-- display directory or open file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Loading…
Cancel
Save