-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from chrox/master
update mupdf and k2pdfopt to latest version
- Loading branch information
Showing
11 changed files
with
187 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--[[ | ||
converting pdf page to willus bmp | ||
--]] | ||
|
||
local ffi = require("ffi") | ||
local dummy = require("ffi/mupdf_h") | ||
local dummy = require("ffi/koptcontext_h") | ||
local mupdf = ffi.load("libs/libmupdf.so") | ||
local k2pdfopt = ffi.load("libs/libk2pdfopt.so.2") | ||
|
||
local Bitmap = {} | ||
|
||
function Bitmap:pixmap_to_bmp(bmp, ctx, pixmap) | ||
bmp.width = mupdf.fz_pixmap_width(ctx, pixmap) | ||
bmp.height = mupdf.fz_pixmap_height(ctx, pixmap) | ||
local ncomp = mupdf.fz_pixmap_components(ctx, pixmap) | ||
if ncomp ~= 2 and ncomp ~= 4 then return -1 end | ||
bmp.bpp = ncomp == 2 and 8 or 24 | ||
k2pdfopt.bmp_alloc(bmp) | ||
if ncomp == 2 then | ||
for i=0, 255 do | ||
bmp.red[i] = i | ||
bmp.green[i] = i | ||
bmp.blue[i] = i | ||
end | ||
end | ||
local p = mupdf.fz_pixmap_samples(ctx, pixmap) | ||
if ncomp == 2 then | ||
for row=0, bmp.height - 1 do | ||
local dest = k2pdfopt.bmp_rowptr_from_top(bmp, row) | ||
for col=0, bmp.width - 1 do | ||
dest[0] = p[0] | ||
dest = dest + 1 | ||
p = p + 2 | ||
end | ||
end | ||
end | ||
return 0 | ||
end | ||
|
||
function Bitmap:pdffile_to_bmp(bmp, filename, pageno, dpi, bpp) | ||
local ctx = mupdf.fz_new_context_imp(nil, nil, bit.lshift(8, 20), "1.4") | ||
if ctx == nil then return -1 end | ||
mupdf.fz_register_document_handlers(ctx) | ||
local colorspace = bpp == 8 and mupdf.fz_device_gray(ctx) or mupdf.fz_device_rgb(ctx) | ||
local doc = mupdf.fz_open_document(ctx, filename) | ||
if mupdf.fz_count_pages(doc) < pageno or pageno < 1 then | ||
return -1 | ||
end | ||
local page = mupdf.fz_load_page(doc, pageno-1) | ||
local ctm = ffi.new("fz_matrix[1]")[0] | ||
local bbox = ffi.new("fz_irect[1]")[0] | ||
local bounds = ffi.new("fz_rect[1]")[0] | ||
mupdf.fz_bound_page(doc, page, bounds) | ||
mupdf.fz_scale(ctm, dpi/72, dpi/72) | ||
mupdf.fz_transform_rect(bounds, ctm) | ||
mupdf.fz_round_rect(bbox, bounds) | ||
local pix = mupdf.fz_new_pixmap_with_bbox(ctx, colorspace, bbox) | ||
mupdf.fz_clear_pixmap_with_value(ctx, pix, 0xFF) | ||
local dev = mupdf.fz_new_draw_device(ctx, pix) | ||
mupdf.fz_run_page(doc, page, dev, ctm, nil) | ||
mupdf.fz_free_device(dev) | ||
if self:pixmap_to_bmp(bmp, ctx, pix) ~= 0 then return -1 end | ||
mupdf.fz_drop_pixmap(ctx, pix) | ||
mupdf.fz_free_page(doc, page) | ||
mupdf.fz_close_document(doc) | ||
mupdf.fz_free_context(ctx) | ||
|
||
return 0 | ||
end | ||
|
||
return Bitmap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule crengine
updated
1 files
+3 −3 | crengine/src/lvtextfm.cpp |
Submodule libk2pdfopt
updated
32 files
+4,115 −4,136 | include_mod/png.h | |
+1 −1 | k2pdfopt.c | |
+1 −1 | k2pdfoptlib/k2bmp.c | |
+1 −1 | k2pdfoptlib/k2file.c | |
+1 −1 | k2pdfoptlib/k2gui.c | |
+1 −1 | k2pdfoptlib/k2mark.c | |
+7 −3 | k2pdfoptlib/k2master.c | |
+1 −1 | k2pdfoptlib/k2menu.c | |
+1 −1 | k2pdfoptlib/k2ocr.c | |
+1 −1 | k2pdfoptlib/k2pdfopt.h | |
+11 −2 | k2pdfoptlib/k2proc.c | |
+31 −11 | k2pdfoptlib/k2publish.c | |
+1 −1 | k2pdfoptlib/k2usage.c | |
+28 −2 | k2pdfoptlib/k2version.c | |
+364 −146 | mupdf_mod/font.c | |
+160 −203 | mupdf_mod/pdf-font.c | |
+160 −86 | mupdf_mod/pdf-fontfile.c | |
+14 −3 | mupdf_mod/pdf-parse.c | |
+2,543 −0 | mupdf_mod/pdf-xref.c | |
+2 −3 | mupdf_mod/string.c | |
+6 −6 | readme_k2src.txt | |
+2 −0 | willuslib/array.c | |
+23 −1 | willuslib/bmpmupdf.c | |
+72 −1 | willuslib/filelist.c | |
+56 −1 | willuslib/strbuf.c | |
+41 −19 | willuslib/wfile.c | |
+31 −3 | willuslib/wgui.c | |
+6 −2 | willuslib/willus.h | |
+1 −1 | willuslib/willusversion.c | |
+2 −0 | willuslib/win.c | |
+158 −88 | willuslib/wmupdf.c | |
+2 −2 | willuslib/wzfile.c |
Submodule mupdf
updated
from 43bcd8 to eebc33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.