From 503c9b077d546ec8d33d09461a46a271bb48b1b9 Mon Sep 17 00:00:00 2001 From: Tigran Aivazian Date: Mon, 8 Oct 2012 16:39:03 +0100 Subject: [PATCH] Initial commit of picviewer. Conflicts: Makefile extentions.lua pic.c reader.lua --- kpdfview.c | 2 ++ pic.c | 26 -------------------------- pic.h | 27 +++++++++++++++++++++++++++ picviewer.lua | 11 +++++++++++ resources/jpg.png | Bin 0 -> 1117 bytes 5 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 pic.h create mode 100644 picviewer.lua create mode 100644 resources/jpg.png diff --git a/kpdfview.c b/kpdfview.c index 94b33ff1a..4a3bd7b33 100644 --- a/kpdfview.c +++ b/kpdfview.c @@ -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" @@ -96,6 +97,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); diff --git a/pic.c b/pic.c index aaec55744..b40e47752 100644 --- a/pic.c +++ b/pic.c @@ -20,7 +20,6 @@ #include #include #include - #include "blitbuffer.h" #include "drawcontext.h" #include "pic.h" @@ -87,11 +86,6 @@ static int openDocument(lua_State *L) { } else { free(raw_image); return luaL_error(L, "Unsupported image format"); - } - - doc->width = width; - doc->height = height; - doc->components = components; return 1; } @@ -171,26 +165,6 @@ static int drawPage(lua_State *L) { scaleImage(scaled_image, page->image, img_width, img_height, img_new_width, img_new_height); - uint8_t *bbptr = bb->data; - uint8_t *pmptr = scaled_image; - bbptr += bb->pitch * y_offset; - for(y = y_offset; y < img_new_height; y++) { - for(x = x_offset/2; x < (img_new_width / 2); x++) { - int p = x*2 - x_offset; - unsigned char low = 15 - (pmptr[p + 1] >> 4); - unsigned char high = 15 - (pmptr[p] >> 4); - if (adjust_pixels) - bbptr[x] = adjusted_high[high] | adjusted_low[low]; - else - bbptr[x] = (high << 4) | low; - } - if (img_new_width & 1) - bbptr[x] = 255 - (pmptr[x*2] & 0xF0); - bbptr += bb->pitch; - pmptr += img_new_width; - } - - free(scaled_image); return 0; } diff --git a/pic.h b/pic.h new file mode 100644 index 000000000..ee6e099a5 --- /dev/null +++ b/pic.h @@ -0,0 +1,27 @@ +/* + KindlePDFViewer: JPEG Picture viewer abstraction for Lua + Copyright (C) 2012 Tigran Aivazian + + 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 . +*/ +#ifndef _JPG_H +#define _JPG_H + +#include +#include +#include + +int luaopen_pic(lua_State *L); + +#endif diff --git a/picviewer.lua b/picviewer.lua new file mode 100644 index 000000000..cc3edbd99 --- /dev/null +++ b/picviewer.lua @@ -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 diff --git a/resources/jpg.png b/resources/jpg.png new file mode 100644 index 0000000000000000000000000000000000000000..f038383226f839382308b40df1bf3d5866fdc1d1 GIT binary patch literal 1117 zcmaJ;SxggA6ul~_REQfwaLfFN3$4zSN?=?)>@;2k`B}9w9@v~>C_e%LMn#My>D-Q)KFhMJCiGB^-DB) zS&CYo{S=KfWTYLdIr5;SxHhQN9~U3% zHEQ$NC#)q^nY7K9q(@fE*qqTLS7x!*%SX39ZCrz%IZDs8w^;7#_j`N7cloPLmTS9i z9^JX8?)&A7`L;K0(MEr5Q&Dg5eAA0iC~`kN)M?K>*V7d_Uc9n|)TwqG17Cl3Z`m;6 z^Xtof{-1p%iOOjMKZ-tn>z?wYIyq<<7+>+DxiPIxZrUhQwWNglzjQUUHgCwk6*Qda zSQ6;z?rtBGe9(~I(Oh(AdqhdBtIyY?$R%HX<{o3)sqBm47kRfU)io^-Rk?EcLf1sF zh3yBc?wqW^!^uVMMv+A>7v~mXxx>j3e!(G%oSP^uC)8F{$`M985|P)AJoSWXKI#9q z`4HC4l5|!^Z{NDmGTDKVs zQez!h+J*!dBZ9-l@Z5r}9*%!*>Aa8ei4rd5G>e=_@Ol^)yO8_VpT!{Y2lO&7kJI7i z6*h(ykpRkoQceXZ>F9gwZpOKu_>i;)PqQpGlNEa;a}*S%AeBe`@)?*rU3&K~SI03{ z{5S`z5RZrzMr~p1g41=Fmo}WYUf?-5TMlmI<~l$0lwrnXi6K~RwAv|xjF7(AJ?Z