Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Uploading v1.14.5
  • Loading branch information
JorjMcKie committed Jan 5, 2019
commit 0ca6d32a05009f74e0dc095e04c94a612fa633a1
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PyMuPDF 1.14.4
# PyMuPDF 1.14.5

![logo](https://github.com/rk700/PyMuPDF/blob/master/demo/pymupdf.jpg)

Expand All @@ -14,7 +14,7 @@ On **[PyPI](https://pypi.org/project/PyMuPDF)** since August 2016: [![](https://

# Introduction

This is **version 1.14.4 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.14.x](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".
This is **version 1.14.5 of PyMuPDF (formerly python-fitz)**, a Python binding with support for [MuPDF 1.14.x](http://mupdf.com/) - "a lightweight PDF, XPS, and E-book viewer".

MuPDF can access files in PDF, XPS, OpenXPS, CBZ, EPUB and FB2 (e-books) formats, and it is known for its top performance and high rendering quality.

Expand Down
Binary file added demo/piechart1.pdf
Binary file not shown.
Binary file added demo/piechart2.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions demo/sierpinski.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def punch(pm, x00, y00, x03, y03):
d = 3 ** 6 # 729
# create a quadratic pixmap with origin (0,0), where width = height = d should
# be a power of 3
t0 = time.clock()
t0 = time.perf_counter()
ir = fitz.IRect(0, 0, d, d)
pm = fitz.Pixmap(fitz.csGRAY, ir, 0)
# fill image area with "black" and then optionally tint and gamma it
Expand All @@ -58,8 +58,8 @@ def punch(pm, x00, y00, x03, y03):
# pm.gammaWith(0.5) # lighten it up
# now punch holes into it, down to 1 pixel granularity
punch(pm, 0, 0, d, d)
t1 = time.clock()
t1 = time.perf_counter()
pm.writePNG(png_name)
t2 = time.clock()
t2 = time.perf_counter()
print("%f sec to create fitz img" % (t1 - t0))
print("%f sec to save fitz img" % (t2 - t1))
11 changes: 5 additions & 6 deletions fitz/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import absolute_import
from fitz.fitz import *
from fitz import _fitz
try:
from fitz import _fitz
except:
pass

# define the supported colorspaces for convenience
fitz.csRGB = fitz.Colorspace(fitz.CS_RGB)
Expand Down Expand Up @@ -45,6 +48,7 @@
fitz.Page.drawOval = fitz.utils.drawOval
fitz.Page.drawPolyline = fitz.utils.drawPolyline
fitz.Page.drawRect = fitz.utils.drawRect
fitz.Page.drawQuad = fitz.utils.drawQuad
fitz.Page.drawSector = fitz.utils.drawSector
fitz.Page.drawSquiggle = fitz.utils.drawSquiggle
fitz.Page.drawZigzag = fitz.utils.drawZigzag
Expand All @@ -61,11 +65,6 @@
fitz.Page.updateLink = fitz.utils.updateLink
fitz.Page.newShape = lambda x: fitz.utils.Shape(x)

#------------------------------------------------------------------------------
# Pixmap
#------------------------------------------------------------------------------
fitz.Pixmap.writeImage = fitz.utils.writeImage

#------------------------------------------------------------------------------
# Rect
#------------------------------------------------------------------------------
Expand Down
66 changes: 60 additions & 6 deletions fitz/fitz.i
Original file line number Diff line number Diff line change
Expand Up @@ -3867,10 +3867,10 @@ struct fz_pixmap_s
}

//----------------------------------------------------------------------
// getPNGData
// Pixmap._getImageData
//----------------------------------------------------------------------
FITZEXCEPTION(getPNGData, !result)
PyObject *getPNGData(int savealpha=-1)
FITZEXCEPTION(_getImageData, !result)
PyObject *_getImageData(int format, int savealpha=-1)
{
struct fz_buffer_s *res = NULL;
fz_output *out = NULL;
Expand All @@ -3879,7 +3879,27 @@ struct fz_pixmap_s
fz_try(gctx) {
res = fz_new_buffer(gctx, 1024);
out = fz_new_output_with_buffer(gctx, res);
fz_write_pixmap_as_png(gctx, out, $self);
switch(format)
{
case(1):
fz_write_pixmap_as_png(gctx, out, $self);
break;
case(2):
fz_write_pixmap_as_pnm(gctx, out, $self);
break;
case(3):
fz_write_pixmap_as_pam(gctx, out, $self);
break;
case(4):
fz_write_pixmap_as_tga(gctx, out, $self);
break;
case(5):
fz_write_pixmap_as_psd(gctx, out, $self);
break;
default:
fz_write_pixmap_as_png(gctx, out, $self);
break;
}
r = JM_BinFromBuffer(gctx, res);
}
fz_always(gctx)
Expand All @@ -3891,6 +3911,19 @@ struct fz_pixmap_s
return r;
}

%pythoncode %{
def getImageData(self, output="png"):
valid_formats = {"png": 1, "pnm": 2, "pgm": 2, "ppm": 2, "pbm": 2,
"pam": 3, "tga": 4, "psd": 5}
idx = valid_formats.get(output.lower(), 1)
return self._getImageData(idx)

def getPNGdata(self):
return self._getImageData(1)
def getPNGData(self, savealpha=-1):
return self._getImageData(1)
%}

//----------------------------------------------------------------------
// _writeIMG
//----------------------------------------------------------------------
Expand All @@ -3913,14 +3946,26 @@ struct fz_pixmap_s
case(4):
fz_save_pixmap_as_tga(gctx, $self, filename);
break;
case(5):
fz_save_pixmap_as_psd(gctx, $self, filename);
break;
default:
fz_save_pixmap_as_png(gctx, $self, filename);
break;
}
}
fz_catch(gctx) return NULL;
return NONE;
}
%pythoncode %{
def writePNG(self, filename, savealpha = -1):
return self._writeIMG(filename, 1, savealpha)
def writeImage(self, filename, output="png"):
valid_formats = {"png": 1, "pnm": 2, "pgm": 2, "ppm": 2, "pbm": 2,
"pam": 3, "tga": 4, "psd": 5}
idx = valid_formats.get(output.lower(), 1)
return self._writeIMG(filename, idx)

def writePNG(self, filename, savealpha = -1):
return self._writeIMG(filename, 1, savealpha)
%}
//----------------------------------------------------------------------
// invertIRect
Expand Down Expand Up @@ -3952,6 +3997,15 @@ struct fz_pixmap_s
width = w
height = h

def pixel(self, x, y):
"""Return a tuple representing one pixel. Item values are integers in range
0 to 255. Last item is the alpha value if Pixmap.alpha is true.
"""
if x not in range(self.width) or y not in range(self.height):
raise IndexError("coordinates outside image")
i = self.stride * y + self.n * x
return tuple(self.samples[i: i + self.n])

def __len__(self):
return self.size

Expand Down
86 changes: 43 additions & 43 deletions fitz/fitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ class _object:


VersionFitz = "1.14.0"
VersionBind = "1.14.4"
VersionDate = "2018-12-18 08:56:44"
version = (VersionBind, VersionFitz, "20181218085644")
VersionBind = "1.14.5"
VersionDate = "2019-01-04 10:29:25"
version = (VersionBind, VersionFitz, "20190104102925")


class Matrix():
Expand Down Expand Up @@ -164,12 +164,7 @@ def invert(self, src=None):
dst = TOOLS._invert_matrix(src)
if dst[0] == 1:
return 1
self.a = dst[1][0]
self.b = dst[1][1]
self.c = dst[1][2]
self.d = dst[1][3]
self.e = dst[1][4]
self.f = dst[1][5]
self.a, self.b, self.c, self.d, self.e, self.f = dst[1]
return 0

def preTranslate(self, tx, ty):
Expand Down Expand Up @@ -239,13 +234,7 @@ def preRotate(self, theta):

def concat(self, one, two):
"""Multiply two matrices and replace current one."""
dst = TOOLS._concat_matrix(one, two)
self.a = dst[0]
self.b = dst[1]
self.c = dst[2]
self.d = dst[3]
self.e = dst[4]
self.f = dst[5]
self.a, self.b, self.c, self.d, self.e, self.f = TOOLS._concat_matrix(one, two)
return self

def __getitem__(self, i):
Expand Down Expand Up @@ -386,7 +375,7 @@ def __init__(self, *args):
raise ValueError("illegal Point constructor")

def transform(self, m):
"""Replace point by its transformation with matrix m."""
"""Replace point by its transformation with matrix-like m."""
x = self.x
self.x = x * m[0] + self.y * m[2] + m[4]
self.y = x * m[1] + self.y * m[3] + m[5]
Expand Down Expand Up @@ -622,29 +611,22 @@ def round(self):

def includePoint(self, p):
"""Extend rectangle to include point p."""
r0 = TOOLS._include_point_in_rect(self, p);
self.x0 = r0[0]
self.y0 = r0[1]
self.x1 = r0[2]
self.y1 = r0[3]
self.x0, self.y0, self.x1, self.y1 = TOOLS._include_point_in_rect(self, p)
return self

def includeRect(self, r):
"""Extend rectangle to include rectangle r."""
r0 = TOOLS._union_rect(self, r)
self.x0 = r0[0]
self.y0 = r0[1]
self.x1 = r0[2]
self.y1 = r0[3]
self.x0, self.y0, self.x1, self.y1 = TOOLS._union_rect(self, r)
return self

def intersect(self, r):
"""Restrict self to common area with rectangle r."""
r0 = TOOLS._intersect_rect(self, r);
self.x0 = r0[0]
self.y0 = r0[1]
self.x1 = r0[2]
self.y1 = r0[3]
self.x0, self.y0, self.x1, self.y1 = TOOLS._intersect_rect(self, r)
return self

def transform(self, m):
"""Replace rectangle with its transformation by matrix m."""
self.x0, self.y0, self.x1, self.y1 = TOOLS._transform_rect(self, m)
return self

def __getitem__(self, i):
Expand Down Expand Up @@ -703,15 +685,6 @@ def __sub__(self, p):
raise ValueError("require rect-like object")
return Rect(self.x0 - p[0], self.y0 - p[1], self.x1 - p[2], self.y1 - p[3])

def transform(self, m):
"""Replace rectangle with its transformation by matrix m."""
r0 = TOOLS._transform_rect(self, m)
self.x0 = r0[0]
self.y0 = r0[1]
self.x1 = r0[2]
self.y1 = r0[3]
return self

def __mul__(self, m):
if hasattr(m, "__float__"):
return Rect(self.x0 * m, self.y0 * m, self.x1 * m, self.y1 * m)
Expand Down Expand Up @@ -3189,16 +3162,34 @@ def setAlpha(self, alphavalues=None):
return _fitz.Pixmap_setAlpha(self, alphavalues)


def _getImageData(self, format, savealpha=-1):
"""_getImageData(self, format, savealpha=-1) -> PyObject *"""
return _fitz.Pixmap__getImageData(self, format, savealpha)


def getImageData(self, output="png"):
valid_formats = {"png": 1, "pnm": 2, "pgm": 2, "ppm": 2, "pbm": 2,
"pam": 3, "tga": 4, "psd": 5}
idx = valid_formats.get(output.lower(), 1)
return self._getImageData(idx)

def getPNGdata(self):
return self._getImageData(1)
def getPNGData(self, savealpha=-1):
"""getPNGData(self, savealpha=-1) -> PyObject *"""
return _fitz.Pixmap_getPNGData(self, savealpha)
return self._getImageData(1)


def _writeIMG(self, filename, format, savealpha=-1):
"""_writeIMG(self, filename, format, savealpha=-1) -> PyObject *"""
return _fitz.Pixmap__writeIMG(self, filename, format, savealpha)


def writeImage(self, filename, output="png"):
valid_formats = {"png": 1, "pnm": 2, "pgm": 2, "ppm": 2, "pbm": 2,
"pam": 3, "tga": 4, "psd": 5}
idx = valid_formats.get(output.lower(), 1)
return self._writeIMG(filename, idx)

def writePNG(self, filename, savealpha = -1):
return self._writeIMG(filename, 1, savealpha)

Expand All @@ -3217,6 +3208,15 @@ def samples(self):
width = w
height = h

def pixel(self, x, y):
"""Return a tuple representing one pixel. Item values are integers in range
0 to 255. Last item is the alpha value if Pixmap.alpha is true.
"""
if x not in range(self.width) or y not in range(self.height):
raise IndexError("coordinates outside image")
i = self.stride * y + self.n * x
return tuple(self.samples[i: i + self.n])

def __len__(self):
return self.size

Expand Down
Loading