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 000000000..f03838322 Binary files /dev/null and b/resources/jpg.png differ