Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Encoding PNGs  (Read 3420 times)
0 Members and 1 Guest are viewing this topic.
Offline krausest

Junior Devvie


Exp: 15 years


I love YaBB 1G - SP1!


« Posted 2005-06-12 15:16:06 »

For a server side app I'll have to create lots of PNG.
I've written a little benchmark that simulates some aspects of what it'll have to do.
The benchmark creates a single BufferedImage (currently TYPE_INT_ARGB)  clears it each frame and writes some text (slightly different for each frame) into it and encodes it as a PNG into a ByteArrayOutputStream. (I've verified that writing to files takes only slightly longer, which means that the JIT don't try to fool me).
I've ported the Benchmark to .NET 2.0, Java 1.5. and Java 1.6B Java's ImageIO PNG encoder is very slow and I've already found PngEncoder from Objectplanet (commercial, but 100$ would fit into the budget) which is faster.

For 100 Images in 300 x 300 with some ĺines of text I got the following results (in milliseconds):

.NET 2.0 Beta
Rendering 100 frames: 296,875
PNG encoding 100 frames: 578,125

JDK 1.5, ImageIO
Rendering 100 frames: 230
PNG encoding 100 frames: 14111

JDK 1.5, JAI 1.1.3-alpha
Rendering 100 frames: 230
PNG encoding 100 frames: 20211

JDK 1.5 -server, PngEncoder
Rendering 100 frames: 223
PNG encoding 100 frames: 2043

JDK 1.6 -server B39, PngEncoder
Rendering 100 frames: 246
PNG encoding 100 frames: 1568

(Conslusion: .NET 2.0's PNG encoder is much faster than the Java alternatives )

So here come my questions:
1. Are there any tricks to make ImageIO's PNGEncoder faster? My code for saving looks like that:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
   
        public PNGSaver()
   {
      Iterator<ImageWriter> it=ImageIO.getImageWritersByFormatName(format);
      if (!it.hasNext())
      {
         throw new IllegalStateException("No PNG ImageWriter found");
      }
      writer=it.next();
   }
   
   public void saveImage(OutputStream os,BufferedImage img) throws IOException
   {
      image = new IIOImage(img, null, null);
      writer.setOutput(new MemoryCacheImageOutputStream(os));
      writer.write(null,image,iwp);
   }


2. Can yourecommend other fast Java PNG encoders?

3. Do you have any other performance tricks for fast server side image generators?

Thanks,
Stefan
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 835
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2005-06-12 16:45:37 »

It might be due to the compression factor in each encoder. I've seen reports of ImageIO being very aggresive on compression.

So to be fair, you should also measure the file-size (or byte[].length)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline krausest

Junior Devvie


Exp: 15 years


I love YaBB 1G - SP1!


« Reply #2 - Posted 2005-06-12 19:48:40 »

You're right. I couldn't set the compression for any implementation (I didn't really search for .NET) except for PngEncoder which was set to compression level 1. Nevertheless all generated files were around 14kb small (and thus hopefully comparable). For my purposes anything smaller than 30kb would be fine.
Is there a possibility to set the compression level for ImageIO or JAI and PNG?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Linuxhippy

Senior Devvie


Medals: 1


Java games rock!


« Reply #3 - Posted 2005-06-13 08:09:12 »

btw. PngEncoder is very inefficient in some areas, it does copying arround memory-blocks which are not really needed and creates useless arrays. I've a tuned version, maybe you could try it?

lg Clemens
Offline krausest

Junior Devvie


Exp: 15 years


I love YaBB 1G - SP1!


« Reply #4 - Posted 2005-06-13 14:13:15 »

I've sent you a private message with my e-mail adress. I'm looking forward to seeing a faster encoder  Wink
Offline Linuxhippy

Senior Devvie


Medals: 1


Java games rock!


« Reply #5 - Posted 2005-06-13 19:36:25 »

for now I am quiet busy and since its non profit work you'll have to wait arround 3 weeks till I've more time.
But I cannot promise how much this tuning would help...

lg Clemens
Offline kevglass

« JGO Spiffy Duke »


Medals: 195
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #6 - Posted 2005-06-13 19:40:16 »

This might help:

http://catcode.com/pngencoder/

Kev

Offline trembovetski

Senior Devvie




If only I knew what I'm talking about!


« Reply #7 - Posted 2005-06-14 04:03:40 »

Check out the imageio codecs from Java Advanced Imaging https://jai.dev.java.net and https://jai-imageio.dev.java.net/ in particular. JAI has optimized imageio codecs.

You can ask questions here: http://www.javadesktop.org/forums/forum.jspa?forumID=59

Thanks,
  Dmitri
Java2D Team
 
Offline krausest

Junior Devvie


Exp: 15 years


I love YaBB 1G - SP1!


« Reply #8 - Posted 2005-06-14 12:37:28 »

Thanks for your help so far.
Here are my results for 100 PNGs (On a P4 2.4 MHz, 2GB RAM, Java runs with server hotspot and -Xmx256M):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
.NET 1.1: PNG - Standard - 11 kb
Total 984,3561 [msec]
Time for rendering 218,7458
Time for writing 734,3609

JDK 1.5 PNG - com.sun.media.imageioimpl.plugins.png.CLibPNGImageWriter - 15 kb (quality=0.8)
Time for rendering 183.7688860000001
Time for writing 5999.278679999998

JDK 1.5 PNG - com.sun.media.imageioimpl.plugins.png.CLibPNGImageWriter - 11 kb (quality=0.5)
Time for rendering 191.49081999999999
Time for writing 6993.622377999999

JDK 1.5 PNG -  com.sun.imageio.plugins.png.PNGImageWriter - 7kb
Time for rendering 182.23461700000004
Time for writing 7528.899063000002

JDK 1.5 PNG -  objectPlanet PNGEncoder - 14 kb
Time for rendering 177.66280500000002
Time for writing 1427.1216050000003

JDK 1.5 PNG - com.keypoint.PngEcoder, TYPE_INT_ARGB, compression level=1, filter=none - 12 kb
Time for rendering 196.32187699999994
Time for writing 2398.2550889999998


The native acceleration of imageio-tools doesn't really help. Is this the correcty way to set it up?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
   public PNGSaver() 
   {
      Iterator<ImageWriter> it=ImageIO.getImageWritersByFormatName(format);
      if (!it.hasNext())
      {
         throw new IllegalStateException("No PNG ImageWriter found");
      }
      while (it.hasNext())
      {
         writer=it.next();
         System.out.println("PNG Writer :"+writer.getClass());
         if (writer.getClass().getName().equals("com.sun.media.imageioimpl.plugins.png.CLibPNGImageWriter"))
         {
            System.out.println("Using PNG Writer :"+writer.getClass());
            break;
         }
      }      
      iwp = writer.getDefaultWriteParam();
      iwp.setCompressionMode( ImageWriteParam.MODE_EXPLICIT);
      iwp.setCompressionQuality( 0.5f);
   }

        /* Invoke each frame */
   public void saveImage(OutputStream os,BufferedImage img) throws IOException
   {
      image = new IIOImage(img, null, null);
      MemoryCacheImageOutputStream mos=new MemoryCacheImageOutputStream(os);
      writer.setOutput(mos);
      writer.write(null,image,iwp);
      mos.close();
       }


Any further tips?
Offline Linuxhippy

Senior Devvie


Medals: 1


Java games rock!


« Reply #9 - Posted 2005-06-14 14:14:11 »

Tada, I have not tuned it fully but results look promising:

Machine: P4/2600/512kb - 256mb - 300x300 image - 100 encodings:
Mustang-server: 700ms
IBM: 897ms
JRockit: 1045ms

I still go to school so I am happy about every peanuts.
If you like I could write a version which does encoding on mustang-server in 470ms on my machine, maybe for the price the objectplanet-stuff does cost?

lg Clemens
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (27 views)
2014-11-22 12:13:56

xFryIx (69 views)
2014-11-13 12:34:49

digdugdiggy (48 views)
2014-11-12 21:11:50

digdugdiggy (42 views)
2014-11-12 21:10:15

digdugdiggy (36 views)
2014-11-12 21:09:33

kovacsa (60 views)
2014-11-07 19:57:14

TehJavaDev (64 views)
2014-11-03 22:04:50

BurntPizza (62 views)
2014-11-03 18:54:52

moogie (77 views)
2014-11-03 06:22:04

CopyableCougar4 (77 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!