User Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
isp:hsl-_rgb [2019/05/27 23:49] – [Setup and constraints] Igor Yefmovisp:hsl-_rgb [2021/07/24 10:53] – [Division-less division] Igor Yefmov
Line 2: Line 2:
 The text below is based on an Excel workbook attached to this page: {{ :isp:hsl-rgb.xlsm |}}. That Excel file provides a sort of playground where you can try various input data and see the final results, both "precise" and "optimized", as well as the discrepancy between the two methods. The text below is based on an Excel workbook attached to this page: {{ :isp:hsl-rgb.xlsm |}}. That Excel file provides a sort of playground where you can try various input data and see the final results, both "precise" and "optimized", as well as the discrepancy between the two methods.
 ===== Preface ===== ===== Preface =====
-Much is written and is available on the color space conversion from HSL to RGB (for example this [[https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB|Wikipedia article]]). However not only this is not meant to be used with integer arithmetics but is also very costly due to division operations. And once you realize that a 4K video running at 60FPS needs to do this conversion half a billion times a second(!) you see why this needs to be heavily optimized ;-)+Much is written and is available on the color space conversion from HSL to RGB (for example this [[https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB|Wikipedia article]]). Howevernot only this is not meant to be used with integer arithmeticsbut is also very costly due to division operations. And once you realize that a 4K video running at 60FPS needs to do this conversion half a billion times a second(!) you see why this needs to be heavily optimized ;-)
  
 The below article details the way to perform this conversion without the use of division operations with high enough precision as to satisfy the imaging pipeline quality requirements for the SUB2r camera based on Artix-7 100T FPGA. The below article details the way to perform this conversion without the use of division operations with high enough precision as to satisfy the imaging pipeline quality requirements for the SUB2r camera based on Artix-7 100T FPGA.
Line 20: Line 20:
 \[\frac{1}{x} = \frac{1*N}{x*N}\] \[\frac{1}{x} = \frac{1*N}{x*N}\]
 and choosing \(N\) such that \(x*N\) is a whole power of \(2\) we have an optimization where a division is replaced by a pair of a multiplication followed by a (super cheap!) bit-shift operation by \(Z\) bits: and choosing \(N\) such that \(x*N\) is a whole power of \(2\) we have an optimization where a division is replaced by a pair of a multiplication followed by a (super cheap!) bit-shift operation by \(Z\) bits:
-\[\frac{C}{x} = C*\frac{1}{x} = C*\frac{1*N}{x*N} = C*\frac{N}{2^Z} = [(C*N)>>Z]\]+\[\frac{C}{x} = C*\frac{1}{x} = C*\frac{1*N}{x*N}\middle|(2^Z = x*N) = C*\frac{N}{2^Z} = [(C*N) \gg Z]\]
 The value \(Z\) depends on the needed precision and, of course, the higher the \(Z\) the less precision loss there will be in the end. The value \(Z\) depends on the needed precision and, of course, the higher the \(Z\) the less precision loss there will be in the end.
  
Line 28: Line 28:
  
 The last part, losing the 14 LSB, doesn't have to be done right away and with the goal of preserving as much precision as possible this operation can be postponed until later time (just need to remember that the "real" value is now augmented by that \(2^{14}\) factor and adjust accordingly). The last part, losing the 14 LSB, doesn't have to be done right away and with the goal of preserving as much precision as possible this operation can be postponed until later time (just need to remember that the "real" value is now augmented by that \(2^{14}\) factor and adjust accordingly).
-===== Step-by-step algorithm ===== 
  
-==== Precise calculations ====+===== Precise calculations =====
 As a refresher this is how [[https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB|Wikipedia]] lists the way to convert HSL to RGB: As a refresher this is how [[https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB|Wikipedia]] lists the way to convert HSL to RGB:
  
Line 59: Line 58:
 \[(R,G,B)=(R_1+m,G_1+m,B_1+m)\] \[(R,G,B)=(R_1+m,G_1+m,B_1+m)\]
  
-==== Detailed algorithm ====+===== Step-by-step algorithm =====
 Armed with the above information we can now compile the necessary sequence of calculations and format it into an easy-to-use table: Armed with the above information we can now compile the necessary sequence of calculations and format it into an easy-to-use table:
  

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information