Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #14780

Compute web-safe colors (was: Detect user graphics card?)

Message-ID <2214440.4GTsLVHtI5@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-06-30 10:40 +0200
Subject Compute web-safe colors (was: Detect user graphics card?)
Newsgroups comp.lang.javascript
References (1 earlier) <js719u$7j2$1@dont-email.me> <4454122.7EdHYbU6jS@PointedEars.de> <jsc6bu$o4k$1@news.albasani.net> <2493601.R5VuAm1OKa@PointedEars.de> <5a0c9692-fe5e-446e-8d8f-558e233859c0@googlegroups.com>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Michael Haufe (TNO) wrote:

> Thomas &#39;PointedEars&#39; Lahn wrote:
         ^^^^^           ^^^^^
Pardon?

>> Stefan Weiss wrote:
>>> […]
>> […]  I think it could be further
>> optimized as follows:
>> 
>>   function getNearestSafeValue (value)
>>   {
>>     if (value >= 0xFF)
>>     {
>>       return 0xFF;
>>     }
>> 
>>     if (value <= 0)
>>     {
>>       return 0;
>>     }
>> 
>>     if (value % 0x33 == 0)
>>     {
>>       return value;
>>     }
>> 
>>     return Math.round(value / 0x33) * 0x33;
>>   }
>> 
>> If there are no objections or further suggestions, I will use that from
>> now on.
>>  
>> […]
>> > A half-hearted benchmark indicates that the last version could be
>> > between 2x faster (Chrome, Opera) and 5x faster (Firefox) than the
>> > original.
>> 
>> AISB, I am not that interested in benchmark results as they are
>> treacherous.
>> I am more interested in provably working, efficient algorithms.  You have
>> provided one.  Thank you.

Thank you for quoting this line, but try to trim to the *relevant* parts 
next time.

And *please* do not Cc: me.

> Constraining values is used relatively often. Have you considered adding a
> Math.clamp method?
> 
> Example:
> <http://msdn.microsoft.com/en-
us/library/microsoft.xna.framework.mathhelper.clamp.aspx>

Not yet (it would be jsx.math.clamp() then).  Calling the method instead of 
the `if' statements above would also introduce another dependency, and 
probably reduce efficiency, both of which I try to avoid.


PointedEars
-- 
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
  -- Richard Cornford, comp.lang.javascript, 2011-11-14

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Detect user graphics card? justaguy <lichunshen84@gmail.com> - 2012-06-24 04:31 -0700
  Re: Detect user graphics card? Gregor Kofler <usenet@gregorkofler.com> - 2012-06-24 14:30 +0200
    Re: Detect user graphics card? justaguy <lichunshen84@gmail.com> - 2012-06-24 07:43 -0700
    Re: Detect user graphics card? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-25 05:14 +0200
      Re: Detect user graphics card? justaguy <lichunshen84@gmail.com> - 2012-06-24 21:01 -0700
      Re: Detect user graphics card? Stefan Weiss <krewecherl@gmail.com> - 2012-06-26 13:27 +0200
        Re: Detect user graphics card? justaguy <lichunshen84@gmail.com> - 2012-06-26 12:54 -0700
        Re: Detect user graphics card? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-26 22:38 +0200
          Re: Detect user graphics card? Stefan Weiss <krewecherl@gmail.com> - 2012-06-27 01:05 +0200
            Re: Detect user graphics card? Scott Sauyet <scott.sauyet@gmail.com> - 2012-06-27 07:07 -0700
          Re: Detect user graphics card? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-06-29 16:41 -0700
            Compute web-safe colors (was: Detect user graphics card?) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-30 10:40 +0200
        Re: Detect user graphics card? Dr J R Stockton <reply1226@merlyn.demon.co.uk.not.invalid> - 2012-06-27 19:44 +0100
  Re: Detect user graphics card? Arno Welzel <usenet@arnowelzel.de> - 2012-06-27 17:57 +0200

csiph-web