PNG transparent colour

BlitzMax Forums/BlitzMax Programming/PNG transparent colour

DrDerekDoctors(Posted 2006) [#1]
Okay, so you know you can nominate a colour as transparent in clutted PNGs in art packages? How can I find out what that colour is so I can set it as the maskimage value?


Grey Alien(Posted 2006) [#2]
I don't think you need to. You load in the PNG that you saved with the transparent colour; make sure you use MASKEDIMAGE with LoadImage and it should just work (well it does for me but I could be wrong).


Punksmurf(Posted 2006) [#3]
Probably you need to start the graphics mode with an alpha buffer too, but I'm not sure.


DrDerekDoctors(Posted 2006) [#4]
Righty, ta'. Also, I just realised I should have posted this in the BlitzPlus part. Dammit dammit dammit!


Haramanai(Posted 2006) [#5]
Edit.Sorry I hasetated and posted.


Grey Alien(Posted 2006) [#6]
well everything I said is invalid then, cos it doesn't apply to BlitzPlus. In Blitplus, use the art package "dropper" over a background pixel, it should say 0,0,0 if black or 255,0,255 if magenta whatever, set this as the MaskImage value in BlitzPlus and it will work fine.


DrDerekDoctors(Posted 2006) [#7]
That's no use to me, though, because BlitzPlus messes up the colours when it loads a PNG with transparency, setting the transparent colour pixels to white. Also I think loading each image into an art package to determine the background colour isn't really a viable option either, is it? PNGs have transparency information for a good reason.


Dreamora(Posted 2006) [#8]
If you use PNG with transparency channel, make sure you set the blendmode to alphablend before drawing.

If you want to use masking, I would suggest using the pixel at 0,0 as "mask reference pixel". Load it as pixmap, read the pixel value, use setmaskcolor with that value and then load an image from the previously loaded pixmap with the above stated MASKEDIMAGE flag (loading image from file would not be faster as it does internally load a pixmap first as well)


tonyg(Posted 2006) [#9]
B+ can't handle transparency. Instead you can specify a colour (default black) to act as transparent.
If you do not intend to use black as the transparent colour you need to use maskimage and specify the RGB values.
If you don't know the transparent colour how can B+?
That's why you either...
a) Need to provide the RGB if you know it
b) Open the image into a paint package and find the RGB to give to B+.


FlameDuck(Posted 2006) [#10]
That's no use to me, though, because BlitzPlus messes up the colours when it loads a PNG with transparency, setting the transparent colour pixels to white.
Actually, that would be Photoshop.


Grey Alien(Posted 2006) [#11]
hmm, I already told him what to do on my second post in a concise manner, oh well. I guess having it said different ways can only help :-) except for the BlitzMax advice haha.

DrDerekDoctors: If it sets the pixels to white, make your mask colour 255,255,255. Better still switch off the transparency and just fill your background with a colour that's not in use in the main graphic (such as magenta 255,0,255) and set this to the mask colour in your game. It's what I do (did) in BlitzPlus.


DrDerekDoctors(Posted 2006) [#12]
1) If it's something caused by the art package then I can't guarantee it'll always be white. Also, the images aren't from Photoshop, they're from a variety of packages.

2) If there's real white in the image, that'll get messed up by the tranparency being set to white, wouldn't it?

I'm talking about PNGs which I haven't created, ones which could come from anywhere which don't all have the same mask colour set as the transparent one in their palette. All I want to do is for Blitz to actually do it's job properly.


tonyg(Posted 2006) [#13]
B+ (in this case) *is* doing it's job properly.
It does not do transparency (think it's because DX1 doesn't do it) so needs you tell it which colour to ignore.
If an image is loaded WITH a transparent colour it will be replaced by white (255,255,255).
I'm sorry if you've got a load of downloaded images with transparency but you'll have to bite the bullet and change them.


Grey Alien(Posted 2006) [#14]
or just save them all as bitmaps, thus forcing a background colour, then resave as png without transparency info. Maybe just resave as png without transparency info and see what the background colour turns out to be.


DrDerekDoctors(Posted 2006) [#15]
The images aren't mine, this is for a program which'll be used by other people so I don't think it's reasonable to ask them to change all their stuff. Also asking them to change them to bitmaps isn't really an option, either.


tonyg(Posted 2006) [#16]
... then B+ is probably not the tool for the job.
You're trying to provide a program to read images with transparency written in a language that doesn't allow transparency.
B3D could handle it and so can BlitzMax.


Wayward(Posted 2006) [#17]
You could write a function to import PNGs with alpha as PNGs with a predictable mask colour. I use something similar to convert 'white-alphas' (thanks, PhotoShop) into 'black-alphas'. The function loads a PNG as a pixmap, scans it for pixels with an alpha of zero, and sets those pixels to the mask colour.
' Process image to turn transparent pixels black so sprites don't display a white fringe when filtered.

Global CrescentPixmap:TPixmap = LoadPixmap( "incbin::Resources\Graphics\Crescent.png" )

For Local yi = 0 To CrescentPixmap.height  - 1
	For Local xi = 0 To CrescentPixmap.width - 1
		Local p = ReadPixel( CrescentPixmap, xi, yi )
		If p & $FF000000 = 0
			WritePixel( CrescentPixmap, xi, yi, 0 )
		EndIf
	Next
Next

Global CrescentImage:TImage = LoadImage( CrescentPixmap, FILTEREDIMAGE )



tonyg(Posted 2006) [#18]
Hmmm, it might be slow but you could set any 0,0,0 pixels to 5,5,5 before changing zero alpha pixels to black.


Grey Alien(Posted 2006) [#19]
The images aren't mine, this is for a program which'll be used by other people
gosh you are a little spartan with this vital info. Yeah as TonyG said, get blitzMax and be done with it. Or if you are feeling brave, do what Wayward said haha.


DrDerekDoctors(Posted 2006) [#20]
Trust me, as soon as someone else posts a solution, I'm gonna' invent another spanner to throw into the works. ;)

I think I need to get Bmax and the GUI plugin I suppose. Ah well.


SoggyP(Posted 2006) [#21]
Hello.

If people are going to be loading their own images why not provide the functionality within the program for them to choose the transparent colour themselves?

Goodbye.


DrDerekDoctors(Posted 2006) [#22]
I'm gonna' have to do that, but really it's something they shouldn't have to do.


tonyg(Posted 2006) [#23]
... that's right. Somebody should be doing it for them by using a product which allows for transparency.


Dreamora(Posted 2006) [#24]
You mean like Gimp, PhotoShop, PaintShopPro, Pixia ( the first and the last are free)


tonyg(Posted 2006) [#25]
... no like BlitzMax.


DrDerekDoctors(Posted 2006) [#26]
Given that part of PNGs spec is that you can nominate a transparent colour I'd say that Blitz+'s PNG loading is incomplete and broken if it doesn't use that information in the proper manner, surely? Anyhoo, looks like my company is gonna' spring for BMAX - I assume that with applications I can use nice variable transparency levels in the windows (ie, see-through stuff, nothing to do with the image's alpha channel)?


tonyg(Posted 2006) [#27]
yep
P.S. Don't think it is B+ fault but DirectDraw. Obviously the decisions to use DX1 might be questioned.
Does B+ really use DX1?


Dreamora(Posted 2006) [#28]
But as a mather of fact, you don't have alpha in 2D so it makes no sense in loading those information.
BM on the other side is full 3D and in 3D, alpha exists, so it makes sense to load the data.


DrDerekDoctors(Posted 2006) [#29]
B+ does support nominating a mask colour, though, so it makes sense if there's information available in a file pertaining to that to actually use it.