10.03.2019 - Round 1 results of our "A Love Letter For FreeBASIC" game dev competition have been published. Please be sure to check the results thread: http://games.freebasic.net/forum/index.php?topic=629.0. Don't forget that the competition is continuing with a round 2, lasting till 29th of April, 300 USD first prize. Stay tuned!

Author Topic: Deh ! strange problem with getting RGBA from screen ...  (Read 3038 times)

Mihail_b

  • Amoeba
  • *
  • Posts: 10
    • View Profile
    • AlphaX - my lovely team
    • Email
Deh ! strange problem with getting RGBA from screen ...
« on: November 21, 2011, 08:24:57 AM »
Quote from: darkhog
In my 2d platformer game which I'm making levels are stored in PNGs (like in Voxatron) using my little steganography algorithm I've developed recently. The problem is that level data are stored in alpha of pixels and to not corrupt level data, I need to set exact RGBA value of pixel (pset with GFX_ALPHA_PRIMITIVES would just add alpha value to current one and mix colors).

Code: [Select]
#Include "fbgfx.bi"
#Include "fbpng.bi"

Screen 18,32
Dim As Any ptr myimg
Dim As Any Ptr imgtest
myimg=ImageCreate(32,32,&Hff000000,32)
PSet myimg,(15,15),RGBA(100,100,100,200)
png_save("myimg.png",myimg)
imgtest=png_load("myimg.png",PNG_TARGET_FBNEW)

' everything is ok until here ! you can use the above code !

Locate  17,1
Print "original pixel value (15,15):0x";Hex(Point(15,15,myimg))
Print "loaded pixel value   (15,15):0x";Hex(Point(15,15,imgtest))
Put (200,100),myimg 'value1
Put (300,100),imgtest 'value2
Print "screen pixel value1  (15,15):0x";Hex(Point(15+200,15+100))
Print "screen pixel value2  (15,15):0x";Hex(Point(15+300,15+100))
Print " you should notice the alpha value from screen :0x";Hex((Point(15+300,15+100) Shr 24)And &hff);" -> 0xff - 0x";Hex(((Point(15+300,15+100) Shr 24)And &hff));"=0x";Hex(255-((Point(15+300,15+100) Shr 24)And &hff))
Get (300,100)-(331,131),imgtest
png_save("myimg.png",imgtest)
deallocate imgtest
imgtest=png_load("myimg.png",PNG_TARGET_FBNEW)
Put (400,100),imgtest 'value3
Print "screen pixel value3  (15,15):0x";Hex(Point(15+400,15+100))
Print "buffer value4        (15,15):0x";Hex(Point(15,15,imgtest))
Sleep

the alpha value gets complemented when I'm takeing it from screen ?!
why ?

everything works OK for puting RGBA pixels to buffer and saveing/loading them from file !
this is ok !

but when I try to get an image from screen and save it to file and then reload it ... then BOOM it gets complemented !

or even if I only want to read a pixel from screen ! it gets the alpha value complemented (not(alpha_value)=255-value)

see full topic at http://www.freebasic.net/forum/viewtopic.php?p=166593#166593
----
home.ro

now matter how far !

Lachie Dazdarian

  • Double dipper
  • Administrator
  • Forum Sage
  • *****
  • Posts: 1308
    • Yahoo Instant Messenger - lachie13
    • View Profile
    • The Maker Of Stuff
    • Email
Re: Deh ! strange problem with getting RGBA from screen ...
« Reply #1 on: November 21, 2011, 09:57:09 AM »
I know PSET doesn't recognize ALPHA value.

Maybe some of the insights in this topic might help you:

http://games.freebasic.net/forum/index.php?topic=511.0

Will check your code for specific issue.
"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist

Mihail_b

  • Amoeba
  • *
  • Posts: 10
    • View Profile
    • AlphaX - my lovely team
    • Email
Re: Deh ! strange problem with getting RGBA from screen ...
« Reply #2 on: November 21, 2011, 11:49:02 PM »
yes, but what is strange is that
pset() and point() works fine for imagebuffers ... but when it comes about the screenbuffer then CRAP ...
Does the coder of fbgfx knows this ? He could surely fix this very easily ...
---

it's no poblem to me :); i can write my own functions for this ...
see yaa;
happy coding ...
----
home.ro

now matter how far !