MEM2SPRITE / SPRITE2MEM: How change any byte on memory?

Previous topic - Next topic

Hark0

Hi!

I have been read all the topics about change pixels color on sprite... none are valid for me...

I have read procedures like:

1- load sprite
2- sprite2mem
3- change memory values
4- mem2sprite

I are very interested on point 3.

How change value of X memory position?

I have tried points 1 and 2... but if I read value of DIM pixels%[memoryposition] I obtain negative values like "-1234567".

In the manual of MEM2SPRITE shows format like 0xAABBGGRR. And this warning: "READ/DATA might probably not read that large negative numbers."

How access directly to AA / BB / GG / RR?


A clear source code are welcome...  :)

TIA, Hark0
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Kitty Hello

Code (glbasic) Select

LOCAL r%,g%,b%,a%

LOCAL abgr% = pixels%[x + y*width]
r = bAND(abgr, 0xff)
g = bAND(ASR(abgr,8), 0xff)
b = bAND(ASR(abgr,16), 0xff)
a = bAND(ASR(abgr,24), 0xff)

// write back to array
pixels%[x + y*width] = bOR(RGB(r,g,b), ASR(a, 24) )



Hark0

Thanks for your fast reply!  =D

A little question...

It's possible to obtain memory position of pixels%[]?
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Kitty Hello

No. It's not just "memory". The pixels are in the memory of the graphics adapter, thus you have to copy them back and forth to work with them. An alternative is to use a pixel shader.

Hark0

http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Albert

I'm using: pixels%[x + y*width] = bOR(RGB(r,g,b), ASR(a, 24) )
but I always get fully transparent pixels.
I made this example:
Code (glbasic) Select
LOCAL c%=INTEGER(RGB(10,10,10))
DEBUG c%+"\n" //0xa0a0a0 (OK)
c%=INTEGER(bOR(c%, INTEGER(ASR(10, 24))))
DEBUG c%+"\n" //0xa0a0a0 (???)
c%=0xa0a0a0a0
DEBUG c%+"\n" //0xa0a0a0a0 (OK)

So what am I making wrong?

Albert

Now I'm using this code:
Code (glbasic) Select

@FUNCTION encodeABGR%: r%, g%, b%, a%
INLINE
return ((unsigned int)a << 24) | ((unsigned int)b <<16) | ((unsigned int)g << 8) | ((unsigned int)r);
ENDINLINE
ENDFUNCTION

Kitty Hello

pixel
  • = bOR(RGB(r,g,b), 0xff000000) try that.
    0xff is the alpha value. Try:
    you must use ASL (left) for the shift.

Albert

oke, I copied that ASR() from the helpfile, and the close parenthesis missing too in help :) But you are right, I want to use ASL() not ASR :)

Kitty Hello