Skip to content

Commit

Permalink
Add proper scaling to mupdf.renderImage() (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
poire-z authored and Frenzie committed Sep 24, 2017
1 parent 82d9eab commit 548077c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ffi/mupdf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,15 @@ function mupdf.renderImage(data, size, width, height)

local p_width = M.fz_pixmap_width(context(), pixmap)
local p_height = M.fz_pixmap_height(context(), pixmap)
-- mupdf_new_pixmap_from_image() may not scale image to the
-- width and height provided, so check and scale it if needed
if width and height and (p_width ~= width or p_height ~= height) then
local scaled_pixmap = M.fz_scale_pixmap(context(), pixmap, 0, 0, width, height, nil)
M.fz_drop_pixmap(context(), pixmap)
pixmap = scaled_pixmap
p_width = M.fz_pixmap_width(context(), pixmap)
p_height = M.fz_pixmap_height(context(), pixmap)
end
local bbtype
local ncomp = M.fz_pixmap_components(context(), pixmap)
if ncomp == 2 then bbtype = BlitBuffer.TYPE_BB8A
Expand Down
1 change: 1 addition & 0 deletions ffi/mupdf_h.lua
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ fz_pixmap *fz_new_pixmap(fz_context *, fz_colorspace *, int, int);
fz_pixmap *mupdf_new_pixmap_with_bbox(fz_context *, fz_colorspace *, const fz_irect *);
fz_pixmap *mupdf_new_pixmap_with_data(fz_context *, fz_colorspace *, int, int, unsigned char *);
fz_pixmap *mupdf_new_pixmap_with_bbox_and_data(fz_context *, fz_colorspace *, const fz_irect *, unsigned char *);
fz_pixmap *fz_scale_pixmap(fz_context *, fz_pixmap *, float, float, float, float, fz_irect *);
void fz_convert_pixmap(fz_context *, fz_pixmap *, fz_pixmap *);
fz_pixmap *fz_keep_pixmap(fz_context *, fz_pixmap *);
void fz_drop_pixmap(fz_context *, fz_pixmap *);
Expand Down

0 comments on commit 548077c

Please sign in to comment.