Jpeg 2k support in blitzmax?

BlitzMax Forums/BlitzMax Programming/Jpeg 2k support in blitzmax?

Robert Cummings(Posted 2006) [#1]
Anyone know if support for jpeg 2k is coming as it is very much superior to standard jpeg, ideal for games actually.

Even supports alpha channels and lossless modes.


TartanTangerine (was Indiepath)(Posted 2006) [#2]
That would be interesting to see if Mark would include it as an official module.

I do have c++ code for encoding and decoding JPG2000, the decoding stuff would be pretty simple to integrate into BMax. I'm not going to implement it though, not if it's going to be added by BRL at a later date.


Robert Cummings(Posted 2006) [#3]
Interestingly, the popcap framework supports it. It seems an ideal solution for online distributed games.


N(Posted 2006) [#4]
Gonna have to look this up now.


ImaginaryHuman(Posted 2006) [#5]
I believe you have to pay like $20,000 for a licence ?


TartanTangerine (was Indiepath)(Posted 2006) [#6]
Well the license I've got says that I can do anything I want with it.


xlsior(Posted 2006) [#7]
It looks that like GIF and JPG before it, JPG2000 also has some company contesting it violates one of its patents... No final ruling yet, though.


Dreamora(Posted 2006) [#8]
GIF patent has passed, while JPG patent is still active thought ... (just no one payed the JPG "inventors" as they promoted it too long for free to make it acceptable to just change that after 10 years or even more)


xlsior(Posted 2006) [#9]
(just no one payed the JPG "inventors" as they promoted it too long for free to make it acceptable to just change that after 10 years or even more)


Actually, the patent in question is NOT held by the JPG inventors -- it's a 3rd party who had a seeminly unrelated patent that could be argues applied to part of the algorithm, if you hold it 'just right' and look at it from the corner of your eyes.

The JPEG file format was created by the JPEG group (Joint Photographic Experts Group), which the intention of being a file format specifically aimed at photographic images, better than alternative formats at the time. It was intended to be completely free. It wasn't until much later that another company laid claim to some of the underwater work.


Vectrex(Posted 2006) [#10]
it has the exact same issues as normal jpeg, ie it's absolutely nothing to worry about. ALL technologies can be contested by sleeper companies with obscure patents. It's way nicer than normal jpg and perfect for smaller online games.


TartanTangerine (was Indiepath)(Posted 2006) [#11]
Someone should implement this : http://www.openjpeg.org/


skidracer(Posted 2006) [#12]
I'm evaluating jasper today which is the only C reference implementation listed here:

http://www.jpeg.org/jpeg2000/j2kpart5.html


ImaginaryHuman(Posted 2006) [#13]
I only say there was a fee because in Graphic Converter on the Mac they implemented JPEG2000 and said they had to pay $20,000 for a lincence. Maybe it's a commercial license?


taumel(Posted 2006) [#14]
Hmm the tests i did once showed that it strongly depends on the material you're having.
While having less artifacts then jpg, it blurs a lot more.
Depends a lot on the picture and the compression level...for instance:


http://www.marune.de/taumel/test/max/_tmp/fral.jp2


Greetings,

taumel


Robert Cummings(Posted 2006) [#15]
It's undeniably better on every level. Gone are the 8x8 compression artifacts.

Don't forget it also allows alpha channel information to be embedded.


taumel(Posted 2006) [#16]
Having a alpha channel and a no lossy mode is a plus but from the picture quality it's not just better. It simply depends on the situation - look at the pictures i've posted...

To get the bmp (source) just use this link: http://www.marune.de/taumel/test/_max/tmp/fral.zip

Artifacts are reduced but please welcome sludgy areas.


Robert Cummings(Posted 2006) [#17]
I don't think I will get sludgy areas :) Thats only with extreme settings.

Even lossless, it is smaller than the smallest comparable PNG. That is very good news.
This is so utterely perfect for online-distributable games.

http://www.fnordware.com/j2k/jp2samples.html

See for yourself. Both 16k and the j2k version is noticably LESS sludgy :)

You can also get the j2k photoshop plugin from there.


taumel(Posted 2006) [#18]
Well, i made those pictures with a photoshop-plugin and if you are able to look at them then you will see that they show the effect i described. But maybe you don't see it as you can't watch jp2/j2k files?

Anyway also if you google around you will find enough picture comparisons where these effects are shown and discussed.

To say that jp2 is the cure for online games is total nonsense as most of the online games are flash games which use vector formats gfx out of the box and if you're talking about the second biggest platform shockwave than also here flash graphics are included (on the fly converted to textures if neede for 3d) or the most common img-fileformat jpg is used. And if using shockwave compression on pictures all so defined pictures are compressed to jpg no matter what they were before. Music is by far a much greater memory eater here as there only exists one mod-tracker xtra which has to be bought seperately and also downloaded beside of the plugin. Here you could spare much more memory.


Robert Cummings(Posted 2006) [#19]
I suggest you discuss that with successful people distributing shareware games for a living before telling me it's total nonsense. Furthermore can you tell me your contribution to this thread?

All you have done is put j2k down and put forwards reasons why you think it's no good.

How about trolling elsewhere?


taumel(Posted 2006) [#20]
I'm not trolling. jp2 just isn't the holy grail for everthing. It's good for this and bad for that, nothing more nothing less. If it's implemented into bmax hey that's good to hear but out of this there won't be a new age of online games...

As for professionlism i do earn my living a.o. with online games...


TartanTangerine (was Indiepath)(Posted 2006) [#21]
@Skid, I have the Jasper Implementation but it's supposed to be really slow compared to the one I posted. I also have the "C" code for OpenJPG and it works on Mac, Linux and OSX. You can get the source from thier site.


xlsior(Posted 2006) [#22]
I'm not trolling. jp2 just isn't the holy grail for everthing. It's good for this and bad for that, nothing more nothing less. If it's implemented into bmax hey that's good to hear but out of this there won't be a new age of online games...


Agreed.

The more image formats readily supported the better of course -- but individual circumstances will always dictate what the best format to use will be.

But since sometimes every byte counts, new options are always appreciated.


taumel(Posted 2006) [#23]
Also agreed.

Do you know what a real revolution would be regarding gfx/sfx-size in online-content?

If there would be editors+mods+plugin for some modular generative concepts like there are in werkkzeug ( http://www.theprodukkt.com/werkkzeug1.html ) or will be in spore. Just take a look at kkrieger ( http://www.theprodukkt.com/kkrieger.html ). I think you won't be able providing such a game experience with only adding jp2 while staying below 100kb.


Greetings,

taumel


Robert Cummings(Posted 2006) [#24]
all you're doing is kissing up to yourselves: you're not CONTRIBUTING.


TartanTangerine (was Indiepath)(Posted 2006) [#25]
@Skid, Do you intend on integrating this? It would certainly be a big USP!


taumel(Posted 2006) [#26]
@One Eyed Jack:

Still whining?


anawiki(Posted 2006) [#27]
I vote for JPEG2000 support. It's so much more important than 3d mod ;-)

Because of alfa channel I stucked with png format and my game is much bigger that I want it to be (17mb already).


bradford6(Posted 2006) [#28]
PNG


ImaginaryHuman(Posted 2006) [#29]
Did you compress your PNG's with maximum compression?


xlsior(Posted 2006) [#30]
AngelDaniel: I wasn't aware PNG's even had variable compression, given that it's lossless (unlike JPG, where you can adjust the quality/filesize)


taxlerendiosk(Posted 2006) [#31]
It does indeed have variable compression (intended for filesize/decoding time tradeoff I suppose) which goes I think from 1 to 9. I know how to set the level with GIMP, not sure about any other programs.


TartanTangerine (was Indiepath)(Posted 2006) [#32]
Not like JPEG2000!

'cmon Skid! An official mod? or a chargeable user mod?


anawiki(Posted 2006) [#33]
Just made a test:
PNG: 597 552
JP2: 597 893 (lossless)
JP2: 123 023 (75 compression factor)

And quality loss between lossless and 75 is marely noticable.

I vote again for official mode. I can even pay for it few bucks (that I will for sure save on bandwidth).

So when its ready? ;-)


Robert Cummings(Posted 2006) [#34]
I have similar results with lossless jpeg actually coming in less than the png. (png suitably crushed) - It depends on the image used. This means it will be pretty fantastic with a little lossy compression...

Drooling over the alpha lossy compressed j2k possibilities :)


anawiki(Posted 2006) [#35]
I don't mean to be offensive ;-) Just want to ask if anyone is working on implementation of JPEG2000?


skidracer(Posted 2006) [#36]
Unless someone can confirm OpenJpeg library works with 32 bit format (documents indicate only 8 and 24 bit) I'll be continuing work on a jasper based jpeg2k imageloader module.


anawiki(Posted 2006) [#37]
Well, docs indicate:

JPEG 2000 encoder
Required arguments
Infile (format pnm, pgm, ppm, pgx or bmp): -i Infile.pgm

And on those sites they say that PNM is PPM + PAM.
http://netpbm.sourceforge.net/doc/pnm.html
http://netpbm.sourceforge.net/doc/pam.html

From PAMS description:

"Transparent

Each of the visual image formats mentioned above has a variation that contains transparency information. In that variation, the tuple type has "_ALPHA" added to it (e.g. "RGB_ALPHA") and one more plane. The highest numbered plane is the opacity plane (sometimes called an alpha plane or transparency plane).

In this kind of image, the color represented by a pixel is actually a combination of an explcitly specified foreground color and a background color to be identified later."

Hope that helps.


anawiki(Posted 2006) [#38]
And just in case, documents indicate 8 or 24 bit for BMP format.


anawiki(Posted 2006) [#39]
Again I don't want to be offensive ;-) Are you working on this Skid?


anawiki(Posted 2006) [#40]
Any news on JPEG2000 support? I had talked to codeminion guys (www.codeminion.com) and it took them only 3 days to implement jp2k support based on jasper implementation.

Thanks for any informations.


skidracer(Posted 2006) [#41]
I've been stuck in bug reports for too long, will dig out and upload work in progress tomorrow.


anawiki(Posted 2006) [#42]
Great news. Thanks for the info.


skidracer(Posted 2006) [#43]
windows users try:

syncmods -u username -p password axe.jasper

you may need to rebuild the module, there is an example with image you can test in mod/axe.mod/jasper.mod/testjasper.bmx that looks something like this:
' testjasper.bmx

Import axe.jasper

Graphics 1024,768
pic=LoadJpeg2000("fral.jp2")
Cls
DrawImage pic,0,0
Flip
WaitKey
End


Warning, it's very work in progress, won't handle incbin files, uses the file "temp.bmp" as an intermediate so only 3 channel (no alpha) jpeg 2000 files are supported. Once the decoding is streamed directly to pixmap will have alpha channel support and I would also expect some improvement in speed also.


Yan(Posted 2006) [#44]
Nice one!

The example works well here. :o)


xlsior(Posted 2006) [#45]
Free jpeg2000 importer/exporter for Photoshop: http://www.fnordware.com/j2k/


anawiki(Posted 2006) [#46]
Works for me as well :) Speed improvement is not so necessary, we may decompres jp2 to png during instalation ;-) (that's what codeminion guys do).


LosButcher(Posted 2006) [#47]
Works great, Skidracer, although the loadtime is a bit long. 1200 millisecs for me, vs normal JPG 80 millisecs.


anawiki(Posted 2006) [#48]
That migth be fault of jasper library (it is very slow and not as efficient as commercial libs).


LosButcher(Posted 2006) [#49]
Oh ok... But doesent it have any benifits, compared to PNG, except using less discspace?


ozak(Posted 2006) [#50]
Nope. Use PNG damnit. It's definately a superior format with good compression and support for many bitdepths and alpha channel :)


anawiki(Posted 2006) [#51]
What benefits would you expect? Using less disc space is very important in downloadable games. It will allow me to add 2 more minigames to Tom's Hen House within the same download size (or smaller) :)


Dreamora(Posted 2006) [#52]
the benefits of being able to use masking on image which is not possible when you leave loseless.


xlsior(Posted 2006) [#53]
the benefits of being able to use masking on image which is not possible when you leave loseless.


True, but you can still mix & match: PNG with masking for your sprites, and JPG/JPG2000 for your background images.


Robert Cummings(Posted 2006) [#54]
jpg2000 supports masking


anawiki(Posted 2006) [#55]
How stable is jpeg2k mod at the moment? I am planning to use it in my very soon coming release. When we can expect alpha channel support? (not offensive question).


Robert Cummings(Posted 2006) [#56]

Warning, it's very work in progress, won't handle incbin files, uses the file "temp.bmp" as an intermediate so only 3 channel (no alpha) jpeg 2000 files are supported. Once the decoding is streamed directly to pixmap will have alpha channel support and I would also expect some improvement in speed also.


I would use it for non-critical testing right now :)

BTW, fab work skid, nice one!


skidracer(Posted 2006) [#57]
Here's latest version which supports reading from any BlitzMax TStream including incbin:: paths and decodes directly to PixMap which in release mode seems to be so so for speed.

If someone can post a 32 bit jp2 file I can test with I'll get that sorted and then turn it into a standard image loader.

overwrite jasper.bmx in axe.mod/jasper.mod with following:



Robert Cummings(Posted 2006) [#58]
http://www.redflame.net/files/mona.zip

4 images of the mona lisa zipped:

one with alpha channel information
one with 4 bit colour depth, and 64x64 tile size
one lossless but half the size
one compressed 'standard'


skidracer(Posted 2006) [#59]
Thanks Rob.


xlsior(Posted 2006) [#60]
.


anawiki(Posted 2006) [#61]
MonaLisa files are corrupted (I can't open them with normal image processing software that supports jp2).

My test image with alpha (512x512x32)
www.anawiki.com/download/alpha.jp2
www.anawiki.com/download/alpha.png

Alpha channel doesn't work and colors are corrupted.

Well, images without alpha channel are corrupted too (colors looks like they misplaced RGB).


xlsior(Posted 2006) [#62]
MonaLisa files are corrupted (I can't open them with normal image processing software that supports jp2).


I was able to open those Mona Lisa pics just fine in Photoshop with Fnordware's free JPG2000 plugin... http://www.fnordware.com/j2k/

Very weird though: I got the plugin to work and show me the fractal image. Then I changed the source to point to one of the mona lisa jp2's, but launching it kept showing me the fractal instead??

Made sure that I hadn't locked the code, and no quick build enabled. Weird.

(It does seem a bit unfortunate that the loader seems sluggish -- the same JP2 images load many times faster in photoshop than in blitzmax with the jasper plugin)


anawiki(Posted 2006) [#63]
Made another test. Alpha doesnt work and image is probably RBG istead of RGB.


Robert Cummings(Posted 2006) [#64]
MonaLisa files are corrupted (I can't open them with normal image processing software that supports jp2).


That might actually be a problem your image processing program. I can't see a fault with fnordware + photoshop.

The speed also seems a bit worrying using Jasper - I wonder if it can be optimised?


anawiki(Posted 2006) [#65]
I used PaintShopPro9 to open MonaLisa and to create my jp2 files.

Mona Lisa loads in BMX, but it has blue colors and as I see it in image viewer it is supposed to be in grey scale?


xlsior(Posted 2006) [#66]
They show up in full-color in Photoshop to me...


anawiki(Posted 2006) [#67]
What about BMX? Do MonaLisa or my test image show up in full color?


skidracer(Posted 2006) [#68]
OK, new version should now support 4 channel jp2 files and 4 bit channels (yuck).

Please apply the following patch to libjasper/jpc/jpc_dec.c so code starting at line 1072 looks like this:
	/* Apply an inverse intercomponent transform if necessary. */
	switch (tile->cp->mctid) {
	case JPC_MCT_RCT:
		assert(dec->numcomps >= 3);
		jpc_irct(tile->tcomps[0].data, tile->tcomps[1].data,
		  tile->tcomps[2].data);
		break;
	case JPC_MCT_ICT:
		assert(dec->numcomps >= 3);
		jpc_iict(tile->tcomps[0].data, tile->tcomps[1].data,
		  tile->tcomps[2].data);
		break;
	}

and replace jasper.bmx with the following:



Robert Cummings(Posted 2006) [#69]
Hi Skid, Emailed you regarding a patch which will boost the speed of jasper.


anawiki(Posted 2006) [#70]
OK, Mona Lisa looks great. Colors and alpha are fine.

But what the hell is wrong with my image? Colors are fine, but there is no alpha. And it doesn't matter if I create jp2 (from PNG with alpha) with Photoshop or PaintShopPro. In both programs I can see alpha channel, but not in BMX.

???


skidracer(Posted 2006) [#71]
Roman, not sure, it is definitely coming in as a 3 channel jp2, perhaps the extension is wrong and it's one of the more complex jpeg2000 file types with channels in alternative layers or something.

Rob, is it possible to create jp2 in alternative color space, cmyk etc?

I would also like some single channel test pics, alpha channel only and greyscale (intensity) if it's possible.


Robert Cummings(Posted 2006) [#72]
Skid: www.redflame.net/files/jp2.zip

mixture of stuff. One of the mono ones will probably have alpha... I think I stuffed the second. Some other assorted bit depth images too.

Let me know when you have them and if you need more.

cymk? I don't know. I think it is converted to rgb?


anawiki(Posted 2006) [#73]
Can anyone give me some clues on how to create jp2 with alpha channel that can be read by BMX? Every test image that I or my friends made doesn't work. The only image that works is mona_alpha.jp2 :(


Robert Cummings(Posted 2006) [#74]
When you create the image in your package, create it as if you were doing a png with alpha. If this fails for you then it is the fault of the exporter you are using.


anawiki(Posted 2006) [#75]
But we are using fnordware exporter for Photoshop :D and I don't see any options in this exporter to turn on or off alpha channel.


Robert Cummings(Posted 2006) [#76]
The alpha channel is supported by the exporter if it exists.

The correct way to do alpha in photoshop is to use layers - the checker pattern is your alpha channel information. The exporter will export it properly.


anawiki(Posted 2006) [#77]
Would you mind posting a link to example PSD file with properly prepared alpha channel? I am not a PSD expert and I believe we do it correctly, but still without success :(


Robert Cummings(Posted 2006) [#78]
1) create a new psd file

2) make sure there are two layers in the file

3) the bottom layer lower down in the layers palette should be empty (checker pattern).

4) any layers above this contain your graphics

Try loading your jpeg2k files back into photoshop. You might be doing it right and this module might be doing it wrong.


Robert Cummings(Posted 2006) [#79]
Ok download this:

www.redflame.net/files/psdj2k.zip

It contains one psd file and one j2k file saved with 80% quality using nothing but default panel on fnordware. No advanced options were used at all.


anawiki(Posted 2006) [#80]
Thanks for help.

It's odd for me, but no matter how we create jp2 file it is properly read and viewed by Photoshop or PaintShopPro, but not in BMX.

Here is my PSD and JP2 files:
www.anawiki.com/download/alpha.zip

It would be great if this module could read transparency info from files that I can manage to create ;-) ie.PaintShopPro files.


Robert Cummings(Posted 2006) [#81]
Perhaps simon hasn't finished it yet.


anawiki(Posted 2006) [#82]
Totaly depresed I loaded your PSD file and exported it to jp2 and guess what? Alpha aint work :(

What version of PSD do you have? What fnordware plugin version do you use?


Robert Cummings(Posted 2006) [#83]
The beta fnordware j2k plugin. Perhaps that is your problem.


anawiki(Posted 2006) [#84]
What are those numbers that mod print out to conslole?
Can we expect any improvemts in the nearest future?

PS. After installing beta j2k plugin my problems with alpha are gone :)


skidracer(Posted 2006) [#85]
That's good to hear anawiki, and yes, new version soon...


Jay Kyburz(Posted 2006) [#86]
ok.. now how about dtx compressed textures :)