Home pageFind It!Contact PJAPJA documentation

PJA

 PJA Toolkit forum

This forum is dedicated to PJA Toolkit.
You may read freely the messages it contents. If you want to write a message or answer to a subject, subscribe to it first.

Subjects Recent messages Login Subscribe

Messages of subject loading jpeg without X libs

jb2224

Member since : Dec 12, 2003
Messages : 1
 Dec 12, 2003 at 4:21 PM
Hi,
I've attempted to search the forum for the answer but without success.
This is what I've so far found please correct me if I'm wrong,
*you can create graphics(text and polygons) from scratch without the Xlibs.
*you can load Gif images using the GifDecoder by Using PJAImage.
*PJAImage and PJAGraphics can run without Xlibs.
But I would like to load an existing JPG image and create a thumbnail for it.
I tried PJAGraphicsManager to call createImage(JPG file) but it still attempts to load java.awt.image.ColorModel which it can't because I don't have Xlibs installed.

So Is it possible to load jpeg images without Xlib?
thanks for any info.

jb

johnpage

Location : Philadelphia, PA USA
Member since : Jan 6, 2004
Messages : 3
 Jan 6, 2004 at 5:27 AM
Yes. I just solved this problem on a headless FreeBSD installation about ten minutes ago. Its not simple. Post again if you are still interested.

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Jan 7, 2004 at 12:18 AM
Please, let us the solution you found, I would be pleased to know it (before all if it's not simple ;-) !)
---
Manu (moderator/modérateur)

johnpage

Location : Philadelphia, PA USA
Member since : Jan 6, 2004
Messages : 3
 Jan 9, 2004 at 9:23 AM
PJA is a great tool. Thanks for developing it, Emmanuel. My hat's off to you!

But let's get to the heart of the matter:

My specs:
Tomcat 4
FreeBSD 4.8
diablo jdk 131 (FreeBSD Java Licensed by Sun!)

First you must start your J2ee engine in such a way that it recognizes the PJAToolkit as the default toolkit.

Here is the message I found here on the message boards which enabled me to leap this hurdle:
http://www.eteks.com/pja/en/forum/viewSubject.jsp?subjectId=38#81

------- excerpt from jmennear's post ---------------------
I simply updated setenv with the following:

JAVA_OPTS="$JAVA_OPTS -Djava2d.font.usePlatformFont=false -Xbootclasspath/a:$APPDIR/lib/pja.jar -Djava.awt.fonts=/opt/java/current/jre/lib/fonts -Dawt.toolkit=com.eteks.awt.PJAToolkit -Djava.awt.graphicsenv=com.eteks.java2d.PJAGraphicsEnvironment"
export JAVA_OPTS

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

Secondly, with Tomcat up and running,
you need to upload the jpeg and save it on the server. There are a number of
ways to accomplish this. Use your personal favorite.

Once the file is onboard, run this code which processes the jpeg image file:

//get image into RAM
PJAToolkit pJAToolkit=new PJAToolkit();
Image originalImage=pJAToolkit.createImage(imageFileDirectory+imageFileName);

//examine it
Canvas observer=new Canvas();
pJAToolkit.createCanvas(observer);//Unnecessary, I suspect
int currentWidth=originalImage.getWidth(observer);
int currentHeight=originalImage.getHeight(observer);
double ratio=(double)currentWidth/(double)currentHeight;
int newHeight=(int)((double)newWidth/ratio);

//create new image
BufferedImage newImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = newImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(originalImage, 0, 0, newWidth, newHeight, null);

// save new image to disc
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(newJpegFileName)));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(newImage);
param.setQuality((float)jpegQuality / 100.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(newImage);

(You might notice some JAI in the mix)

Cheers. I have benefited a great deal from these forums and the open-source movement, I hope this helps someone else. And again thank you Emmanuel Puybaret.

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Jan 9, 2004 at 8:05 PM
Thank you johnpage for your very kind message, but it miserably doesn't answer to the question of this subject : Is it possible to load JPEG images without **any** X libs installed on the system ?
It's possible for GIF images thanks to the internal com.eteks.awt.image.GIFDecoder class, but not with default Java JPEG loader that requires java.awt.image.IndexColorModel class and then awt lib and some basic X11 libs...

During initial PJA development, I started JPEG decoder/encoder classes adapted from original C sources, but stopped it because of the required amount of work and possible legal issues with JPEG group.
If there's a real need for this feature, I may achieve the development of these classes, but people should first convince me that there won't be any legal issue.
Please, give me your opinion on this forum about this and any link that may answer to my questions.
---
Manu (moderator/modérateur)

Manu

Location : Paris / France
Member since : Apr 29, 2003
Messages : 394
 Jan 10, 2004 at 9:49 PM
I added a survey about future PJA features at http://www.eteks.com/pja/en/x11survey.jsp .
Please answer to it to help eTeks decide if JPEG decoder/encoder is a feature you really need (among other ones).
---
Manu (moderator/modérateur)

johnpage

Location : Philadelphia, PA USA
Member since : Jan 6, 2004
Messages : 3
 Jan 10, 2004 at 10:46 PM
I see. I didn't realize PJAToolkit relied on some - - - >awt - - - > x11 libraries. Looking at your source code I see the dependency now. I assumed.

I had been getting the classic ":0.0" error previously, because the server has no display. So despite the fact that it is not completely X11-independent, it accomplishes what I need with jdk1.3.

I wonder how much the JAI library depends on awt and x11 libraries. The java.awt.image.BufferedImage object is a common product of JAI method calls, which leads me to suspect that the two are deeply entwined. Perhaps JAI bears investigation.

Regarding the legal issues: clearly Sun has managed to sidestep them since they have both a JPEG Encoder and Decoder. My understanding was that Gifs recently became a bit more sensitive from a legal perspective, with HP(?) threatening to pursue copyright infringement cases.


Home pageFind It!ContactTop

© Copyrights 1997-2014 eTeks - All rights reserved

PJAPJA documentation