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.

Newcomers AppGameKit Corner / the color of a pixel

Author
Message
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
Posted: 1st Apr 2016 11:21
Hello everyone!

Please, I need to know what is the color of one pixel in the image.
In PureBasic (and also the FreeBasic) is the command POINT.

https://www.purebasic.com/documentation/2ddrawing/point.html

There is something similar in the AGK2? Thanks!
I am sorry for poor English
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Apr 2016 12:24
You could:

* getImage() of one pixel.
* MakeMemblockFromImage()
* query the values in the memblock.

It isn't fast or pretty, but it's possible.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
Posted: 1st Apr 2016 13:03
Thanks for a idea!
I am sorry for poor English
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
Posted: 9th Apr 2016 21:45
BatVink:
Please, an example? I'm trying, but I can not do it

Thank you in advance!
I am sorry for poor English
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 10th Apr 2016 17:49 Edited at: 10th Apr 2016 17:50
Here's a little demo. I have put the colour selection in a function so you can copy it straight into your code. The parameter is an array with 4 elements - red, green, blue, alpha

Hold down the mouse button and hover over the colours on the screen.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
Posted: 11th Apr 2016 09:52 Edited at: 11th Apr 2016 09:53
Thank you VERY much!!
Perfect job!
And now, I have this problem. I have one picture and I need to know RGB color coordinates X, Y. Can I make of it? It is using sprites weird is not it?

E.g.

(X,Y) RGB
(1,1) RGB 175,171,160
(2,1) RGB 60,214,90
(3,1) RGB 111,99,87
(4,1) ...
I am sorry for poor English
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 11th Apr 2016 10:15
Memblocks will let you do that, you work out the size of the memblock and set the size, width and depth, then each pixel is made up from groups of 4 bytes, blue, green, red, and alpha.

Then you make the memblock into an image. The speed depends on how big the memblock is, but say you had a 64x64 memblock, you could update that completely in a main loop. AppGameKit is a nice language for retro games, especially given how easy it is to pixelate things, just set your virtual resolution and image filtering and you have lovely pixels.

I'm not sure what the examples for image memblock are like, but they are the same as with DBPro, so a lot of us know them quite well.

Like, say you wanted a random image, like coloured noise, really just to show the makeup of a memblock.

Image properties first...

img_wid=64
img_hig=64
img_dep=32
img_size=12+(64*64*4)
creatememblock(1,img_size)
setmemblockint(1,0,img_wid)
setmemblockint(1,4,img_hig)
setmemblockint(1,8,img_dep)

Now step through each pixel and set a colour for it...

For y=0 to img_hig-1
For x=0 to img_wid-1
pos=12+(((y*img_wid)+x)*4)
cr=random(0,255)
cg=random(0,255)
cb=random(0,255)
ca=random(0,255)
setmemblockbyte(1,pos+0,cb)
setmemblockbyte(1,pos+1,cg)
setmemblockbyte(1,pos+2,cr)
setmemblockbyte(1,pos+3,ca)
Next x
Next y
createimagefrommemblock(1,1)

There are other ways to draw to images, like using render targets for example, but I like the total control you get with a memblock.
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
Posted: 11th Apr 2016 11:31 Edited at: 11th Apr 2016 11:32
Thanks so much!

This is complicated enough for me. Mainly English Sorry....

I have 1 image.

And I need to know what color is at specific coordinates (I'll need all the colors of all of the pixels in the image).

For example. What is the color (RGBA) of the coordinate: X=140, Y=75 ?



This is my code now, but it's not right:
I am sorry for poor English
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 11th Apr 2016 11:50
I'll have a look at making a code example of a little memblock image library - can't do much right now as I'm still at work. I'm thinking that it might be easier to just render the screen to an image, and grab the colour from that image instead, so you wouldn't grab a 1x1 image and sample that, you'd sample from the rendered image. It depends on what else you need to do really, maybe an idea to give some details on your project - there tends to be an easier way to do everything
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
Posted: 12th Apr 2016 08:05
OK, I'll try. But with my English ... Sorry. I hope you understand.

I have an image.

LoadImage (0, "image.png")
... or from the camera.

The aim is to make image adjustments (still do not know exactly what's going to be, but eg. to count the number of green colors. Or to turn green to blue, etc.).

I need to know the color of each pixel in this image.

So I need to know to coordinate X,Y is the color RGB.

(X,Y) RGB
(1,1) 175,171,160
(2,1) 60,214,90
(3,1) 111,99,87
(4,1) ...

(1,2) 160,160,160
(2,2) 170,20,15
(3,2) 200,140,217
(4,2) ...

Then I can continue with any work.

The best thing would probably be to reduce the image to 800x480 (?) And write down all the colors in the array.
Then create a second array, where I made adjustments to the colors. And from this array reconstruct a new image.

I am sorry for poor English
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 12th Apr 2016 09:32 Edited at: 12th Apr 2016 09:42
Van B: The order of bytes has changed in AGK. It is RGBA, not BGRA like it was in DBPro.

This code maps all the colours into an array. Again, I have enclosed the hard work in a function, and exported a 10x10 section into a text file so that you can see what the data looks like.
I DO NOT recommend putting all of the data into an array, it is simply duplicating data. use the equations you see in the function to examine the pixel data in the memblock.

The output looks like this:




And this is the code:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 12th Apr 2016 16:36
AMOS used to have a good set of pixel commands from memory
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
Posted: 12th Apr 2016 20:13 Edited at: 12th Apr 2016 20:15
Thank you!
It looks very good!

Now, I've edited the function CreateImage() for LoadImage. But where is the file "results.txt"? I don't have it in my computer.

I am sorry for poor English
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Apr 2016 00:37
It is created in the Write folder...

C:\Users\<USERNAME>\AppData\Local\AGKApps\
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
zxretrosoft
AGK Developer
9
Years of Service
User Offline
Joined: 10th Dec 2014
Location: Prague, Czech Republic
Posted: 13th Apr 2016 06:57
Yes, thank you! (It was a hidden file.)

I'm going to scrutinize your code now
I am sorry for poor English

Login to post a reply

Server time is: 2024-04-19 06:53:12
Your offset time is: 2024-04-19 06:53:12