Bugs item #1510885, was opened at 2006-06-22 21:24
Message generated for change (Comment added) made by wobsta
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=442886&aid=1510885&group_id=45430

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Josiah Carlson (josiahcarlson)
Assigned to: Nobody/Anonymous (nobody)
Summary: pyx draws bitmaps incorrectly

Initial Comment:
Running the following script should produce a series of
blocks of the 256 shades of grey between and including
black and white.

import pyx
pbb = pyx.bitmap.bitmap
pbi = pyx.bitmap.image
c = pyx.canvas.canvas()
for i in xrange(256):
    c.insert(pbb(.5*(i&15), .5*(i>>4),
pbi(10,10,"L",100*chr(i)), height=.5))
c.writePDFfile('test.pdf')

Instead, it produces either an all-white or all-black
image at random.  This is the case when using Windows
2000, Python 2.3 and 2.4, and is verifiable in both
Adobe Acrobat 7 and Foxit Reader 1.3 .  Adjusting the
above code as necessary for RGB images does not fix the
problem.

The problem exists for the two most recent versions of PyX.

----------------------------------------------------------------------

>Comment By: André Wobst (wobsta)
Date: 2006-06-23 18:48

Message:
Logged In: YES 
user_id=405853

Let me add another short comment although the report was already answered 
and closed.

The real problem is, that PyX uses the id of the image object to generate a 
unique number of the image to be drawn. The idea is to make it possible to 
reuse the same image resource several times and have the image included 
only once in the output. This works automatically in PDF, since there is such a 
image object by default. In PostScript this can be done as well and PyX 
supports this, but you need to use memory (it might be a lot of memory) on 
the PostScript interpreter, since PostScript is a "get a stream and immediately 
execute it" language.

And your problem is related to the fact, that the garbage collector collects 
the 
image instance as soon as it's not refered anymore and then the other image 
instance reuses the memory and thus has the same id. While we have fixed 
this in PyX resently (after a stepped into the problem myself last weekend), 
you can also work around easily on old PyX versions by just ensuring, that the 
garbage collector does not collect the image instances as long as you create 
other instances. (The id of the image instance is calculated during the 
constructor of the bitmap instance.) So a workaround for your code without 
changing the PyX core would be:

import pyx
pbb = pyx.bitmap.bitmap
pbi = pyx.bitmap.image
c = pyx.canvas.canvas()
images = []
for i in xrange(256):
  image = pbi(10,10,"L",100*chr(i))
  c.insert(pbb(.5*(i&15), .5*(i>>4), image, height=.5))
  images.append(image)
c.writePDFfile('test.pdf')

Best, André

----------------------------------------------------------------------

Comment By: Jörg Lehmann (joergl)
Date: 2006-06-23 09:36

Message:
Logged In: YES 
user_id=390410

Hello Josiah,

thanks for your bug report. This bug has already been
fixed in SVN (revision 2825). The fix is a one-liner:

Index: pyx/bitmap.py
===================================================================
--- pyx/bitmap.py       (Revision 2824)
+++ pyx/bitmap.py       (Revision 2825)
@@ -259,6 +259,9 @@
                        PSstoreimage=0, PSmaxstrlen=4093,
PSbinexpand=1,
                        compressmode="Flate",
flatecompresslevel=6,
                        dctquality=75, dctoptimize=0,
dctprogression=0):
+        # keep a copy of the image instance to ensure
different id's
+        self.image = image
+
         self.xpos = xpos
         self.ypos = ypos
         self.imagewidth, self.imageheight = image.size

I'm marking this bug as fixed and closing it.

    Jörg

----------------------------------------------------------------------

Comment By: Josiah Carlson (josiahcarlson)
Date: 2006-06-23 01:28

Message:
Logged In: YES 
user_id=341410

A work-around is to create a temporary canvas, insert the
image into the temporary canvas, and insert the temporary
canvas into the main canvas.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=442886&aid=1510885&group_id=45430

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
PyX-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyx-devel

Reply via email to