Bitmap pixel alignment

Source: Internet
Author: User

I did not understand this last time. I went to C guago today to see this and moved it to the storage.

 

It's strange to see a pieceCodeCx = (BM. bmwidth + 31 )&(~ 31)> 3. bmwidth indicates the actual storage width of the bitmap row (in a monochrome bitmap, one pixel is represented by one bit). The Unit is bit and the unit of Cx is byte.

After a long time, Google knows that this is to obtain the width value of the bitmap stored in the hard disk. In fact, in order to improve the processing speed of bitmap, The DIB bitmap requires that the number of bytes in each row of pixel data must be a multiple of 4, that is, 32-bit (that is, the length of a 32-bit machine ), fill in the following (usually 0) when the number is insufficient. Note that this is not about the bitmap pixel digits!

Return to the previous Code and find the Row Storage width. In fact, you need to directly integer the actual pixel width, that is, Ceil (BM. bmwidth/32) * 4 (unit: byte, So multiply by 4 ). However, if we call a function and perform multiplication and division, the efficiency is definitely not high.

The value range of the data to be filled is: 0 ~ 31 (unit: Bit, bit), (BM. bmwidth + 31) will not cause 32 more bits than the actual data to be filled. And ~ 31 is 1... 11100000, and after the calculation, that is, the last five digits are set to 0, which is equivalent to the division of the next integer, 31 is added and 32 is divided by (BM. bmwidth/32) is rounded up. In fact, this process is equivalent to (BM. bmwidth + 31)/32. Then,> 3 shifts the right to three places, divided by 8, and the final result is the number of bytes of the actually stored rows.

Address: http://www.cguage.com/2012/10/%E4%BD%8D%E5%9B%BE%E5%83%8F%E7%B4%A0%E5%AF%B9%E9%BD%90.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.