Any Java programmers here?

Discuss stuff not about Indigo.
User avatar
dougal2
Developer
Posts: 2532
Joined: Wed Nov 15, 2006 8:17 am
Location: South London

Post by dougal2 » Sat Jan 19, 2008 1:21 pm

OK, so I thought I'd better give a little update in my learning adventure: think I've grasped the basics. :D

So far I've written a program that reads IGI files... :shock: ;)
...though it doesn't do anything with the data yet.

User avatar
oodmb
Posts: 271
Joined: Thu Oct 26, 2006 5:39 am
Location: USA
Contact:

Post by oodmb » Sat Jan 19, 2008 2:09 pm

thats certainly odd... i see, it just seems to apply to the == operator though, the others work (the == operator seems to work that way for every primitive Object type) <= and >= still seem to work as expected though. this goes against everything my teacher just taught us about java.
a shiny monkey is a happy monkey

User avatar
eman7613
Posts: 597
Joined: Sat Sep 16, 2006 2:52 pm

Post by eman7613 » Sat Jan 19, 2008 5:41 pm

@oodmb (your name + dyslexia = hard to spell)
thats because he didnt teach you what those operators are doing! Since java dosent support overloading operators (the one thing i realy wish it did, but usualy inst a problem) all operators do the same thing. int stores a value, so it works fine. Integer and String store locations of data, not actual values, so your comparing arbitrary numbers. When you say String A = "bob", and then say A = "bob" + ""; you create a new string object with a new location, which is why my previous example creates a false "false". You also can run into bugs with >= and such with strings, instead you should use compareTo() method. (Java 1.5+ you can do Integer == or >= becasue of autoboxing though).

@dougal2
heh, reading is always the easier part ;p
hint: when reading files use a class called StringBuffer, otherwise you get a lot of overhead.
Yes i know, my spelling sucks

User avatar
dougal2
Developer
Posts: 2532
Joined: Wed Nov 15, 2006 8:17 am
Location: South London

Post by dougal2 » Sat Jan 19, 2008 11:33 pm

eman: I'm using ByteBuffer because of the necessary endian-ness conversion.

Code: Select all

data_in = DataInputStream( new FileInputStream ( myFile ) );
byte[] bArr = new byte[4];
data_in.readFully( bArr );
myInt = ByteBuffer.wrap ( bArr ).order ( ByteBuffer.LITTLE_ENDIAN ).getInt();

User avatar
dougal2
Developer
Posts: 2532
Joined: Wed Nov 15, 2006 8:17 am
Location: South London

Post by dougal2 » Mon Jan 21, 2008 1:25 am

first program output...

read in an IGI, scale it's float values, display it on screen and saved it to JPG.

Yes, I am in fact attempting to port Violet to Java :shock:
Attachments
room.jpg
room.jpg (110.12 KiB) Viewed 2826 times

User avatar
psor
1st Place Winner
Posts: 1295
Joined: Sun Jun 25, 2006 1:25 am
Location: Berlin
Contact:

Post by psor » Mon Jan 21, 2008 5:01 am

Cool! That's the sh*t Sir! :shock:

Is this a project just for fun, or do you have a specific goal?
Where do you wanna go with it? :D :D ;)



take care
psor
"The sleeper must awaken"

User avatar
dougal2
Developer
Posts: 2532
Joined: Wed Nov 15, 2006 8:17 am
Location: South London

Post by dougal2 » Mon Jan 21, 2008 5:11 am

My primary goal is to learn Java.

Second to that, I want to understand a bit better some of the algorithms used in tonemapping and filtering. (I already know a bit about 1-dimensional convolution theory from studying DSP, but have very little practical knowledge of how to apply this thoery - and no experience in doing 2D processing)

Violet seems like a useful launchpad to get me started, as all the c++ source is available, works and is fairly easy to read.

If I can get jViolet to a state where it does the same as the existing Violet, and test it on other platforms, perhaps it'll be useful too to the community here. Everyone wil have gained something :)

User avatar
psor
1st Place Winner
Posts: 1295
Joined: Sun Jun 25, 2006 1:25 am
Location: Berlin
Contact:

Post by psor » Mon Jan 21, 2008 5:24 am

That's sounds pretty good to me! Then no porting to linux, macos
would be needed and everybody would be happy! 8) :D :wink:

Thank you in advance for this effort! ;o))



take care
psor
"The sleeper must awaken"

User avatar
dougal2
Developer
Posts: 2532
Joined: Wed Nov 15, 2006 8:17 am
Location: South London

Post by dougal2 » Mon Jan 21, 2008 8:21 am

OK, so today I have managed to implement (erm, copy from c++ ;) ) XYZ->RGB conversion with whitepoint settings, Linear tonemapping (buggy) and Reinhard tonemapping.

There's something wrong with my Lienar tonemapping though because my image is brighter than it should be.
Attachments
jV - linear(-0.5, 1.2).png
jViolet Linear tonemapping
jV - linear(-0.5, 1.2).png (509.09 KiB) Viewed 2792 times
cV - reinh(-1.0,1.0,4.5).png
C++ Violet Reinhard tonemapping
cV - reinh(-1.0,1.0,4.5).png (412.9 KiB) Viewed 2792 times
jV - reinh(-1.0,1.0,4.5).png
jViolet Reinhard tonemapping
jV - reinh(-1.0,1.0,4.5).png (545.17 KiB) Viewed 2792 times
cV - linear(-0.5, 1.2).png
C++ Violet, Linear tonemapping
cV - linear(-0.5, 1.2).png (338.27 KiB) Viewed 2793 times

User avatar
eman7613
Posts: 597
Joined: Sat Sep 16, 2006 2:52 pm

Post by eman7613 » Mon Jan 21, 2008 9:22 am

dougal2 wrote:Yes, I am in fact attempting to port Violet to Java :shock:
cool, you have a UI yet or just terminal?
Yes i know, my spelling sucks

User avatar
dougal2
Developer
Posts: 2532
Joined: Wed Nov 15, 2006 8:17 am
Location: South London

Post by dougal2 » Mon Jan 21, 2008 10:05 am

I have a UI that shows the image in a scrollPanel, and a single button to fire off my methods.

All the controls for the linear and reinhard could be built to make those functions useable. Figuring out file choosers would then make the app useable.

The basic gaussian/median etc filtering should be fairly straightforward... the diffraction limited bloom stuff I'm not sure about yet, as I don't really know how it works.

IanT
Posts: 153
Joined: Fri Aug 25, 2006 3:13 am

Post by IanT » Tue Jan 22, 2008 10:25 am

Cool project idea Dougal :)

Most of the advice you've been given is great. Watch out for the String == thing... the reason that...

Code: Select all

foo = "hello";
foo2 = "hello";
if (foo == foo2) System.out.println("foo and foo2 are equal");
... works is because the Java compiler recognises the string literals are the same and re-uses the same object again. Use string1.equals(string2) to be sure. Be aware that Strings use TONS of memory (24 bytes before you even put anything in it) so think about using char[] instead where you can.

I'd advise buying a book on Java... seems like a silly outlay but they're usually a good thing to read for 30 mins before beddy-byes every night and quicker than Google for reference purposes most of the time.

For what you're doing, it's not so much of a consideration but, in general, Java memory usage sucks so beware of creating objects all the time, especially if you care about performance. Modern JVMs do a cracking job of escape analysis (determining that an object is only used within a single method call and binning it immediately, saving the garbage collector loads of time) but still... if you can re-use objects, do it. Many Java evangelists claim that the garbage collector is soooo good, but in some cases, it's a pain.

On this note... Java 1.5+ does auto-boxing for you (converting Integer to int) but that will result in object creation. Try to stick to primitives where possible. If you want a list of ints and are forced to use Integer in the Collections classes, try writing your own version that uses the primitive.

If you think of a useful class and find yourself thinking "hey, that's a cool, generic utility type thing" then check to see if it already exists in the standard libraries. You'll be surprised how much is in there and how easy it can make your job (but DO check the library's source code to make sure it's not a performance hog... if it is, subclass it).

Use static inner classes for simple, class-local things... it'll avoid code clutter. Be aware that non-static inner classes use more memory than static ones.

Avoid synchronization unless you know for a fact you need it. It's amazing how much can be achieved through use of the members of the
java.util.concurrent package (e.g. AtomicInteger), especially for keeping counters that are accessed by multiple threads.

Learn how to hand-code Swing... it's the best thing about Java :wink:

Reflection is also one of the best things about Java. It's worth learning and isn't as slow (for most things) as many people say.

Get your code working before optimising too much. I know this is a general saying for most languages but the JVM is soooo clever nowadays that sometimes premature optimisation makes your programs run slower rather than faster.

Always, always use the -server option when running java.exe. It can double performance for maths-intensive apps, sometimes more. Recent JVMs detect whether your box has 2Gb+ and 2+ cores and will use -server automatically but bung it on the command line just to be sure. I've found BEA JRockit is the fastest JVM for maths-heavy stuff but it might very well be architecture/configuration dependent.

That was all just a brain dump... there will be loads more, and better qualified wisdom in books on the subject :wink:

I personally use Netbeans for my IDE. It's come on a lot since v4.0 but it's very much a preference thing. In particular, the profiler is bloody excellent for finding memory leaks and sussing out performance bottlenecks. Eclipse is also mighty fine.

Ian.

User avatar
dougal2
Developer
Posts: 2532
Joined: Wed Nov 15, 2006 8:17 am
Location: South London

Post by dougal2 » Tue Jan 22, 2008 10:33 am

Thanks Ian, some nice tips there.

I've also found the profiler in netbeans to provide some useful info - I'll be working on how to optimise certain routines at some point, but as you say getting it working first is always a good idea :)

BTW, I've started a thread in the Development forum to keep track of my progress on this project.

Post Reply
28 posts

Who is online

Users browsing this forum: No registered users and 33 guests