Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  compress and read images (4K)  (Read 678 times)
0 Members and 1 Guest are viewing this topic.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Posted 2012-11-11 19:07:56 »

So, this is my first time in the java4k competition, and I've figured out how to use pack200 (yay-game size 2.02 kb)
However, my images are still rather large in size, and I don't know the right way to compress them and then read it in the code.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2012-11-11 19:16:02 »

Also I'm not too sure how the exact rules work; do I submit a pack.gz file? But then where do I put the images?
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #2 - Posted 2012-11-11 23:36:24 »

This is probably the wrong forum... but I dont have power to move so I will leave it up to the powers that be to decide Smiley

However to answer your question... it depends Tongue

The simplest method with very little overhead is to simply utilise the pack200 format. That is create your jar including your images and simple pack200/gzip that. You will be able to access your images in the normal manner.

Over the years there have been quire a few image formats optimised for low colour count images proposed and utilised. You can perform a search over the competition forum and sub-forums to find them. These require custom code to read the image and that the image data is embedded within the class.

Normally data is embedded as an encoded string, however this year (using java 7) you might be able to use an embedded byte array of byte literals.



Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pjt33
« Reply #3 - Posted 2012-11-12 00:04:41 »

I don't know the right way to compress them and then read it in the code.
Various options.

1. Use a format which you can load with built-in libraries. JAI is probably the best bet here, so look at which formats it's guaranteed to support and test with those.
2. Use a custom format, render it to the back buffer of a BufferedImage, and use Graphics2D.renderImage. Probably quite expensive in terms of string pool, but very flexible. The data can be stored in a file or directly in code.
3. Use a custom format and render directly to the back buffer of your main BufferedImage each time round the render loop. This is my favoured option, but it limits your ability to do things like arbitrary rotations.
Offline Danny02
« Reply #4 - Posted 2012-11-12 01:31:25 »

gif images can be quite small, when used with colormaps, in comperrision with jpg
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #5 - Posted 2012-11-12 09:22:38 »

Normally data is embedded as an encoded string, however this year (using java 7) you might be able to use an embedded byte array of byte literals.

I'm used to store everything in a string (be carefull of the encoding process of UTF-8, ...). In fact, I use 1 big string to store graphics, maps and music. Same thing for variables, 1 big int array and 1 big double array to store every things.

Moogie can you develop a little more about Java 7 and the new possibilities to store data ?
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #6 - Posted 2012-11-12 12:23:30 »

hmm i though that there was now byte literals... my bad, i think i saw binary literals and though that it was byte literals Sad

1  
2  
3  
public class test1 {
   byte[] data = {0b1001,0b11111,0b1011};
}


I am not sure whether it is just syntatic sugar hiding the casts and so expensive... will have make some tests.
Online Riven
« League of Dukes »

JGO Overlord


Medals: 742
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2012-11-12 12:28:08 »

in bytecode that's:

1  
2  
3  
4  
5  
ALOAD (for byte[])
BIPUSH/SIPUSH/LDC (for index)
     (1,2,4 byte value)
BIPUSH (for byte)
     (1 byte value)
per byte. Hence the approach to make a string hold raw data.

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

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #8 - Posted 2012-11-12 12:32:17 »

just as i feared Sad ah well
Offline Damocles
« Reply #9 - Posted 2012-11-12 13:13:15 »

Also, dont forget:

putting effort to create "short looking code" (or bytecode, or encoded data in a bytestream) does not mean it packs well.

The compressor will works best with repetions.

example:

Quote
imtheking
imtheking
imtheking
imtheking
imtheking
imtheking
imtheking
imtheking
imtheking
imtheking
oftheworld
oftheworld
oftheworld
oftheworld
oftheworld
oftheworld
oftheworld
youknow
youknow
youknow
youknow
youknow
youknow

compresses way better than

Quote
imtheking
imtheking
imtheking
oftheworld
youknow
imtheking
imtheking
imtheking
imtheking
oftheworld
imtheking
youknow
imtheking
oftheworld
oftheworld
imtheking
oftheworld
youknow
oftheworld
oftheworld
youknow
youknow
oftheworld
youknow

although both contain the same raw data.
(just in different order)

What I mean is that repeating loops of data help the compressor.
So even longer code (bytecode) can compress better in the end.

->You will only know what works best AFTER running all your packing and compression steps.

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.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (65 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!