Purple Border on Image - Why?

BlitzMax Forums/BlitzMax Programming/Purple Border on Image - Why?

therevills(Posted 2009) [#1]
Hi All,

Can anyone please explain to me why I have a purple border around an image if I dont use the flag MIPMAPPEDIMAGE?



Ive read that MIPMAPPEDIMAGE requires more memory, so how can I remove this purple border without this flag?

Here is some test code:


And this is the image:



Finally here is the exe/code and image in a zip:

http://therevills.syntaxbomb.com/tests/mipmappedtest.zip

Cheers!


Floyd(Posted 2009) [#2]
Go to http://yanbloke.googlepages.com/ and download the DeFringe utility.


therevills(Posted 2009) [#3]
Cool... Thanks Floyd that fixes it...

So what is the "fringing"? And why does it not show up using MIPMAPPEDIMAGE?

Cheers!

PS Also is there a tool like DeFringe but allows you to select a bunch of pngs?


therevills(Posted 2009) [#4]
Found out that if I re-save my graphics using Paint.NET (v3.36) using the following options, it too removes the alpha rgb:

Bit Depth: 8-bit (the images Im using uses less the 255 colours)
Dithering Level: 7
Transparency Threshold: 128

Drag all the images into Paint.NET:

press CTRL-S (to display save), press enter (to save), press CTRL-W (to close)... repeat 200 times...my fingers are a bit tired now... (I couldnt find a batch process in Paint.NET)


plash(Posted 2009) [#5]
I know the RAD tools can convert video, audio and image file types (in batches).. But I don't know if it allows you to change parameters on the output file type.


Grey Alien(Posted 2009) [#6]
I normally get a white glow round images made in photoshop so I used defringe all the time. Sometimes you can't see the glow when the item is drawn at integer coords but if you move such an image slowly in increments of less that 1 pixel the glow looks pretty bad as it fluctuates.


ImaginaryHuman(Posted 2009) [#7]
I don't think the fringing comes from you using mipmapping, I think it comes from you NOT using filtering. It is the filtering that is smoothing out pixel values and blending them with surrounding pixels. Surely you don't get the purple glow when you use no mipmap and no filter?


plash(Posted 2009) [#8]
Confirmed, no flags gets me no fringing: http://img12.imageshack.us/img12/8738/fringyness.png

Default flags must use filtering/mipmapping.


Grey Alien(Posted 2009) [#9]
AutoImageFlags details the defaults which are MASKEDIMAGE and FILTEREDIMAGE. You only need to add MIPMAPPEDIMAGE if you plan to scale the image down. If you plan to draw the image at sub-pixel coords or scale it then FILTEREDIMAGE is essential - I always use it. Sometimes I've found that MIPMAPPEDIMAGE doesn't actually looks as good when some things are scaled down (e.g. bitmap fonts), or if sometimes is scaled down in an animated way you get that jump when it crosses from one mipmap to another which I don't think looks good.


therevills(Posted 2009) [#10]
Thanks for the replies guys...

RAD tools can convert video, audio and image file types (in batches)..


@Plash, thanks Ill try it out tonight... I did quite a bit of searching last night to find a batch tool for this, but didnt find any...

so I used defringe all the time


@GA, have you made a script or something for Defringe? As it would be quite time consuming to do all your graphics....


Grey Alien(Posted 2009) [#11]
No Script, wish I had the original code as I would improve the app. I'd love it if the original author was around to make the code public...


Gabriel(Posted 2009) [#12]
If you wanted to make your own, it shouldn't be too hard. I would assume all it's doing is looking for pixels with less than a certain alpha threshold and then coloring them equal to the color of the nearest opaque pixel, without changing the alpha value.


therevills(Posted 2009) [#13]
If you wanted to make your own, it shouldn't be too hard.


Could you do it BlitzMax? How would your read the pixels, would it be using a pixmap (I havent really used these)?

I would assume all it's doing is looking for pixels with less than a certain alpha threshold and then coloring them equal to the color of the nearest opaque pixel, without changing the alpha value.


Sounds about right... I found this post made by the author himself:

http://www.blitzbasic.co.nz/Community/posts.php?topic=81818#922799

The 'DeFringe' program referred to here, works by simply setting the colour of all transparent pixels to the average colour of it's neighbouring opaque pixels.



Czar Flavius(Posted 2009) [#14]
The 'DeFringe' program referred to here, works by simply setting the colour of all transparent pixels to the average colour of its neighbouring opaque pixels.

Corrected grammar.


Grey Alien(Posted 2009) [#15]
Let's petition Yan to make an update, or release the code for free, or update it and sell it, any of those 3 work for me :-)


GfK(Posted 2009) [#16]
Corrected grammar.
Why don't you just change your name to Captain Pedantic and be done with it?


therevills(Posted 2009) [#17]
Let's petition Yan to make an update, or release the code for free, or update it and sell it, any of those 3 work for me :-)


Ive started to code my own last night... with a bit of help from REDi from Syntax Bomb, its nearly there...

Ill post the code and exe soon... ;-)

Could anyone with any example images which has this problem please post them on this post....


therevills(Posted 2009) [#18]
Think its done... it may not be the neatest code, but it works pretty well....



Exe and Code:
http://therevills.syntaxbomb.com/Multi-Defringe/Multi-Defringe.zip


Czar Flavius(Posted 2009) [#19]
therevills is making me twitch :)

Why don't you just change your name to Captain Pedantic and be done with it?
Coming from Captain GrumpyfK..


ImaginaryHuman(Posted 2009) [#20]
It would be more ideal that the graphics softare with which you create your images in the first place, saves the data in the correct manner, separating alpha from pixel values rather than combining them, then you wouldn't have to try to fake a defringe after the fact?


therevills(Posted 2009) [#21]
It would be more ideal that the graphics softare with which you create your images in the first place, saves the data in the correct manner


True, but if you are getting someone else to do the graphics, you haven't got much of a choice...

BTW When I was quickly commenting the code, I got the left and right comments back to front... ;-)


Grey Alien(Posted 2009) [#22]
Cool! So are you averaging the surrounding 8 pixels or what? How does the algorithm work exactly? I wonder if it's the same as the original and if there are any pitfalls that need to be avoided etc?


therevills(Posted 2009) [#23]
So are you averaging the surrounding 8 pixels or what?


I did originally do the surrounding 8 pixels but it worked out better to do just 4 (above, below, right and left)... but if you need that the code is there, just add it eg:

' above & left
						If y>0 and x>0 Then
							pixel% = array[x-1,y-1]
							If ((pixel Shr 24)& $ff) <> 0 Then
								r = r + (pixel Shr 16)& $ff
								g = g + (pixel Shr 8)& $ff
								b = b + pixel & $ff
								no:+1					
							EndIf
						End If						


How does the algorithm work exactly?


It stores the pixels image into an array, then loops thru the array, if any of the pixels are transparent it then checks the 4 pixels above, below, right and left of it, if they are not transparent it stores their colour, once it has got all the colours it averages it and stores it back into the array.

Once its done all the array, it then writes the array back as pixels and saves the png...

This is all wrapped in a read directory loop...

It would be great, if anyone could test it... I converted all my graphics for my next game (200 images) last night with it and it seems to work quite well...


Grey Alien(Posted 2009) [#24]
Great, thanks for the detail. I'm glad you used the array system as I was worried that if you altered a pixel straight away that it would affect the average for other nearby pixels. You are too clever for that, I worried needlessly :-)

Can't test now as I'm on laptop in Seattle, but also I'm not sure if I have any non-defringed images any more!