bitmap - please explain this code to me.. (convert_bitfield) -


This code appears in the framebuffer driver.

  Fixed inline u32 convert- bitfile (int Val, Struct fb_bitfield * bf) {unsigned int mask = (1 & lt; bf- & gt; length) - 1; Return (Val> & gt; (16-BF-> Length) & Masks) & lt; & Lt; Bf- & gt; Offset; }  

By knowing how it is used in the form of

  if (regno <15) {fb-> cmap [ Regno] = convert_bitfield Transparent, & amp; Fb-> Fb.var.transp). Convert_bittfield (blue, and fb-> fb.Wor.W). Convert_bittfield (green, and FB-> FB..gov.green). Convert_bittfield (red, and fb-> fb. var.red); Return 0; }  

I thought this function transfers the value to its 16 bit value. For example if a 16 bit value is made of 5-bit R, 6-bit G, and 5-BB and R = 1, G = 2, B = 3, then the 16-bit value will be 0x0843. (Not alpha bits) 00001 000010 00011 = 0000 1000 0100 0011 = 0x0843.

But the code above does not work as it is supposed to be. Due to the word (16 - BF-> length), the value is transferred to zero before masking. Someone please tell how does this work? (3 framebuffer drivers get so that people are happy with it ..)

thanks in advance Chan

EDIT: Walter, here is FBI_bitfid.

  struct fb_bitfield {__u32 offset; / * Bitfield * / __u32 beginning of length; / * Bitfield length * / __u32 msb_right; / *! = 0: The most important bit is * / / * right *;  

I will try to explain what the function does:

< P> blue green red 16 bit and vice versa

  blue = 28 = 0b0000000000011100 In fact 0b0011100000000000  

pass values, consider RGB565, then the blue length is 5:

< Pre> val & gt; & Gt; (16 - BF-> Length) Blue Blue 11 Location Blue = 0B 0000000000000111

Then Mask 5 - 1 = 4 Beat,

  (Val> and gt; (16 - BF-> Length) and Masks) 0b0000000000000111 & amp;  


Comments