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.

DarkBASIC Professional Discussion / Strange PNG transparency artifacts...

Author
Message
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 24th Jan 2012 09:39 Edited at: 24th Jan 2012 09:57
Hi all,

I've found that when loading in PNG files which deal with very high levels of transparency (such as the one attached) DBpro will sometimes render them with grey, solid artifact pixels in them. Sometimes lines of pixels, where there should not be grey pixels...

The method I am using is loading in the image with LOAD IMAGE, then creating a sprite using the SPRITE command, then using PASTE SPRITE to draw them to the screen.

Has anyone seen this? And, more importantly, does anyone have any idea of how to stop it happening? Perhaps in the way I export the PNG from Photoshop?

*edit* added the attachment... Thanks TheComet!


TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 24th Jan 2012 09:53
Quote: "(such as the one attached)"


Where?

TheComet

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 24th Jan 2012 09:57
WHOOPS! Ha, not enough caffeine.... Or too much... One or the other...


BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 24th Jan 2012 12:00
I've seen it with the fine line at the edge of an image. Someone mentioned it being an odd number of lines in the image.

I wonder if making the transparent background black (e.g, black layer, 100% transparent) or white would fix it?

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 24th Jan 2012 12:02
Worth a try... If it IS a lines issue, perhaps forcing the PNG file to be progressive scan would fix it also... I will experiment and report back...


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Jan 2012 12:18
I couldn't reproduce the problem using your image. Could you post a sample screenshot showing the problem?

This is the code I used:

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 24th Jan 2012 12:39
Hard to repro sorry, as it only happens occasionally. But one thing to try is that it only ever occurs when they're placed on top of each other, or placed over the top of a solid (non-transparent) image.


CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 24th Jan 2012 15:00
GAHHHH!!!! NOOOOO!!!!

/facepalm /facepalm /facepalm

I hadn't set the image colorkey to something non-black.

Set it to magenta and it fixed it.

/facepalm /facepalm /facepalm




basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 24th Jan 2012 15:55
I didn't have your problem:


Naphier
15
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 24th Jan 2012 16:34
::Welcomes CumQuaT to the Facepalming Club:::


Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 25th Jan 2012 00:12
Are you sure you fixed it by changing the colorkey?
That doesn't seems right to me because the use of png files in DBP overwrites the colorkey setting due to png's having their own transparency.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 25th Jan 2012 00:35
I fixed it. The same code ran perfectly fine. I stress-tested it last night for a couple of hours and didn't hit a single bug. Remember, I'm not having a problem with the SPRITE command or PASTE SPRITE. It's in the final screen bitmap through the use of PASTE SPRITE. And the final screen bitmap DOES use the colourkey.


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Jan 2012 02:01
Weird.

I thought exactly the same as Scraggle. We'd need some code plus relevant media to understand what's happening.

At the moment your symptoms and solution seem contrary to what we'd expect.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 25th Jan 2012 02:38
It's pretty straightforward, actually. It's probably just my terrible ability to describe things properly

The code is a little something like this:



If you run it, it makes the areas that end up totally black show through to the background image, rather than just drawing them black.
If you set the colorkey to something like Magenta, you don't get the problem.
Needless to say, the problem hasn't been encountered since using the SET IMAGE COLORKEY command.


Jeff Miller
21
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: New Jersey, USA
Posted: 25th Jan 2012 12:08
I had the same problem a few years ago and tripped upon the same solution. As I recall, budging the colorkey just slightly up from pure black did not help. I settled on "Set Image Colorkey 100,100,100" as part of a block of standard commands that I paste into all of my programs. Ditto for "Set Bitmap Format 21", so I don't have to worry if I'm running on a Vista vs. non-Vista Windows system.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Jan 2012 15:35
I believe DBPro relies on the colorkey setting unless you tell it to use transparency. Does the problem persist if you use set sprite to change the transparency setting?
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 25th Jan 2012 15:36
My bad, the problem was actually happening when I used the GET IMAGE command to capture and area of the screen where the sprites had been drawn to.


Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Jan 2012 15:44
That sounds like a different issue. Could you post a short snippet plus images which illustrate the problem?
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 25th Jan 2012 18:52
@CumQuaT: I had this problem before, I was trying to fade a text then save it as PNG to get multiple transparency levels. I thought the hint is in matrix1_util 33 dll. but I couldn't solve this problem.

if someone answered your question then he/she already has answered mine.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 26th Jan 2012 07:01
It's really simple, GreenGandalf. I was using PASTE SPRITE to draw semi-transparent faded black circle PNGs to the screen, sometimes over the top of each other, then I would use GET IMAGE to grab a part of the screen and save it to an image. That image would sometimes have black pixels in it because of the PNGs I was drawing, and when I turned that image into a sprite, the black was taken as transparent by DBpro since I hadn't declared SET IMAGE COLORKEY as anything other than black yet. Nothing fancy or weird, just me being silly and forgetting that DBpro's colorkey defaults to black!


Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 26th Jan 2012 11:28 Edited at: 26th Jan 2012 11:28
It's only "really simple" now that you have told us you were using GRAB IMAGE. In your original post you said you were using LOAD IMAGE. That is a HUGE difference that monumentally changes what the problem actually is.
If you had described the problem correctly in the first place, then the answer would have been obvious.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 26th Jan 2012 11:48 Edited at: 26th Jan 2012 11:48
Yeah, scraggle, but I already confirmed that I was using GRAB IMAGE in a subsequent post before GG posted. Hence my facepalm moment. Read all the posts before getting snarky.


Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 26th Jan 2012 12:01
Snarky? I don't know what that means.
But my point is still valid. If you had been specific about your issue in the original post then we could all have helped you much quicker. Which is what we were all trying to do ... help you.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 26th Jan 2012 12:12
Snarky means being bitchy, pretty much.

If you read the posts, I didn't realise that the issue was with the image. I thought it was with the sprites. Lots of awesome people came in to help me, but then I realised that the problem wasn't where I thought it was at all, and I clarified that. The problem was over and solved, and I didn't need posts like yours being rude about it. Everyone has facepalm moments.


Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 26th Jan 2012 12:17
I thought I was trying to help. I'm sorry that you feel otherwise but you can rest assured I won't be helping you again.

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 26th Jan 2012 12:55 Edited at: 26th Jan 2012 12:56
but it's not working with me. I can't seem to be able to save multiple transparency levels.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 26th Jan 2012 13:02 Edited at: 26th Jan 2012 13:03
Hey basjack. Basically, what happened was the dip.png only goes to about 50% opacity, which isn't enough to trigger the alpha effect on it's own, but when i pasted it on top of itself a few times, it was enough to make it 100% opacity in the middle, which, when I used GET IMAGE, made that image have perfectly black pixels in it, which registered as transparent since I hadn't set the SET IMAGE COLORKEY to anything else than black yet. For example, code like this:



Hopefully this explains my facepalm. I wasn't even thinking that the problem would be with the resulting image. I thought it was with how I was using the original DIP image with PASTE SPRITE.

Because if you add the line
at the start of the program, you won't get the problem anymore


basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 26th Jan 2012 13:45 Edited at: 26th Jan 2012 14:01
thanks CumQuaT. what am looking for is how you created the image "dip.PNG" at first place using DBpro.

if you've noticed, your image has multiple transparency levels which causing the circle to fade gradually.

however, if you saved the image using DBpro command "save image", these transparent levels will merge with the back ground colour.

did you make this image using DBpro?.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 26th Jan 2012 13:50
Ohhhhhhhhhhhh I see what you mean... No, I used photoshop, sorry. But if you don't have photoshop, you can also make that sort of thing in GIMP, which is free


basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 26th Jan 2012 14:02
then am still in trouble.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 26th Jan 2012 14:07 Edited at: 26th Jan 2012 14:07
How can I help? What specifically are you trying to make happen?


basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 26th Jan 2012 16:09 Edited at: 26th Jan 2012 16:14
I was trying to create a letters maker software that create letters of specific font format then, save the letters image as PNG to be used in mobile phones.

as you may know, the last four pixels of a letter fade gradually making it nicer to read.

the software is done but I stopped here.

I know I can do that using graphics software such as photo shop (personally I use draw plus 5). but I would like to make my own.
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 26th Jan 2012 22:17 Edited at: 26th Jan 2012 22:28
@basjak If I understand you correctly, you want to be able to write text to a bitmap, then grab that bitmap and save it as a PNG whilst retaining the alpha values associated with the anti-aliasing but not grabbing the background.

If that is what you want to do then this function fits the bill:


I have hardcoded the bitmap and images numbers for brevity, you might want to change that if you intend to use this function.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 27th Jan 2012 01:00
Yep, scraggle nailed it!

An interesting concept you've got happening there. Just remember that fonts are fairly heavy in the copyrights, so be careful!


basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 27th Jan 2012 02:02 Edited at: 27th Jan 2012 02:05
no scraggle you haven't nailed it. the last four pixels are still merged with black.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 27th Jan 2012 04:06
Hmm...

You could scan the image line by line, and any pixel that isn't pure white or pure black could have its shade analyzed and then redrawn as a pixel of the correct transparency level by making a 1x1 pixel sized sprite and using SET SPRITE ALPHA to change its transparency level...

A bit of a crazy-ass hack, but it might work...

But then again, it all comes down to DBpro's ability to export partial transparency in its images, which I'm not sure about, sorry.


Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 27th Jan 2012 11:40 Edited at: 27th Jan 2012 11:41
I'm very confused!
Which four pixels are you talking about?

The image below is what I get when I run my code. Obviously I have enlarged it for clarity. The top part is how it appears in Photoshop showing the transparency and the bottom half is the same image placed over a magenta background. I don't see any pixels that are 'merged with black' Could you explain what you are seeing or better still show a screenshot?



basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 27th Jan 2012 13:18
@CunQuat: congratulation your winning indie game of the year. we're still waiting for the party .

@scraggle: the last four pixels of each letter has merged with black, even though it look transparent.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Jan 2012 13:48 Edited at: 27th Jan 2012 14:15
Quote: "@scraggle: the last four pixels of each letter has merged with black, even though it look transparent. "


As Scraggle requested, could you explain what you mean or show a screenshot/image?

@Scraggle I've played around with your code and can only get the faded edges if the get image command needs to stretch the image to powers of two. If the bitmap happens to be powers of two already then you don't get the fading when you use get image. That seems to mean that the output of your function is somewhat unpredictable - but otherwise it works fine. Perhaps I've misunderstood what you're trying to do?
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 27th Jan 2012 14:15 Edited at: 27th Jan 2012 14:22
the top one is a cut from an image used in AppGameKit examples (sorry I couldn't put the whole image for copyright purposes.

the bottom image is a cut from what my software can produce.

I don't know what font type used for the top picture. the bottom picture use times new Roman.

however I tried other font types and I got the same results.

if you enlarged the image you will notice that the top script transparency is fading away. while my script is black fading.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Jan 2012 14:34 Edited at: 27th Jan 2012 14:35
Quote: "top script transparency is fading away. while my script is black fading."


I see what you mean - except it isn't quite fading to black. It seems to be some sort of awkward compromise between black and the background colour.

Over to you Scraggle.

Edit: fixed quote tags.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 27th Jan 2012 14:53
@basjack - Only nominated, unfortunately. Didn't win. But still a great honour!

Perhaps it might be easier to use a program such as GIMP to create the font images necessary for your AppGameKit project?


Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 27th Jan 2012 15:03
Try sticking a ,2 flag on the end of GET IMAGE see if that helps.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Jan 2012 15:59
It doesn't.

I think you need to have the rgb colours non-faded, but corresponding to the faded pixels, and the original faded alpha values. I'll see if I can knock up a demo using your code.

I haven't yet worked out exactly what DBPro is doing when it pastes those images.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Jan 2012 16:22 Edited at: 27th Jan 2012 16:25
Try this (uses IanM's Matrix1 plug-ins - couldn't see a way of doing this without):



Edit: I've assumed that the original pixels were ARGB = (a, a, a, a) so I could use the red channel as the alpha. I couldn't access the alpha value directly though as it seemed to be read as 255 regardless .
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 27th Jan 2012 17:24
wow green Gandalf, you've nailed it. dealing with the image pixel by pixel was miles away from me .

many thanks.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Jan 2012 17:28
Quote: "dealing with the image pixel by pixel"


Hopefully someone can find a simpler way.

Glad it worked.
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 27th Jan 2012 18:12
of course a simpler way can be done using memblocks.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Jan 2012 02:14
Simpler? Faster perhaps.

Login to post a reply

Server time is: 2026-07-10 08:27:30
Your offset time is: 2026-07-10 08:27:30