4-bit 16-color grayscale image processing

Source: Internet
Author: User

Define several auxiliary macros as follows.

 
// Split and merge byte # define hibits (w) (byte) (w)> 4) & 0xf) # define lobits (W) (byte) (w) & 0xf) # define makebits (A, B) (byte) (a) & 0xf) | (byte) (B) & 0xf) <4 ))

Simple operation...

// Read and write a 16-color image demo. Add 20 bool cimgprocess: test4bppindexedbitmap (cimgprocess * PTO) to the value of each pixel) {// first check whether the image is an 8-bit grayscale image if (m_pbmih-> bibitcount! = 4) {afxmessagebox (_ T ("fuck, this is not a 4-Digit Image"); Return false ;}// test byte gray = 0x4c; // assume that this byte is two pixels of a 16-level grayscale image, byte HI = hibits (Gray), // 0 xflo = lobits (Gray ); // 0 xcbyte test = makebits (0x34, 0x56); // combine the status of the two bytes into a new byte, therefore, 0x64trace3 ("high = 0x % x, low = 0x % x, test = 0x % x \ n", hi, lo, test) should be output here ); // byte A = (Lo + 20) % 0xf; byte B = (hi + 20) % 0xf; test = makebits (A, B ); trace3 ("A = 0x % x, B = 0x % x, test add = 0x % d \ n", a, B, test ); // working.................int nheight = getheight (), nwidth = getwidthpixel (); // pixel width trace2 ("width = % d, Height = % d \ n", nwidth, nheight ); int I, j; for (I = 0; I <nheight; I ++) {for (j = 0; j <nwidth/2; j ++) // nwidth indicates the number of pixels, but only nwidth/2 bytes {byte pixel2 = This-> m_lpdata [I] [J]; // HI = hibits (pixel2) containing two pixels; // pixel decomposition Lo = lobits (pixel2); A = (Lo + 20) % 0xf; B = (hi + 20) % 0xf; test = makebits (a, B); // merge pixel PTO-> m_lpdata [I] [J] = test; // write data} return true ;}

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.