Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  fastest image writing  (Read 1539 times)
0 Members and 2 Guests are viewing this topic.
Offline counterp

Full Member
**

Posts: 235
Medals: 11



« on: 2011-08-11 17:28:17 »

ImageIO.write is dangerously slow and I guess that's because it's compressing the image to another format.

So how do I go about doing this, when size isn't a factor?

The fastest method of writing an image. Do I grab all pixels and write them?
Offline Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5866
Medals: 255


Hand over your head.


« Reply #1 on: 2011-08-11 17:56:27 »

TGA

it's basically a header + dump of the pixels

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline counterp

Full Member
**

Posts: 235
Medals: 11



« Reply #2 on: 2011-08-11 18:04:49 »

Is there a faster way of getting all the pixels or do I just have to use

1  
2  
3  
BufferedImage img = region.images[i];
int[] ARGB = new int[w * h];
img.getRGB(0, 0, w, h, ARGB, 0, w);


is there a way to avoid the integer array all together and write info directly to a byte array?
Games published by our own members! Go get 'em!
Offline Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5866
Medals: 255


Hand over your head.


« Reply #3 on: 2011-08-11 18:07:01 »

about a zillion times faster:
1  
2  
3  
4  
5  
6  
7  
8  
9  
   public static int[] accessRasterIntArray(BufferedImage src)
   {
      return ((DataBufferInt) src.getRaster().getDataBuffer()).getData();
   }

   public static byte[] accessRasterByteArray(BufferedImage src)
   {
      return ((DataBufferByte) src.getRaster().getDataBuffer()).getData();
   }

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline counterp

Full Member
**

Posts: 235
Medals: 11



« Reply #4 on: 2011-08-11 18:08:11 »

1  
2  
3  
4  
public static byte[] accessRasterByteArray(BufferedImage src)
{
   return ((DataBufferByte) src.getRaster().getDataBuffer()).getData();
}


I think that was exactly what I was looking for Wink

thanks
Offline Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5866
Medals: 255


Hand over your head.


« Reply #5 on: 2011-08-11 18:09:50 »

btw: you can use BufferedImage().getType() to pick the correct backing DataBuffer

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline counterp

Full Member
**

Posts: 235
Medals: 11



« Reply #6 on: 2011-08-11 18:29:30 »

EDIT: Alright everything's working
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.078 seconds with 19 queries.