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.

AppGameKit Classic Chat / How to convert Device camera's image to memblock invert

Author
Message
AlphaCeph
User Offline
Joined: 29th Sep 2018
Location:
Posted: 19th Nov 2018 19:44
I need help. How can i do this ? :

How to convert Device camera's image to memblock invert

Please give me a code
Jack
14
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 19th Nov 2018 22:54
What do you mean by memblock invert?

Do you want to invert the image to negative colors?
If so, a shader would be 1000x faster than a memblock operation, but I can only guess.

[/url]
AlphaCeph
User Offline
Joined: 29th Sep 2018
Location:
Posted: 20th Nov 2018 14:54
Yes, i want to invert the image to negative colors
How can do this ?

If i have a mistake, I'm so sorry. My english isn't good, but I learning English in prep school.
Jack
14
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 20th Nov 2018 17:08 Edited at: 20th Nov 2018 17:30
We don't care about language skills, as long as you can describe it somehow, just give us as much information as you can imagine
As I now know what you mean, here is some shader code to invert an image:

There are about 100 things to improve, and I still don't know if you want to have it in Real-time, if so, you can spare the renderimage rendering and directly render over a sprite to the screen.

You can download my code in the attachments.

For a realtime application, remove following lines:

and change
SetSpritePosition(spr_inverted,520,0)
to
SetSpritePosition(temp,520,0)

Please take a look here first:
https://www.appgamekit.com/documentation/guides/13_shaders.htm
You need to know what to do. Instead of an image from the media folder, you can input the camera Image.
Shaders can be complex, you can actually create a whole game inside a shader and direct the input from AppGameKit to it, but they can also help you to make complex operations with no effort.

This is the invert shader:


If you compare this to the regular sprite .ps shader, you will notice, that I only added a 1.0-(color value mentioned in the manual)
This means the colors in the shader image will become inverted

A memblock operation to invert colors would also be possible, but a lot slower, because you have to go though each byte in each pixel and do (255-bytevalue)
If you do memblock stuff, you are using the CPU, shaders are using the GPU, but they have a strict command set, well that's all.

This is the result of the shader:

[/url]

Attachments

Login to view attachments
AlphaCeph
User Offline
Joined: 29th Sep 2018
Location:
Posted: 20th Nov 2018 17:14
Yes, i want to real time. I looking this page now. But how can i write this code ? If you know, please write.

AlphaCeph
User Offline
Joined: 29th Sep 2018
Location:
Posted: 20th Nov 2018 17:52
Oohh Thanks thanks so so thanks. You did it. So so thanks you.
My Code:
[img]
local img as Integer
local cam as integer
local spr as integer

img=1

cam=0

SetDeviceCameraToImage(cam,img)

spr=CreateSprite(img)

shader = LoadSpriteShader("InvertColors.ps")

SetSpriteShader(SPR, shader)



setspritesize(spr,GetVirtualWidth(),GetVirtualHeight())


[/img]

It worked. This title is finish. Thank you Jack and TGC ^^

Login to post a reply

Server time is: 2019-08-19 08:31:25
Your offset time is: 2019-08-19 08:31:25