Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 17th Mar 2011 05:02
Ok. I've searched the forums and can't find anything on this. I've been trying to use jpgs to bypass ghosting and transparent colors on sprites, but every time I load a jpg image into a sprite, it is surrounded by a strange grey box... I'm using my native screen res, and there is no scaling on the sprite. Could it possibly be that I'm using Vista? Are there any 3rd party plug-ins to help?

Thanks, Amo.

If life were like a box of chocolates, I'd know what I would get... The one that got dropped on the floor and put back in the box.

Iye nehvur yoose spehl chehk, ahn mie tippyng izz fiyne.
Jimmy
22
Years of Service
User Offline
Joined: 20th Aug 2003
Location: Back in the USA
Posted: 17th Mar 2011 05:39
I know exactly what you're talking about, and the only way I've been able to get around it is to use .gif or .png files, because they contain the appropriate alpha data, while .jpg files do not. But that may just be because of how I export them. Not sure.

NaGaFailMo.
Quel
17
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 17th Mar 2011 10:34
Maybe use the type of image which actually has transparency data...

(.png)
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Mar 2011 15:18
JPG files are not good for transparent textures, because they don't store the exact same colours that you put into them - they store approximations that you ordinarily wouldn't notice (at least if you keep the quality high enough).

You should stick to PNG.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Mar 2011 20:49
Quote: "JPG files are not good for transparent textures"


Are they any use at all for transparency with an alpha layer? Are you referring to the colorkey method of transparency?

But yes, stick to PNG or DDS.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Mar 2011 21:16
Quote: "Are they any use at all for transparency with an alpha layer?"

There is no alpha channel in the JPG format, so you'd have to store your alpha channel externally to the JPG file itself. You could do that, but it's far easier to use an image format that supports alpha channels out of the box.

Quote: "Are you referring to the colorkey method of transparency?"

Yes. Because of the way that JPG stores not-quite the colours that you originally used (as it uses a lossy compression method), even in what was originally a block of a single colour the resulting image colour could vary, and it's pretty much guaranteed at the borders between two colours (ie, between the colorkey colour and the actual image you want displayed).

PNG, with its built-in alpha channel and lossless compression is far better for use in games anyway, although you could make a case for using JPG for non-transparent textures (or for a dirty window texture maybe ).

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Mar 2011 02:28
Quote: "There is no alpha channel in the JPG format"


That's what I thought.

Quote: "Because of the way that JPG stores not-quite the colours that you originally used (as it uses a lossy compression method), even in what was originally a block of a single colour the resulting image colour could vary, and it's pretty much guaranteed at the borders between two colours (ie, between the colorkey colour and the actual image you want displayed)."


Yes, that's one reason I rarely use them.

Quote: "PNG, with its built-in alpha channel and lossless compression is far better for use in games anyway"


Agreed - although if loading times are a problem I believe Cash Curtis II showed that DDS files are best (but they don't use lossless compression I believe).
Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 18th Mar 2011 03:09
OOPS! Heh heh! My bad, I meant pngs are giving me the problem. Dang. Sorry! I wish I could rename the topic now!

I know jpgs aren't for alpha channels.

The sprite is transparent, but there's a grey outlined box around it. Should I turn the default transparency off? Could the default transparency and the pngs alpha channel be muddling each other up?

And, on a related note. Why can't you change the settings of a sprite before calling it? Couldn't DBP just save the settings of the sprite in the correct sprite slot so that when the sprite is loaded, the settings take effect, or something? I hate having to call the sprite function twice to be able to set it, then move it.

If life were like a box of chocolates, I'd know what I would get... The one that got dropped on the floor and put back in the box.

Iye nehvur yoose spehl chehk, ahn mie tippyng izz fiyne.
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 18th Mar 2011 03:17
Quote: "There is no alpha channel in the JPG format"

Yeah, that's true.

Quote: "Yes. Because of the way that JPG stores not-quite the colours that you originally used (as it uses a lossy compression method), even in what was originally a block of a single colour the resulting image colour could vary, and it's pretty much guaranteed at the borders between two colours (ie, between the colorkey colour and the actual image you want displayed)."

Well, I dont exactly know what you mean. The images below are two identical images, except that the first one is a .bmp file, and the second one is a .jpg file. And, maybe I need glasses, but I really dont see a difference between them.
If you have a decent paint program, you can change the settings for the exporting (saving) of .jpg images and they'll look as good as any bitmap. And, the file size of a .jpg (even at good quality) is still far less than a .bmp, and even a .png.






Cheers

SLAYER RULES! YEAH, MAN!!
Randomness 128
19
Years of Service
User Offline
Joined: 13th Feb 2007
Location:
Posted: 18th Mar 2011 07:24 Edited at: 18th Mar 2011 07:29
Try taking a closer look. Here are the images you posted with 800% zoom.

jpg:


bmp:



Quote: "Agreed - although if loading times are a problem I believe Cash Curtis II showed that DDS files are best (but they don't use lossless compression I believe). "

DDS files can use lossy compression. However, unlike any other files you use, these files will remain compressed in video memory. Your textures can take up a lot less space in video RAM if you use it. More information.
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 18th Mar 2011 14:09 Edited at: 18th Mar 2011 14:13
Quote: "Try taking a closer look. Here are the images you posted with 800% zoom."

Well, sorry to disagree, Randomness 128, but I zoomed in on the images I posted, and there was no pixelation, or deformation at all.
My guess is that either your image program plays tricks on you, or you loaded in one of my images, and saved it back as a .jpg file with lesser quality.

If there was really that much pixelation on the images I posted, than you would definately be able to see it without zooming in.

SLAYER RULES! YEAH, MAN!!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Mar 2011 14:21 Edited at: 18th Mar 2011 14:21
I see the same as Randomness 128. I saved the files as bmp and jpg as you suggested:

The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 18th Mar 2011 14:23 Edited at: 18th Mar 2011 14:33
Quote: "I saved the files as bmp and jpg as you suggested:"

I didn't suggest to save them. The files I uploaded ( hint: download button) are already in the appropriate formats.



SLAYER RULES! YEAH, MAN!!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Mar 2011 16:06
I see what you mean. Thanks.

I didn't notice the download - I just saved them from the displayed images.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Mar 2011 16:31
It might be an issue with the image itself. For example, I use PaintShopPro9 - and if I have an alpha trans image, and delete bits of it, I am actually just deleting the alpha data. I could take an image and delete everything, save it as a PNG, then what you would see is a blank image. But that's not the case, the image is actually full colour and still intact, but the alpha layer has gone. With a mask or something, I could get the image back easily.

So the grey edges could well be leftover colour data that is being regurgitated by mipmapping. A mipmap might be reducing in resolution and mixing in those nasty greys, because the alpha layer is being 'digitised'. DDS files can have lots of options set for compression, mipmap generation, scaling, even alpha fading - so imagine your PNG is loaded up, then DBPro itself decides how to mipmap it, and maybe it's doing a bad job.

I suggest using the ,1 flag when loading the image, see it unmipped and direct in memory - and if the artifacts go away, then perhaps consider a custom DDS version. You can get a DDS export plugin for PSP9 and PS from the nVidia website - googling should turn it up.

Health, Ammo, and bacon and eggs!
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 18th Mar 2011 16:36
Quote: "I didn't notice the download - I just saved them from the displayed images."

No worries, Green Gandalf. I guess that's the same thing that Randomness 128 did.

Quote: "Because of the way that JPG stores not-quite the colours that you originally used"

I must admit that there's a slight difference in color, but its hardly noticeable at 100%. You really have to zoom in a lot to see it.
In a lot of cases, .jpg files are well suited. And, that's why I use them wherever I can.
Of course, everyone has its own preferences.

SLAYER RULES! YEAH, MAN!!
Randomness 128
19
Years of Service
User Offline
Joined: 13th Feb 2007
Location:
Posted: 18th Mar 2011 16:43 Edited at: 18th Mar 2011 16:53
Quote: "I didn't suggest to save them. The files I uploaded ( hint: download button) are already in the appropriate formats."

I just checked, and both of the images you posted are jpg's, but one of them is using less compression than the other one. I seem to recall that photobucket automatically converts bmp's to jpg's when you upload them.

Quote: "I must admit that there's a slight difference in color, but its hardly noticeable at 100%. You really have to zoom in a lot to see it.
In a lot of cases, .jpg files are well suited. And, that's why I use them wherever I can. "

And yes, it is hardly noticeable, to us at least. But even the slightest difference could cause a problem if you're using colour key transparency. Not to mention they take a lot longer to load in DBP than other formats. Basically, use them wherever you can except for DBP.
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 18th Mar 2011 16:52
Quote: "I just checked, and both of the images you posted are jpg's"

That's weird. I downloaded them myself twice, and both times I got one .bmp and one .jpg.

Cheers

SLAYER RULES! YEAH, MAN!!
Randomness 128
19
Years of Service
User Offline
Joined: 13th Feb 2007
Location:
Posted: 18th Mar 2011 17:36
I just did a quick test to see how quickly different image formats would load in DBP. I saved the same image in several formats and wrote a quick program that would load them repeatedly and time how long it took to load. I also monitored how much memory the program used while running.

4096 x 4096 texture loaded 15 times

File size:
jpg: 18.7 MB
bmp: 64.0 MB
png: 47.6 MB
dds: 64.0 MB
dds with pregenerated mipmaps: 85.3 MB
dds with pregenerated mipmaps and texture compression: 10.6 MB

Loading time results:
jpg: 248.7 seconds
bmp: 111.9 seconds
png: 16.4 seconds
dds: 0.852 seconds
dds with pregenerated mipmaps: 0.706 seconds
dds with pregenerated mipmaps and texture compression: 0.96 seconds

RAM used:
dds with pregenerated mipmaps and texture compression: 171 MB
everything else: 1293 MB

512 x 512 texture loaded 100 times

File size:
jpg: 199 KB
bmp: 768 KB
png: 435 KB
dds: 768 KB
dds with pregenerated mipmaps: 1024 KB
dds with pregenerated mipmaps and texture compression: 170 KB

Loading time results:
jpg: 19.4 seconds
bmp: 9.999 seconds
png: 1.306 seconds
dds: 0.665 seconds
dds with pregenerated mipmaps: 0.844 seconds
dds with pregenerated mipmaps and texture compression: 0.37 seconds

RAM used:
dds with pregenerated mipmaps and texture compression: 29 MB
everything else: 146 MB
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Mar 2011 17:43
I think there's a bit of confusion here. If you save the displayed images the default format is jpg - but you in fact have a choice of jpg and bmp. In either case one image shows quality loss and one doesn't. I get the same on both my machines - XP and Vista.

The images in the download seem to be the same quality though.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Mar 2011 19:13
@ The Slayer:

You can see the difference when you do a flood fill on a section of those images (see attached image... the .jpg is on the right side).

The .jpg will always have more artifacts in the images because it doesn't do colors just right (what IanM mentioned). The results are an approximation of a solid color so if we use .jpgs for sprites we'll always get artifacts around the sprite because a solid color for transparencies is impossible with .jpg.

Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Mar 2011 19:20
@ The Slayer:

The best way to see the problems with using .jpg is to show images that will actually be sprites rather than a background scene. The attached image is of a small ship that was taken from a .bmp with a black background and resaved as .jpg and .png and then flood filled with blue. The .jpg has some off-black artifacts around the green exhaust and the entire ship looks horrible because of the muddled colors. The .png does not have any black artifacts at all and all the colors are exactly the way the .bmp shows. I always use .pngs because they retain the exact colors of the original and because they retain alpha transparencies.

The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 18th Mar 2011 19:40
@Grog Grueslayer

I never said .jpg's are to be used where transparency is needed or for sprites. Yes, I know that they do not retain the exact colors. But, they do have their purpose for other things in a game, like backgrounds, textures, etc...

Cheers

SLAYER RULES! YEAH, MAN!!
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Mar 2011 19:59
We seem to have wandered away from the original poster's question which now appears to be this:

Quote: "OOPS! Heh heh! My bad, I meant pngs are giving me the problem. Dang. Sorry! I wish I could rename the topic now!

I know jpgs aren't for alpha channels.

The sprite is transparent, but there's a grey outlined box around it. Should I turn the default transparency off? Could the default transparency and the pngs alpha channel be muddling each other up?"


If you're still having trouble could you post a typical image for us to test?
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Mar 2011 20:48 Edited at: 18th Mar 2011 20:48
@ The Slayer:

Oh ok. I only use .jpg for textures and family pictures.


Now back to the original poster...


@ Amo Deus Man:

Quote: "And, on a related note. Why can't you change the settings of a sprite before calling it? Couldn't DBP just save the settings of the sprite in the correct sprite slot so that when the sprite is loaded, the settings take effect, or something? I hate having to call the sprite function twice to be able to set it, then move it."


It's the nature of the beast. The sprite has to exist before any settings can be changed on it. If you had a non-existent trash can sitting by you could you put trash into it?

Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 18th Mar 2011 21:44
Hmm... I had accidentally deleted the source file(It was only the mouse code anyway), so I quickly recoded the pointer code which was:


And, the results were perfect:


I must have used a lower quality compression. I guess I just didn't set it right.

Also, @ Grog:
Yeah, I understand. Just seems like it could be done in less lines of code.

Thanks, guys. Moral of the story DB newcomers? Set your compression right!!!

If life were like a box of chocolates, I'd know what I would get... The one that got dropped on the floor and put back in the box.

Iye nehvur yoose spehl chehk, ahn mie tippyng izz fiyne.
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Mar 2011 21:52 Edited at: 18th Mar 2011 21:53
Use ,1 after LOAD IMAGE to stop the blurring effect of the image. Without a texture flag of 1 Darkbasic Pro treats the image as if you're going to use it as a 3D texture so it blurs it a bit automatically.



Westmere
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: Germany
Posted: 18th Mar 2011 21:59
Quote: "OOPS! Heh heh! My bad, I meant pngs are giving me the problem. Dang. Sorry! I wish I could rename the topic now!

I know jpgs aren't for alpha channels.

The sprite is transparent, but there's a grey outlined box around it. Should I turn the default transparency off? Could the default transparency and the pngs alpha channel be muddling each other up?"


I haven't had any problems with these mixing up (with Image commands at least). Did you double check the Alpha values of your images? Paint Shop Pro for instance shows R, G, B and O(pacy) values for your mouse position so it's easy to see there.

If it still doesn't work, could you post a small example code and one of the picture files that causes your problems?

Login to post a reply

Server time is: 2026-07-17 14:00:13
Your offset time is: 2026-07-17 14:00:13