Jump to content

JPEG vs PNG vs TGA


You are about to reply to a thread that has been inactive for 1937 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi all,

I have always used JPEG for SL developments since the size is smaller and in a literal sense would reduce download time, but how about performance considerations? 

Does PNG / TGA have any advantages over JPEG in SL applications apart from PNG being able to carry alpha configuration?

Edited by iamyourneighbour
Link to comment
Share on other sites

As I understand it all uploads get turned into jpgs (jpeg2000 I think but I have no idea exactly what that is). MOST folks use png as far as I know as there is no point really in starting OUT "compressed" when the item will get MORE compress LOL.  Do some tests on your own and decide.

 

  • Like 1
Link to comment
Share on other sites

TGA and PNG have one huge advantage over JPG.  They support an alpha channel, which JPG does not.  Almost as important, they support layers, so you can build up an image from a composite of sub-images with different opacities, luminosities, etc. and can treat highlights, shadows, and whatnot as separate editable elements.  JPG gives you none of that.  I used TGA exclusively for years because I find it much easier to handle the alpha channel in that format, but I now use PNG almost as frequently.  I never use JPG.  Its only advantage is file size.

  • Like 2
Link to comment
Share on other sites

JPEG (but not JPEG 2000) has real trouble with sharp edges. Never store something with sharp edges, like a sign or a picture of text, in JPEG format. It will look terrible.

JPEG files are smaller, but there's no gain in sending them to Second LIfe, because they get decompressed, then recompressed as JPEG 2000 for storage on the asset servers.

  • Like 2
Link to comment
Share on other sites

I know there already are three good answers but to make it absolutely clear, Second Life only supports one image format, JPEG2000. Apart from the JPEG limitations Rolig and Animats mentioned, it should not matter which file format you choose to use locally. (I say should because there may be some minor differences in how efficiently the uploader handles the conversion from different formats.)

What viewer you use to upload may actually matter since they use different JPEG2000 libraries to convert the images. Firestorm uses Kakadu, a rather expensive commercial library. Other third party viewers (including self-compiled versions of Firestorm) use the open source OpenJPEG instead. Kakadu used to be regarded as the best option but things have changed and the official viewer switched from Kakadu to OpenJPEG recently. It may only be a matter of time before Firestorm does too.

Incidentally, the only relation between the JPEG and JPEG2000 formats is that they were comissioned by and named after the same organisation. The Joint Photographic Experts Group launched JPEG in 1992 as a compact file format for photos. The format soon turned out to be a bit too limiting so it didn't take them long before they started from scratch and in 1997 they launched the everything-but-the-kitchen-sink JPEG2000.

Why Linden Lab chose JPEG2000 is a good question. It's not the most efficient format for lossless compression (typically it achieves 2:1 compression rate that way while PNG tend to achieve 2.5:1 or more), it's a rather messy standard and all those extra features we don't need for textures add quite a bit of superfluous code. PNG also seems to have a better pixel loading sequence with less annoying not-yet-fully-loaded images. I suppose the explanation is that JPEG2000 is the only format that offers a choice between lossless and lossy compression and although we don't really use the latter in SL anymore, it's too late to change.

Edited by ChinRey
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

In my work, I have always used TGA for uploads to SL, and JPG for uploads to the MP (it doesn't accept TGA, it does however accept PNG and GIF as well). There's been a lot of discussion over the years as to which is better, TGA or PNG. For me, I never detected a difference, and in gimp, I've found it much easier to use tga for export.

One thing I've noticed while working is that the temp/local function to view textures on a build in world is always superior to the final upload. So seeing that conversion to JPG2000 is always a bit of a letdown.

I agree with ChinRey - The biggest difference is the viewer :

Quote

What viewer you use to upload may actually matter since they use different JPEG2000 libraries to convert the images. Firestorm uses Kakadu, a rather expensive commercial library. Other third party viewers (including self-compiled versions of Firestorm) use the open source OpenJPEG instead. Kakadu used to be regarded as the best option but things have changed and the official viewer switched from Kakadu to OpenJPEG recently. It may only be a matter of time before Firestorm does too.

I can see a discernible difference in resolution and quality of an upload depending on the viewer I use. In my opinion, Firestorm is hands down the best in terms of upload quality. I hope it doesn't change!

Edited by Arwen Serpente
clarification
Link to comment
Share on other sites

8 hours ago, Love Zhaoying said:

Perhaps JPEG2000 favored the fuzzy “still loading” texture behavior?

Yes, that's the whole point. The JPEG 2000 files are created as progressive files - reading the first part gets you a low-rez image, reading more gets you a higher res image, and reading it all get the full image. The viewer's texture system uses this feature heavily.

Link to comment
Share on other sites

2 minutes ago, animats said:

Yes, that's the whole point. The JPEG 2000 files are created as progressive files - reading the first part gets you a low-rez image, reading more gets you a higher res image, and reading it all get the full image. The viewer's texture system uses this feature heavily.

I read about that feature on Wikipedia this morning. Sounded familiar when I guessed.

Link to comment
Share on other sites

9 hours ago, Christhiana said:

What happens if you try to upload a texture that's already in jpg2000 format? Does it still get decrompressed and compressed?

Actually we cannot upload JPG2000 files to SL.

The only image files we can upload are: TGA, BMP, JPG, PNG
After uploading SL will convert those to JPG2000 format.

(There is also JPEG but it is exactly the same as JPG. The difference is only in the file suffix. In early Windows versions the suffix was limited to three letters, so the JPEG had to be shortened to JPG.)

Edited by Coby Foden
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

11 hours ago, animats said:

Yes, that's the whole point. The JPEG 2000 files are created as progressive files - reading the first part gets you a low-rez image, reading more gets you a higher res image, and reading it all get the full image. The viewer's texture system uses this feature heavily.

Without being able to do a reality check, I believe the way that is done is one of JPEG2000's main disadvantages compared to PNG. Both formats provide low resolution "early" versions of the image but the way they are generated are very different.

JPEG2000 uses frequency decomposition, essentially it starts with a version with a heavily lossy compression, then progresses through increasingly less lossy images.

PNG has interlacing, using the Adam7 algorithm. That's a much simpler process, only based on the order the pixel are sorted and delivered and it also seems to provide a sharper and more satisfying early image. The image simplification method added to VR headsets recently to speed them up with a minimum of quality loss, is essentially the last stage of Adam7 reversed.

Link to comment
Share on other sites

Over the three options, my answer to the question at hand is PNG and TGA with regard to their final use.

PNG is lossless and compresses images quite well, but the way it handles alpha limits its use. It is simpler to handle on a user's standpoint, but the alpha feature can be used only as a mean for transparency and it does it pretty badly in my opinion. The edges between the opaque and the transparent part of an image will almost always show a little white or black rim. For this reason, i limit PNG format use to fully opaque textures just to save on HD space on my computer.

TGA is still lossless but the same file is way bigger than storing it as PNG. The way it handles alpha makes it the format of choice. The RGB channels get stored separately from the alpha (as opposed to how PNG does it), which means a chance for an extended use for this format. Alpha doesn't necessarily mean transparency. It can be used as a separate channel to carry linear data (black-white AKA 0-1 values) for multiple purposes.

1) Most common use is transparency. This means that any RGB values found in the transparent part of the image is still there to be used, as opposed to PNG's method which deletes that data altogether to mark transparency. This avoids the rim effect on the opaque/transparent border by using some padding on the edges and letting the alpha channel define the transparency. This is the method that was used to "secure" sculpt maps, back in the days: full transparency still carried the RGB values needed for the sculptmap to displace the prim's vertices.

2) Linear data map: this is the case for the material feature in the viewer, where the glossiness map is being stored in the normal map's alpha, the environment map is being stored in the specular map's alpha and the glow map sits in the diffuse's alpha. This method is largely used in CGI and game development across the board because it allows saving in number of total images (asset management) and disk space (also, texture loading takes less time and loads more data at the same time). This can be seen in action in many game engines, like Unity with its glossiness (smoothness) embedded in either the metallic or the albedo map; in the Creation Engine (Skyrim engine, for modding purposes) where the glossiness is loaded in the normal map's alpha; in UnrealEngine4 where you can use R,G,B and A to store linear data at your discretion and, of course, in Maya and 3DSMax where the alpha output is a separate plug from color data in the texture file nodes.

To summarize my approach, based on the explanation above, i tend to ask myself this question:

Q) do i need the alpha? (including but not limited to the use for transparency)

A_1) No --> PNG

A_2) Yes --> TGA

  • Like 3
  • Thanks 2
Link to comment
Share on other sites

50 minutes ago, OptimoMaximo said:

PNG is lossless and compresses images quite well, but the way it handles alpha limits its use. It is simpler to handle on a user's standpoint, but the alpha feature can be used only as a mean for transparency and it does it pretty badly in my opinion. The edges between the opaque and the transparent part of an image will almost always show a little white or black rim.

I have found that this has to do with the anti-aliasing settings around your selection. The answer is to shrink the selection by two or three pixels to trim any possible anti-aliased background from the wanted foreground (knock-out) portion. (I do this kind of stuff all day in my day job) :) I use Calculations feature of Pixelmator Pro (and also available in Photoshop) to define the contrast between foreground and background in the proper color channel, then merge those into a new alpha channel, then using the overlay brush to wipe-out ay overlap and then sharpen the alpha edge.

I concur that TGA (Targa) is a superior format, superior even to TIFF (Tagged Image File Format) - though TGA is also a depreciated, antiquated, dying format that is at the bottom of the "I use this format" totem-pole. Even software apps that used to support it are dropping support. Long-in-the-tooth (a.k.a. in my words: Crusty) old apps like Photoshop, etc., will continue to support it for some time to come, but the format and its usefulness has been falling out of favor exponentially over the last decade or so.

The only viable and best replacement is Portable Network Graphics (a.k.a. PNG) - with is currently the new most-popular format (even for physical publishing, unless you need CMYK color-space, which is where TIFF shines).

I am not debunking @OptimoMaximo in any way whatsoever: TGA is certainly the most superior format, and it was the first to support all amazing features like layers and alpha-masks and the rest, though it's also not a compressed format (it's kind of like a RAW picture your camera can give you. It's just going the way of the mini-plug earphone jack. LOL

Edited by Alyona Su
  • Like 1
Link to comment
Share on other sites

@Alyona Su the matter at hand involved the image formats in use in SL, however. My intervention wasn't intended to cover a general cgi or game development format usage. In that regard, the most common formats are indeed TIFF, in Maya it's IFF nad EXR (i don't know about 3DSMax), and many applications rely on DDS (especially for nomal maps) for the dedicated alpha channel support. Not to mention the Substance Archives to generate images on the fly using instancing. But all this technology wealth is far from being available to SL users. 

Anyway, reading my post, all the features i listed there revolve around the alpha channel and its use. What format supports it, is marginally relevant and in the user case at hand, the only one that does it is TGA, regardless of how long it will be supported/cheered upon externally. That's what we've got in SL.

  • Like 2
Link to comment
Share on other sites

22 minutes ago, Alyona Su said:

I have found that this has to do with the anti-aliasing settings around your selection. The answer is to shrink the selection by two or three pixels to trim any possible anti-aliased background from the wanted foreground (knock-out) portion. (I do this kind of stuff all day in my day job) :)

I somehow missed this part. This is something that shouldn't happen, and it doesn't when using a dedicated alpha channel. Moreover, using a dedicated alpha also allows to make partial transparencies that work with alpha masking at a minimal rendering cost and no Z buffer / depth fighting with other alpha textures

EDIT to add an example: a glass on a window. I know that alpha mask blending mode isn't optimal for finely cut contours.

Edited by OptimoMaximo
  • Like 1
Link to comment
Share on other sites

1 hour ago, Alyona Su said:

The only viable and best replacement is Portable Network Graphics (a.k.a. PNG) - with is currently the new most-popular format

Relatively new at least. PNG 1.0 was introduced in 1996, the current version 1.2 in 1999.

For comparasion:

  • TGA: 1984
  • BMP: 1986
  • TIFF: 1986
  • GIF: 1987
  • JPEG: 1992
  • JPEG2000: 1997
Link to comment
Share on other sites

3 minutes ago, ChinRey said:

Relatively new at least. PNG 1.0 was introduced in 1996, the current version 1.2 in 1999.

For comparasion:

  • TGA: 1984
  • BMP: 1986
  • TIFF: 1986
  • GIF: 1987
  • JPEG: 1992
  • JPEG2000: 1997

I was refering to the comparison to GIF, it's now PNG for most web UI and other images used when transparency is wanted. Perhaps the hyphen was misplaced:  New-most popular (not as in new by existence) :)

Link to comment
Share on other sites

1 minute ago, Alyona Su said:

I was refering to the comparison to GIF, it's now PNG for most web UI and other images used when transparency is wanted.

And you were right too. PNG 1.2 is the most recent of the common graphics file formats. Very little happened to graphics file formats for more than a decade afterwards. There were some attempts at improved JPEG2000 and PNG inspired alternatives but they never caught on.

That may change soon though. There are at least three quite interesting recent fomrats, WebP, BPG, FLIF/FLYF. Whether any of them succeed remains to be seen. FLIF seems to be the most promising (but also the most risky in SL context) but WebP is powered by Google and already supported by all major browsers so it probably has the best chance.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1937 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...