Calculator Community > HP Calculators

Splitting colors/getting the value of a part of a color

(1/4) > >>

DJ Omnimaga:
Does anyone know how to extract the value of a color? For example, if I use GETPIX_P(X,Y), how would I access the value of the blue color in particular, so that I can modify it?

I am curious about changing each value separately, since it might make it easier to do some graphical effects such as fade-in/outs or whatever. I would prefer not having to use divisions, since they seem much slower (but again, this is the emulator, so maybe other means are as slow on the real calc anyway).

This is what I have right now, by the way:


--- Code: ---EXPORT fadein()
BEGIN
FOR C FROM 0 TO 3 DO
FOR X FROM 0 TO 319 DO
FOR Y FROM 0 TO 239 DO
INT(GETPIX_P(X,Y)/2)▶P;
PIXON_P(X,Y,P);
END;
END;
END;
END;
--- End code ---

Matrefeytontias:
IIRC, the HP Prime's screen uses 16-bits colors (R5G6B5 format), so you can't access  colors separately unless you use bitwise operators (and, or, not) and bit shifting. I don't think HP basic permits you to do that.

Jim Bauwens:
If you divide by 2^n (and remove the remainder, with something like int() ) it's the same like shifting with n. And then you can use the modulus operator to get the bits you want. (So basically you simulate bitwise operators).

DJ Omnimaga:

--- Quote from: Matrefeytontias on August 27, 2013, 07:33:37 am ---IIRC, the HP Prime's screen uses 16-bits colors (R5G6B5 format), so you can't access  colors separately unless you use bitwise operators (and, or, not) and bit shifting. I don't think HP basic permits you to do that.

--- End quote ---
Actually it's A1R5G5B5, due to transparency being supported (per individual pixel basis).
--- Quote from: Jim Bauwens on August 27, 2013, 07:37:00 am ---If you divide by 2^n (and remove the remainder, with something like int() ) it's the same like shifting with n. And then you can use the modulus operator to get the bits you want. (So basically you simulate bitwise operators).

--- End quote ---
What would n be for? Would it have to be 5 (the amount of bits per color)? Also what about the alpha bit?

lkj:
For the blue part you would do: color MOD 2^5
For the green part IP(color / 2^5) MOD 2^5
And for the red part IP(color / 2^10) MOD 2^5
For the alpha: IP(color / 2^15)

Edit: IP is the integer part function on the prime

Navigation

[0] Message Index

[#] Next page

Go to full version