Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
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  
  Image loading....  (Read 3029 times)
0 Members and 1 Guest are viewing this topic.
Offline rsk

Senior Newbie




I love YaBB 1G - SP1!


« Posted 2002-10-22 13:39:10 »

I was reading the Java2D (iPlanet painting) article from the Swing Connectio and noticed them using this to load an image that they paint as a panel background:

BufferedImage image = ImageIO.read("background.jpg");
imageFill = new ImageFill(image);


Now from what I've read here on JG, BufferedImages are the (only?) kind of image that cannot be accelerated. So wouldn't it have been better for them to do a Toolkit.getImage? Why, in this performance-minded article, would they use a BufferedImage? I think the name's misleading, as it "sounds" faster than a Image Smiley

Thanks!

P.S.> The reason I ask is because it seems nice and tempting to use the ImageIO class to load images, (read methods) but all it can return is BufferedImages, and I don't want to forgo the (automatic) images that are accelerated (when available).
Online princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2002-10-22 15:20:13 »

If you've got other reasons for using ImageIO please ignore this, but there's much more sensible ways of loading images for games in Java if you're interested in performance.

Use your own file format for a start if you can. Plain gzip with a header is absolutely adequate where once you might have used .PNG or .GIF. If you need to use JPEG then you're probably better off using ImageIO, but otherwise you cut down on a vast amount of overhead and crud that gets dragged along with the ImageIO libraries and Java2D.

Secondly, as you are using your own file format, you can load them directly into whatever storage you want - for example, straight into a VolatileImage. If you're lucky the VolatileImage will be in exactly the same byte-format as your image data; otherwise you'll have to translate the pixels on the fly into the native format from your image format.

Thirdly, if you're doing cleverer stuff with native libraries then load the image data directly into a ByteBuffer. If you're sending the image directly to DirectX or OpenGL or SDL then this is by far and away the fastest way of doing things, and uses a fraction of the memory.

Cas Smiley

Offline rsk

Senior Newbie




I love YaBB 1G - SP1!


« Reply #2 - Posted 2002-10-22 15:25:24 »

Thanks for the info princec, I hadn't even considered using my own file format, you have good points.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline morbo

Senior Newbie





« Reply #3 - Posted 2002-10-22 17:50:20 »

ImageIO is good because the formats it can load is extensible. Also,  it provides a lot more control  over how the image is loaded (including what ColorModel to use).

A handy thing about loading into a BufferedImage is that you can do some pre-rendering-processing on it. And if you want speed, after you finish the processing you can convert it to an automatic Image using a MemoryImageProducer, or by creating an ImageProducer that reads directly from the BufferedImage.

I'd debate the values of using your own image format. First, that requires a converstion step in the art pipeline. Second, any new features you'll have to add yourself. Say you need a transparency channel down the road; now not only do you have to change your format, but you have to modify the converter AND the loader. I recommed you find an exsiting format and work from that: PNG is a good one, as it's fairly simple, yet has a lot of options (plus ImageIO supports it).

If load time is an issue, wait until near the end of the project to convert all the images to the most efficient format. Worrying about that during dev will only cause you grief.
Offline rsk

Senior Newbie




I love YaBB 1G - SP1!


« Reply #4 - Posted 2002-10-22 17:53:02 »

I'm mostly concerned with little things like icons at this point, so the custom format, as you pointed out, is a bad idea (as photoshop will just laugh at me).

Offline trembovetski

Senior Duke




If only I knew what I'm talking about!


« Reply #5 - Posted 2002-10-23 01:57:11 »

FYI: it's only the current state of affairs that BufferedImage's aren't accelerated. In future releases we're planning to have all of the images acceleratable.

As pointed out, ImageIO allows for much greater extensibility. For example, you can combine the benefits of having your own file format with the standard infrastructure already in place by writing your own ImageIO plugin (ImageReader/Writer). You can make it read the files into whatever images you like, then.

Offline GergisKhan

Junior Duke




"C8 H10 N4 O2"


« Reply #6 - Posted 2002-10-28 14:14:24 »

princec,

I am assuming that in order to use a custom format, you're responsible for also writing some form of converter, right?


gK

"Go.  Teach them not to mess with us."
          -- Cao Cao, Dynasty Warriors 3
Online princec

JGO Kernel


Medals: 404
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #7 - Posted 2002-10-28 15:47:06 »

Yep.
I convert from .PNG files using ImageIO.
Source code is in http://sourceforge.net/projects/spgl - look around the CVS in the "tools" section, there's an image converter in there, and in com.shavenpuppy.jglib.Image you'll find the actual image class I use myself. It's a WIP at the moment as I'm adding palette support.

Cas Smiley

Offline abies

Senior Duke





« Reply #8 - Posted 2002-10-30 14:06:22 »

If we are talking about performance, maybe following will do: Have original images in any format you want (jpg,png,anything). Then, when running for the first time on given system, check screen resolution/format you want to use. Then convert all images to this format, in raw form on disk. If for some reasons, format of screen has changed, you will need to purge the cache and convert again.

If you feel brave, you can even construct one big file, to avoid file open/close calls, and use one big MappedByteBuffer to access it.

Artur Biesiadowski
Offline gZi

Innocent Bystander




Java games rock!


« Reply #9 - Posted 2002-12-13 11:58:06 »

Performance...

So how about the quickest way of loading them to a window/frame from disk. Something like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
Frame f = new Frame(); // created somewhere else just as a reference
 
Image theImage;
MediaTracker mt = new MediaTracker(f);
mt.addImage((theImage = Toolkit.getDefaultToolkit().getImage("whatever.png)),0);
try {
   mt.waitForID(0); // to make sure the image is loaded
}catch(Exception e) {}
// and then draw to the frame with a render or via paint/repaint


With an Image 512x512x32bit (68793bytes in PNG) on a Sun SunBlade 100 256Mb ram it the procedure will have an average of 300milliseconds I tested with a WinXP 1.4GHz 256Mb ram and it had an average of 200milliseconds. There must be a quicker way!

gZi   Cool

Thanx for your reply, rsk. Modified the code. Loading the frame should be done alot earlier. But from your answer I assume there are no faster way?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline rsk

Senior Newbie




I love YaBB 1G - SP1!


« Reply #10 - Posted 2002-12-13 12:23:27 »

I can only assume the frame creation is slowing you down, that's expensive Sad

I don't typically like this solution, but using an ImageIcon will do exactly the code you just posted, minus the frame creation because it keeps a static reference to a Component that it uses.

So you can use the ImageIcon class to speed things up (since it Component is already creataed for you).

Offline anubis

Innocent Bystander




Java games rock!


« Reply #11 - Posted 2003-11-06 11:39:32 »

Hey!

now i have a problem concerning image loading.

I have menu that when i click a button removes old content of container and draws new one. The point is, that after clicking i have to wait short time to let the image load completely. It's only when i do it first time. Then i can click "back" and it will show fast.

I'm trying to prepare preloader of those backgrounds, and all graphic (jpg) files for menu.

Can someone please give me some hints, becouse as for now - it's my second day fighting with this problem, and i obviously need help.

Thx in advance.
Offline MGodehardt

Junior Duke




why does the chicken cross the road?


« Reply #12 - Posted 2003-11-07 08:53:05 »

i use my own image format gzip over my special image format.

I wrote my own converter in C++, but its easy for a professional to do this in 2 or 3 hours.

For my tilesets its the best solution, i can compress better than gif or png, because i know all special properties, which gif or png does not know.

for isometric tiles some pixels will be never used, but gif or png compresses them, believe me you will have less trouble if u use your own image format.
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.

Longarmx (34 views)
2014-10-17 03:59:02

Norakomi (25 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (74 views)
2014-10-11 22:30:10
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!