Using imagez I can get a pixel from an image as [r g b]. Using this colour wheel I have verified that this extraction part is almost certainly working. This is the imagez code that does the extraction:
(defn components-rgb
"Return the RGB components of a colour value, in a 3-element vector of long values"
([^long rgb]
[(bit-shift-right (bit-and rgb 0x00FF0000) 16)
(bit-shift-right (bit-and rgb 0x0000FF00) 8)
(bit-and rgb 0x000000FF)]))
I need to do the opposite of this extraction. Here are some examples of the 'colour value' (or pixel) being extracted:
First pixel: -6700606 (in HEX: FFFFFFFFFF99C1C2)
Last pixel: -11449516 (in HEX: FFFFFFFFFF514B54)
First as colour: [153 193 194] (in HEX: 99 C1 C2)
Last as colour: [81 75 84] (in HEX: 51 4B 54)
Doing the opposite would mean that [153 193 194] becomes -6700606. This question has been asked before on SO, for example here. Here are two of my attempts which do not work:
;rgb = 0xFFFF * r + 0xFF * g + b
(defn my-rgb-1 [[r g b]]
(+ (* 0xFFFF r) (* 0xFF g) b))
;int rgb = ((r&0x0ff)<<16)|((g&0x0ff)<<8)|(b&0x0ff);
(defn my-rgb-2 [[r g b]]
(let [red (bit-shift-left 16 (bit-and r 0x0FF))
green (bit-shift-left 8 (bit-and g 0x0FF))
blue (bit-and b 0x0FF)]
(bit-or red green blue)))
image --1--> extracted-pixel --2--> rgb colour --3--> to-write-pixel --4--> image
Steps 1 and 2 are working, but step 3 is not. If step 3 were working extracted-pixel would be the same as to-write-pixel.
There is an rgb function in imagez, but it too does not work for me. (The author updated me to say it is not supposed to. See here). I might also add that the imagez function get-pixel is first used to get the pixel (step 1), followed by components-rgb (step 2) as shown above.
Take a look here where I have outlined the steps.
my-rgb-2attempt: the commented line is a description of what you want? Then you are missing a fewbit-shift-lefts (you do thebit-ands andbit-ors - but decided to ignore<<?)(format "0x%x" -6700606) => "0xffffffffff99c1c2"is possiblty helpful when printing bits/hexThere is an rgb function in imagez, but it too does not work for me.can you clarify this ? the function looks exactly like what you want ?rgbfunction in imagez does not work for me. Thanks.