Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AW: Reading PICT Images



Just wanted to tie up the loose ends on this one and let people know what
I've found.

On 12/09/2008 16:21, "Greg Guerin" <email@hidden> wrote:
(Regarding using /usr/bin/sips or a custom ImageIO plugin)
> It depends.  If the file-format conversion is a fundamental feature
> of the overall task, then exec()'ing the sips command is not that
> different from schlepping the file in through one ImageIO converter
> and out through another.  Also, for an applet, the total code size
> might be important, and exec()'ing sips could be smaller than sending
> ImageIO conversion classes in the applet's jar.

For my particular use case, the image in question is coming from the
clipboard so I get it as an input stream and given that most images from the
clipboard come through as a java.awt.Image instance I already have code to
write those out to a file and handle the paste action from there. So
essentially, I want to convert a PICT image from an InputStream to a
java.awt.Image.  This makes the ImageIO plugin simpler to code for.

There are some unexpected lessons most of which are fairly well known around
the internet but worth mentioning for anyone who stumbles across this thread
later:

1. Images from the OS X clipboard normally come through as an instance of
java.awt.Image. The one exception to this is when you take a screen shot to
the clipboard with command-control-shift-4 or command-control-shift-3. These
images only come through as image/pict;class=java.io.InputStream

2. There seems to be a bug (radar #5648142) in recent versions of Java 1.5
on OS X which cause a NoSuchMethodError when you try to access the
java.awt.Image data from the clipboard. To be precise the exception is:
Exception in thread "AWT-EventQueue-2" java.lang.NoSuchMethodError: <init>
    at apple.awt.CDataTransferer.getImageForByteStream(Native Method)
    at 
apple.awt.CDataTransferer.platformImageBytesOrStreamToImage(CDataTransferer.
java:266)
    
You can work around this bug by instead reading the
image/pict;class=java.io.InputStream data which is also present.

3. The PICT data that OS X provides on the clipboard is missing the 512 byte
header that most PICT software expects.  You can work around this by
prepending 512 bytes, eg:
new SequenceInputStream(new ByteArrayInputStream(new byte[512]),
inputStream)

With this I managed to get the ImageIO plugin from
https://twelvemonkeys-imageio.dev.java.net/ to correctly read the PICT data,
but I never did get sips to handle it correctly. Very likely there was
somewhere in the file writing and reading code I had to write just to get
the image data to sips. I didn't spend much time tracking down what the
problem was.

4. The Twelve Monkeys PICT plugin is somewhat annoying to check out and
build. The PICT jar itself was about 60k but it depends on a utils jar which
brings the total size to 584k. You could probably reduce this a lot by
stripping out the utils classes that aren't actually used. For applets
you'll want to download this in the background - fortunately it seems to
work unsigned and registered from a separate class loader so you can just
create a new URLClassLoader to pull it down and then manually register the
PICT plugin with IIORegistry.

5. sips and the Twelve Monkeys PICT plugin appear to be the only long term
viable methods of reading PICT data. You can use QTJ to do it with 32bit
JREs today but the future of that process doesn't look too safe.
 
Thanks to everyone for the help on this, it was greatly appreciated.

Regards,

Adrian Sutton.
______________________
Adrian Sutton, CTO
UK: +44 1 753 27 2229  US: +1 (650) 292 9659 x717
Ephox <http://www.ephox.com/>
Ephox Blogs <http://planet.ephox.com/>, Personal Blog
<http://www.symphonious.net/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: AW: Reading PICT Images (From: Greg Guerin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.