Author Topic: Good, fast, stable support for JPEG files in LOADSPRITE etc.  (Read 10014 times)

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
To quote the online manual:

Quote
LOADSPRITE bmp$, num%


Loads the graphic file (bmp or png) into memory for using it with DRAWSPRITE commands later on. Every loaded sprite needs a unique ID number (num%) which allows you to access the sprite. If an ID is reused, the image in memory for that ID will be replaced by the new image.

Now I've read apparent comments that JPEG support had been added, but that it tended to cuase problems - I really want to be able to use JPEGs. Please?
« Last Edit: 2010-Sep-15 by Cliff3D »

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4149
  • On the shoulders of giants.
    • View Profile
    • My Apps
Don't we all (well some of us). :(
I came. I saw. I played.

Offline doimus

  • Dr. Type
  • ****
  • Posts: 284
    • View Profile
There are some advantages to JPG. For example, in casual Hidden Object games that have lots of full screen backgrounds, huge "sprites" etc. it's sensible to use JPG. In fact almost all casual frameworks support it.
Sometimes is acceptable to have slightly lossy images but with the benefit of much smaller game download. JPG at 95% quality is still way smaller than PNG, without apparent degradation in quality.

Also, textures for 3d models mostly don't have to be losless, due to the way they're displayed on screen.

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
Also, in my instance many 3D models in .OBJ format have .jpg textures. If I supply a program to someone I doubt they will want to convert all their textures to .png and fix the references to go to the .pngs before using whatever I could write to use them :(

I'm surpriseed no-one has written a user function to read JPEGS - is the file format not available, or really convoluted?

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
Can "we", as a user group, find the jpeg spec and write a reader (as I'm currently attempting with .OBJ files)? I don't know how into "group helping and sharing" we are here, yet. I'll learn!

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10720
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
You can try to load jpeg on Win32. On most platforms it works - iPhone does for sure _not_.
I am aware of that bug, but so far I can't get it fixed as it's a different library I have to use.

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
Cool - I'll try it on Win32 a bit later. Personally I don't need iPhone support yet but was nervous about jpeg as it doesn't seem to be documented and the forum posts I found seemed to suggest it was, ah, flakey?

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4149
  • On the shoulders of giants.
    • View Profile
    • My Apps
JPEG doesn't work properly EVEN on Windows, I'm afraid.

It might load one or more images once, but try to use them more than once and/or other images and it all fecks up.

I brought this up ages ago, as I was working on a Top Trumps game and wanted the card images to use JPEG. It seems fine at first, but goes awry very quickly when JPEGs are loaded and displayed.
I came. I saw. I played.

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
:( thanks Ian, I had a horrible feeling that's what I'd found - so jpeg support is back on my list of things to consider trying to write. Ah well! :|

MrTAToad

  • Guest
As it causes immense problems, I dont see it being in for quite a while.

At the moment you can only use it with one file - any further use (especially to the same id number) will crash your program...

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
I must admit, I had hoped that someone would ahve taken a similar approach to my initial thoughts on the .obj file format - and started tackling the .jpeg file format in GLBasic from first principles. Possibly even converting from C source code freely avaiable at site slike:

http://www.ijg.org/
or
http://www.faqs.org/faqs/jpeg-faq/part1/index.html

(links very quickly obtained via google).

I have slightly fond memories of using a version of FORTH which had been written and compiled in an earlier version of FORTH, and have wondered whether producing our own 2libraries" might be something the community was "up for" on a collective basis - there certainly seem to be some code snippets along those lines. Maybe those who post their code thend not to be those interested in 3D or different graphic formats?

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1781
    • View Profile
    • Homepage
The ability to load raw image data to a sprite has only been available for a few days, hold your horses :-)

MrTAToad

  • Guest
Apparently Gernot is using the jpeg code from http://www.ijg.org/ - but its being a problem...

Offline Cliff3D

  • Dr. Type
  • ****
  • Posts: 268
    • View Profile
I can wait a bit. Even without days like today when my head's splitting too much to code, I've got a fair few bits and pieces to put together and test out. Plenty of refining before I NEED good .jpeg support - though I fear I have lost sight of the prudence I intended to have when approaching GLB to eval :(

Offline phaelax

  • Mc. Print
  • *
  • Posts: 36
    • View Profile
Quote
JPG at 95% quality is still way smaller than PNG, without apparent degradation in quality.

I must be the only one who prefers PNGs because they almost always seem to be smaller than JPGs with better quality. That's why I typically only use PNGs for web design.  After a certain size a JPG might be smaller, but for mostly what I've done PNG has been smaller.