Talk:RGBPercToHex

From Warcraft Wiki
Jump to navigation Jump to search

+.5?

What's the point? The colors returned by :GetTextColor() are (0,1). These numbers when multiplied by 255 can never be higher than 255 nor lower than 0. Adding .5 to the result of (0,1)*255 leads to (0.5,255.5) which, when converted to Hex, will return (01,100) instead of (00,ff). (correct me if I'm wrong and show your work) Posted by: EGingell (T|C|F) on 11:08, 11 June 2009 (UTC)

That and the addition was very poorly written. I'm removing it until it's shown that the new code is even needed. User:Tekkub/Sig 18:58, 11 June 2009 (UTC)

+5 is tru try it :)

hey sorry but my English is Not good as you can see :) and sorry if i doit the wrong way :)

The colors returned by :GetTextColor() are (0,1) i want to say yes but no, try it :)

when i use GetTextColor() i get r=0.99999780301005 g=0.99999779462814 b=0.99999779462814

for a color there shall be r=1 g=1 b=1 ,

if i look at the color in a graphic program it say it is FFFFFF not FEFEFE

show your work it is a BIG addon but here is some of it

   MyGameTooltip:SetBagItem(bag, slot);  
   for iLine = 1, MyGameTooltip:NumLines() do
       local LLine = getglobal(MyGameTooltip:GetName().."TextLeft"..iLine);
       local r, g, b, a = LLine:GetTextColor();

the data i get from "Recruit's Shirt"

Recruit's Shirt r=0.99999780301005 g=0.99999779462814 b=0.99999779462814

return string.format("%02x%02x%02x", r*255, g*255, b*255)

Hex=fefefe

return string.format("%02x%02x%02x", r*255+.5, g*255+.5, b*255+.5)

Hex=ffffff


grey color

r=0.50195968151093 g=0.50195968151093 b=0.50195968151093

it will giv Hex=7f7f7f not Hex=808080


(0.5,255.5) which, when converted to Hex, will return (01,100) instead of (00,ff).

yes i understand you :) but no it will remove .5 so it will be (0,255) for it rounds value down not up

try look at API floor

> local x = floor(10.9);
> = x
10
The error is not in this function, but in the values you're passing to it. If the values you're passing into the function aren't completely in the range (0.0 - 1.0) then you're going to have exactly these sorts of issues. If you know for a fact that a blizzy API doesn't return back proper numbers, you should round them off before you pass them to this function. Something like 4 decimals should be enough...
 x = math.floor(x*10000+.5)/10000
Also, there are much better ways to get an item's quality color. I suggest you check out GetItemInfo() and GetItemQualityColor() User:Tekkub/Sig 07:53, 13 June 2009 (UTC)


it is tru the error is not in you function it is for sure :)

i like you small and elegant function so i will use it with +.5 for it will fix the error from blizzy API :)

local function RGBPercToHex(r, g, b)
    r = r <= 1 and r >= 0 and r or 0
    g = g <= 1 and g >= 0 and g or 0
    b = b <= 1 and b >= 0 and b or 0
    return string.format("%02x%02x%02x", r*255+.5, g*255+.5, b*255+.5)
end

it is the most elegant way to fix it :) and it allso work if there is no error :)

thx for the function :)