Calculator Community > HP Calculators

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

<< < (2/4) > >>

Matrefeytontias:
Then you'd use something like that :
--- Code: ---.alpha = int(color / 32768)
red = int(color / 1024) % 32
green = int(color / 32) % 32
blue = color % 32
--- End code ---
l
Alpha is now the 15th bit of the color, red is the 10th to 14th bits, green is the 5th to 9th bit and blue the 0th to 4th bit. You can also build a color this way :
--- Code: ---color = (alpha % 2) * 32768 + (red % 32) * 1024 + (green % 32) * 32 + (blue % 32)
--- End code ---
Assuming % is the modulo operator.

EDIT : ninja'd

DJ Omnimaga:
Ok thanks, I'll see how to do this on an HP Prime when I have time (hoping there's a mod command)

lkj:
I tested my code in the prime emu, it should work ;)

Gilles59:
Hi all !

I don't understand how the alpha channel works (it use 1 bit or 3 bits ? one bit per channel color ?) ...

However, this  works for RGB :


--- Code: ---EXPORT Red(c) BEGIN BITAND(BITSR(c,16),#7Fh); END;
EXPORT Green(c) BEGIN BITAND(BITSR(c,8),#7Fh); END;
EXPORT Blue(c) BEGIN BITAND(c,#7Fh); END;

--- End code ---

I think it will be faster than divisions and modulo. Note that there is no need of RETURN keyword as the Prime always returns its last calculation


--- Quote ---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 ---

Seems to be  24 bits colors scheme with alpha transparency. It seems that you can define for each R G B color if there is transparency or not
So you have 128 x 128 x 128 colors,and 1 bit of tranparency for each R V B color ( it's just a guess ...)


This one is a lot faster :


--- 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
    PIXON_P(X,Y,BITSR(GETPIX_P(X,Y)));  //avoid division and  variable ...
   END;
 END;
 END;
END;

--- End code ---

By the way I wonder what happen when you use 'transparency' and copy a grob in another grob with the BLIT_P command ?

DJ Omnimaga:
Actually the HP Prime colors are A1R5G5B5, meaning 1 bit for the alpha channel and 5 bits for each color. However, when we use the RGB command, it seems to be multiplied so that every value can be up to 255.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version