Porting Violet to Java

A forum for exporter development discussion.
Post Reply
137 posts
User avatar
dougal2
Developer
Posts: 2532
Joined: Wed Nov 15, 2006 8:17 am
Location: South London

Porting Violet to Java

Post by dougal2 » Tue Jan 22, 2008 5:46 am

As I've mentioned in the Off Topic forum, this is what I am doing, mainy as an exercise to teach myself Java.

I might as well bring this topic "On Topic" here in the right place.

So far I have IGI loading, basic tonemapping, and image saving (jpg, png or other that the ImageIO class supports - no IGI output yet) functions working fine.

I feel that I will be able to get somw of the basic filtering (gaussian, median etc) working fine, possibly within the next few days - after that I may need help (diffraction limited bloom is beyond my comprehension at present).

Are any of the Java people here interested in contributing to this project? I don't mind if you don't, but I might learn something if other people look at/change/expand on my code.

Particularly there is also work to do with making the app properly threaded - I have implemented the main processing in a thread (as far as I can tell) but I don't relly know if I'm doing it right.
There are also issues I have with being able to update the GUI with processing progress. I've no idea how.

Anyway, I'm willing to share the code (open source, as per the original Violet) and will take on board advice, suggestions and help :)

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

Post by eman7613 » Tue Jan 22, 2008 4:21 pm

idd be glad to have fun & contribute to this project.

threads - nasty little buggers to get ahold of.

1.) All GUI related activity occurs on the Event Dispatch Thread (EDT), and since swing is "light weight" all comonent drawing and stuff happens there.

The way i like to do this, there are other ways, is to create a private class that looks something like this.

Code: Select all

private class DoCrap implements Runnable
{
	public DoCrap()
	{
	}

	public void run()
	{
		for(int x=0; x<SOME_NUM; x++)
		{
			/** length code, can be a method from other class **/
			SwingUtilities.invokeLater(new Runnable() 
			{
		                public void run()
		                {
	                    		progressBar.setValue(NUM);
		                }
			});
		}
	}
}

"But eman, you scallion, what is that doing?" Well, all threads in java implement runable which has one thing you NEED to define, run(). inside the run method, we do what we want, and have access to all the methods and variables since we are a private internal class (or whatever the "proper" wording is). So, we do our work, and then when we finish an increment of work, we want to let the user know.

SwingUtilities.invokeLater() will take any Runnable object and launch its run() method, BUT it does this on the EDT at the next convinent time. I simple chose to define my new Runnable object inside the call to it. This way, the GUI related task is done were it should be & the user will see it update without freezing the current thread or GUI. Additional, this WONT que up hundreds of new run events, it will only launch the most recent one, so if we have called invokeLater() 7 times before the EDT gets a turn, only the most recent call will be processed, saving overhead and redundant method calls.

You will want to declare the jproggres bar synchronized so that two threads can access the object simultaneously, and you will have to define the range of the progress bar before you try to set its progress (setMaximum(int maxValue). So, lets say were about to do something, it would be done like so

Code: Select all

/** show dialog with focus & jProggresbar **/
setStuffUp();
disableButtons(); //we don't want them clicking while we are busy!
new Thread(new DoCrap()).start();
You COULD save the thread object and declare it inside the scope of the entire program to save a smidgion of overhead, but it wont make a difference since its a few milliseconds compared to a multi second task. and its more OOP to keep things in a proper scope :roll:

There are other ways, many people are a fan of the SwingWorker class (comes with the JRE in 1.6+, packported completly to 1.5, can be used in 1.4 w/o generics dl: https://swingworker.dev.java.net/). But my way is just a personal preffrence, that i feel teaches you a littble bit more of what exactly is going on if you look up the class docs (i tried to sum it up in a short, conceptual bite... okay maybe a few bites).
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 » Tue Jan 22, 2008 10:58 pm

Hi eman, thanks for that. I've sent you a PM with details of the SVN repository where I'm keeping the code.

If you work on the code, please post back here so that I can see that there are changes ;)

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

Post by dougal2 » Wed Jan 23, 2008 12:39 pm

OK, changes this evening include me looking over the threading code to change from single- to multi-threaded operation.

The processing does now indeed work with many threads in parallel, but i've managed to break the tonemapping in the process.

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

Post by eman7613 » Wed Jan 23, 2008 4:34 pm

Im still trying to get teh SVN conection to your server to play nice >.> (downloaded the tarball but it wouldent compile in NB) are you using NB 6.0 or 5.5?
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 » Wed Jan 23, 2008 11:32 pm

I think I forgot to include a build file first time round. I should have added it last night when i comitted those changes.

I'm using netbeans 6.0 - however I think there may be a problem somewhere because the compiled JAR that i've made so far has only worked on windows systems, and my Mac (also using netbeans 6.0) won't compile either?

I don't know what the problem is really. Could it be a jdk/jre version issue? I'm using jdk 5 on the machine that works as I need support for Generics (I implemented a generic Array2d class).

You should have all the correct .java sources anyway.

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

Post by dougal2 » Thu Jan 24, 2008 2:47 am

Further update:
Mac won't compile or run due to lack of JDK 1.6 for OSX/PowerPC as far as I can tell.

I've re-built the project files and comitted them, the SVN should contain a working netbeans 6.0 project for windows.

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

Post by eman7613 » Thu Jan 24, 2008 9:18 am

i kee getting this error
(domain & dir blocked out with ##### by me)

Code: Select all

org.tigris.subversion.svnclientadapter.commandline.CmdLineException: svn: PROPFIND request failed on '/#####'
svn: PROPFIND of '/#####': 405 Method Not Allowed (https://#######)


This could have the following meaning(s):
- the folder specified in the repository URL does not exist on the host
- your proxy does not allow the svn command you have invoked
ill try again from a diffrent computer when i get back home.

Ya, OSX dosent have a realse JDk6 yet, but you can go download the development snapshot and it should work.
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 » Thu Jan 24, 2008 9:38 am

Hmm that's odd, and I must admit I don't really know what that error means or how to fix it.
Can you check the URL I gave you? It is case sensitive, the project location is https://[domain]/svn-jViolet

Do you have a link to the dev snapshot of the jdk for osx? I've looked around several sites today and nothing offered seemed convincing enough to try downloading and installing.

It shouldn't need JDK6 though. JDK5 should work, do you know if that exists?

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

Post by psor » Thu Jan 24, 2008 9:43 am

@dougal2

Maybe this is what you're searching for?! ;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 » Thu Jan 24, 2008 9:52 am

hmm OK. i'll give it a go.

EDIT: no, hang on, thats for intel and AMD64 processors only. it won't run on my old(er) PowerPC Powerbook G4.

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

Post by psor » Thu Jan 24, 2008 10:12 am

What a pity ... *grmpf*
"The sleeper must awaken"

User avatar
ViennaLinux
Posts: 191
Joined: Thu Jul 26, 2007 9:26 am
Location: Vienna/Austria
Contact:

Post by ViennaLinux » Thu Jan 24, 2008 11:29 am

what for do you need java 6?
java 5 should be enough - I never needed anything form 1.6 but its faster - the java vm i mean.

I'm not good in threading and swing but I can code quite well java and i like oop so if you need some help - I will be here too ;-)

porting violet to java is a great idea because then it will rock on every platform you know :twisted:

keep me informed about the progress and the obstacles.
Core2duo e6600 @ 3.1GHz watercooled at default VCore ^^

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

Post by dougal2 » Thu Jan 24, 2008 11:46 am

there's no JDK 5 either :(

BTW, I'n kinda confused over the version numbers - is 5 the same as 1.5 ? and 6 the same as 1.6 ? WTF?

User avatar
ViennaLinux
Posts: 191
Joined: Thu Jul 26, 2007 9:26 am
Location: Vienna/Austria
Contact:

Post by ViennaLinux » Thu Jan 24, 2008 11:56 am

yes dougal 1.5 is the same as 5 and 1.6 is the same like 6.

Dont know why they are doing this.
and mac os x tiger has java 1.5 - if you dont have it do a system update? or what are you missing exactly?
Core2duo e6600 @ 3.1GHz watercooled at default VCore ^^

Post Reply
137 posts

Who is online

Users browsing this forum: No registered users and 13 guests