From: <jd...@us...> - 2008-12-17 12:54:28
|
Revision: 6645 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6645&view=rev Author: jdh2358 Date: 2008-12-17 12:54:24 +0000 (Wed, 17 Dec 2008) Log Message: ----------- Merged revisions 6644 via svnmerge from https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_98_5_maint ........ r6644 | jdh2358 | 2008-12-17 06:51:22 -0600 (Wed, 17 Dec 2008) | 1 line added Jouni's pdf image dpi patch; apply fix to figimage ........ Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/figimage_demo.py trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py trunk/matplotlib/lib/matplotlib/figure.py trunk/matplotlib/lib/matplotlib/image.py Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-6640 + /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-6644 Modified: trunk/matplotlib/examples/pylab_examples/figimage_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/figimage_demo.py 2008-12-17 12:51:22 UTC (rev 6644) +++ trunk/matplotlib/examples/pylab_examples/figimage_demo.py 2008-12-17 12:54:24 UTC (rev 6645) @@ -15,6 +15,11 @@ im1 = plt.figimage(Z, xo=50, yo=0, cmap=cm.jet, origin='lower') im2 = plt.figimage(Z, xo=100, yo=100, alpha=.8, cmap=cm.jet, origin='lower') +dpi = 200 +plt.savefig('figimage.png', dpi=dpi) +plt.savefig('figimage.pdf', dpi=dpi) +plt.savefig('figimage.svg', dpi=dpi) +plt.savefig('figimage.eps', dpi=dpi) plt.show() Modified: trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2008-12-17 12:51:22 UTC (rev 6644) +++ trunk/matplotlib/lib/matplotlib/backends/backend_pdf.py 2008-12-17 12:54:24 UTC (rev 6645) @@ -1184,13 +1184,14 @@ truetype_font_cache = maxdict(50) afm_font_cache = maxdict(50) - def __init__(self, file, dpi): + def __init__(self, file, dpi, image_dpi): RendererBase.__init__(self) self.file = file self.gc = self.new_gc() self.file.used_characters = self.used_characters = {} self.mathtext_parser = MathTextParser("Pdf") self.dpi = dpi + self.image_dpi = image_dpi self.tex_font_map = None def finalize(self): @@ -1230,9 +1231,10 @@ stat_key, (realpath, set())) used_characters[1].update(charset) + def get_image_magnification(self): + return self.image_dpi/72.0 + def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None): - #print >>sys.stderr, "draw_image called" - # MGDTODO: Support clippath here gc = self.new_gc() if bbox is not None: @@ -1240,6 +1242,7 @@ self.check_gc(gc) h, w = im.get_size_out() + h, w = 72.0*h/self.image_dpi, 72.0*w/self.image_dpi imob = self.file.imageObject(im) self.file.output(Op.gsave, w, 0, 0, h, x, y, Op.concat_matrix, imob, Op.use_xobject, Op.grestore) @@ -1873,13 +1876,13 @@ return 'pdf' def print_pdf(self, filename, **kwargs): - dpi = 72 # there are 72 Postscript points to an inch - # TODO: use the dpi kwarg for images - self.figure.set_dpi(dpi) + ppi = 72 # Postscript points in an inch + image_dpi = kwargs.get('dpi', 72) # dpi to use for images + self.figure.set_dpi(ppi) width, height = self.figure.get_size_inches() - file = PdfFile(width, height, dpi, filename) + file = PdfFile(width, height, ppi, filename) renderer = MixedModeRenderer( - width, height, dpi, RendererPdf(file, dpi)) + width, height, ppi, RendererPdf(file, ppi, image_dpi)) self.figure.draw(renderer) renderer.finalize() file.close() Modified: trunk/matplotlib/lib/matplotlib/figure.py =================================================================== --- trunk/matplotlib/lib/matplotlib/figure.py 2008-12-17 12:51:22 UTC (rev 6644) +++ trunk/matplotlib/lib/matplotlib/figure.py 2008-12-17 12:54:24 UTC (rev 6645) @@ -755,7 +755,7 @@ # make a composite image blending alpha # list of (_image.Image, ox, oy) mag = renderer.get_image_magnification() - ims = [(im.make_image(mag), im.ox*mag, im.oy*mag) + ims = [(im.make_image(mag), im.ox, im.oy) for im in self.images] im = _image.from_images(self.bbox.height * mag, Modified: trunk/matplotlib/lib/matplotlib/image.py =================================================================== --- trunk/matplotlib/lib/matplotlib/image.py 2008-12-17 12:51:22 UTC (rev 6644) +++ trunk/matplotlib/lib/matplotlib/image.py 2008-12-17 12:54:24 UTC (rev 6645) @@ -630,6 +630,7 @@ self.ox = offsetx self.oy = offsety self.update(kwargs) + self.magnification = 1.0 def contains(self, mouseevent): """Test whether the mouse event occured within the image. @@ -659,22 +660,30 @@ -0.5+self.oy, numrows-0.5+self.oy) def make_image(self, magnification=1.0): - # had to introduce argument magnification to satisfy the unit test - # figimage_demo.py. I have no idea, how magnification should be used - # within the function. It should be !=1.0 only for non-default DPI< - # settings in the PS backend, as introduced by patch #1562394 - # Probably Nicholas Young should look over this code and see, how - # magnification should be handled correctly. if self._A is None: raise RuntimeError('You must first set the image array') x = self.to_rgba(self._A, self._alpha) - - im = _image.fromarray(x, 1) + self.magnification = magnification + # if magnification is not one, we need to resize + ismag = magnification!=1 + #if ismag: raise RuntimeError + if ismag: + isoutput = 0 + else: + isoutput = 1 + im = _image.fromarray(x, isoutput) fc = self.figure.get_facecolor() im.set_bg( *mcolors.colorConverter.to_rgba(fc, 0) ) im.is_grayscale = (self.cmap.name == "gray" and len(self._A.shape) == 2) + + if ismag: + numrows, numcols = self.get_size() + numrows *= magnification + numcols *= magnification + im.set_interpolation(_image.NEAREST) + im.resize(numcols, numrows) if self.origin=='upper': im.flipud_out() @@ -683,9 +692,8 @@ def draw(self, renderer, *args, **kwargs): if not self.get_visible(): return # todo: we should be able to do some cacheing here - im = self.make_image() - - renderer.draw_image(round(self.ox), round(self.oy), im, self.figure.bbox, + im = self.make_image(renderer.get_image_magnification()) + renderer.draw_image(round(self.ox/self.magnification), round(self.oy/self.magnification), im, self.figure.bbox, *self.get_transformed_clip_path_and_affine()) def write_png(self, fname): @@ -772,7 +780,7 @@ x.shape = im.size[1], im.size[0], 4 return x -def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear', +def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear', preview=False): """ make a thumbnail of image in *infile* with output filename This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |