"Wrong" colours in png files

Just starting out? Need help? Post your questions and find answers here.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

"Wrong" colours in png files

Post by Trond »

When I use this code the png file looks very white. When I load the image using GDI+ it looks normal. Is this is a problem in PB or with something else?

Code: Select all

UsePNGImageDecoder()

OpenWindow(0, 0, 0, 512, 384, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_LAYERED)

LoadImage(0, "clock.png")

hDC = StartDrawing(ImageOutput(0))
  GetObject_(ImageID(0), SizeOf(BITMAP), @BitmapInfo.BITMAP)
  ContextOffset.POINT
  BlendMode.BLENDFUNCTION
  BlendMode\SourceConstantAlpha = 255
  BlendMode\AlphaFormat = 1
  UpdateLayeredWindow_(WindowID(0), 0, 0, @BitmapInfo+4, hDC, @ContextOffset, 0, @BlendMode, 2)
StopDrawing()

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

PNG's have a gamma information on them, so probably it depends if PB reads it and applies the gamma correction...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Hmm, I could have swore I unchecked "save gamma information", but I'll try to fiddle with it.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Maybe this is not required anymore.. I saved out a 32bit PNG in Photoshop & tried it with the above code and found no problem.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Did you save gamma?
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Show me where the save gamma option is when saving a PNG in Photoshop & I'll try it ... usually it's a non-issue for me using PS.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I used GIMP for mine. But on Photoshop for mac there´s a checkbox in the save as dialog. I´ll try a few different png´s when I get home.

Edit: No, there wasn´t a checkbox for that. But did you check "build in colour profile"? I think gamma is myabe part of a colour profile.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

You can't save ICC profile info in a PNG using Photoshop. Sounds like you're better off using Photoshop on your Mac than using GIMP.

Maybe try using something like irfanview to re-save out your PNG. Maybe you can get some clues >here< (see the section "File size and optimisation software", specifically PNG chunks).

Use Photoshop, it's better :wink:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Hmm, I tried some images from the internet and 7 displayed incorrectly. 2 displayed correctly.

To see an example of incorrect display, try this: http://www.w3.org/Graphics/PNG/inline-alpha.html

To see an example of correct display, try this: http://www.ncf.ca/~bh447/pngdemo/bird.png

Edit: When I loaded the broken one using GDI+ it displayed correctly. Could this be a bug in PB's PNG decoder?
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Using the following code with the examples you've mentioned, the PNGs seem to display correctly, which would suggest PB's PNG decoder is ok:

Code: Select all

UsePNGImageDecoder() 
LoadImage(0,"alphatest.png") 
OpenWindow(0,0,0,640,480,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
StartDrawing(WindowOutput(0)) 
  Box(10,10,620,460,RGB(212,220,234))
  DrawAlphaImage(ImageID(0),100,50) 
StopDrawing() 
Repeat 
  ev=WaitWindowEvent() 
Until ev=#PB_Event_CloseWindow
What do you think?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

mskuma - that code shows correctly here. I've used the alphalayer of png and tiff regularly since beta 1 of PB 4 and with the exception of one early bug that was fixed months ago, never had a problem. I'd be surprised if there were a bug in the decoder.
BERESHEIT
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

Yes it was thanks to netmaestro who showed us all the way of how to use this function in the early beta days. Many thanks to you sir.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I tried resaving it with IrfanView then it didn't show at all using my code above. It worked (but no alpha transparency) when I loaded it with GDI+.

I then tried resaving it (from the original) with Pixel. It then had that same whiteness to it. As usual, no problem when I used GDI+ for loading.

I then tried resaving it (from the original) with Corel PhotoPaint. It did not show at all. It worked (but no alpha transparency) when I loaded it with GDI+.

Since one png image works and another not, what else can be wrong than the decoder or the png files?
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

I think there's something wrong with the PB PNG decoder. If most of the images show better in GDI+, I'd go with it.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

I could be wrong, but I think there's absolutely nothing wrong with the decoder - did you guys try the code I posted above & see netmaestro's result also? Using the 'defective' image, I could get the same result (i.e. alpha/transparency effects) as exhibited on the original web page (i.e. http://www.w3.org/Graphics/PNG/inline-alpha.html). [edit: Note that the alphatest.png image is from that page].
Post Reply