Jump to content
  • Advertisement
Sign in to follow this  
kevinlynx

Question about jpg and tga file---mixed them like a png file

This topic is 4389 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Recently I have found there are many games using a jpg and a tag file for their sprites ! As you know , we can use a png file with alpha-channel to transparent them on the screen . This is used for sprites in a game specially . But I have found these games only use jpg and tga file ! And it seems the tga file is only a black-white image ! So ,the questions is : How to use a jpg and a tga file to work together like a png file ? --Especially in HGE . Thanks for your time .

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
TGA has also support for Alpha channel and the std. RGB colors, so TGA can replace PNG i most cases (when we talk about RGB +A)
But why peope use JPG, i have no ide.

Share this post


Link to post
Share on other sites
It seems that the tga has only alpha-channel , and the jpg contains RGB .So mix them to ARGB ...If i guess correctly , then how to blt them on the screen like a png ?
I need transparent them on the screen .

Share this post


Link to post
Share on other sites
that is not correct. TGA stores RGB+ alpha channel.

Jpges are rarely used in games(n i think it's because of their compression)

regards,
m4gnus

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
JPEG is a compression format that works well with photorealistic images (digital pictures). JPEG should NOT be used for games because of its compression scheme. Whatever games are using JPEG shouldn't be.

But anyway, to answer your question. The JPEG used by these games is the actual that needs to be drawn on screen and the TGA is this thing called a mask: it has only black and white color and it defines what parts of the first image (the JPEG) get drawn to the screen. The mask is drawn first, with a bitwise source AND operation. The image is drawn second, with a bitwise source XOR operation. These two images combine to form an image with a transparent background.

However, the previously described process is rather obselete nowadays because of hardware supported alpha blending. Basically, alpha blending assigns an extra value A to the RGB values already stored in a pixel which determines how see-through that pixel is. A pixel with an alpha value of 255 is completely transparent. This is the desirable way to achieve transparency in modern games as APIs such as DirectX and XNA support alpha blending at a very high level. Basically, you can just load the image with alpha information and draw it, and hey presto! it has a transparent background. DirectX also allows you to specify a color key that is filled in with an alpha value of 255 when the bitmap is loaded.

As far as game graphics formats go, I would suggest using either BMP, TGA, or DDS (the latter is DirectX's native file format and has a utility specially designed for it called the DirectX Texture Tool, which is available in the DirectX SDK).

Exact implementation details for your problem depend on the API you're using, so I can't help you until you post that too.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
JPEG is a compression format that works well with photorealistic images (digital pictures). JPEG should NOT be used for games because of its compression scheme. Whatever games are using JPEG shouldn't be.


Thank you very much for your particular explation !

And I use HGE API ! And if you give me some DirectX8 codes , i'll also thank you !

Share this post


Link to post
Share on other sites
JPG compression is best used for graphics that are just displayed as-is... Backgrounds, portraits of people/items/whatever and so on. In this case you know the compression won't look any worse in the game than it does in your image manipulation tool of choice, and it can save a lot of space and/or download time. It's really no different from using jpg's on a website. The way I've implemented jpg alpha masking is by writing a generic "asset loader" that loads both the jpg and the mask tga and combines them into 32-bit RGBA image, which can then be used just the same as if I'd loaded a 32-bit tga. (Well, actually since it uses sdl_image it works with all formats... so the mask can be png)

What you shouldn't use jpg's for are things like textures that can be seen close-up in a 3D game, or sprites that can be scaled larger than the original size because these will "exaggerate" the compression artifacts. Also, things like colored lighting applied to a texture will sometimes bring out problems... And using jpg's for normal maps is absolutely out of the question.

Share this post


Link to post
Share on other sites
JPGs are extremely useful for many game purposes, especially for downloadable games but others as well. Despite what people here say, a high-quality JPG is almost indistinguishable from its lossless source, and much smaller than the equivalent PNG, TGA, TIF, BMP, etc. I've seen a lot of 1200k PNG files that can be reduced to 200k JPGs and a casual user would never notice the quality difference.

The compression power involved here is so useful that I wrote a routine that lets me use a JPG and then an additional JPG for the corresponding alpha information. The quality is almost as good and the two files are still something like 30% as large as the originals at 1024x1024 (and more savings as you go up from there.)

The rules I go by are, JPG for everything that doesn't need an alpha channel and doesnt need to be perfect, and PNG for everything else. This gives very high quality with the smallest possible (practically speaking) size. Don't be scared of JPEG!

Share this post


Link to post
Share on other sites
Quote:
Original post by Matt Aufderheide
Using JPEG is a stupid thing.. just use normal DTX compression.

...which takes up much more room and looks way worse for many applications. Nice post though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!