Note that there are some explanatory texts on larger screens.

plurals
  1. POAn integer [0,4095] 12bits to a tuble{A,B,C} the fastest way in c++
    primarykey
    data
    text
    <p>Intput: An integer [0,4095] 12bits.<br> Output: A tuble of {A,B,C} all [0,255]</p> <p>The A,B,C are given as 0 to 255, where 255 maps to 15 in the 4 bits. Reason are that I want to construct a Color struct having RGB defined from 0 to 255.</p> <p>I assume the solution to be something like bit shifting the input to extract the 3 sets of 4bits and then multiply by 17 as (255/15 | 15 = 1111(binary)).</p> <p>How would you compute this fastest?</p> <p>my own solution:</p> <pre><code>QColor mycolor(int value) { if(value &gt; 0xFFF) value = 0xFFF; int a=0,b=0,c=0; a = (value &amp; 0xF) * 17; b = ((value&amp;(0xF&lt;&lt;4))&gt;&gt;4) *17; c = ((value&amp;(0xF&lt;&lt;8))&gt;&gt;8) *17; return QColor(c,b,a); } cv::Mat cv_image(10,10,CV_16U,cv::Scalar::all(1)); QImage image(cv_image.data, 10,10,QImage::Format_RGB444); QPainter p(&amp;image); p.setPen(mycolor(255)); p.drawLine(0,0,9,0); p.setPen(mycolor(4095)); p.drawLine(0,1,9,1); p.setPen(mycolor(0)); p.drawLine(0,2,9,2); p.setPen(mycolor(10000)); p.drawLine(0,3,9,3); ********* Start testing of Test1 ********* Config: Using QTest library 4.7.4, Qt 4.7.4 PASS : Test1::initTestCase() [255, 255, 255, 255, 255, 255, 255, 255, 255, 255; 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095, 4095; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] PASS : Test1::test1() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload